Sorry for highjacking the threat.
I’m trying to write a glass shader with a lot of tweaking options and I have to make it look as good as possible. I used the strumpy shader editor to put together my shader, but now I am probably in the same situation as mentioned above:
If I want my shader to draw the inner structure of the object, I have to cull the backfaces and turn off writing to depth. But then the faces in the foreground are not shown correctly. Or I turn off culling and write to the depth buffer, which leads in not seeing the inner structure. Did I miss something, or is there no solution?
Here is an image:
Here is the strumpy-generated shader for the left glass:
Shader "StrumpyGlas"
{
Properties
{
_Color("Main Color", Color) = (0.3529412,0.3529412,0.3529412,1)
_GlossNoYes("_GlossNoYes", Range(0,1) ) = 0
_Spraying("Base (RGB) Gloss (A)", 2D) = "white" {}
_Metalization("_Metalization", 2D) = "white" {}
_Painting("_Painting", 2D) = "black" {}
_UVOffset("_UVOffset", Range(0,1) ) = 0.5
_Reflection("_Reflection", Cube) = "black" {}
_BumpMap("Normalmap", 2D) = "bump" {}
_Distorsion("_Distorsion", Range(0,0.1) ) = 0
_Refraction("_Refraction", Range(0,1) ) = 0.5
_Shininess("Shininess", Range(0.01,1) ) = 1
_Fresnel("_Fresnel", Range(0.1,3) ) = 0.45
}
SubShader
{
Tags
{
"Queue"="Transparent"
"IgnoreProjector"="False"
"RenderType"="Transparent"
}
GrabPass { }
Cull Back
ZWrite Off
ZTest LEqual
ColorMask RGBA
Fog{
}
CGPROGRAM
#pragma surface surf BlinnPhongEditor vertex:vert
#pragma target 3.0
float4 _Color;
float _GlossNoYes;
sampler2D _Spraying;
sampler2D _Metalization;
sampler2D _Painting;
float _UVOffset;
samplerCUBE _Reflection;
sampler2D _BumpMap;
float _Distorsion;
float _Refraction;
float _Shininess;
float _Fresnel;
sampler2D _GrabTexture;
struct EditorSurfaceOutput {
half3 Albedo;
half3 Normal;
half3 Emission;
half3 Gloss;
half Specular;
half Alpha;
half4 Custom;
};
inline half4 LightingBlinnPhongEditor_PrePass (EditorSurfaceOutput s, half4 light)
{
half3 spec = light.a * s.Gloss;
half4 c;
c.rgb = (s.Albedo * light.rgb + light.rgb * spec);
c.a = s.Alpha;
return c;
}
inline half4 LightingBlinnPhongEditor (EditorSurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
{
half3 h = normalize (lightDir + viewDir);
half diff = max (0, dot ( lightDir, s.Normal ));
float nh = max (0, dot (s.Normal, h));
float spec = pow (nh, s.Specular*128.0);
half4 res;
res.rgb = _LightColor0.rgb * diff;
res.w = spec * Luminance (_LightColor0.rgb);
res *= atten * 2.0;
return LightingBlinnPhongEditor_PrePass( s, res );
}
struct Input {
float3 viewDir;
float4 screenPos;
float2 uv_BumpMap;
float2 uv_Spraying;
float2 uv_Metalization;
float3 simpleWorldRefl;
float2 uv_Painting;
};
void vert (inout appdata_full v, out Input o) {
float4 VertexOutputMaster0_0_NoInput = float4(0,0,0,0);
float4 VertexOutputMaster0_1_NoInput = float4(0,0,0,0);
float4 VertexOutputMaster0_2_NoInput = float4(0,0,0,0);
float4 VertexOutputMaster0_3_NoInput = float4(0,0,0,0);
o.simpleWorldRefl = -reflect( normalize(WorldSpaceViewDir(v.vertex)), normalize(mul((float3x3)_Object2World, SCALED_NORMAL)));
}
void surf (Input IN, inout EditorSurfaceOutput o) {
o.Normal = float3(0.0,0.0,1.0);
o.Alpha = 1.0;
o.Albedo = 0.0;
o.Emission = 0.0;
o.Gloss = 0.0;
o.Specular = 0.0;
o.Custom = 0.0;
float4 Fresnel1_1_NoInput = float4(0,0,1,1);
float4 Fresnel1=(1.0 - dot( normalize( float4( IN.viewDir.x, IN.viewDir.y,IN.viewDir.z,1.0 ).xyz), normalize( Fresnel1_1_NoInput.xyz ) )).xxxx;
float4 Multiply5=Fresnel1 * _Refraction.xxxx;
float4 Add1=Multiply5 + ((IN.screenPos.xy/IN.screenPos.w).xyxy);
float4 Tex2D5=tex2D(_BumpMap,(IN.uv_BumpMap.xyxy).xy);
float4 UnpackNormal0=float4(UnpackNormal(Tex2D5).xyz, 1.0);
float4 Multiply4=UnpackNormal0 * _Distorsion.xxxx;
float4 Add0=Add1 + Multiply4;
float4 Tex2D0=tex2D(_GrabTexture,Add0.xy);
float4 Tex2D1=tex2D(_Spraying,(IN.uv_Spraying.xyxy).xy);
float4 Multiply2=Tex2D0 * Tex2D1;
float4 Tex2D2=tex2D(_Metalization,(IN.uv_Metalization.xyxy).xy);
float4 Multiply3=Tex2D1 * Tex2D2;
float4 Lerp2=lerp(Multiply2,Multiply3,Tex2D2);
float4 TexCUBE0=texCUBE(_Reflection,float4( IN.simpleWorldRefl.x, IN.simpleWorldRefl.y,IN.simpleWorldRefl.z,1.0 ));
float4 Multiply1=Tex2D1 * TexCUBE0;
float4 Lerp1=lerp(TexCUBE0,Multiply1,Tex2D2);
float4 Fresnel0_1_NoInput = float4(0,0,1,1);
float4 Fresnel0=(1.0 - dot( normalize( float4( IN.viewDir.x, IN.viewDir.y,IN.viewDir.z,1.0 ).xyz), normalize( Fresnel0_1_NoInput.xyz ) )).xxxx;
float4 Pow0=pow(Fresnel0,_Fresnel.xxxx);
float4 Min0=min(Pow0,float4( 1.0, 1.0, 1.0, 1.0 ));
float4 Max0=max(float4( 0.1,0.1,0.1,0.1 ),Min0);
float4 Lerp0=lerp(Lerp2,Lerp1,Max0);
float4 Split0=(IN.uv_Painting.xyxy);
float4 Add2=float4( Split0.x, Split0.x, Split0.x, Split0.x) + _UVOffset.xxxx;
float4 Assemble0_2_NoInput = float4(0,0,0,0);
float4 Assemble0_3_NoInput = float4(0,0,0,0);
float4 Assemble0=float4(Add2.x, float4( Split0.y, Split0.y, Split0.y, Split0.y).y, Assemble0_2_NoInput.z, Assemble0_3_NoInput.w);
float4 Tex2D4=tex2D(_Painting,Assemble0.xy);
float4 Lerp3=lerp(Lerp0,Tex2D4,Tex2D4.aaaa);
float4 Tex2D3=tex2D(_Spraying,(IN.uv_Spraying.xyxy).xy);
float4 Multiply0=Tex2D3 * _GlossNoYes.xxxx;
float4 Master0_1_NoInput = float4(0,0,1,1);
float4 Master0_5_NoInput = float4(1,1,1,1);
float4 Master0_7_NoInput = float4(0,0,0,0);
float4 Master0_6_NoInput = float4(1,1,1,1);
o.Albedo = _Color;
o.Emission = Lerp3;
o.Specular = _Shininess.xxxx;
o.Gloss = Multiply0;
o.Normal = normalize(o.Normal);
}
ENDCG
}
Fallback "Transparent"
}