Skip to content

Commit

Permalink
trace from actor center
Browse files Browse the repository at this point in the history
  • Loading branch information
RicardoLuis0 committed Jan 18, 2025
1 parent 494b84c commit e054e67
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 10 deletions.
12 changes: 12 additions & 0 deletions src/common/rendering/hwrenderer/data/hw_renderstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class FRenderState
uint8_t mWireframe : 2;
uint8_t mShadeVertex : 1;
uint8_t mLightNoNormals : 1;
uint8_t mUseSpriteCenter : 1;

FVector4 mWireframeColor;
FVector4 uObjectColor;
Expand Down Expand Up @@ -185,6 +186,7 @@ class FRenderState

void Reset()
{
mUseSpriteCenter = 0;
mLightNoNormals = 0;
mShadeVertex = 0;
mWireframe = 0;
Expand Down Expand Up @@ -279,6 +281,11 @@ class FRenderState
mLightNoNormals = value;
}

void SetUseSpriteCenter(bool value)
{
mUseSpriteCenter = value;
}

void SetWireframeColor(FVector4 color)
{
mWireframeColor = color;
Expand All @@ -294,6 +301,11 @@ class FRenderState
mSurfaceUniforms.uVertexNormal = { x, y, z, 0.f };
}

void SetActorCenter(float x, float y, float z)
{
mSurfaceUniforms.uActorCenter = { x, y, z };
}

void SetColor(float r, float g, float b, float a = 1.f, int desat = 0)
{
mSurfaceUniforms.uVertexColor = { r, g, b, a };
Expand Down
4 changes: 3 additions & 1 deletion src/common/rendering/hwrenderer/data/hw_surfaceuniforms.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ struct SurfaceUniforms
float uAlphaThreshold;
int uTextureIndex;
float uDepthFadeThreshold;
float padding3;
float padding1;
FVector3 uActorCenter;
float padding2;
};

struct SurfaceLightUniforms
Expand Down
1 change: 1 addition & 0 deletions src/common/rendering/vulkan/shaders/vk_shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ void VkShaderManager::BuildDefinesBlock(FString &definesBlock, const char *defin

if (key.ShadeVertex) definesBlock << "#define SHADE_VERTEX\n";
if (key.LightNoNormals) definesBlock << "#define LIGHT_NONORMALS\n";
if (key.UseSpriteCenter) definesBlock << "#define USE_SPRITE_CENTER\n";

definesBlock << ((key.Simple2D) ? "#define uFogEnabled -3\n" : "#define uFogEnabled 0\n");
}
Expand Down
3 changes: 2 additions & 1 deletion src/common/rendering/vulkan/shaders/vk_shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ class VkShaderKey
uint64_t ShadowmapFilter : 4; // SHADOWMAP_FILTER
uint64_t ShadeVertex : 1; // SHADE_VERTEX
uint64_t LightNoNormals : 1; // LIGHT_NONORMALS
uint64_t Unused : 28;
uint64_t UseSpriteCenter : 1; // USE_SPRITE_CENTER
uint64_t Unused : 27;
};
uint64_t AsQWORD = 0;
};
Expand Down
3 changes: 3 additions & 0 deletions src/common/rendering/vulkan/vk_renderstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ void VkRenderState::ApplyRenderPass(int dt)

pipelineKey.ShaderKey.ShadeVertex = mShadeVertex;
pipelineKey.ShaderKey.LightNoNormals = mLightNoNormals;
pipelineKey.ShaderKey.UseSpriteCenter = mUseSpriteCenter;

pipelineKey.ShaderKey.UseShadowmap = gl_light_shadows == 1;
pipelineKey.ShaderKey.UseRaytrace = gl_light_shadows >= 2;
Expand Down Expand Up @@ -1082,6 +1083,8 @@ void VkRenderState::ApplyLevelMeshPipeline(VulkanCommandBuffer* cmdbuffer, VkPip
}

pipelineKey.ShaderKey.ShadeVertex = mShadeVertex;
pipelineKey.ShaderKey.LightNoNormals = mLightNoNormals;
pipelineKey.ShaderKey.UseSpriteCenter = mUseSpriteCenter;

// Global state that don't require rebuilding the mesh
pipelineKey.ShaderKey.NoFragmentShader = noFragmentShader;
Expand Down
13 changes: 12 additions & 1 deletion src/rendering/hwrenderer/scene/hw_sprites.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,18 +294,28 @@ void HWSprite::DrawSprite(HWDrawInfo *di, FRenderState &state, bool translucent)
SetSplitPlanes(state, topp, bottomp);
}

