Simple faked highly reflective crystal

Here is a shader which aims to give the effect of black crystal. Assign a grayscale image (dark with occasional highlight) to the main texture slot and adjust brightness.

Shader ignores original mapping coordinates of mesh and performs a type of spherical mapping (with help from: [Cg] Environment Maps - Ogre Forums)

I am using this shader for the windows of a ship!

Shader "Custom/Black Crystal" {
Properties {
    _MainTex ("Main Texture", 2D) = "black" {}
    _Brightness ("Brightness", Range(0, 1)) = 1
}
SubShader {
    Tags { "Queue"="Geometry" }
    Lighting Off
    
    Pass {
    CGPROGRAM
        #pragma vertex vert
        #pragma fragment frag
        
        #include "UnityCG.cginc"
        
        struct appdata {
            half4 vertex    : POSITION;
            half3 normal    : NORMAL;
        };
        
        struct v2f {
            half4 pos        : SV_POSITION;
            half2 uv        : TEXCOORD0;
        };
        
        sampler2D _MainTex;
        half _Brightness;
        
        half4 _MainTex_ST;

        v2f vert(appdata v) {
            v2f o;
            o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
            
            half3 normalViewSpace = mul((float3x3)UNITY_MATRIX_MVP, v.normal);
            o.uv = normalViewSpace - o.pos.xy / 10;
            
            return o;
        }
        
        half4 frag(v2f i) : COLOR {
            half4 outColor = tex2D(_MainTex, half2(0.5, -0.5) * i.uv.xy * half2(0.75, 0.75));
            return outColor * _Brightness;
        }
    ENDCG
    }
}
}
1 Like

This is exactly what I was looking for! Thanks so much for sharing it, brother.

Thanks! That’s pretty neat. I should save this somewhere in case I want to use it…