Color waves

parent 39e5d48f
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
// This file is part of SWE_CUDA (see file SWE_Block.cu for details). // This file is part of SWE_CUDA (see file SWE_Block.cu for details).
// //
// Copyright (C) 2010,2011 Tobias Schnabel // Copyright (C) 2010,2011 Tobias Schnabel
// Copyright (C) 2012 Sebastian Rettenberger
// //
// SWE_CUDA is free software: you can redristribute it and/or modify // SWE_CUDA is free software: you can redristribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
...@@ -17,9 +18,12 @@ ...@@ -17,9 +18,12 @@
// along with SWE_CUDA. If not, see <http://www.gnu.org/licenses/>. // along with SWE_CUDA. If not, see <http://www.gnu.org/licenses/>.
// ===================================================================== // =====================================================================
varying vec3 V; #define MAX_H 0.5
#define USE_BRIGHTNESS 0
varying vec3 N; varying vec3 N;
varying vec4 ambient; varying vec4 ambient;
varying vec4 worldCoordinates;
/* Shading of water surfaces with fresnel effect */ /* Shading of water surfaces with fresnel effect */
...@@ -28,6 +32,10 @@ void main() ...@@ -28,6 +32,10 @@ void main()
// Helper variable for color // Helper variable for color
vec4 color = ambient; vec4 color = ambient;
// Calculate vector from vertex to the eye,
// which resides at (0,0,0)
vec3 V = -vec3(gl_ModelViewMatrix*worldCoordinates);
// Get normal and view vector // Get normal and view vector
vec3 view = normalize(V); vec3 view = normalize(V);
vec3 normal = normalize(N); ; vec3 normal = normalize(N); ;
...@@ -41,7 +49,23 @@ void main() ...@@ -41,7 +49,23 @@ void main()
// Combine color with fresnel factor // Combine color with fresnel factor
color += gl_LightSource[0].specular * fresnelFactor; color += gl_LightSource[0].specular * fresnelFactor;
color = mix(color, vec4(0.2, 0.4, 0.9, 1.0), 0.2);
// Scale and limit height
float h = worldCoordinates.y / 5.0;
if (h > MAX_H)
h = MAX_H;
else if (h < -MAX_H)
h = -MAX_H;
#if (USE_BRIGHTNESS == 1)
// brightness depending on height
vec4 blue = vec4(0.2+h, 0.4+h, 0.9+h, 1.0);
#else // USE_BRIGHTNESS
// color depending on height
vec4 blue = 2 * vec4(0.5+h, 0.5-abs(h), 0.5-h, abs(h));
blue = mix(blue, vec4(0.2, 0.4, 0.9, 1.0), 0.3);
#endif // USE_BRIGHTNESS
color = mix(color, blue, 0.7);
// Set constant transparency // Set constant transparency
gl_FragColor = vec4(color.xyz, 0.7); gl_FragColor = vec4(color.xyz, 0.7);
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
// This file is part of SWE_CUDA (see file SWE_Block.cu for details). // This file is part of SWE_CUDA (see file SWE_Block.cu for details).
// //
// Copyright (C) 2010,2011 Tobias Schnabel // Copyright (C) 2010,2011 Tobias Schnabel
// Copyright (C) 2012 Sebastian Rettenberger
// //
// SWE_CUDA is free software: you can redristribute it and/or modify // SWE_CUDA is free software: you can redristribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
...@@ -18,8 +19,8 @@ ...@@ -18,8 +19,8 @@
// ===================================================================== // =====================================================================
varying vec3 N; varying vec3 N;
varying vec3 V;
varying vec4 ambient; varying vec4 ambient;
varying vec4 worldCoordinates;
/* Shading of water surfaces with fresnel effect */ /* Shading of water surfaces with fresnel effect */
...@@ -32,9 +33,8 @@ void main() ...@@ -32,9 +33,8 @@ void main()
// Transform our normal into eye space // Transform our normal into eye space
N = normalize(gl_NormalMatrix * gl_Normal); N = normalize(gl_NormalMatrix * gl_Normal);
// Calculate vector from vertex to the eye, // Save world coordinates
// which resides at (0,0,0) worldCoordinates = gl_Vertex;
V = -vec3(gl_ModelViewMatrix*gl_Vertex);
// Compute vertex position via internal transform function // Compute vertex position via internal transform function
gl_Position = ftransform(); gl_Position = ftransform();
......
...@@ -147,7 +147,7 @@ class SWE_SplashingPoolScenario : public SWE_Scenario { ...@@ -147,7 +147,7 @@ class SWE_SplashingPoolScenario : public SWE_Scenario {
}; };
float getWaterHeight(float x, float y) { float getWaterHeight(float x, float y) {
return 260.0f+(1.0f-(x+y)/200); return 250.0f+(5.0f-(x+y)/200);
}; };
virtual float endSimulation() { return (float) 15; }; virtual float endSimulation() { return (float) 15; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment