Open kvark opened 2 years ago
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.
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);
Follow-up to #178, which was the source of regression here.![vangers-cable-issue](https://user-images.githubusercontent.com/107301/149649917-d484b1c7-a427-4240-ad8b-13251a408672.jpg)