Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 167 vs 168 for /trunk/assets/shaders/GLSL/water.glsl

Diff revisions: vs.
  @@ -1,106 +1,100 @@
1 1 -- Vertex
2 2 #include "vboInputData.vert"
3 - out vec3 vPixToLight;
4 - out vec3 vPixToEye;
5 - out vec4 _vertexMV;
6 - out vec4 vVertexFromLightView;
3 + out vec3 _pixToLight;
4 + out vec3 _pixToEye;
7 5
8 6 uniform vec3 water_bb_min;
9 - uniform vec3 water_bb_max;
7 + uniform vec3 water_bb_diff;
10 8 uniform mat4 dvd_lightProjectionMatrices[MAX_SHADOW_CASTING_LIGHTS];
11 9
12 10 void main(void)
13 11 {
14 12 computeData();
15 13
14 + vec3 vertex = dvd_Vertex.xyz;
16 15
17 - _vertexMV = dvd_Vertex;
18 - vec3 vPositionNormalized = (dvd_Vertex.xyz - water_bb_min.xyz) / (water_bb_max.xyz - water_bb_min.xyz);
16 + vec3 vPositionNormalized = (vertex - water_bb_min) / water_bb_diff;
19 17 _texCoord = vPositionNormalized.xz;
20 18
21 - vPixToLight = -(gl_LightSource[0].position.xyz);
22 - vPixToEye = -vec3(dvd_ModelViewMatrix * dvd_Vertex);
19 + _pixToLight = -(gl_LightSource[0].position.xyz);
20 + _pixToEye = -vec3(dvd_ModelViewMatrix * dvd_Vertex);
23 21
24 - vVertexFromLightView = dvd_lightProjectionMatrices[0] * dvd_Vertex;
25 22 gl_Position = dvd_ModelViewProjectionMatrix * dvd_Vertex;
26 23
27 24 }
28 25
29 26 -- Fragment
30 27
31 - uniform ivec2 screenDimension;
32 - uniform float noise_tile;
33 - uniform float noise_factor;
34 - uniform float time;
35 - uniform float water_shininess;
28 + uniform vec2 _noiseTile;
29 + uniform vec2 _noiseFactor;
30 + uniform float _waterShininess;
31 + uniform float _transparencyBias;
36 32 uniform bool underwater;
37 - uniform mat4 material;
38 - uniform mat4 dvd_ModelViewMatrix;
39 33 uniform sampler2D texWaterReflection;
40 34 uniform sampler2D texWaterNoiseNM;
41 35
42 - in vec3 vPixToLight;
43 - in vec3 vPixToEye;
44 - in vec4 _vertexMV;
45 - in vec4 vVertexFromLightView;
36 + //built-in uniforms
37 + uniform mat4 material;
38 + uniform float dvd_time;
39 + uniform mat4 dvd_ModelViewMatrix;
40 + uniform mat3 dvd_NormalMatrix;
41 + uniform ivec2 screenDimension;
42 +
43 + in vec3 _pixToLight;
44 + in vec3 _pixToEye;
46 45 in vec2 _texCoord;
47 46 out vec4 _colorOut;
48 - ///Global NDotL, basically
49 - float iDiffuse;
50 47
51 48 #include "fog.frag"
52 49 #include "shadowMapping.frag"
53 50
54 - float Fresnel(vec3 incident, vec3 normal, float bias, float power);
51 + float Fresnel(in vec3 incident, in vec3 normal, in float bias, in float power);
55 52
53 + const float shadow_distance_max = 200.0;
56 54 void main (void)
57 55 {
58 - float time2 = time * 0.00001;
59 - vec2 uvNormal0 = _texCoord*noise_tile;
60 - uvNormal0.s += time2;
61 - uvNormal0.t += time2;
62 - vec2 uvNormal1 = _texCoord*noise_tile;
56 + float time2 = dvd_time * 0.00001;
57 + vec2 noiseUV = _texCoord * _noiseTile.x;
58 + vec2 uvNormal0 = noiseUV + time2;
59 + vec2 uvNormal1 = noiseUV;
60 + uvNormal1.t = uvNormal0.t;
63 61 uvNormal1.s -= time2;
64 - uvNormal1.t += time2;
65 62
66 63 vec3 normal0 = texture(texWaterNoiseNM, uvNormal0).rgb * 2.0 - 1.0;
67 64 vec3 normal1 = texture(texWaterNoiseNM, uvNormal1).rgb * 2.0 - 1.0;
68 65 vec3 normal = normalize(normal0+normal1);
69 66
70 67 vec2 uvReflection = vec2(gl_FragCoord.x/screenDimension.x, gl_FragCoord.y/screenDimension.y);
71 - vec2 uvFinal = uvReflection.xy + noise_factor*normal.xy;
72 - if(!underwater){
73 - uvFinal.x = 1.0 - uvFinal.x;
74 - }
75 - vec4 cDiffuse = texture(texWaterReflection, uvFinal);
68 + vec2 uvFinal = (_noiseFactor * normal) + uvReflection;
69 +
76 70
77 - vec3 N = normalize(vec3(dvd_ModelViewMatrix * vec4(normal.x, normal.z, normal.y, 0.0)));
78 - vec3 L = normalize(vPixToLight);
79 - vec3 V = normalize(vPixToEye);
80 - float iSpecular = pow(clamp(dot(reflect(-L, N), V), 0.0, 1.0), water_shininess);
81 - iDiffuse = max(dot(L, N), 0.0);
71 + vec3 N = normalize(dvd_NormalMatrix * normal);
72 + vec3 L = normalize(_pixToLight);
73 + vec3 V = normalize(_pixToEye);
74 + float iSpecular = pow(clamp(dot(normalize(-reflect(L, N)), V), 0.0, 1.0), _waterShininess);
75 +
82 76 //vec4 cAmbient = gl_LightSource[0].ambient * material[0];
83 - vec4 cSpecular = gl_LightSource[0].specular * material[2] * iSpecular;
84 - /////////////////////////
85 - // SHADOW MAPS
86 - float distance_max = 200.0;
87 - float shadow = 1.0;
88 - float distance = length(vPixToEye);
89 - if(distance < distance_max) {
90 - applyShadowDirectional(iDiffuse, 0, shadow);
91 - }
92 - /////////////////////////
77 + // add Diffuse
78 + _colorOut.rgb = texture(texWaterReflection, uvFinal).rgb;
79 + // add Specular
80 + _colorOut.rgb += vec4(gl_LightSource[0].specular * material[2] * iSpecular).rgb;
93 81
94 - vec4 color = (0.2 + 0.8 * shadow) * cDiffuse + shadow * cSpecular;
95 - // FRESNEL ALPHA
96 - color.a = Fresnel(V, N, 0.5, 2.0);
97 - applyFog(color);
82 + // shadow mapping
83 +
84 + if(length(_pixToEye) < shadow_distance_max) {
85 + float shadow = 1.0;
86 + applyShadowDirectional(max(dot(L, N), 0.0), 0, shadow);
87 + // add Shadow
88 + _colorOut.rgb *= (0.2 + 0.8 * shadow);
89 + }
90 + // add Fog
91 + applyFog(_colorOut);
92 + // calculate Transparency
93 + _colorOut.a = Fresnel(V, N, _transparencyBias, 2.0); //< Fresnel alpha
98 94
99 - _colorOut = color;
100 95 }
101 96
102 -
103 - float Fresnel(vec3 incident, vec3 normal, float bias, float power){
97 + float Fresnel(in vec3 incident, in vec3 normal, in float bias, in float power){
104 98 float scale = 1.0 - bias;
105 99 return bias + pow(1.0 - dot(incident, normal), power) * scale;
106 100 }