Skip to content

Instantly share code, notes, and snippets.

@ialex32x
Created June 21, 2013 07:19
Show Gist options
  • Save ialex32x/5829466 to your computer and use it in GitHub Desktop.
Save ialex32x/5829466 to your computer and use it in GitHub Desktop.
Unity3D shader scrabble
/*
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
uniform sampler2D _Ramp;
uniform half4 _Color;
struct v2f {
float4 pos : SV_POSITION;
float4 uv : TEXCOORD0;
};
v2f vert (appdata_base v) {
v2f o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
float3 viewDir = normalize(ObjSpaceViewDir(v.vertex));
o.uv = float4( dot(viewDir,v.normal), 0.5, 0.0, 1.0 );
return o;
}
half4 frag(v2f v) : COLOR {
return tex2D(_Ramp, v.uv.xy) * _Color;
}
ENDCG
*/
@ialex32x
Copy link
Author

Shader "XRay" {
    Properties {
        _MainTex ("Main (RGB)", 2D) = "white" {}
        _Ramp ("Ramp (RGB)", 2D) = "white" {}
        _Color ("Tint (RGB)", Color) = (1,1,1,1)
    }
    SubShader {
        Tags { "Queue"="Geometry+1" "RenderType"="Opaque" }
        Pass {
            blend one one
            ztest greater 
            zwrite off

            settexture[_Ramp] {
                combine texture
            }
        }
        Pass {
            settexture[_MainTex] {
                combine texture
            }
        }
    }
    Fallback Off
}

@ialex32x
Copy link
Author

// *****************
// compute luminance
// *****************
float3 rgb2lum = float3(0.30, 0.59, 0.11);

luminance = dot(col.rgb, rgb2lum);

// *****************
// TRANSFORM_TEX
// *****************

define TRANSFORM_TEX(tex,name) (tex.xy * name##_ST.xy + name##_ST.zw)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment