using vertex shaders with surface shaders - "extrusion"/displace by normal?

Here's a nice & simple vert-surface shader that affects the appearance of the object's vertices. If you click the object in the editor view, you'll see the object outline remains normal - it is just the rendered appearance.

The magic happens in the vert function, where you add the normal of the vertex, multiplied by the extrude amount to the vertex's original position.

 

 Shader "Dave/Unlit/Extrude"{
    Properties{
        _MainTex("MainTex",2D) = "white"{}
        _Amount ("extrude",Range(-1,1))=0.01

    }

        SubShader{
        CGPROGRAM
        #pragma surface surf Lambert vertex:vert

        struct Input {
            float2 uv_MainTex;

        };
        
        struct appdata {
            float4 vertex: POSITION;
            float3 normal: NORMAL;
            float4 texcoord: TEXCOORD0;

        };

        float _Amount;

        void vert(inout appdata v){
            v.vertex.xyz += v.normal*_Amount;
            }

        sampler2D _MainTex;

        void surf(Input IN, inout SurfaceOutput o)
        {
            o.Albedo = tex2D(_MainTex, IN.uv_MainTex).rgb;
        }

        ENDCG



    }

    Fallback "Diffuse"
}

Comments

Popular posts from this blog

setting VFX graph properties using C#