rendering: unify builtin forward and depth-style shaders
This commit is contained in:
@@ -6,26 +6,67 @@ Shader "Builtin Shadow Caster"
|
||||
_Cutoff ("Alpha Cutoff", Range) = 0.5 [Semantic(AlphaCutoff)]
|
||||
_MainTex ("Base Map", 2D) = "white" [Semantic(BaseColorTexture)]
|
||||
}
|
||||
HLSLINCLUDE
|
||||
cbuffer PerObjectConstants : register(b0)
|
||||
{
|
||||
float4x4 gProjectionMatrix;
|
||||
float4x4 gViewMatrix;
|
||||
float4x4 gModelMatrix;
|
||||
};
|
||||
|
||||
cbuffer MaterialConstants : register(b1)
|
||||
{
|
||||
float4 gBaseColorFactor;
|
||||
float4 gAlphaCutoffParams;
|
||||
};
|
||||
|
||||
Texture2D BaseColorTexture : register(t0);
|
||||
SamplerState LinearClampSampler : register(s0);
|
||||
|
||||
struct VSInput
|
||||
{
|
||||
float3 position : POSITION;
|
||||
float3 normal : NORMAL;
|
||||
float2 texcoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct PSInput
|
||||
{
|
||||
float4 position : SV_POSITION;
|
||||
float2 texcoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
PSInput MainVS(VSInput input)
|
||||
{
|
||||
PSInput output;
|
||||
const float4 positionWS = mul(gModelMatrix, float4(input.position, 1.0f));
|
||||
const float4 positionVS = mul(gViewMatrix, positionWS);
|
||||
output.position = mul(gProjectionMatrix, positionVS);
|
||||
output.texcoord = input.texcoord;
|
||||
return output;
|
||||
}
|
||||
|
||||
float MainPS(PSInput input) : SV_Depth
|
||||
{
|
||||
#ifdef XC_ALPHA_TEST
|
||||
const float4 baseColor =
|
||||
BaseColorTexture.Sample(LinearClampSampler, input.texcoord) * gBaseColorFactor;
|
||||
clip(baseColor.a - gAlphaCutoffParams.x);
|
||||
#endif
|
||||
return input.position.z;
|
||||
}
|
||||
ENDHLSL
|
||||
SubShader
|
||||
{
|
||||
Pass
|
||||
{
|
||||
Name "ShadowCaster"
|
||||
Tags { "LightMode" = "ShadowCaster" }
|
||||
Resources
|
||||
{
|
||||
PerObjectConstants (ConstantBuffer, 0, 0) [Semantic(PerObject)]
|
||||
MaterialConstants (ConstantBuffer, 1, 0) [Semantic(Material)]
|
||||
BaseColorTexture (Texture2D, 2, 0) [Semantic(BaseColorTexture)]
|
||||
LinearClampSampler (Sampler, 3, 0) [Semantic(LinearClampSampler)]
|
||||
}
|
||||
HLSLPROGRAM
|
||||
#pragma target 4.5
|
||||
#pragma vertex MainVS
|
||||
#pragma fragment MainPS
|
||||
#pragma shader_feature_local _ XC_ALPHA_TEST
|
||||
#pragma backend D3D12 HLSL "shadow-caster.vs.hlsl" "shadow-caster.ps.hlsl" vs_5_0 ps_5_0
|
||||
#pragma backend OpenGL GLSL "shadow-caster.vert.glsl" "shadow-caster.frag.glsl"
|
||||
#pragma backend Vulkan GLSL "shadow-caster.vert.vk.glsl" "shadow-caster.frag.vk.glsl"
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user