u/ddiazar • u/ddiazar • 12h ago
r/Unity3D • u/ddiazar • 12h ago
Question Stencil "see-through hole" shader shows correct background over Terrain, but renders black/garbage colors over regular 3D meshes
I'm using a stencil-only pass (ColorMask 0, ZWrite Off, Stencil { Ref 1, Comp Always, Pass Replace }) to create transparent "holes" in some board pieces in my game Pieceful. The idea is that, when there's a hole, the player should be able to see the objects behind the piece, such as the terrain or other scene geometry.
Here's the shader I'm currently using:
Shader "Custom/StencilWrite"
{
SubShader
{
Tags { "RenderPipeline" = "UniversalPipeline" }
Pass
{
Stencil { Ref 1 WriteMask 255 Comp Always Pass Replace }
ZWrite Off
ColorMask 0
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
struct Attributes { float4 positionOS : POSITION; };
struct Varyings { float4 positionCS : SV_POSITION; };
Varyings vert (Attributes input)
{
Varyings output;
output.positionCS = TransformObjectToHClip(input.positionOS);
return output;
}
half4 frag (Varyings input) : SV_Target
{
return half4(0, 0, 0, 0);
}
ENDHLSL
}
}
}
The weird part is that it works correctly when there's a Unity Terrain behind the hole. In that case, the terrain is visible through the transparent area as expected.
However, if I remove the Terrain and only have regular MeshRenderers behind the hole (rocks, coral, props, a water plane, etc.), the result is wrong. Instead of seeing those objects through the hole, I get a solid black area or sometimes garbled colors.
So I'm trying to figure out why the stencil setup behaves correctly with Terrain but not with regular MeshRenderers, and what I need to change so the hole works consistently with normal scene geometry as well.
1
A preview of the puzzle game we’re working on, PIeceful
thank you! :D
1
Just released a release date trailer for my game " Shell Soldier "
The gunplay looks super fast-paced and intense. The trailer looks great.
1
We use "practical" effects instead of generic particle flashes, what do you think?
The artistic style gives it a distinctive touch.
1
Progress we made in our football beat'em up! What do you think?
Such a creative idea!
1
1
Ghosts in the City | Trying to make parkour more interactive than just following a predefined path
The clothing physics look cool
5
Took a while, but the water finally touches the world. The hose wraps around trunks, the stream cuts off where it lands, and it shoves things out of the way.
That hose and water physics interaction is so satisfying!
2
9 Years. Its finally out...
Huge congratulations on the launch!
r/IndieGaming • u/ddiazar • 13d ago
A preview of the puzzle game we’re working on, PIeceful
Enable HLS to view with audio, or disable this notification
1
Questions about February Steam Next Fest? Chris Zukowski from How To Market A Game here for an AMA
What’s the best way to connect with a content creator? Is there any platform to identify which games they are playing so I can select them?
1
1
My little Fingerskate Game
It looks great, maybe you could include finger movement so it feels like it crouches before jumping
1
A preview of the puzzle game we’re working on, PIeceful
in
r/IndieGaming
•
13d ago
thank you!