Hi,
I have looked all over the internets for this, but found nothing that could help me get anywhere. Reading the documentation made me realise all there is left for me to do is read up on everything and just try until I have something that works. There are no assets on the asset store, or code available that I could find anywhere either. All I could find that was relevant to this was this post, but it had no code to look at: Wind Waker Style Firefly Lights — polycount
So the question is, how can I make this work with stencils in shaders in Unity 3D? Attached is the current setup and hilited in blue is the overlapping issues I get (among others). I started this based on the Unity Stencil documentation here: Unity - Manual: ShaderLab command: Stencil
The shader code I have is here:
Shader "Test/Light" {
Properties {
_Color ("Main Color", Color) = (1,1,1,0)
}
SubShader {
Tags { "RenderType"="Opaque" "Queue"="Geometry+2"}
ColorMask RGB
Cull Front
ZTest Always
Blend One One
Stencil {
Ref 1
Comp notequal
}
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// make fog work
#pragma multi_compile_fog
#include "UnityCG.cginc"
fixed4 _Color;
struct appdata
{
float4 vertex : POSITION;
};
struct v2f
{
float4 vertex : SV_POSITION;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(float4(v.vertex.xyz, 1.0f)); //UnityObjectToClipPos(v.vertex);
return o;
}
fixed4 frag () : SV_Target
{
return _Color;
}
ENDCG
}
}
}
And here:
Shader "Test/LightHelp" {
SubShader {
Tags { "RenderType"="Opaque" "Queue"="Geometry+1"}
ColorMask 0
ZWrite off
Stencil {
Ref 1
Comp always
Pass replace
}
CGINCLUDE
struct appdata {
float4 vertex : POSITION;
};
struct v2f {
float4 pos : SV_POSITION;
};
v2f vert(appdata v) {
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
return o;
}
half4 frag(v2f i) : SV_Target {
return half4(1,1,0,1);
}
ENDCG
Pass {
Cull Front
ZTest Less
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
ENDCG
}
Pass {
Cull Back
ZTest Greater
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
ENDCG
}
}
}
All I want is for the surface that intersects the mesh to be coloured in a bright colour without the issues you can see in the attached image “show2.PNG” below, but I seem to be unable to get somewhere with this.
Please help. (There is also an asset store idea for you here as mentioned earlier, I’d be willing to pay for it and am sure others would too.)