File: hpl1_refract_water.fragment

package info (click to toggle)
scummvm 2.9.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 450,580 kB
  • sloc: cpp: 4,299,825; asm: 28,322; python: 12,901; sh: 11,302; java: 9,289; xml: 7,895; perl: 2,639; ansic: 2,465; yacc: 1,670; javascript: 1,020; makefile: 933; lex: 578; awk: 275; objc: 82; sed: 11; php: 1
file content (58 lines) | stat: -rw-r--r-- 1,692 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright 2006-2010 (C) - Frictional Games
//
// This file is part of HPL1 Engine
//
// For conditions of distribution and use, see copyright notice in LICENSE-shaders
//

///////////////////////////////////////////////////////
/// REFRACTION FRAGMENT PROGRAM /////////////////
///////////////////////////////////////////////////////

in vec2 vUv; //in object space
in vec3 vNormal;
in vec3 vEyePos;
in vec4 vColor;

OUTPUT

uniform sampler2DRect tex0; //screenMap
uniform sampler2D tex1; //refractMap
uniform sampler2D tex2; //diffuseMap

uniform vec2 screenSize;
uniform float scale;
uniform float t;

void main()
{
	//t *= 1;
	vec2 uv_offset1 = vUv;
	uv_offset1.x += sin(t*0.8 + vUv.y*10.0)*0.04;
	uv_offset1.y += sin(t*0.8 + uv_offset1.x*10.0)*0.04;

	vec3 offset1 = ((texture(tex1, uv_offset1)*2.0) - vec4(1.0)).xyz;

	vec2 uv_offset2 = vUv;
	uv_offset2.x += sin(t*-2.6 + vUv.y*12.0)*0.03;
	uv_offset2.y += sin(t*-2.6 + uv_offset2.x*12.0)*0.03;

	vec3 offset2 = ((texture(tex1, uv_offset2)*2.0) - vec4(1.0)).xyz;
	offset2.xy = -offset2.xy;

	vec3 offset = normalize(offset1*0.7 + offset2*0.3);

	//float fresnel = saturate(dot(normalize(vEyePos), normalize(vNormal)));
	//fresnel = (fresnel + 0.2)*0.8;

	vec3 waterColor = texture(tex2, uv_offset1).xyz;

	vec4 screenColor = texture2DRect(tex0, gl_FragCoord.xy + offset.xy * -scale);
	if(screenColor.w < 0.5) screenColor = texture2DRect(tex0, gl_FragCoord.xy);

	outColor.xyz = screenColor.xyz * waterColor;

	//outColor.y = uv.y+1 + uv_offset1.y;
	outColor.xyz *= clamp(dot(vec3(1.0/3.0, 1.0/3.0, 1.0/3.0), offset), 0.0, 1.0)*0.5 + 0.5;
	outColor.xyz += pow(clamp(dot(vec3(1.0/3.0, 1.0/3.0, 1.0/3.0), offset), 0.0, 1.0), 8.0)*5.0;
}