So, a while back I got some help with a transparent water shader (without refraction/reflection - indie license for now).
It works well, and since it’s using a gradient for the alpha it looks pretty good for what it is and allows me to use some old-school tricks like objects below water to fake reflectivity and so on.
Anyway, the weird part is that the shader affects other objects than the one it’s applied on. If I have an object with an alpha (diffuse+alpha) over the water plane, it too will become fully transparant at certain angles. It doesn’t follow the fade-in/out caused by the fresnel-gradient in the water material either, it just switches on/off.
If I disable the water shader or switch it to the standard (indie) water material, the problem goes away. So it seems this shader is affecting more of the drawing than just the water plane.
I have no experience with writing shaders myself, so I can’t really pinpoint the problem myself.
Any help would be much appreciated!
Here’s parts of the code, I can post it all if need be:
// -----------------------------------------------------------
// ARB fragment program
Subshader {
Tags { "Queue" = "Transparent" }
Blend SrcAlpha OneMinusSrcAlpha
ColorMask RGB
Pass {
CGPROGRAM
// profiles arbfp1
// vertex vert
// fragment frag
// fragmentoption ARB_precision_hint_fastest
// fragmentoption ARB_fog_exp2
sampler2D _BumpMap : register(s0);
sampler2D _ColorControl : register(s1);
half4 frag( v2f i ) : COLOR
{
half3 bump1 = tex2D( _BumpMap, i.bumpuv[0] ).rgb;
half3 bump2 = tex2D( _BumpMap, i.bumpuv[1] ).rgb;
half3 bump = bump1 + bump2 - 1;
half fresnel = dot( i.viewDir, bump );
half4 water = tex2D( _ColorControl, float2(fresnel,fresnel) );
half4 col;
col.rgb = lerp( water.rgb, _horizonColor.rgb, water.a);
//col.a = water.a*2+0.2;
return col;
}
ENDCG
SetTexture [_BumpMap] {}
SetTexture [_ColorControl] {}
}
}
// -----------------------------------------------------------
// Radeon 9000
Subshader {
Tags { "Queue" = "Transparent" }
Blend SrcAlpha OneMinusSrcAlpha
ColorMask RGB
Pass {
CGPROGRAM
// vertex vert
// just define 'vert' as a vertex shader, the code is included
// from the section on top
ENDCG
Program "" {
SubProgram {
Local 0, [_horizonColor]
"!!ATIfs1.0
StartConstants;
CONSTANT c0 = program.local[0];
EndConstants;
StartPrelimPass;
SampleMap r0, t0.str;
SampleMap r1, t1.str;
PassTexCoord r2, t2.str;
ADD r1, r0.bias, r1.bias; # bump = bump1 + bump2 - 1
DOT3 r2, r1, r2; # fresnel: dot (bump, viewer-pos)
EndPass;
StartOutputPass;
SampleMap r2, r2.str;
LERP r0.rgb, r2.a, c0, r2; # fade in reflection
MOV r0.a, r2.a;
EndPass;
"
}
}
SetTexture [_BumpMap] {}
SetTexture [_BumpMap] {}
SetTexture [_ColorControl] {}
}
}