if(actor)
{
state.SetActorCenter(actor->X(), actor->Center(), actor->Y());
}

if (!modelframe)
{
state.SetLightNoNormals(true);
state.SetNormal(0, 0, 0);

if(actor && gl_spritelight < 2)
{
state.SetUseSpriteCenter(true);
}

CreateVertices(di, state);

if (polyoffset)
{
state.SetDepthBias(-1, -128);
}

state.SetLightNoNormals(true);
state.SetLightIndex(dynlightindex);
state.Draw(DT_TriangleStrip, vertexindex, 4);
state.SetLightIndex(-1);
Expand All @@ -320,6 +330,7 @@ void HWSprite::DrawSprite(HWDrawInfo *di, FRenderState &state, bool translucent)
state.SetTextureMode(TM_NORMAL);
}
state.SetLightNoNormals(false);
state.SetUseSpriteCenter(false);
}
else
{
Expand Down
4 changes: 3 additions & 1 deletion wadsrc/static/shaders/binding_struct_definitions.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ struct SurfaceUniforms
float uAlphaThreshold;
int uTextureIndex;
float uDepthFadeThreshold;
float padding3;
float padding1;
vec3 uActorCenter;
float padding2;
};

struct SurfaceLightUniforms
Expand Down
1 change: 1 addition & 0 deletions wadsrc/static/shaders/scene/layout_shared.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#define uAlphaThreshold data[uDataIndex].uAlphaThreshold
#define uTextureIndex data[uDataIndex].uTextureIndex
#define uDepthFadeThreshold data[uDataIndex].uDepthFadeThreshold
#define uActorCenter data[uDataIndex].uActorCenter

#if defined(USE_LEVELMESH)
#define uVertexColor lightdata[uDataIndex].uVertexColor
Expand Down
5 changes: 4 additions & 1 deletion wadsrc/static/shaders/scene/light_trace.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ float traceHit(vec3 origin, vec3 direction, float dist)
float traceShadow(vec3 lightpos, float softShadowRadius)
{
vec3 target = lightpos.xyz + 0.01; // nudge light position slightly as Doom maps tend to have their lights perfectly aligned with planes
#ifdef LIGHT_NONORMALS
#ifdef USE_SPRITE_CENTER
vec3 origin = uActorCenter.xyz;
vec3 direction = normalize(target - origin);
#elif defined(LIGHT_NONORMALS)
vec3 origin = pixelpos.xyz;
vec3 direction = normalize(target - origin);
origin -= direction;
Expand Down
16 changes: 11 additions & 5 deletions wadsrc/static/shaders/scene/vert_main.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "shaders/scene/bones.glsl"

#if defined(SHADE_VERTEX) && !defined(PBR) && !defined(SPECULAR) && !defined(SIMPLE)

#undef SHADOWMAP_FILTER
#define SHADOWMAP_FILTER 0
#include <shaders/scene/lightmodel_shared.glsl>
Expand All @@ -10,12 +11,21 @@

vec3 lightValue(DynLightInfo light)
{
#ifdef USE_SPRITE_CENTER
float lightdistance = distance(light.pos.xyz, uActorCenter.xyz);

if (light.radius < lightdistance)
return vec3(0.0); // Early out lights touching surface but not this fragment

vec3 lightdir = normalize(light.pos.xyz - uActorCenter.xyz);
#else
float lightdistance = distance(light.pos.xyz, pixelpos.xyz);

if (light.radius < lightdistance)
return vec3(0.0); // Early out lights touching surface but not this fragment

vec3 lightdir = normalize(light.pos.xyz - pixelpos.xyz);
#endif

float attenuation = distanceAttenuation(lightdistance, light.radius, light.strength, light.linearity);

Expand Down Expand Up @@ -54,11 +64,6 @@

vec3 ProcessVertexLight()
{
#if defined(USE_LEVELMESH)
const int lightTileSize = 1;
uLightIndex = int(uint(gl_FragCoord.x) / 64 + uint(gl_FragCoord.y) / 64 * uLightTilesWidth) * lightTileSize;
#endif

vec3 light = vec3(0.0);

if (uLightIndex >= 0)
Expand All @@ -83,6 +88,7 @@

return light;
}

#endif

void ModifyVertex();
Expand Down

0 comments on commit e054e67

Please sign in to comment.