Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

new wireframe with ddx

Discussion in 'Shaders' started by dreamerflyer, Jan 28, 2015.

  1. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    927
    I found this code in flash 3d http://arieln.com/blog/2014/08/new-wireframe-rendering-using-ddx-and-ddy/

    and i try below code,but not work, where is wrong:
    Code (CSharp):
    1. Shader "Hidden/wireframe" {
    2.     Properties {
    3.     }
    4.     SubShader {
    5. Tags { "Queue"="Geometry" }
    6.  // Cull back
    7. // Lighting Off
    8.  ZWrite off
    9.  //ZTest Always
    10.  Fog { Mode Off }
    11.  Blend One OneMinusSrcAlpha
    12.     Pass {
    13.  
    14.             CGPROGRAM
    15.  
    16.         #pragma vertex vert
    17.         #pragma fragment frag
    18.  
    19.         #pragma glsl
    20.  
    21.         #include "UnityCG.cginc"
    22.  
    23.             struct v2f {
    24.                 float4 pos : POSITION;
    25.                 float4 depth : TEXCOORD0;
    26.             };
    27.  
    28.             v2f vert( appdata_full v )
    29.             {
    30.                 v2f o;
    31.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    32.  
    33.                 return o;
    34.             }
    35.  
    36.             half4 frag( v2f i ) : COLOR
    37.             {
    38.  
    39.                 float3 pos=i.pos;
    40.                 float3 a3=smoothstep(float3(0),fwidth(pos),pos);
    41.                 float4 enc=float4((1-min(min(a3.x,a3.y),a3.z).xxx),0)*0.5f;
    42.  
    43.  
    44.         return enc;
    45.             }
    46.  
    47.             ENDCG
    48.         }
    49.     }
    50. }
    51.  
     
    Last edited: Jan 28, 2015
  2. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    927
    anybody help?