Hi Everyone,
I’d like to take the RGB values of _MainTex and put them into the Alpha channel (adding them up and dividing by 3)
The code below is for a Transparency Projector (from http://forum.unity3d.com/threads/35808-Projecting-a-hole) - it uses the alpha to cut a hole in a mesh.
The input texture I’d like to use has no alpha, hence why I need to change things a bit…
Original code:
Shader "Transparency Projector" {
Properties {
_MainTex ("Base (RGB)", 2D) = "" {TexGen ObjectLinear}
}
SubShader
{
Lighting On
Tags {"Queue" = "Geometry+10"}
Pass
{
ColorMask A
SetTexture[_MainTex] {
Matrix[_Projector]
}
}
}
}
I’ve tried adding
CGPROGRAM
#pragma vertex vert_img
#pragma fragment frag
#include "UnityCG.cginc"
uniform sampler2D _MainTex;
float4 frag(v2f_img i) : COLOR {
fixed4 tex = tex2D(_MainTex, i.uv);
float newAlpha = (tex.r+tex.g+tex.g)/3;
return fixed4(0.0,0.0,0.0,newAlpha);
}
ENDCG
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
… to the pass. This does the trick (converts texture to alpha) but the texture no longer acts as a projector (it doesnt move and just apples the texture all surfaces). Not certain why this is.
Any help would be greatly appreciated. Total novice when it comes to shaders