Indeximal / UnderstoryScene

The project for NTNU TDT4230 Graphics and Visualization 2024
Other
0 stars 0 forks source link

Clamped displacement #1

Open pbsds opened 3 weeks ago

pbsds commented 3 weeks ago

I ran this on my computer and got image

Clearly the distant terrain is clamped. I tried changing rust toolchain and display driver and even linux distro with no effect. I landed on this janky workaround:

diff --git a/shaders/terrain.vert b/shaders/terrain.vert
index 1621722..15fd6c0 100644
--- a/shaders/terrain.vert
+++ b/shaders/terrain.vert
@@ -20,7 +20,7 @@ const float dx = 0.05;

 float sample_displacement(vec2 wcoord) {
     vec3 w_uv = world_to_uv * vec3(wcoord, 1.0);
-    return texture(displacement_map, w_uv.xy).r;
+    return texture(displacement_map, w_uv.xy).r*4;
 }

 void main() {
@@ -32,7 +32,7 @@ void main() {
     float du = (z - zu) / dx;
     float dv = (z - zv) / dx;

-    v_variant = texture(variant_map, (world_to_uv * vec3(world_pos.xy, 1.0)).xy).r;
+    v_variant = texture(variant_map, (world_to_uv * vec3(world_pos.xy, 1.0)).xy).r*4;

     // FIXME: This might be wrong
     v_normal = normalize(vec3(du, dv, 1.0));
diff --git a/src/texture.rs b/src/texture.rs
index d9c1bae..390d084 100644
--- a/src/texture.rs
+++ b/src/texture.rs
@@ -128,7 +128,7 @@ impl Texture {
                 let current_y = y_min + y_step * (y as f32 + 0.5);

                 result_map[(y * resolution + x) as usize] =
-                    noise.get([current_x as f64, current_y as f64]) as f32;
+                    (noise.get([current_x as f64, current_y as f64]) * 0.25) as f32;
             }
         }

result: image

Indeximal commented 3 weeks ago

Oh I guess the texture is somehow configured to clamp to [0,1] for your drivers, but not mine. I didn’t explicitly set this behavior in the code, and also don’t know OpenGL well enough to know what parameter to set, or if it is impossible. And honestly, it is quite unlikely that I‘ll ever fix that.