Piflik:
I know this thread is old, but if anyone is still looking for this shader as a working example, here is my version, using the VFACE semantic mentioned earlier. I use it to visualize X-Ray imaging, that’s why my absorption can go negative, to emulate empty space (like lungs). All in all it is a good approximation for X-Ray.
Shader "Custom/Thickness" {
Properties {
_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"
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 half4(depth, depth, depth, 1);
}
ENDCG
}
}
}
I freakin love you!!!
Thank you so much. You won’t believe how long i was looking for this.
I knew it was something very simple but unfortunately i was not able to achieve it.
Regarding to the negative Absorbtion, I have it the other way around. The thick areas are represented dark