aboutsummaryrefslogtreecommitdiff
path: root/client/shaders/water_surface_shader
diff options
context:
space:
mode:
authorRealBadAngel <maciej.kasatkin@o2.pl>2015-06-14 21:13:36 +0200
committerRealBadAngel <maciej.kasatkin@o2.pl>2015-06-14 21:13:36 +0200
commit43fcfbfe05578d7471d40c8c087fd04e24b264b5 (patch)
tree7b26cc3c87f3255d36bfdee21f1f65785d274bef /client/shaders/water_surface_shader
parentd105bf27dd9f570754f470c3bb6a46369c4aaaad (diff)
downloadminetest-43fcfbfe05578d7471d40c8c087fd04e24b264b5.tar.gz
minetest-43fcfbfe05578d7471d40c8c087fd04e24b264b5.tar.bz2
minetest-43fcfbfe05578d7471d40c8c087fd04e24b264b5.zip
Improved parallax mapping. Generate heightmaps on the fly.
Diffstat (limited to 'client/shaders/water_surface_shader')
-rw-r--r--client/shaders/water_surface_shader/opengl_fragment.glsl24
-rw-r--r--client/shaders/water_surface_shader/opengl_vertex.glsl17
2 files changed, 21 insertions, 20 deletions
diff --git a/client/shaders/water_surface_shader/opengl_fragment.glsl b/client/shaders/water_surface_shader/opengl_fragment.glsl
index 6dc96eb48..386f77486 100644
--- a/client/shaders/water_surface_shader/opengl_fragment.glsl
+++ b/client/shaders/water_surface_shader/opengl_fragment.glsl
@@ -14,7 +14,7 @@ varying vec3 tsEyeVec;
varying vec3 lightVec;
varying vec3 tsLightVec;
-bool normalTexturePresent = false;
+bool normalTexturePresent = false;
const float e = 2.718281828459;
const float BS = 10.0;
@@ -40,15 +40,15 @@ void main (void)
vec4 bump;
vec2 uv = gl_TexCoord[0].st;
bool use_normalmap = false;
-
+
#ifdef USE_NORMALMAPS
- if (texture2D(useNormalmap,vec2(1.0,1.0)).r > 0.0){
+ if (texture2D(useNormalmap,vec2(1.0,1.0)).r > 0.0) {
normalTexturePresent = true;
}
#endif
#ifdef ENABLE_PARALLAX_OCCLUSION
- if (normalTexturePresent){
+ if (normalTexturePresent) {
vec3 tsEye = normalize(tsEyeVec);
float height = PARALLAX_OCCLUSION_SCALE * texture2D(normalTexture, uv).a - PARALLAX_OCCLUSION_BIAS;
uv = uv + texture2D(normalTexture, uv).z * height * vec2(tsEye.x,-tsEye.y);
@@ -56,14 +56,13 @@ void main (void)
#endif
#ifdef USE_NORMALMAPS
- if (normalTexturePresent){
+ if (normalTexturePresent) {
bump = get_normal_map(uv);
use_normalmap = true;
}
#endif
-
-#ifdef GENERATE_NORMALMAPS
- if (use_normalmap == false){
+
+ if (GENERATE_NORMALMAPS == 1 && use_normalmap == false) {
float tl = get_rgb_height (vec2(uv.x-SAMPLE_STEP,uv.y+SAMPLE_STEP));
float t = get_rgb_height (vec2(uv.x-SAMPLE_STEP,uv.y-SAMPLE_STEP));
float tr = get_rgb_height (vec2(uv.x+SAMPLE_STEP,uv.y+SAMPLE_STEP));
@@ -77,16 +76,15 @@ void main (void)
bump = vec4 (normalize(vec3 (dX, -dY, NORMALMAPS_STRENGTH)),1.0);
use_normalmap = true;
}
-#endif
vec4 base = texture2D(baseTexture, uv).rgba;
-
+
#ifdef ENABLE_BUMPMAPPING
- if (use_normalmap){
+ if (use_normalmap) {
vec3 L = normalize(lightVec);
vec3 E = normalize(eyeVec);
- float specular = pow(clamp(dot(reflect(L, bump.xyz), E), 0.0, 1.0),0.5);
- float diffuse = dot(E,bump.xyz);
+ float specular = pow(clamp(dot(reflect(L, bump.xyz), E), 0.0, 1.0),0.5);
+ float diffuse = dot(E,bump.xyz);
/* Mathematic optimization
* Original: color = 0.05*base.rgb + diffuse*base.rgb + 0.2*specular*base.rgb;
* This optimization save 2 multiplications (orig: 4 multiplications + 3 additions
diff --git a/client/shaders/water_surface_shader/opengl_vertex.glsl b/client/shaders/water_surface_shader/opengl_vertex.glsl
index 6e70bbc36..53678800d 100644
--- a/client/shaders/water_surface_shader/opengl_vertex.glsl
+++ b/client/shaders/water_surface_shader/opengl_vertex.glsl
@@ -18,20 +18,23 @@ varying vec3 tsLightVec;
const float e = 2.718281828459;
const float BS = 10.0;
-float smoothCurve( float x ) {
- return x * x *( 3.0 - 2.0 * x );
+float smoothCurve(float x)
+{
+ return x * x * (3.0 - 2.0 * x);
}
-float triangleWave( float x ) {
- return abs( fract( x + 0.5 ) * 2.0 - 1.0 );
+float triangleWave(float x)
+{
+ return abs(fract( x + 0.5 ) * 2.0 - 1.0);
}
-float smoothTriangleWave( float x ) {
- return smoothCurve( triangleWave( x ) ) * 2.0 - 1.0;
+float smoothTriangleWave(float x)
+{
+ return smoothCurve(triangleWave( x )) * 2.0 - 1.0;
}
void main(void)
{
gl_TexCoord[0] = gl_MultiTexCoord0;
-
+
#if (MATERIAL_TYPE == TILE_MATERIAL_LIQUID_TRANSPARENT || MATERIAL_TYPE == TILE_MATERIAL_LIQUID_OPAQUE) && ENABLE_WAVING_WATER
vec4 pos = gl_Vertex;
pos.y -= 2.0;