Hello, I got the shader called "Simple Glass" to work for me in objects with some requirements: -Allow transparency change -Render both faces But the color the object presents is a bit odd, although it is set to white. I think there's a simple solution to it, but I can't find it. Below I show an object with this color and the shader code: Code (CSharp): Shader "Simple Glass" { Properties { _Color ("Main Color", Color) = (1,1,1,1) _MainTex ("Base (RGB)", 2D) = "white" { } } SubShader { // We use the material in many passes by defining them in the subshader. // Anything defined here becomes default values for all contained passes. Material { Diffuse [_Color] Ambient [_Color] } Lighting On // Set up alpha blending Blend SrcAlpha OneMinusSrcAlpha // Render the back facing parts of the object. // If the object is convex, these will always be further away // than the front-faces. Pass { Cull Front SetTexture [_MainTex] { Combine Primary *Texture } } // Render the parts of the object facing us. // If the object is convex, these will be closer than the // back-faces. Pass { Cull Back SetTexture [_MainTex] { Combine Primary * Texture } } } } Since the color pattern varies acording to the light direction I think the problem is related to backfaces blending issues, but I'm not sure.
Try this one Code (CSharp): Shader "Simple Glass" { Properties { _Color ("Main Color", Color) = (1,1,1,1) _MainTex ("Base (RGB)", 2D) = "white" {} _Alpha ("Alpha", Range(0,1)) = 1 } SubShader { // We use the material in many passes by defining them in the subshader. // Anything defined here becomes default values for all contained passes. Material { Diffuse [_Color] Ambient [_Color] } Lighting On // Set up alpha blending Blend SrcAlpha OneMinusSrcAlpha // Render the back facing parts of the object. // If the object is convex, these will always be further away // than the front-faces. Pass { Cull Off SetTexture [_MainTex] { constantColor(1,1,1,[_Alpha]) Combine Texture*constant } } } }
Hello, sorry for the late reply. Thanks for your answer. I've tried something similiar it already and also yours, but then the object is just pure white with no lightning or shadows :\
sorry but I'm not familiar with your shader style I use this style and works correctly I hope this is what you want without color mask: Code (CSharp): Shader "Example/Diffuse Texture" { Properties { _Color("Color",Color) = (1,1,1,1) _MainTex ("Texture", 2D) = "white" {} _Alpha("Alpha",Range(0,1)) = 0.5 } SubShader { Tags { "RenderType" = "Transparent" } Cull Off //Render Both Sides CGPROGRAM #pragma surface surf Lambert alpha:fade float4 _Color; struct Input { float2 uv_MainTex; }; float _Alpha; sampler2D _MainTex; void surf (Input IN, inout SurfaceOutput o) { o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb*_Color; o.Alpha = _Alpha; } ENDCG } Fallback "Diffuse" } with color mask: Code (CSharp): Shader "Example/Diffuse Texture" { Properties { _Color("Color",Color) = (1,1,1,1) _MainTex ("Texture", 2D) = "white" {} _Alpha("Alpha",Range(0,1)) = 0.5 } SubShader { Tags { "RenderType" = "Transparent" } Cull Off //Render Both Sides pass{ ColorMask 0 } CGPROGRAM #pragma surface surf Lambert alpha:fade float4 _Color; struct Input { float2 uv_MainTex; }; float _Alpha; sampler2D _MainTex; void surf (Input IN, inout SurfaceOutput o) { o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb*_Color; o.Alpha = _Alpha; } ENDCG } Fallback "Diffuse" }