Hi everyone, how are you?, hope you’re fine, well, I have this problem with this shader, I was struggling and trying to understand what is the piece I need to change to achieve the wanted effect, you’ll see, this is a “Thickness” shader that works rendering the depth of an object mesh with color, I modified the code to give it color but something in one of the functions is not working as I expected, when the object intersect another object this intersection appears in negative, I tried to change some parameters as Culling or ZTest, that isn’t in the code, in some way it worked but, object interpose to another or when I move camera away from object it loses is color…
I’m using URP.
This is how shader works:
And this is the wanted effect:
And this is the shader, isn’t mine, I guess I’m not the only one who was searching:
Shader "Custom/Thickness" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_Absorption("Absorption", Range(-10, 10)) = 1
}
SubShader {
Tags {
"Queue" = "Transparent"
"IgnoreProjector" = "True"
"RenderType" = "Transparent"
}
Pass {
Cull Off
Blend One One
Lighting Off
ZWrite Off
Fog { Mode Off }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
fixed4 _Color;
struct a2v {
float4 vertex : POSITION;
};
struct v2f {
float4 pos : SV_POSITION;
half dist : TEXCOORD0;
};
v2f vert(a2v v) {
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
COMPUTE_EYEDEPTH(o.dist);
return o;
}
float _Absorption;
fixed4 frag(v2f i, fixed facing : VFACE) : COLOR {
float depth = -_Absorption * sign(facing) * i.dist;
return _Color * depth;
}
ENDCG
}
}
}
Any advice is welcome .