All pastes #488390 Raw Edit

Debris

public text v1 · immutable
·published 2007-05-14 23:49 UTC
rendered paste body

//#version 110

uniform sampler2D ReflectionTexture;
uniform sampler2D RefractionTexture;
uniform sampler2D DudvMap;
uniform sampler2D NormalMap;

#ifdef USE_FEATURE_TEXTURE
uniform sampler2D FeatureTexture;
#endif

#ifdef USE_TEXTURE
uniform sampler2D	Texture;
#endif

uniform vec4 WaterOffset;
varying vec3 ViewVector;
varying vec4 EyeCoords;

#if defined(NO_HALF_TYPES) || !defined(__GLSL_CG_DATA_TYPES)
# define half float
# define half2 vec2
# define half3 vec3
# define half4 vec4
#endif

#ifndef WATER_COLOR
#define WATER_COLOR vec4( 0.6, 0.7, 1.0, 1.0 )
#endif

float saturate( float x )
{
	return clamp( x, 0.0, 1.0 );
}

float fresnel( vec3 Normal, vec3 EyeVector, vec3 ScaleBiasPower )
{
	return ScaleBiasPower.x * pow( saturate( dot( -Normal, EyeVector ) ), ScaleBiasPower.z ) + 

ScaleBiasPower.y;
}

void main( void )
{
#ifdef USE_FEATURE_TEXTURE
	float Alpha = texture2D( FeatureTexture, gl_TexCoord[ 0 ].xy ).a;
#endif

	#vec2 ScreenCoords = (EyeCoords.xy / EyeCoords.w) * 0.5 + 0.5;
	#const float kShine = 128.0;
	#const float kDistortion = 0.025;
	#const float kRefraction = 0.018;

	#vec4 distOffset = texture2D( DudvMap, ( gl_TexCoord[ 1 ].xy + WaterOffset.xy )*0.25 ) * 

kDistortion;
	vec4 dudvColor = texture2D( DudvMap, gl_TexCoord[ 1 ].xy - WaterOffset.xy + distOffset.xy );
	dudvColor = normalize(dudvColor * 2.0 - 1.0) * kRefraction;

	vec3 Normal = normalize( texture2D( NormalMap, vec2(gl_TexCoord[ 1 ] - WaterOffset + 

distOffset)).xyz * 2.0 - 1.0 );
	
	#float Fresnel = fresnel( Normal, normalize( ViewVector ), vec3( 1.0, 0.0, 0.5 ) );
	
	// Get the actual texture coords for refraction and reflection
	vec2 ClipCoords = ScreenCoords;
	
#ifdef USE_FEATURE_TEXTURE
	#dudvColor.st *= Alpha;
#endif

	#ClipCoords += dudvColor.st;
	#ClipCoords = clamp( ClipCoords, 0.0, 1.0 );

	// Get the texture values
	#vec4 RefractionColor  = texture2D( RefractionTexture, ClipCoords );
	#vec4 ReflectionColor  = texture2D( ReflectionTexture, ClipCoords );	

	
	#gl_FragColor = mix( ReflectionColor, RefractionColor, Fresnel );
	#gl_FragColor *= WATER_COLOR;
	gl_FragColor = vec4( 0.0, 0.0, 1.0, 1.0 )
#ifdef USE_TEXTURE
	gl_FragColor *= texture2D( Texture, gl_TexCoord[ 2 ].st + WaterOffset.xy );
#endif
}