Add **Depth Offset to materials**
This commit is contained in:
@@ -22,6 +22,9 @@ void PS_GBuffer(
|
||||
#if USE_GBUFFER_CUSTOM_DATA
|
||||
,out float4 RT3 : SV_Target4
|
||||
#endif
|
||||
#endif
|
||||
#if USE_DEPTH_OFFSET
|
||||
,out float Depth : SV_Depth
|
||||
#endif
|
||||
)
|
||||
{
|
||||
@@ -36,11 +39,16 @@ void PS_GBuffer(
|
||||
MaterialInput materialInput = GetMaterialInput(input);
|
||||
Material material = GetMaterialPS(materialInput);
|
||||
|
||||
// Depth offset
|
||||
#if USE_DEPTH_OFFSET
|
||||
Depth = (materialInput.SvPosition.z * materialInput.SvPosition.w) / (materialInput.SvPosition.w + material.DepthOffset);
|
||||
#endif
|
||||
|
||||
// Masking
|
||||
#if MATERIAL_MASKED
|
||||
clip(material.Mask - MATERIAL_MASK_THRESHOLD);
|
||||
#endif
|
||||
|
||||
|
||||
#if USE_LIGHTMAP
|
||||
float3 diffuseColor = GetDiffuseColor(material.Color, material.Metalness);
|
||||
float3 specularColor = GetSpecularColor(material.Color, material.Specular, material.Metalness);
|
||||
|
||||
@@ -33,9 +33,15 @@ DECLARE_LIGHTSHADOWDATA_ACCESS(DirectionalLightShadow);
|
||||
|
||||
// Pixel Shader function for Forward Pass
|
||||
META_PS(USE_FORWARD, FEATURE_LEVEL_ES2)
|
||||
float4 PS_Forward(PixelInput input) : SV_Target0
|
||||
void PS_Forward(
|
||||
in PixelInput input
|
||||
,out float4 output : SV_Target0
|
||||
#if USE_DEPTH_OFFSET
|
||||
,out float Depth : SV_Depth
|
||||
#endif
|
||||
)
|
||||
{
|
||||
float4 output = 0;
|
||||
output = 0;
|
||||
|
||||
#if USE_DITHERED_LOD_TRANSITION
|
||||
// LOD masking
|
||||
@@ -45,6 +51,11 @@ float4 PS_Forward(PixelInput input) : SV_Target0
|
||||
// Get material parameters
|
||||
MaterialInput materialInput = GetMaterialInput(input);
|
||||
Material material = GetMaterialPS(materialInput);
|
||||
|
||||
// Depth offset
|
||||
#if USE_DEPTH_OFFSET
|
||||
Depth = (materialInput.SvPosition.z * materialInput.SvPosition.w) / (materialInput.SvPosition.w + material.DepthOffset);
|
||||
#endif
|
||||
|
||||
// Masking
|
||||
#if MATERIAL_MASKED
|
||||
@@ -148,6 +159,4 @@ float4 PS_Forward(PixelInput input) : SV_Target0
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
@@ -587,14 +587,18 @@ void ClipLODTransition(PixelInput input)
|
||||
|
||||
// Pixel Shader function for Depth Pass
|
||||
META_PS(true, FEATURE_LEVEL_ES2)
|
||||
void PS_Depth(PixelInput input)
|
||||
void PS_Depth(PixelInput input
|
||||
#if USE_DEPTH_OFFSET
|
||||
,out float Depth : SV_Depth
|
||||
#endif
|
||||
)
|
||||
{
|
||||
#if USE_DITHERED_LOD_TRANSITION
|
||||
// LOD masking
|
||||
ClipLODTransition(input);
|
||||
#endif
|
||||
|
||||
#if MATERIAL_MASKED || MATERIAL_BLEND != MATERIAL_BLEND_OPAQUE
|
||||
#if MATERIAL_MASKED || MATERIAL_BLEND != MATERIAL_BLEND_OPAQUE || USE_DEPTH_OFFSET
|
||||
// Get material parameters
|
||||
MaterialInput materialInput = GetMaterialInput(input);
|
||||
Material material = GetMaterialPS(materialInput);
|
||||
@@ -606,6 +610,11 @@ void PS_Depth(PixelInput input)
|
||||
#if MATERIAL_BLEND != MATERIAL_BLEND_OPAQUE
|
||||
clip(material.Opacity - MATERIAL_OPACITY_THRESHOLD);
|
||||
#endif
|
||||
|
||||
// Depth offset
|
||||
#if USE_DEPTH_OFFSET
|
||||
Depth = (materialInput.SvPosition.z * materialInput.SvPosition.w) / (materialInput.SvPosition.w + material.DepthOffset);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user