I have a problem with a custom shader I did. I created a shader for my Character Sprite. But when it is submerged in a transparent water , he is not rendered properly. SS example : https://www.dropbox.com/s/xpxxls4s79kx44i/errorunity.png My Shader: Code (csharp): Shader "Toon/Lighted with Alpha" { Properties { _Color ("Main Color", Color) = (0.5,0.5,0.5,1) _MainTex ("Base (RGB)", 2D) = "white" {} _Ramp ("Toon Ramp (RGB)", 2D) = "gray" {} } SubShader { Tags {"Queue"="Transparent" "RenderType"="Transparent"} Blend SrcAlpha OneMinusSrcAlpha LOD 200 CGPROGRAM #pragma surface surf ToonRamp sampler2D _Ramp; // custom lighting function that uses a texture ramp based // on angle between light direction and normal #pragma lighting ToonRamp exclude_path:prepass inline half4 LightingToonRamp (SurfaceOutput s, half3 lightDir, half atten) { #ifndef USING_DIRECTIONAL_LIGHT lightDir = normalize(lightDir); #endif half d = dot (s.Normal, lightDir)*0.5 + 0.5; half3 ramp = tex2D (_Ramp, float2(d,d)).rgb; half4 c; c.rgb = s.Albedo * (_LightColor0.rgb*2) * ramp * (atten * 2); c.a = s.Alpha;///-> test return c; } sampler2D _MainTex; float4 _Color; struct Input { float2 uv_MainTex : TEXCOORD0; }; void surf (Input IN, inout SurfaceOutput o) { half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color; o.Albedo = c.rgb; o.Alpha = c.a; } ENDCG } Fallback "Diffuse" } I wish that when it is submerged rendering equals the cube. Does anyone have any idea how to fix?
change your tag to Tags {"Queue"="Transparent-10" "RenderType"="Transparent"} or Tags {"Queue"="Transparent+10" "RenderType"="Transparent"} or some other value until it works.
https://www.dropbox.com/s/hwlqg4p2xg17qs5/errorunity2.png Any negative number works (tested several -10 ~ -200). But this bug appears at the top.
See you behind the character's head, where not is submerged in water, he does not rendered the water, only the grass. This is the part where is opaque with grass texture should be transparent. In Original Sprite, and before putting the -10, was transparent. Ex (without '-10'): https://www.dropbox.com/s/xpxxls4s79kx44i/errorunity.png
I dont see any grass in that picture. Just a head a cube and probably the water. Drawing order is Opaque.1.2.3...etc -> Transparent cutout.1.2.3...etc ->Transparent.1.2.3...etc Try zwrite off on your character model with the same transparency level as your water.
Sorry. The grass in the image1 : https://www.dropbox.com/s/hwlqg4p2xg17qs5/errorunity2.png the image2(https://www.dropbox.com/s/xpxxls4s79kx44i/errorunity.png) is only for you see the original transparence of character. Dont work the zwrite off. ( it is as if he had always submerged even when it is surface ) **i understand the sequence. The sequence looks like it's right, water should render after. But it is not rendered in the transparent part of the character sprite. :S
eh, i didnt check your shader before. remove the blend srcalpha oneminussrcalpha from your shader and change your pragma state to #pragma surface surf ToonRamp alpha
CODE NOW: Code (csharp): Shader "Toon/Lighted with Alpha" { Properties { _Color ("Main Color", Color) = (0.5,0.5,0.5,1) _MainTex ("Base (RGB)", 2D) = "white" {} _Ramp ("Toon Ramp (RGB)", 2D) = "gray" {} } SubShader { Tags {"Queue"="Transparent-10" "RenderType"="Transparent"} LOD 200 CGPROGRAM #pragma surface surf ToonRamp alpha sampler2D _Ramp; // custom lighting function that uses a texture ramp based // on angle between light direction and normal #pragma lighting ToonRamp exclude_path:prepass inline half4 LightingToonRamp (SurfaceOutput s, half3 lightDir, half atten) { #ifndef USING_DIRECTIONAL_LIGHT lightDir = normalize(lightDir); #endif half d = dot (s.Normal, lightDir)*0.5 + 0.5; half3 ramp = tex2D (_Ramp, float2(d,d)).rgb; half4 c; c.rgb = s.Albedo * (_LightColor0.rgb*2) * ramp * (atten * 2); c.a = s.Alpha;///-> test return c; } sampler2D _MainTex; float4 _Color; struct Input { float2 uv_MainTex : TEXCOORD0; }; void surf (Input IN, inout SurfaceOutput o) { half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color; o.Albedo = c.rgb; o.Alpha = c.a; } ENDCG } Fallback "Diffuse" } same problem as zwrite off. it is as if he had always submerged even when it is surface. https://www.dropbox.com/s/82c1ac3hpxnwttl/error3.png In this example the character is not submerged but depending on the camera position/angle, the water is rendered over him. ***I tried to modify the number "" Queue "=" Transparent-10 "." also without success. Thanks for the help!
Just speculating without seeing the actual scene and all your files used in it. Is your character mesh a plane object which rotates towards the camera all the time? If so, when you look at him from an angle above, obviously the plane object rotates down under the water mesh and it looks submerged. If that is not the case, i need to see a sample scene.
Understand. Is not the case my friend. I'm packing the scene, but found a problem. You have the 2d Toolkit?
No i dont have it, and if you are using a commercial product like 2d toolkit, you should ask to its owner about your problem.