XRay

From Unify Community Wiki

Jump to: navigation, search


Author: Patrik Svensson

Contents

[edit] Description

A simple additive shader that uses a ramp texture to give it that X-Ray look.

[edit] Usage

Create a ramp texture for the facing ratio lookup. For a standard X-Ray look make it light to the left and dark to the right. This texture will be mapped onto the object depending on the angle between the surface normal and the view direction.

[edit] ShaderLab - X-Ray Shader for Unity 2.x

Shader "XRay" {

    Properties {
        _Color ("Tint (RGB)", Color) = (1,1,1,1)
        _RampTex ("Facing Ratio Ramp (RGB)", 2D) = "white" {}
    }
    SubShader {
        ZWrite Off
        Tags { "Queue" = "Transparent" }
        Blend One One
        Pass {
           
            CGPROGRAM
            #pragma vertex vert
            #include "UnityCG.cginc"

            struct v2f {
                V2F_POS_FOG;
                float4 uv : TEXCOORD0;
            };
           
            v2f vert (appdata_base v) {
                v2f o;
                PositionFog( v.vertex, o.pos, o.fog );
                float3 viewDir = normalize(ObjSpaceViewDir(v.vertex));
                o.uv = float4( dot(viewDir,v.normal), 0.5, 0.0, 1.0 );
                return o;
            }
            ENDCG

            SetTexture [_RampTex] {constantColor[_Color] combine texture * constant}
        }
    }
    Fallback Off

}

[edit] ShaderLab - X-Ray Shader for Unity 1.x

Shader "XRay" {

    Properties {
        _Color ("Tint (RGB)", Color) = (1,1,1,1)
        _RampTex ("Facing Ratio Ramp (RGB)", 2D) = "white" {}
    }
    SubShader {
        ZWrite Off
        Tags { "Queue" = "Transparent" }
        Blend One One
        Pass {
           
            CGPROGRAM
            // profiles arbfp1
            // vertex vert
            #include "UnityCG.cginc"

            struct v2f {
                V2F_POS_FOG;
                float4 uv : TEXCOORD0;
            };
           
            v2f vert (appdata_base v) {
                v2f o;
                PositionFog( v.vertex, o.pos, o.fog );
                float3 viewDir = normalize(ObjSpaceViewDir(v.vertex));
                o.uv = float4( dot(viewDir,v.normal), 0.5, 0.0, 1.0 );
                return o;
            }
            ENDCG

            SetTexture [_RampTex] {constantColor[_Color] combine texture * constant}
        }
    }
    Fallback Off

}
Personal tools