Hey! Im trying to create holes in walls using the stencil buffer but im not experienced with shaders. I found some shaders online to write and read from the stencil buffer in the hdrp
The write stencil code:
Shader "Custom/StencilWriteShader"
{
Properties
{
_StencilMask("Stencil Mask", Int) = 0
}
HLSLINCLUDE
#pragma target 4.5
#pragma only_renderers d3d11 ps4 xboxone vulkan metal switch
#pragma multi_compile_instancing
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/UnlitProperties.hlsl"
ENDHLSL
SubShader
{
Tags{ "RenderPipeline" = "HDRenderPipeline"
"RenderType" = "HDUnlitShader"
"Queue"="Geometry+1"
}
Pass
{
Name "Forward Unlit"
Tags { "LightMode" = "ForwardOnly" }
ZWrite Off
ColorMask 0
Stencil
{
WriteMask [_StencilMask]
Ref [_StencilMask]
Comp Always
Pass Replace
}
HLSLPROGRAM
#pragma multi_compile _ DEBUG_DISPLAY
#ifdef DEBUG_DISPLAY
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl"
#endif
#define SHADERPASS SHADERPASS_FORWARD_UNLIT
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/Unlit.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/ShaderPass/UnlitSharePass.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/UnlitData.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassForwardUnlit.hlsl"
#pragma vertex Vert
#pragma fragment Frag
ENDHLSL
}
}
}
The read code is the same the only changes are the render queue, the stencil part and the Color Mask
"Queue"="Geometry+2"
ZWrite On
ColorMask RGB
Stencil
{
Ref [_StencilMask]
Comp [_Compare]
}
It works fine:
But I need the wall material to be a normal HDRP Lit with textures and etc… I copied an empty shader graph code and inserted the stencil part from the read code but it didnt work, its a massive 9k line code and I dont know where to edit it to make it work.
If anyone knows how to change the stencil buffer on the default Lit shader, I need some help
Thanks!
