Hi, I’m working on a shader that sets the fragment color from a 1D texture based on a mask. The 1D texture is a gradient from transparent to red, to yellow to white, and I have tested it applying it directly to a Unity object using the transparent diffuse shader and it works, I see a sphere with a transparent part. The problem is that when using my shader the parts that are supposed to be transparent are black, here’s my code, does anyone know what I’m doing wrong?
Shader “Corpus/Spots” {
Properties {
_MainTex(“Base”, 2D) = “white” {}
_Gradient(“Gradient”, 2D) = “white” {}
_NoiseO(“Noise1”, 2D) = “white” {}
_NoiseT(“Noise2”, 2D) = “white” {}
}
SubShader {
Tags { “RenderType”=“TransparentCutout” }
LOD 200
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include “UnityCG.cginc”
float Luminance( float4 Color ){
return 0.3 * Color.r + 0.6 * Color.g + 0.1 * Color.b;
}
struct v2f {
float4 pos : SV_POSITION;
float2 uv_MainTex : TEXCOORD0;
};
float4 _MainTex_ST;
v2f vert(appdata_base v) {
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv_MainTex = TRANSFORM_TEX(v.texcoord, _MainTex);
return o;
}
sampler2D _MainTex;
sampler2D _Gradient;
sampler2D _NoiseO;
sampler2D _NoiseT;
float4 frag(v2f IN) : COLOR {
half4 nO = tex2D (_NoiseO, IN.uv_MainTex);
half4 nT = tex2D (_NoiseT, IN.uv_MainTex);
float4 turbulence = nO + nT;
float lum = Luminance(turbulence);
half4 c = tex2D (_MainTex, IN.uv_MainTex);
if (lum >= 1.0f){
float pos = lum - 1.0f;
if( pos > 0.98f ) pos = 0.98f;
if( pos < 0.02f ) pos = 0.02f;
float2 texCord = (pos, pos);
half4 turb = tex2D (_Gradient, texCord);
return turb;
}
else return c;
}
ENDCG
}
}
}