From daf0eb3897a747ebfed031603f8ab2a1dfdf31e6 Mon Sep 17 00:00:00 2001 From: Paris DOUADY Date: Sun, 10 Dec 2023 23:26:02 +0100 Subject: [PATCH] rename LevelData to ChunkData --- assets/shaders/terrain.frag.wgsl | 4 ++-- assets/shaders/terrain.vert.wgsl | 18 +++++++++--------- engine/src/drawables/terrain.rs | 8 ++++---- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/assets/shaders/terrain.frag.wgsl b/assets/shaders/terrain.frag.wgsl index 5e54ecb4..21d2db3e 100644 --- a/assets/shaders/terrain.frag.wgsl +++ b/assets/shaders/terrain.frag.wgsl @@ -6,7 +6,7 @@ struct FragmentOutput { @location(0) out_color: vec4, } -struct LevelData { +struct ChunkData { lod: u32, resolution: u32, } @@ -17,7 +17,7 @@ struct LevelData { @group(2) @binding(1) var s_terraindata: sampler; @group(2) @binding(2) var t_grass: texture_2d; @group(2) @binding(3) var s_grass: sampler; -@group(2) @binding(4) var ldata: LevelData; +@group(2) @binding(4) var cdata: ChunkData; @group(3) @binding(0) var t_ssao: texture_2d; @group(3) @binding(1) var s_ssao: sampler; diff --git a/assets/shaders/terrain.vert.wgsl b/assets/shaders/terrain.vert.wgsl index 3dd102ab..e35e710d 100644 --- a/assets/shaders/terrain.vert.wgsl +++ b/assets/shaders/terrain.vert.wgsl @@ -13,7 +13,7 @@ struct VertexOutput { @builtin(position) member: vec4, } -struct LevelData { +struct ChunkData { lod: u32, resolution: u32, distance_lod_cutoff: f32, // max distance at which to switch to the next lod to have smooth transitions @@ -27,7 +27,7 @@ struct LevelData { @group(2) @binding(0) var t_terraindata: texture_2d; @group(2) @binding(1) var s_terraindata: sampler; -@group(2) @binding(4) var ldata: LevelData; +@group(2) @binding(4) var cdata: ChunkData; /* normal: vec3(self.cell_size * scale as f32, 0.0, hx - height) @@ -51,29 +51,29 @@ fn unpack_diffs(v: u32) -> vec2 { @vertex fn vert(@builtin(vertex_index) vid: u32, @location(0) in_position: vec2, @location(1) in_off: vec2) -> VertexOutput { - let tpos: vec2 = vec2((in_position + in_off) * ldata.inv_cell_size); + let tpos: vec2 = vec2((in_position + in_off) * cdata.inv_cell_size); let texLoad: vec2 = textureLoad(t_terraindata, tpos, 0).rg; let height: f32 = unpack_height(texLoad.r); let diffs: vec2 = unpack_diffs(texLoad.g); - let step: i32 = i32(pow(2.0, f32(ldata.lod))); + let step: i32 = i32(pow(2.0, f32(cdata.lod))); - let zf_off: vec2 = vec2( step * (i32(vid % ldata.resolution) % 2), - step * (i32(vid / ldata.resolution) % 2)); + let zf_off: vec2 = vec2( step * (i32(vid % cdata.resolution) % 2), + step * (i32(vid / cdata.resolution) % 2)); let world_pos: vec3 = vec3(in_position + in_off, height); //let dist_to_cam: f32 = length(params.cam_pos.xyz - vec3(pos.xy, 0.0)); - //let transition_alpha: f32 = smoothstep(ldata.distance_lod_cutoff * 0.8, ldata.distance_lod_cutoff, dist_to_cam); + //let transition_alpha: f32 = smoothstep(cdata.distance_lod_cutoff * 0.8, cdata.distance_lod_cutoff, dist_to_cam); - var out_normal: vec3 = normalize(vec3(diffs.x, diffs.y, ldata.cell_size * 2.0)); // https://stackoverflow.com/questions/49640250/calculate-normals-from-heightmap + var out_normal: vec3 = normalize(vec3(diffs.x, diffs.y, cdata.cell_size * 2.0)); // https://stackoverflow.com/questions/49640250/calculate-normals-from-heightmap let position: vec4 = global.u_view_proj * vec4(world_pos, 1.0); #ifdef DEBUG - var debug = f32(ldata.lod); + var debug = f32(cdata.lod); if(height >= MAX_HEIGHT) { debug = diffs.x; diff --git a/engine/src/drawables/terrain.rs b/engine/src/drawables/terrain.rs index 24cd44b1..35b7de54 100644 --- a/engine/src/drawables/terrain.rs +++ b/engine/src/drawables/terrain.rs @@ -61,7 +61,7 @@ impl TerrainRender Float32x2]; @@ -369,7 +369,7 @@ impl PipelineBuilder for TerrainPipeline { .create_bind_group_layout(&BindGroupLayoutDescriptor { entries: &Texture::bindgroup_layout_entries(0, [TL::UInt, TL::Float].into_iter()) .chain(std::iter::once( - Uniform::::bindgroup_layout_entry(4), + Uniform::::bindgroup_layout_entry(4), )) .collect::>(), label: Some("terrain bindgroup layout"),