rendering: thread global shader keywords into builtin variants

This commit is contained in:
2026-04-06 20:30:25 +08:00
parent 0761079b4c
commit c318f34f07
14 changed files with 119 additions and 26 deletions

View File

@@ -43,6 +43,9 @@ in vec3 vPositionWS;
layout(location = 0) out vec4 fragColor;
float ComputeShadowAttenuation(vec3 positionWS) {
#ifndef XC_MAIN_LIGHT_SHADOWS
return 1.0;
#else
if (gShadowOptions.x < 0.5) {
return 1.0;
}
@@ -66,6 +69,7 @@ float ComputeShadowAttenuation(vec3 positionWS) {
float receiverDepth = shadowNdc.z * 0.5 + 0.5 - gShadowBiasAndTexelSize.x;
float shadowStrength = clamp(gShadowBiasAndTexelSize.w, 0.0, 1.0);
return receiverDepth <= shadowDepth ? 1.0 : (1.0 - shadowStrength);
#endif
}
float ComputeRangeAttenuation(float distanceSq, float range) {

View File

@@ -45,6 +45,9 @@ layout(location = 2) in vec3 vPositionWS;
layout(location = 0) out vec4 fragColor;
float ComputeShadowAttenuation(vec3 positionWS) {
#ifndef XC_MAIN_LIGHT_SHADOWS
return 1.0;
#else
if (gShadowOptions.x < 0.5) {
return 1.0;
}
@@ -68,6 +71,7 @@ float ComputeShadowAttenuation(vec3 positionWS) {
float receiverDepth = shadowNdc.z - gShadowBiasAndTexelSize.x;
float shadowStrength = clamp(gShadowBiasAndTexelSize.w, 0.0, 1.0);
return receiverDepth <= shadowDepth ? 1.0 : (1.0 - shadowStrength);
#endif
}
float ComputeRangeAttenuation(float distanceSq, float range) {

View File

@@ -45,6 +45,9 @@ struct PSInput {
};
float ComputeShadowAttenuation(float3 positionWS) {
#ifndef XC_MAIN_LIGHT_SHADOWS
return 1.0f;
#else
if (gShadowOptions.x < 0.5f) {
return 1.0f;
}
@@ -68,6 +71,7 @@ float ComputeShadowAttenuation(float3 positionWS) {
const float receiverDepth = shadowNdc.z - gShadowBiasAndTexelSize.x;
const float shadowStrength = saturate(gShadowBiasAndTexelSize.w);
return receiverDepth <= shadowDepth ? 1.0f : (1.0f - shadowStrength);
#endif
}
float ComputeRangeAttenuation(float distanceSq, float range) {

View File

@@ -25,6 +25,7 @@ Shader "Builtin Forward Lit"
HLSLPROGRAM
#pragma vertex MainVS
#pragma fragment MainPS
#pragma multi_compile _ XC_MAIN_LIGHT_SHADOWS
#pragma backend D3D12 HLSL "forward-lit.vs.hlsl" "forward-lit.ps.hlsl" vs_5_0 ps_5_0
#pragma backend OpenGL GLSL "forward-lit.vert.glsl" "forward-lit.frag.glsl"
#pragma backend Vulkan GLSL "forward-lit.vert.vk.glsl" "forward-lit.frag.vk.glsl"