this is the relevant code:
Texture2D g_MaskMap : MaskMap;
uniform float g_MaskSpecularColorMulti : MaskSpecMulti = 1.0f;
uniform float g_MaskTransmissionMaskMulti : TransmissionMaskMulti = 1.0f;
uniform float g_MaskClipValue : MaskClip = 0.3333f;
uniform float g_EnableMasked : EnableMasked = 0.0f;
float4 GetMaterialMaskMapData( FDeferredShadingPSInput Input )
{
return g_MaskMap.Sample( g_SamplerStateLinearFlit, Input.oTex.xy ).xyzw;
}
float GetMaskedValue( float4 MaskData )
{
return MaskData.r;
}
void TryClip( float2 vTex )
{
if( g_EnableMasked < 1.0 )
{
return;
}
float4 vMaskData = g_MaskMap.Sample( g_SamplerStateLinearFlit, vTex.xy ).xyzw;
float MaskValue = GetMaskedValue( vMaskData );
MaskValue -= g_MaskClipValue;
clip( MaskValue );
}
float4 StaticMeshSpotLighting( HStaticMeshMaterialVSOutput Input ) : SV_TARGET
{
TryClip( Input.oTex );
return SpotLightingShading( Input );
}
this is the final output:
[attachment=7426:2.png]
but it produce a problem in shadow map, the gap of leaf is not rendered to depth buffer, I wan't to make a depth buffer which is masked by that mask texture.
this is the depth buffer, copy from nsight.
[attachment=7427:1.png]
// this is draw shadow map code:
float4 DrawShadowMapVS( HStaticMeshPositionVertexFactory Input ):SV_Position
{
float4 vWorldPos = mul( float4(Input.vPos, 1.0f ), mWorld );
float4 oPos = mul( vWorldPos, mLightViewProj );
return oPos;
}
technique10 DrawShadowMap
{
pass p0
{
SetVertexShader ( CompileShader( vs_5_0, DrawShadowMapVS() ) );
SetGeometryShader( NULL );
SetPixelShader( NULL );
SetRasterizerState( DisableCulling );
SetDepthStencilState( ZTestLess_DS, 0x00000000 );
SetBlendState( NoBlending_BS, float4( 1.0f, 1.0f, 1.0f, 1.0f ), 0xffffffff );
}
}
I realize we can use texture sample in vertex shader in dx11, so i make a new vertex shader for make the depth value of masked vertex always 1.0, but it doesn't work.
struct FMaskedShadowMapVSOutput
{
float4 oPos:SV_Position;
float2 oTex:TEXCOORD0;
};
FMaskedShadowMapVSOutput DrawShadowMapMaskedVS( HStaticMeshPositionWithTexVertexFactory Input )
{
FMaskedShadowMapVSOutput Output = (FMaskedShadowMapVSOutput)0;
float4 vWorldPos = mul( float4(Input.vPos, 1.0f ), mWorld );
Output.oPos = mul( vWorldPos, mLightViewProj );
Output.oTex = Input.vTex;
float4 vMaskData = g_MaskMap.Load( float3(Input.vTex.xy,0) ).xyzw;
float MaskValue = GetMaskedValue( vMaskData );
MaskValue -= g_MaskClipValue;
// it always far!!!
if( MaskValue <= 0 )
{
Output.oPos.z = Output.oPos.w;
}
return Output;
}
so, i wan't to know, how to render a msked primitive into a depth buffer, when the masked value is less or equal to 0, discard that pixel, and did not write the depth value to depth buffer.
or other do you have a better way to do that.