Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lighting under cables is weird #180

Open
kvark opened this issue Jan 16, 2022 · 2 comments
Open

Lighting under cables is weird #180

kvark opened this issue Jan 16, 2022 · 2 comments

Comments

@kvark
Copy link
Owner

kvark commented Jan 16, 2022

Follow-up to #178, which was the source of regression here.
vangers-cable-issue

@kvark
Copy link
Owner Author

kvark commented Jan 16, 2022

Here is the original code - https://github.com/KranX/Vangers/blob/60b4dec789f1e68ed99b5601350248bdf9ad2744/src/terra/land.cpp#L1014-L1048

It seems to me that the artifacts should have been present in the original game as well. Neither the double level or single level code paths don't bother checking if the cells to the left/right are double-level or not.

@kvark
Copy link
Owner Author

kvark commented Jan 16, 2022

Tried following the original code verbatim, it doesn't solve it:

diff --git a/res/shader/color.inc.wgsl b/res/shader/color.inc.wgsl
index 43cb6a6..8e28f73 100644
--- a/res/shader/color.inc.wgsl
+++ b/res/shader/color.inc.wgsl
@@ -40,9 +40,20 @@ fn evaluate_palette(ty: u32, value_in: f32, ycoord: f32) -> f32 {
 fn evaluate_color_id(ty: u32, tex_coord: vec2<f32>, height_normalized: f32, lit_factor: f32) -> f32 {
     // See the original code in "land.cpp": `LINE_render()`
     //Note: we could have a different code path for double level here
-    let diff =
-        textureSampleLevel(t_Height, s_Main, tex_coord, 0.0, vec2<i32>(0, 0)).x -
-        textureSampleLevel(t_Height, s_Main, tex_coord, 0.0, vec2<i32>(-2, 0)).x;
+    let pos = tex_coord * u_Surface.texture_scale.xy;
+    let tci = vec2<i32>(pos - floor(pos / u_Surface.texture_scale.xy) * u_Surface.texture_scale.xy);
+
+    let meta = textureLoad(t_Meta, tci, 0).x;
+    var diff = 0.0;
+    if ((meta & c_DoubleLevelMask) != 0u) {
+    diff =
+        textureLoad(t_Height, (tci | vec2<i32>(1, 0)) + vec2<i32>(2, 0), 0).x -
+        textureLoad(t_Height, (tci | vec2<i32>(1, 0)) + vec2<i32>(0, 0), 0).x;
+    } else {
+        diff =
+        textureLoad(t_Height, tci + vec2<i32>(1, 0), 0).x -
+        textureLoad(t_Height, tci + vec2<i32>(-1, 0), 0).x;
+    }
     // See the original code in "land.cpp": `TERRAIN_MATERIAL` etc
     let material = select(vec3<f32>(1.0), vec3<f32>(5.0, 1.25, 0.5), ty == 0u);
     let light_clr = evaluate_light(material, diff);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant