- Home /
How can i add transparency to this shader?
Hello,
I have this shader that does not support alpha map. How can I modify it so I can adjust the alpha channel so as to be transparent (not cutout)?
Thanks!
Shader "Custom/WaterDistortion" {
Properties {
_MainTex ("Main texture", 2D) = "white" {}
_NoiseTex ("Noise texture", 2D) = "grey" {}
_Mitigation ("Distortion mitigation", Range(1, 30)) = 1
_SpeedX("Speed along X", Range(0, 5)) = 1
_SpeedY("Speed along Y", Range(0, 5)) = 1
}
SubShader {
Tags { "RenderType"="opaque" }
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex;
sampler2D _NoiseTex;
float _SpeedX;
float _SpeedY;
float _Mitigation;
struct v2f {
half4 pos : SV_POSITION;
half2 uv : TEXCOORD0;
};
fixed4 _MainTex_ST;
v2f vert(appdata_base v) {
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
return o;
}
half4 frag(v2f i) : COLOR {
half2 uv = i.uv;
half noiseVal = tex2D(_NoiseTex, uv).r;
uv.x = uv.x + noiseVal * sin(_Time.y * _SpeedX) / _Mitigation;
uv.y = uv.y + noiseVal * sin(_Time.y * _SpeedY) / _Mitigation;
return tex2D(_MainTex, uv);
}
ENDCG
}
}
FallBack "Diffuse"
}
,Hello,
I have this shader that does not support alpha map. How can I modify it so I can adjust the alpha channel so as to be transparent?
Thanks! Shader "Custom/WaterDistortion" { Properties { _MainTex ("Main texture", 2D) = "white" {} _NoiseTex ("Noise texture", 2D) = "grey" {}
_Mitigation ("Distortion mitigation", Range(1, 30)) = 1
_SpeedX("Speed along X", Range(0, 5)) = 1
_SpeedY("Speed along Y", Range(0, 5)) = 1
}
SubShader {
Tags { "RenderType"="opaque" }
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex;
sampler2D _NoiseTex;
float _SpeedX;
float _SpeedY;
float _Mitigation;
struct v2f {
half4 pos : SV_POSITION;
half2 uv : TEXCOORD0;
};
fixed4 _MainTex_ST;
v2f vert(appdata_base v) {
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
return o;
}
half4 frag(v2f i) : COLOR {
half2 uv = i.uv;
half noiseVal = tex2D(_NoiseTex, uv).r;
uv.x = uv.x + noiseVal * sin(_Time.y * _SpeedX) / _Mitigation;
uv.y = uv.y + noiseVal * sin(_Time.y * _SpeedY) / _Mitigation;
return tex2D(_MainTex, uv);
}
ENDCG
}
}
FallBack "Diffuse"
}
Answer by xibanya · Dec 27, 2019 at 09:36 PM
Assuming the texture you're using has alpha transparency, what you need also is add Blend SrcAlpha OneMinusSrcAlpha
under your tags to indicate you want to use the premultiplied transparency blend mode.
Also change your tags to "RenderType"="Transparent" "Queue"="Transparent"