Search Unity

custom shaders still don't Zwrite in unity 5 ?

Discussion in 'Shaders' started by antislash, May 25, 2015.

  1. antislash

    antislash

    Joined:
    Apr 23, 2015
    Posts:
    646
    hi guys,
    i know ths issue is old and aven't found any working solution trough the posts i'v read....
    so, sorry to bring this issue on again but......

    so.... i need a transparend surface shader (moss shader)...
    okay it doesn't receive shadows.... that's a point.

    the other annoying point is : it doesn't write to zbuffer...
     
    Last edited: May 27, 2015
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    If you want a shader to write to the zbuffer, just program it to do that. There's nothing special about custom shaders.

    --Eric
     
  3. antislash

    antislash

    Joined:
    Apr 23, 2015
    Posts:
    646
    well, how ? i didn't find any working solution , despite i searched and read lots of posts...
    so, witch is the good solution?
    thanks for helping
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
  5. antislash

    antislash

    Joined:
    Apr 23, 2015
    Posts:
    646
    thank you, appreciate your help
    but i use a surface shader so the doc doesn't apply

    my shader has 4 CG "dirty passes", the 3 last ones use transparency for mossy effect
    i'd like the first one at least to be written to z

    writhe_that_z.jpg

    here is the kind of transparent pass i use ( the first one is like opaque) , i use zwrite on
    Code (CSharp):
    1. //// second pass
    2.         Tags { "Queue"="Transparent" "RenderType"="TransparentCutout" }
    3.              
    4.         CGPROGRAM
    5.  
    6.         #pragma surface surf Standard fullforwardshadows alpha:fade vertex:vert
    7.         //fullforwardshadows
    8.         // Use shader model 3.0 target, to get nicer looking lighting
    9.         #pragma target 3.0
    10.         #include "UnityCG.cginc"
    11.      
    12.         sampler2D _MainTex;
    13.         float _RimPower;
    14.         float4 _RimColor;
    15.      
    16.         struct Input {
    17.             float2 uv_MainTex;
    18.             float3 viewDir;
    19.         };
    20.      
    21.         float _Dist;
    22.      
    23.         void vert (inout appdata_full v) {
    24.             v.vertex.xyz += float3(v.normal.xyz * _Dist*0.33);
    25.         }
    26.  
    27.         void surf (Input IN, inout SurfaceOutputStandard o) {
    28.             fixed4 TexColor = tex2D (_MainTex, IN.uv_MainTex);
    29.             o.Alpha = TexColor.a;
    30.  
    31.             o.Albedo = TexColor.rgb*0.2;  // main albedo texture
    32.                              
    33.             o.Metallic = 0;
    34.             o.Smoothness = -0.1;
    35.  
    36.         }
    37.         ENDCG
    38.         //////// end second pass
    appreciate your sense of humor

    thanks eric
     
  6. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,412
  7. antislash

    antislash

    Joined:
    Apr 23, 2015
    Posts:
    646
    this one might help also..
    i didn't figure how to do the "replace shader" in my surface shader or how to adapt the docs example to a surface shader
    i just want the original mesh to be rendered as opaque and wrote to Z
    thanks mgear
     
  8. VileDog

    VileDog

    Joined:
    Sep 6, 2012
    Posts:
    6
    "Queue"="Transparent" - draw after all geometry & i gues, filling Z-bufeer (_CameraDepthTexture) Thats why no moss in Z-buffer, i think...
    "Queue"="Opaque" - render moss with all geometry & it has to be in Z-buffer(_CameraDepthTexture) too...
     
  9. antislash

    antislash

    Joined:
    Apr 23, 2015
    Posts:
    646
    hi vile dog
    i kinda solved the problem with the help of ZICANDAR wich i thank lots and lots
    i just used the tags like this:

    Code (CSharp):
    1. Tags { "Queue"="AlphaTest+50" "IgnoreProjector"="True"  "RenderType"="TransparentCutout" }
    and it worked fine, at least, i have the basic geometry on zdepth for now, good progress.

    i forward the links that helped me (from Zicandar, thanks again)

    http://forum.unity3d.com/threads/si...th-separate-mask-texture.321147/#post-2090803

    http://forum.unity3d.com/threads/depth-of-field-unity-5-and-transparent-shaders.307291/#post-2118371

    http://forum.unity3d.com/threads/custom-depth-buffer-rendering.323279/#post-2110538

    and alphatest:_Cutoff in pragma allows cast an receive every shadow
     
    Last edited: May 27, 2015