Skip to content

Commit

Permalink
scale replacement local lights by the sector lightlevel
Browse files Browse the repository at this point in the history
  • Loading branch information
vs-shirokii committed May 6, 2024
1 parent 04e078a commit 81d61b4
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
38 changes: 37 additions & 1 deletion src/common/rendering/rt/rt_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ namespace cvar
// RT_CVAR( rt_light_s, 1000.f, "intensity of lights defined by a map")
// RT_CVAR( rt_light_radius, 0.02f, "default radius for original lights (in meters)")

RT_CVAR( rt_lightlevel_min, 80, "min bound for mapping gzdoom lightlevel to light intensity: if lightlevel below this, lights are multiplied by 0.0; must be >= 0" )
RT_CVAR( rt_lightlevel_max, 230, "max bound for mapping gzdoom lightlevel to light intensity: if lightlevel above this, lights are multiplied by 1.0; must be <= 255" )
RT_CVAR( rt_lightlevel_exp, 2.0f, "exponent to apply when converting gzdoom lightlevel to light intensity" )

RT_CVAR( rt_flsh, false, "flashlight enable")
RT_CVAR( rt_flsh_intensity, 800.f, "flashlight intensity")
RT_CVAR( rt_flsh_radius, 0.02f, "flashlight source disk radius in meters")
Expand Down Expand Up @@ -1261,6 +1265,37 @@ class RTRenderState : public FRenderState
return RG_TRANSFORM_IDENTITY;
}

auto MapLightLevel( int lightlevel ) -> float
{
assert( lightlevel <= 255 );
int lmin = std::max< int >( cvar::rt_lightlevel_min, 0 );
int lmax = std::min< int >( cvar::rt_lightlevel_max, 255 );

if( lmin >= lmax )
{
return 0.0f;
}
if( lightlevel <= lmin )
{
return 0.0f;
}
if( lightlevel >= lmax )
{
return 1.0f;
}
float t = float( lightlevel - lmin ) / float( lmax - lmin );

if( std::abs( cvar::rt_lightlevel_exp - 2.f ) < 0.01f )
{
return t * t;
}
if( std::abs( cvar::rt_lightlevel_exp - 1.f ) < 0.01f )
{
return t;
}
return std::powf( t, cvar::rt_lightlevel_exp );
}

auto MakeFirstPersonQuadInWorldSpace( std::span< const RgPrimitiveVertex > verts )
-> std::pair< RgTransform, std::span< const RgPrimitiveVertex > >
{
Expand Down Expand Up @@ -1504,7 +1539,8 @@ class RTRenderState : public FRenderState
.transform = transform,
.isExportable =
rtstate.is< RtPrim::ExportMap >() || rtstate.is< RtPrim::ExportInstance >(),
.animationTime = 0.0f,
.animationTime = 0.0f,
.localLightsIntensity = MapLightLevel( rtstate.m_lightlevel ),
};

auto makePrimFlags = [ this, &verts ]( bool isUI ) -> RgMeshPrimitiveFlags {
Expand Down
3 changes: 3 additions & 0 deletions src/common/rendering/rt/rt_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#endif


#include "defer.h"
#include "rt_helpers.h"

#include <optional>
Expand Down Expand Up @@ -237,6 +238,8 @@ struct FRtState
FVector3 m_lastthingposition{};
uint8_t m_berserkBlend{ 0 };

int m_lightlevel{ 255 };

private:
uint32_t m_state{ 0 }; // RtPrim flags
uint64_t m_curUniqueID{ 0 }; // to identify an object between frames
Expand Down
3 changes: 3 additions & 0 deletions src/rendering/hwrenderer/scene/hw_sprites.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ void HWSprite::DrawSprite(HWDrawInfo *di, FRenderState &state, bool translucent)
);
static_assert(RT_MAX_SPRITE_FRAMES == MAX_SPRITE_FRAMES, "change RT_MAX_SPRITE_FRAMES to match");

rtstate.m_lightlevel = actor && actor->Sector ? actor->Sector->GetSpriteLight() : 255;
defer{ rtstate.m_lightlevel = 255; };

if (actor)
{
rtstate.m_lastthingposition = FVector3{ actor->InterpolatedPosition(di->Viewpoint.TicFrac) };
Expand Down

0 comments on commit 81d61b4

Please sign in to comment.