Forum begins after the advertisement:


[Resource] Simple shader script for highlighting objects

Home Forums General Discussion [Resource] Simple shader script for highlighting objects

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #16150
    Terence
    Level 30
    Keymaster
    Helpful?
    Up
    0
    ::

    Hi folks, here is a simple shader script that you can use to create highlights on your 3D GameObjects.

    View post on imgur.com
    Shader "Custom/UnlitColourisation"
    {
        Properties
        {
            _Colour("Color", Color) = (0, 0, 0, 1) // Renamed to Colour
        }
            SubShader
        {
            Tags { "RenderType" = "Opaque" }
    
            // This pass will render the outline
            Pass
            {
                Name "OUTLINE"
                Tags { "LightMode" = "Always" }
    
                Cull Front
    
                ZWrite On
                ZTest LEqual
    
                ColorMask RGB
                Blend SrcAlpha OneMinusSrcAlpha
    
                CGPROGRAM
                #pragma vertex vert
                #pragma fragment frag
                #include "UnityCG.cginc"
    
                struct appdata
                {
                    float4 vertex : POSITION;
                    float3 normal : NORMAL;
                };
    
                struct v2f
                {
                    float4 pos : SV_POSITION;
                    float4 color : COLOR;
                };
    
                float4 _Colour; // Renamed to Colour
    
                v2f vert(appdata v)
                {
                    v2f o;
                    // No face offsets, directly use vertex position
                    o.pos = UnityObjectToClipPos(v.vertex);
                    o.color = _Colour; // Pass the outline color
                    return o;
                }
    
                fixed4 frag(v2f i) : SV_Target
                {
                    return i.color; // Directly use the outline color
                }
                ENDCG
            }
        }
            // Disable receiving shadows and depth writing for the outline.
                    Fallback "Diffuse"
    }
Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: