water.ps [water fog fix skyloader]

Created Diff never expires
4 removals
Lines
Total
Removed
Words
Total
Removed
To continue using this feature, upgrade to
Diffchecker logo
Diffchecker Pro
131 lines
16 additions
Lines
Total
Added
Words
Total
Added
To continue using this feature, upgrade to
Diffchecker logo
Diffchecker Pro
141 lines
#include "common.h"
#include "common.h"


struct vf
struct vf
{
{
float4 hpos : POSITION ;
float4 hpos : POSITION ;
float2 tbase : TEXCOORD0 ; // base
float2 tbase : TEXCOORD0 ; // base
float2 tnorm0 : TEXCOORD1 ; // nm0
float2 tnorm0 : TEXCOORD1 ; // nm0
float2 tnorm1 : TEXCOORD2 ; // nm1
float2 tnorm1 : TEXCOORD2 ; // nm1
half3 M1 : TEXCOORD3 ;
half3 M1 : TEXCOORD3 ;
half3 M2 : TEXCOORD4 ;
half3 M2 : TEXCOORD4 ;
half3 M3 : TEXCOORD5 ;
half3 M3 : TEXCOORD5 ;
half3 v2point : TEXCOORD6 ;
half3 v2point : TEXCOORD6 ;
#ifdef USE_SOFT_WATER
#ifdef NEED_SOFT_WATER
float4 tctexgen : TEXCOORD7 ;
float4 tctexgen : TEXCOORD7 ;
#endif // USE_SOFT_WATER
#endif // NEED_SOFT_WATER
half4 c0 : COLOR0 ;
half4 c0 : COLOR0 ;
// float fog : FOG ;
float fog : FOG ;
};
};


uniform sampler2D s_nmap;
uniform sampler2D s_nmap;
uniform samplerCUBE s_env0;
uniform samplerCUBE s_env0;
uniform samplerCUBE s_env1;
uniform samplerCUBE s_env1;
uniform sampler2D s_leaves;
uniform sampler2D s_leaves;


#if defined(USE_SOFT_WATER) && defined(NEED_SOFT_WATER)
#if defined(USE_SOFT_WATER) && defined(NEED_SOFT_WATER)
half3 water_intensity;
uniform half3 water_intensity;
#endif // defined(USE_SOFT_WATER) && defined(NEED_SOFT_WATER)
#endif // defined(USE_SOFT_WATER) && defined(NEED_SOFT_WATER)


////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Pixel
// Pixel
/*
/*
half4 main ( v2p I ) : COLOR
half4 main ( v2p I ) : COLOR
{
{


half4 t_base = tex2D (s_base,I.tbase);
half4 t_base = tex2D (s_base,I.tbase);
half3 t_env = texCUBE (s_env, I.tenv);
half3 t_env = texCUBE (s_env, I.tenv);


half3 refl = lerp (t_env,t_base,I.c0.a);
half3 refl = lerp (t_env,t_base,I.c0.a);
half3 color = lerp (refl, t_base,t_base.a);
half3 color = lerp (refl, t_base,t_base.a);
half3 final = color*I.c0*2 ;
half3 final = color*I.c0*2 ;


half alpha_shift = saturate(.5-I.c0.a);
half alpha_shift = saturate(.5-I.c0.a);
half alpha_add = alpha_shift*alpha_shift;
half alpha_add = alpha_shift*alpha_shift;
half alpha = t_base.a;
half alpha = t_base.a;
// out
// out
return half4 (final, t_base.a ); //t_base.a + (1-I.c0.a)); //half4 (final, t_base.a );
return half4 (final, t_base.a ); //t_base.a + (1-I.c0.a)); //half4 (final, t_base.a );
}
}
*/
*/


