Improve #1077 to use a single pixel shader with permutations

This commit is contained in:
Wojtek Figat
2023-05-07 11:01:30 +02:00
parent 10541ac743
commit 713cf0d4b2
3 changed files with 22 additions and 40 deletions

BIN
Content/Shaders/DebugDraw.flax (Stored with Git LFS)

Binary file not shown.

View File

@@ -632,10 +632,10 @@ void DebugDrawService::Update()
desc.VS = shader->GetVS("VS");
// Default
desc.PS = shader->GetPS("PSUnlit");
desc.PS = shader->GetPS("PS", 0);
desc.PrimitiveTopologyType = PrimitiveTopologyType::Line;
failed |= DebugDrawPsLinesDefault.Create(desc);
desc.PS = shader->GetPS("PS");
desc.PS = shader->GetPS("PS", 1);
desc.PrimitiveTopologyType = PrimitiveTopologyType::Triangle;
failed |= DebugDrawPsTrianglesDefault.Create(desc);
desc.Wireframe = true;
@@ -643,10 +643,10 @@ void DebugDrawService::Update()
// Depth Test
desc.Wireframe = false;
desc.PS = shader->GetPS("PS_DepthTestUnlit");
desc.PS = shader->GetPS("PS", 2);
desc.PrimitiveTopologyType = PrimitiveTopologyType::Line;
failed |= DebugDrawPsLinesDepthTest.Create(desc);
desc.PS = shader->GetPS("PS_DepthTest");
desc.PS = shader->GetPS("PS", 3);
desc.PrimitiveTopologyType = PrimitiveTopologyType::Triangle;
failed |= DebugDrawPsTrianglesDepthTest.Create(desc);
desc.Wireframe = true;

View File

@@ -27,49 +27,31 @@ VS2PS VS(float3 Position : POSITION, float4 Color : COLOR)
return output;
}
void PerformDepthTest(float4 svPosition)
META_PS(true, FEATURE_LEVEL_ES2)
META_PERMUTATION_2(USE_DEPTH_TEST=0,USE_FAKE_LIGHTING=0)
META_PERMUTATION_2(USE_DEPTH_TEST=0,USE_FAKE_LIGHTING=1)
META_PERMUTATION_2(USE_DEPTH_TEST=1,USE_FAKE_LIGHTING=0)
META_PERMUTATION_2(USE_DEPTH_TEST=1,USE_FAKE_LIGHTING=1)
float4 PS(VS2PS input) : SV_Target
{
#if USE_DEPTH_TEST
// Depth test manually if compositing editor primitives
FLATTEN
if (EnableDepthTest)
{
float sceneDepthDeviceZ = SceneDepthTexture.Load(int3(svPosition.xy, 0)).r;
float interpolatedDeviceZ = svPosition.z;
float sceneDepthDeviceZ = SceneDepthTexture.Load(int3(input.Position.xy, 0)).r;
float interpolatedDeviceZ = input.Position.z;
clip(sceneDepthDeviceZ - interpolatedDeviceZ);
}
}
#endif
float4 PerformFakeLighting(float4 svPosition, float4 c)
{
float4 color = input.Color;
#if USE_FAKE_LIGHTING
// Reconstruct view normal and calculate faked lighting
float depth = svPosition.z * 10000;
float depth = input.Position.z * 10000;
float3 n = normalize(float3(-ddx(depth), -ddy(depth), 1.0f));
c.rgb *= saturate(abs(dot(n, float3(0, 1, 0))) + 0.5f);
return c;
}
color.rgb *= saturate(abs(dot(n, float3(0, 1, 0))) + 0.5f);
#endif
META_PS(true, FEATURE_LEVEL_ES2)
float4 PS(VS2PS input) : SV_Target
{
return PerformFakeLighting(input.Position, input.Color);
}
META_PS(true, FEATURE_LEVEL_ES2)
float4 PSUnlit(VS2PS input) : SV_Target
{
return input.Color;
}
META_PS(true, FEATURE_LEVEL_ES2)
float4 PS_DepthTest(VS2PS input) : SV_Target
{
PerformDepthTest(input.Position);
return PerformFakeLighting(input.Position, input.Color);
}
META_PS(true, FEATURE_LEVEL_ES2)
float4 PS_DepthTestUnlit(VS2PS input) : SV_Target
{
PerformDepthTest(input.Position);
return input.Color;
return color;
}