From 09062b72a90a9c0b938ab0e7db97e3c217256692 Mon Sep 17 00:00:00 2001
From: ThorstenB <brehmt@gmail.com>
Date: Mon, 4 Jul 2011 20:20:26 +0200
Subject: [PATCH] Robert (dogg360): make shaders work for AMD/ATI graphics
 (#96,#335 related) AMD/ATI compiler requires proper float values for
 conditions/expressions.

---
 Shaders/3dcloud.vert           |  4 ++--
 Shaders/clouds-box.vert        |  4 ++--
 Shaders/clouds-layered.vert    |  4 ++--
 Shaders/clouds-test.vert       |  4 ++--
 Shaders/clouds-thick.vert      |  4 ++--
 Shaders/clouds-thin.vert       |  4 ++--
 Shaders/clouds-thinlayer.vert  |  4 ++--
 Shaders/contrail.vert          | 14 +++++++-------
 Shaders/forest.frag            | 14 +++++++-------
 Shaders/rain-layer.vert        |  2 +-
 Shaders/reflect-bump-spec.frag |  4 ++--
 Shaders/reflect.frag           |  4 ++--
 Shaders/test.vert              |  4 ++--
 Shaders/water-orig.frag        |  4 ++--
 14 files changed, 37 insertions(+), 37 deletions(-)

diff --git a/Shaders/3dcloud.vert b/Shaders/3dcloud.vert
index df4ef1c1c..3a692be1c 100644
--- a/Shaders/3dcloud.vert
+++ b/Shaders/3dcloud.vert
@@ -23,7 +23,7 @@ void main(void)
   // Find a rotation matrix that rotates 1,0,0 into u. u, r and w are
   // the columns of that matrix.
   vec3 absu = abs(u);
-  vec3 r = normalize(vec3(-u.y, u.x, 0));
+  vec3 r = normalize(vec3(-u.y, u.x, 0.0));
   vec3 w = cross(u, r);
 
   // Do the matrix multiplication by [ u r w pos]. Assume no
@@ -61,7 +61,7 @@ void main(void)
   gl_FrontColor += gl_FrontLightModelProduct.sceneColor;
 
   // As we get within 100m of the sprite, it is faded out. Equally at large distances it also fades out.
-  gl_FrontColor.a = min(smoothstep(10.0, 100.0, fogCoord), 1 - smoothstep(15000.0, 20000.0, fogCoord));
+  gl_FrontColor.a = min(smoothstep(10.0, 100.0, fogCoord), 1.0 - smoothstep(15000.0, 20000.0, fogCoord));
   gl_BackColor = gl_FrontColor;
 
   // Fog doesn't affect clouds as much as other objects.
diff --git a/Shaders/clouds-box.vert b/Shaders/clouds-box.vert
index a58e716f5..11b2cbb75 100644
--- a/Shaders/clouds-box.vert
+++ b/Shaders/clouds-box.vert
@@ -28,7 +28,7 @@ void main(void)
   // Find a rotation matrix that rotates 1,0,0 into u. u, r and w are
   // the columns of that matrix.
   vec3 absu = abs(u);
-  vec3 r = normalize(vec3(-u.y, u.x, 0));
+  vec3 r = normalize(vec3(-u.y, u.x, 0.0));
   vec3 w = cross(u, r);
 
   // Do the matrix multiplication by [ u r w pos]. Assume no
@@ -63,7 +63,7 @@ void main(void)
   gl_FrontColor += gl_FrontLightModelProduct.sceneColor;
 
   // As we get within 100m of the sprite, it is faded out. Equally at large distances it also fades out.
-  gl_FrontColor.a = min(smoothstep(10.0, 100.0, fogCoord), 1 - smoothstep(25000.0, 30000.0, fogCoord));
+  gl_FrontColor.a = min(smoothstep(10.0, 100.0, fogCoord), 1.0 - smoothstep(25000.0, 30000.0, fogCoord));
   gl_BackColor = gl_FrontColor;
 
   // Fog doesn't affect clouds as much as other objects.
diff --git a/Shaders/clouds-layered.vert b/Shaders/clouds-layered.vert
index bb78d1c0e..e0e6be78e 100644
--- a/Shaders/clouds-layered.vert
+++ b/Shaders/clouds-layered.vert
@@ -17,7 +17,7 @@ void main(void)
   // Find a rotation matrix that rotates 1,0,0 into u. u, r and w are
   // the columns of that matrix.
   vec3 absu = abs(u);
-  vec3 r = normalize(vec3(-u.y, u.x, 0));
+  vec3 r = normalize(vec3(-u.y, u.x, 0.0));
   vec3 w = cross(u, r);
 
   // Do the matrix multiplication by [ u r w pos]. Assume no
@@ -54,7 +54,7 @@ void main(void)
   gl_FrontColor += gl_FrontLightModelProduct.sceneColor;
 
   // As we get within 100m of the sprite, it is faded out. Equally at large distances it also fades out.
-  gl_FrontColor.a = min(smoothstep(100.0, 300.0, fogCoord), 1 - smoothstep(40000.0, 45000.0, fogCoord));
+  gl_FrontColor.a = min(smoothstep(100.0, 300.0, fogCoord), 1.0 - smoothstep(40000.0, 45000.0, fogCoord));
   gl_BackColor = gl_FrontColor;
 
   // Fog doesn't affect clouds as much as other objects.
diff --git a/Shaders/clouds-test.vert b/Shaders/clouds-test.vert
index a58e716f5..11b2cbb75 100644
--- a/Shaders/clouds-test.vert
+++ b/Shaders/clouds-test.vert
@@ -28,7 +28,7 @@ void main(void)
   // Find a rotation matrix that rotates 1,0,0 into u. u, r and w are
   // the columns of that matrix.
   vec3 absu = abs(u);
-  vec3 r = normalize(vec3(-u.y, u.x, 0));
+  vec3 r = normalize(vec3(-u.y, u.x, 0.0));
   vec3 w = cross(u, r);
 
   // Do the matrix multiplication by [ u r w pos]. Assume no
@@ -63,7 +63,7 @@ void main(void)
   gl_FrontColor += gl_FrontLightModelProduct.sceneColor;
 
   // As we get within 100m of the sprite, it is faded out. Equally at large distances it also fades out.
-  gl_FrontColor.a = min(smoothstep(10.0, 100.0, fogCoord), 1 - smoothstep(25000.0, 30000.0, fogCoord));
+  gl_FrontColor.a = min(smoothstep(10.0, 100.0, fogCoord), 1.0 - smoothstep(25000.0, 30000.0, fogCoord));
   gl_BackColor = gl_FrontColor;
 
   // Fog doesn't affect clouds as much as other objects.
diff --git a/Shaders/clouds-thick.vert b/Shaders/clouds-thick.vert
index a25af4ec8..d25947f2a 100644
--- a/Shaders/clouds-thick.vert
+++ b/Shaders/clouds-thick.vert
@@ -18,7 +18,7 @@ void main(void)
   // Find a rotation matrix that rotates 1,0,0 into u. u, r and w are
   // the columns of that matrix.
   vec3 absu = abs(u);
-  vec3 r = normalize(vec3(-u.y, u.x, 0));
+  vec3 r = normalize(vec3(-u.y, u.x, 0.0));
   vec3 w = cross(u, r);
 
   // Do the matrix multiplication by [ u r w pos]. Assume no
@@ -54,7 +54,7 @@ void main(void)
   gl_FrontColor += gl_FrontLightModelProduct.sceneColor;
 
   // As we get within 100m of the sprite, it is faded out. Equally at large distances it also fades out.
-  gl_FrontColor.a = min(smoothstep(10.0, 100.0, fogCoord), 1 - smoothstep(40000.0, 45000.0, fogCoord));
+  gl_FrontColor.a = min(smoothstep(10.0, 100.0, fogCoord), 1.0 - smoothstep(40000.0, 45000.0, fogCoord));
   gl_BackColor = gl_FrontColor;
 
   // Fog doesn't affect clouds as much as other objects.
diff --git a/Shaders/clouds-thin.vert b/Shaders/clouds-thin.vert
index 90630d562..2cb900d83 100644
--- a/Shaders/clouds-thin.vert
+++ b/Shaders/clouds-thin.vert
@@ -28,7 +28,7 @@ void main(void)
   // Find a rotation matrix that rotates 1,0,0 into u. u, r and w are
   // the columns of that matrix.
   vec3 absu = abs(u);
-  vec3 r = normalize(vec3(-u.y, u.x, 0));
+  vec3 r = normalize(vec3(-u.y, u.x, 0.0));
   vec3 w = cross(u, r);
 
   // Do the matrix multiplication by [ u r w pos]. Assume no
@@ -63,7 +63,7 @@ void main(void)
   gl_FrontColor += gl_FrontLightModelProduct.sceneColor;
 
   // As we get within 100m of the sprite, it is faded out. Equally at large distances it also fades out.
-  gl_FrontColor.a = min(smoothstep(10.0, 100.0, fogCoord), 1 - smoothstep(40000.0, 45000.0, fogCoord));
+  gl_FrontColor.a = min(smoothstep(10.0, 100.0, fogCoord), 1.0 - smoothstep(40000.0, 45000.0, fogCoord));
   gl_BackColor = gl_FrontColor;
 
   // Fog doesn't affect clouds as much as other objects.
diff --git a/Shaders/clouds-thinlayer.vert b/Shaders/clouds-thinlayer.vert
index bcc6e791e..75802b752 100644
--- a/Shaders/clouds-thinlayer.vert
+++ b/Shaders/clouds-thinlayer.vert
@@ -17,7 +17,7 @@ void main(void)
   // Find a rotation matrix that rotates 1,0,0 into u. u, r and w are
   // the columns of that matrix.
   vec3 absu = abs(u);
-  vec3 r = normalize(vec3(-u.y, u.x, 0));
+  vec3 r = normalize(vec3(-u.y, u.x, 0.0));
   vec3 w = cross(u, r);
 
   // Do the matrix multiplication by [ u r w pos]. Assume no
@@ -54,7 +54,7 @@ void main(void)
   gl_FrontColor += gl_FrontLightModelProduct.sceneColor;
 
   // As we get within 100m of the sprite, it is faded out. Equally at large distances it also fades out.
-  gl_FrontColor.a = min(smoothstep(100.0, 300.0, fogCoord), 1 - smoothstep(40000.0, 45000.0, fogCoord));
+  gl_FrontColor.a = min(smoothstep(100.0, 300.0, fogCoord), 1.0 - smoothstep(40000.0, 45000.0, fogCoord));
   gl_BackColor = gl_FrontColor;
 
   // Fog doesn't affect clouds as much as other objects.
diff --git a/Shaders/contrail.vert b/Shaders/contrail.vert
index c738a452d..a1ec81eb9 100644
--- a/Shaders/contrail.vert
+++ b/Shaders/contrail.vert
@@ -26,8 +26,8 @@ void main(void)
 
     // map noise vectors
     vec4 noisevec = texture3D(Noise, rawpos.xyz);
-    float noise0 = (noisevec.r * 2) - 1;
-    float noise1 =(noisevec.g * 2) - 1;
+    float noise0 = (noisevec.r * 2.0) - 1.0;
+    float noise1 =(noisevec.g * 2.0) - 1.0;
     vec2 noise2 = noisevec.xy;
 
     gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
@@ -39,7 +39,7 @@ void main(void)
     // Find a rotation matrix that rotates 1,0,0 into u. u, r and w are
     // the columns of that matrix.
     vec3 absu = abs(u);
-    vec3 r = normalize(vec3(-u.y, u.x, 0));
+    vec3 r = normalize(vec3(-u.y, u.x, 0.0));
     vec3 w = cross(u, r);
 
     // Do the matrix multiplication by [ u r w pos]. Scale
@@ -50,11 +50,11 @@ void main(void)
     gl_Position.xyz += gl_Vertex.z * w * scale_z;
 
     // Adjust the position post-rotation and scaling
-    gl_Position.yz -= 3/2;
+    gl_Position.yz -= 3.0/2.0;
 
     // Offset in y and z directions using a random noise factor
-    float offset_Y = (noise0 * offset_y) + offset_y/2;
-    float offset_Z = (noise0 * offset_z) + offset_z/2;
+    float offset_Y = (noise0 * offset_y) + offset_y/2.0;
+    float offset_Z = (noise0 * offset_z) + offset_z/2.0;
 
     distanceFactor = 1.0 - clamp(abs(noise0), fade_min, fade_max);
 //    distanceFactor = 0.5;
@@ -90,7 +90,7 @@ void main(void)
     gl_FrontColor += gl_FrontLightModelProduct.sceneColor;
 
     // As we get within 100m of the sprite, it is faded out. Equally at large distances it also fades out.
-    gl_FrontColor.a = min(smoothstep(10.0, 100.0, fogCoord), 1 - smoothstep(60000.0, 80000.0, fogCoord));
+    gl_FrontColor.a = min(smoothstep(10.0, 100.0, fogCoord), 1.0 - smoothstep(60000.0, 80000.0, fogCoord));
     gl_BackColor = gl_FrontColor;
 
     // Fog doesn't affect clouds as much as other objects.
diff --git a/Shaders/forest.frag b/Shaders/forest.frag
index b0b08697f..f68c33a29 100644
--- a/Shaders/forest.frag
+++ b/Shaders/forest.frag
@@ -137,39 +137,39 @@ void main (void)
 	c5a = mix(c3, c4a, 1.0);
 	
 	
-	if (vegetationlevel <= 2200) {
+	if (vegetationlevel <= 2200.0) {
 	c1 = mix(c2, c5, clamp(0.65, n*0.1, 0.5));
 	diffuse = gl_Color.rgb * max(0.7, dot(N, l)) * max(0.9, dot(VNormal, gl_LightSource[0].position.xyz));
 	}
 	
-	if (vegetationlevel > 2200 && vegetationlevel < 2300) {
+	if (vegetationlevel > 2200.0 && vegetationlevel < 2300.0) {
 	c1 = mix(c2, c5, clamp(0.65, n*0.5, 0.35));
 	diffuse = gl_Color.rgb * max(0.7, dot(N, l)) * max(0.9, dot(VNormal, gl_LightSource[0].position.xyz));
 	}
 	
-	if (vegetationlevel >= 2300 && vegetationlevel < 2480) {
+	if (vegetationlevel >= 2300.0 && vegetationlevel < 2480.0) {
 	c1 = mix(c2, c5a, clamp(0.65, n*0.5, 0.30));
 	diffuse = gl_Color.rgb * max(0.85, dot(N, l)) * max(0.9, dot(VNormal, gl_LightSource[0].position.xyz));
 	}
 	
-	if (vegetationlevel >= 2480 && vegetationlevel < 2530) {
+	if (vegetationlevel >= 2480.0 && vegetationlevel < 2530.0) {
 	c1 = mix(c2, c5a, clamp(0.65, n*0.5, 0.20));
 	diffuse = gl_Color.rgb * max(0.85, dot(N, l)) * max(0.9, dot(VNormal, gl_LightSource[0].position.xyz));
 	}
 	
-	if (vegetationlevel >= 2530 && vegetationlevel < 2670) {
+	if (vegetationlevel >= 2530.0 && vegetationlevel < 2670.0) {
 	c1 = mix(c2, c5, clamp(0.65, n*0.5, 0.10));
 	diffuse = gl_Color.rgb * max(0.85, dot(N, l)) * max(0.9, dot(VNormal, gl_LightSource[0].position.xyz));
 	}
 	
-	if (vegetationlevel >= 2670) {
+	if (vegetationlevel >= 2670.0) {
 	c1 = mix(c2, c5, clamp(0.0, n*0.1, 0.4));
 	diffuse = gl_Color.rgb * max(0.85, dot(N, l)) * max(0.9, dot(VNormal, gl_LightSource[0].position.xyz));
 	}
 	
 	
 	//adding snow and permanent snow/glacier
-	if (vegetationlevel > snowlevel || vegetationlevel > 3100) {
+	if (vegetationlevel > snowlevel || vegetationlevel > 3100.0) {
 	c3 = mix(vec4(n+1.0, n+1.0, n+1.0, 0.0), c1, smoothstep(0.990, 0.965, abs(normalize(Normal).z)+nvL[2]*1.3));
 	c4 = mix(vec4(n+1.0, n+1.0, n+1.0, 0.0), c1, smoothstep(0.990, 0.965, abs(normalize(Normal).z)+nvL[2]*0.9));
 	c5 = mix(c3, c4, 1.0);
diff --git a/Shaders/rain-layer.vert b/Shaders/rain-layer.vert
index f505e15f7..52c4dbd5c 100644
--- a/Shaders/rain-layer.vert
+++ b/Shaders/rain-layer.vert
@@ -45,7 +45,7 @@ void main(void)
   gl_FrontColor += gl_FrontLightModelProduct.sceneColor;
 
   // As we get within 100m of the sprite, it is faded out. Equally at large distances it also fades out.
-  gl_FrontColor.a = min(smoothstep(100.0, 250.0, fogCoord), 1 - smoothstep(40000.0, 45000.0, fogCoord));
+  gl_FrontColor.a = min(smoothstep(100.0, 250.0, fogCoord), 1.0 - smoothstep(40000.0, 45000.0, fogCoord));
   gl_BackColor = gl_FrontColor;
 
   // Fog doesn't affect rain as much as other objects.
diff --git a/Shaders/reflect-bump-spec.frag b/Shaders/reflect-bump-spec.frag
index 70a6c1a60..862494624 100644
--- a/Shaders/reflect-bump-spec.frag
+++ b/Shaders/reflect-bump-spec.frag
@@ -88,14 +88,14 @@ void main (void)
     float transparency_offset = clamp(refl_correction, -1.0, 1.0);
     float reflFactor = 0.0;
 
-    if(reflect_map > 0){
+    if(reflect_map > 0.0){
         // map the shininess of the object with user input 
         vec4 map = texture2D(Map, gl_TexCoord[0].st);
         //float pam = (map.a * -2) + 1; //reverse map
         reflFactor = map.a + transparency_offset;
     } else {
         // set the reflectivity proportional to shininess with user input 
-        reflFactor = (gl_FrontMaterial.shininess / 128) * ns.a + transparency_offset;
+        reflFactor = (gl_FrontMaterial.shininess / 128.0) * ns.a + transparency_offset;
     }
 
     reflFactor = clamp(reflFactor, 0.0, 1.0);
diff --git a/Shaders/reflect.frag b/Shaders/reflect.frag
index d1424b478..98bde6f6e 100644
--- a/Shaders/reflect.frag
+++ b/Shaders/reflect.frag
@@ -81,7 +81,7 @@ void main (void)
     float transparency_offset = clamp(refl_correction, -1.0, 1.0);
     float reflFactor = 0.0;
 
-    if(reflect_map > 0){
+    if(reflect_map > 0.0){
         // map the shininess of the object with user input 
         vec4 map = texture2D(Map, gl_TexCoord[0].st);
         //float pam = (map.a * -2) + 1; //reverse map
@@ -89,7 +89,7 @@ void main (void)
     } else {
         // set the reflectivity proportional to shininess with user 
         // input 
-        reflFactor = (gl_FrontMaterial.shininess / 128) + transparency_offset;
+        reflFactor = (gl_FrontMaterial.shininess / 128.0) + transparency_offset;
     }
 
     reflFactor = clamp(reflFactor, 0.0, 1.0);
diff --git a/Shaders/test.vert b/Shaders/test.vert
index e991cb9d1..eb3e1155d 100644
--- a/Shaders/test.vert
+++ b/Shaders/test.vert
@@ -47,7 +47,7 @@ void main(void)
   // Find a rotation matrix that rotates 1,0,0 into u. u, r and w are
   // the columns of that matrix.
   vec3 absu = abs(u);
-  vec3 r = normalize(vec3(-u.y, u.x, 0));
+  vec3 r = normalize(vec3(-u.y, u.x, 0.0));
   vec3 w = cross(u, r);
 
   // Do the matrix multiplication by [ u r w pos]. Assume no
@@ -82,7 +82,7 @@ void main(void)
   gl_FrontColor += gl_FrontLightModelProduct.sceneColor;
 
   // As we get within 100m of the sprite, it is faded out. Equally at large distances it also fades out.
-  gl_FrontColor.a = min(smoothstep(10.0, 100.0, fogCoord), 1 - smoothstep(15000.0, 20000.0, fogCoord));
+  gl_FrontColor.a = min(smoothstep(10.0, 100.0, fogCoord), 1.0 - smoothstep(15000.0, 20000.0, fogCoord));
   gl_BackColor = gl_FrontColor;
 
   // Fog doesn't affect clouds as much as other objects.
diff --git a/Shaders/water-orig.frag b/Shaders/water-orig.frag
index 50ae098f8..1b6896bb9 100644
--- a/Shaders/water-orig.frag
+++ b/Shaders/water-orig.frag
@@ -77,9 +77,9 @@ void main (void)
     float ReflectedEye = max(dot(Reflected, Eye), 0.0);
     float eyeFact = pow(ReflectedEye, 20.0);
     c1 += 0.3 * gl_LightSource[0].diffuse * (1.0-eyeFact) * bumpFact*bumpFact;
-    c1 += 0.4 * gl_LightSource[0].diffuse * eyeFact * 3*bumpFact;
+    c1 += 0.4 * gl_LightSource[0].diffuse * eyeFact * 3.0*bumpFact;
     eyeFact = pow(eyeFact, 20.0);
-    c1 += gl_LightSource[0].specular * eyeFact * 4*bumpFact;
+    c1 += gl_LightSource[0].specular * eyeFact * 4.0*bumpFact;
 
     vec4 finalColor = c1;
     gl_FragColor = mix(gl_Fog.color, finalColor, fogFactor);