half4 main( vf I ) : COLOR
half4 main( vf I ) : COLOR
{
{
half4 base = tex2D (s_base,I.tbase);
half4 base = tex2D (s_base,I.tbase);
half3 n0 = tex2D (s_nmap,I.tnorm0);
half3 n0 = tex2D (s_nmap,I.tnorm0);
half3 n1 = tex2D (s_nmap,I.tnorm1);
half3 n1 = tex2D (s_nmap,I.tnorm1);
half3 Navg = n0 + n1 - 1;
half3 Navg = n0 + n1 - 1;


half3 Nw = mul (half3x3(I.M1, I.M2, I.M3), Navg);
half3 Nw = mul (half3x3(I.M1, I.M2, I.M3), Navg);
Nw = normalize (Nw);
Nw = normalize (Nw);
half3 v2point = normalize (I.v2point);
half3 v2point = normalize (I.v2point);
half3 vreflect= reflect(v2point, Nw);
half3 vreflect= reflect(v2point, Nw);
vreflect.y= vreflect.y*2-1; // fake remapping
vreflect.y= vreflect.y*2-1; // fake remapping
/* // true remapping. Slow.
/* // true remapping. Slow.
half3 vreflectabs = abs(vreflect);
half3 vreflectabs = abs(vreflect);
half vreflectmax = max( vreflectabs.x, max(vreflectabs.y, vreflectabs.z));
half vreflectmax = max( vreflectabs.x, max(vreflectabs.y, vreflectabs.z));
vreflect /= vreflectmax;
vreflect /= vreflectmax;
if (vreflect.y<0.99)
if (vreflect.y<0.99)
vreflect.y = vreflect.y*2-1;
vreflect.y = vreflect.y*2-1;
*/
*/


half3 env0 = texCUBE (s_env0, vreflect);
half3 env0 = texCUBE (s_env0, vreflect);
half3 env1 = texCUBE (s_env1, vreflect);
half3 env1 = texCUBE (s_env1, vreflect);
half3 env = lerp (env0,env1,L_ambient.w);
half3 env = lerp (env0,env1,L_ambient.w);
env *= env*2;
env *= env*2;


half fresnel = saturate (dot(vreflect,v2point));
half fresnel = saturate (dot(vreflect,v2point));
half power = pow(fresnel,9);
half power = pow(fresnel,9);
half amount = 0.15h+0.25h*power; // 1=full env, 0=no env
half amount = 0.15h+0.25h*power; // 1=full env, 0=no env


half3 c_reflection = env*amount;
half3 c_reflection = env*amount;
half3 final = lerp(c_reflection,base.rgb,base.a);
half3 final = lerp(c_reflection,base.rgb,base.a);


final *= I.c0*2;
final *= I.c0*2;


// tonemap
// tonemap
#ifdef USE_VTF
#ifdef USE_VTF
// final *= I.c0.w ;
// final *= I.c0.w ;
#else
#else
// final *= tex2D (s_tonemap,I.tbase).x ; // any TC - OK
// final *= tex2D (s_tonemap,I.tbase).x ; // any TC - OK
#endif
#endif


#ifdef NEED_SOFT_WATER
#ifdef NEED_SOFT_WATER


half alpha = 0.75h+0.25h*power; // 1=full env, 0=no env
half alpha = 0.75h+0.25h*power; // 1=full env, 0=no env


#ifdef USE_SOFT_WATER
#ifdef USE_SOFT_WATER
// Igor: additional depth test
// Igor: additional depth test
half4 _P = tex2Dproj( s_position, I.tctexgen);
half4 _P = tex2Dproj( s_position, I.tctexgen);
half waterDepth = _P.z-I.tctexgen.z;
half waterDepth = _P.z-I.tctexgen.z;


// water fog
// water fog
half fog_exp_intens = -4.0h;
half fog_exp_intens = -4.0h;
float fog = 1-exp(fog_exp_intens*waterDepth);
float fog = 1-exp(fog_exp_intens*waterDepth);
half3 Fc = half3( 0.1h, 0.1h, 0.1h) * water_intensity.r;
half3 Fc = half3( 0.1h, 0.1h, 0.1h) * water_intensity.r;
// half3 Fc = lerp(half3( 1.0h, 0.0h, 0.0h), half3( 0.0h, 1.0h, 0.0h), water_intensity.r);
// half3 Fc = lerp(half3( 1.0h, 0.0h, 0.0h), half3( 0.0h, 1.0h, 0.0h), water_intensity.r);
// half3 Fc = half3( 0.1h, 0.1h, 0.2h);
// half3 Fc = half3( 0.1h, 0.1h, 0.2h);
// half3 Fc = half3( 1.0h, 0.0h, 0.0h);
// half3 Fc = half3( 1.0h, 0.0h, 0.0h);
final = lerp (Fc, final, alpha);
final = lerp (Fc, final, alpha);


alpha = min(alpha, saturate(waterDepth));
alpha = min(alpha, saturate(waterDepth));


alpha = max (fog, alpha);
alpha = max (fog, alpha);


// Leaves
// Leaves
half4 leaves = tex2D(s_leaves, I.tbase);
half4 leaves = tex2D(s_leaves, I.tbase);
leaves.rgb *= water_intensity.r;
leaves.rgb *= water_intensity.r;
half calc_cos = -dot(float3(I.M1.z, I.M2.z, I.M3.z), normalize(v2point));
half calc_cos = -dot(float3(I.M1.z, I.M2.z, I.M3.z), normalize(v2point));
half calc_depth = saturate(waterDepth*calc_cos);
half calc_depth = saturate(waterDepth*calc_cos);
half fLeavesFactor = smoothstep(0.025, 0.05, calc_depth );
half fLeavesFactor = smoothstep(0.025, 0.05, calc_depth );
fLeavesFactor *= smoothstep(0.1, 0.075, calc_depth );
fLeavesFactor *= smoothstep(0.1, 0.075, calc_depth );
final = lerp(final, leaves, leaves.a*fLeavesFactor);
final = lerp(final, leaves, leaves.a*fLeavesFactor);
alpha = lerp(alpha, leaves.a, leaves.a*fLeavesFactor);
alpha = lerp(alpha, leaves.a, leaves.a*fLeavesFactor);


#endif // USE_SOFT_WATER
#endif // USE_SOFT_WATER


return half4 (final, alpha*I.c0.a*I.c0.a ) ;
// Fogging
final = lerp(fog_color, final, I.fog);
alpha *= I.fog*I.fog;

return half4 (final, alpha ) ;


#else // NEED_SOFT_WATER
#else // NEED_SOFT_WATER


return half4 (final, 1 ) ;
// Fogging
final = lerp(fog_color, final, I.fog);
return float4 (final, I.fog*I.fog ) ;


#endif // NEED_SOFT_WATER
#endif // NEED_SOFT_WATER
}
}