diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index 5bed8a9fe6..95dc5af837 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -28,20 +28,20 @@ cross = ["wgc/cross"] [target.'cfg(not(target_arch = "wasm32"))'.dependencies.wgc] package = "wgpu-core" git = "https://github.com/gfx-rs/wgpu" -rev = "6a6a9a4aedbbf7c8cc6b11a4b0c42341ac50a798" +rev = "523ef2dfec0bf18c696bc53fea252fd6fa7350c6" features = ["raw-window-handle"] [target.'cfg(target_arch = "wasm32")'.dependencies.wgc] package = "wgpu-core" git = "https://github.com/gfx-rs/wgpu" -rev = "6a6a9a4aedbbf7c8cc6b11a4b0c42341ac50a798" +rev = "523ef2dfec0bf18c696bc53fea252fd6fa7350c6" features = ["raw-window-handle"] optional = true [dependencies.wgt] package = "wgpu-types" git = "https://github.com/gfx-rs/wgpu" -rev = "6a6a9a4aedbbf7c8cc6b11a4b0c42341ac50a798" +rev = "523ef2dfec0bf18c696bc53fea252fd6fa7350c6" [dependencies] arrayvec = "0.5" @@ -71,13 +71,13 @@ env_logger = "0.8" # used to test all the example shaders [dev-dependencies.naga] git = "https://github.com/gfx-rs/naga" -tag = "gfx-21" +tag = "gfx-22" features = ["wgsl-in"] # used to generate SPIR-V for the Web target [target.'cfg(target_arch = "wasm32")'.dependencies.naga] git = "https://github.com/gfx-rs/naga" -tag = "gfx-21" +tag = "gfx-22" features = ["wgsl-in", "spv-out"] [[example]] diff --git a/wgpu/examples/boids/compute.wgsl b/wgpu/examples/boids/compute.wgsl index 4a5bc6bb09..f5d1b67c09 100644 --- a/wgpu/examples/boids/compute.wgsl +++ b/wgpu/examples/boids/compute.wgsl @@ -1,5 +1,5 @@ // This should match `NUM_PARTICLES` on the Rust side. -const NUM_PARTICLES: u32 = 1500u; +let NUM_PARTICLES: u32 = 1500u; struct Particle { pos : vec2; @@ -29,7 +29,7 @@ struct Particles { // https://github.com/austinEng/Project6-Vulkan-Flocking/blob/master/data/shaders/computeparticles/particle.comp [[stage(compute), workgroup_size(64)]] fn main([[builtin(global_invocation_id)]] global_invocation_id: vec3) { - const index : u32 = global_invocation_id.x; + let index : u32 = global_invocation_id.x; if (index >= NUM_PARTICLES) { return; } diff --git a/wgpu/examples/boids/draw.wgsl b/wgpu/examples/boids/draw.wgsl index d9cf38124c..8980eb7d11 100644 --- a/wgpu/examples/boids/draw.wgsl +++ b/wgpu/examples/boids/draw.wgsl @@ -4,8 +4,8 @@ fn main( [[location(1)]] particle_vel: vec2, [[location(2)]] position: vec2, ) -> [[builtin(position)]] vec4 { - const angle = -atan2(particle_vel.x, particle_vel.y); - const pos = vec2( + let angle = -atan2(particle_vel.x, particle_vel.y); + let pos = vec2( position.x * cos(angle) - position.y * sin(angle), position.x * sin(angle) + position.y * cos(angle) ); diff --git a/wgpu/examples/conservative-raster/triangle_and_lines.wgsl b/wgpu/examples/conservative-raster/triangle_and_lines.wgsl index 2f0331f04e..a553ff4f69 100644 --- a/wgpu/examples/conservative-raster/triangle_and_lines.wgsl +++ b/wgpu/examples/conservative-raster/triangle_and_lines.wgsl @@ -1,8 +1,8 @@ [[stage(vertex)]] fn vs_main([[builtin(vertex_index)]] vertex_index: u32) -> [[builtin(position)]] vec4 { - const i: i32 = i32(vertex_index % 3u); - const x: f32 = f32(i - 1) * 0.75; - const y: f32 = f32((i & 1) * 2 - 1) * 0.75 + x * 0.2 + 0.1; + let i: i32 = i32(vertex_index % 3u); + let x: f32 = f32(i - 1) * 0.75; + let y: f32 = f32((i & 1) * 2 - 1) * 0.75 + x * 0.2 + 0.1; return vec4(x, y, 0.0, 1.0); } diff --git a/wgpu/examples/conservative-raster/upscale.wgsl b/wgpu/examples/conservative-raster/upscale.wgsl index 45fc3ff4cc..edb87df173 100644 --- a/wgpu/examples/conservative-raster/upscale.wgsl +++ b/wgpu/examples/conservative-raster/upscale.wgsl @@ -5,8 +5,8 @@ struct VertexOutput { [[stage(vertex)]] fn vs_main([[builtin(vertex_index)]] vertex_index: u32) -> VertexOutput { - const x: f32 = f32(i32(vertex_index & 1u) << 2u) - 1.0; - const y: f32 = f32(i32(vertex_index & 2u) << 1u) - 1.0; + let x: f32 = f32(i32(vertex_index & 1u) << 2u) - 1.0; + let y: f32 = f32(i32(vertex_index & 2u) << 1u) - 1.0; var output: VertexOutput; output.position = vec4(x, -y, 0.0, 1.0); output.tex_coords = vec2(x + 1.0, y + 1.0) * 0.5; diff --git a/wgpu/examples/hello-triangle/shader.wgsl b/wgpu/examples/hello-triangle/shader.wgsl index 8256492b99..a1ef447d6c 100644 --- a/wgpu/examples/hello-triangle/shader.wgsl +++ b/wgpu/examples/hello-triangle/shader.wgsl @@ -1,7 +1,7 @@ [[stage(vertex)]] fn vs_main([[builtin(vertex_index)]] in_vertex_index: u32) -> [[builtin(position)]] vec4 { - const x = f32(i32(in_vertex_index) - 1); - const y = f32(i32(in_vertex_index & 1u) * 2 - 1); + let x = f32(i32(in_vertex_index) - 1); + let y = f32(i32(in_vertex_index & 1u) * 2 - 1); return vec4(x, y, 0.0, 1.0); } diff --git a/wgpu/examples/mipmap/blit.wgsl b/wgpu/examples/mipmap/blit.wgsl index 8d4c014448..f8a91dfc59 100644 --- a/wgpu/examples/mipmap/blit.wgsl +++ b/wgpu/examples/mipmap/blit.wgsl @@ -6,9 +6,9 @@ struct VertexOutput { [[stage(vertex)]] fn vs_main([[builtin(vertex_index)]] vertex_index: u32) -> VertexOutput { var out: VertexOutput; - const x = i32(vertex_index) / 2; - const y = i32(vertex_index) & 1; - const tc = vec2( + let x = i32(vertex_index) / 2; + let y = i32(vertex_index) & 1; + let tc = vec2( f32(x) * 2.0, f32(y) * 2.0 ); diff --git a/wgpu/examples/mipmap/draw.wgsl b/wgpu/examples/mipmap/draw.wgsl index 3179f39e19..9cf0eb93a7 100644 --- a/wgpu/examples/mipmap/draw.wgsl +++ b/wgpu/examples/mipmap/draw.wgsl @@ -12,7 +12,7 @@ var r_data: Locals; [[stage(vertex)]] fn vs_main([[builtin(vertex_index)]] vertex_index: u32) -> VertexOutput { - const pos = vec2( + let pos = vec2( 100.0 * (1.0 - f32(vertex_index & 2u)), 1000.0 * f32(vertex_index & 1u) ); diff --git a/wgpu/examples/shadow/main.rs b/wgpu/examples/shadow/main.rs index 67dda6838d..008576963c 100644 --- a/wgpu/examples/shadow/main.rs +++ b/wgpu/examples/shadow/main.rs @@ -573,7 +573,7 @@ impl framework::Example for Example { visibility: wgpu::ShaderStage::FRAGMENT, ty: wgpu::BindingType::Sampler { comparison: true, - filtering: false, + filtering: true, }, count: None, }, diff --git a/wgpu/examples/shadow/shader.wgsl b/wgpu/examples/shadow/shader.wgsl index f23bba68ab..f7826712ec 100644 --- a/wgpu/examples/shadow/shader.wgsl +++ b/wgpu/examples/shadow/shader.wgsl @@ -32,8 +32,8 @@ fn vs_main( [[location(0)]] position: vec4, [[location(1)]] normal: vec4, ) -> VertexOutput { - const w = u_entity.world; - const world_pos = u_entity.world * vec4(position); + let w = u_entity.world; + let world_pos = u_entity.world * vec4(position); var out: VertexOutput; out.world_normal = mat3x3(w.x.xyz, w.y.xyz, w.z.xyz) * vec3(normal.xyz); out.world_position = world_pos; @@ -66,20 +66,20 @@ fn fetch_shadow(light_id: u32, homogeneous_coords: vec4) -> f32 { return 1.0; } // compensate for the Y-flip difference between the NDC and texture coordinates - const flip_correction = vec2(0.5, -0.5); + let flip_correction = vec2(0.5, -0.5); // compute texture coordinates for shadow lookup - const proj_correction = 1.0 / homogeneous_coords.w; - const light_local = homogeneous_coords.xy * flip_correction * proj_correction + vec2(0.5, 0.5); + let proj_correction = 1.0 / homogeneous_coords.w; + let light_local = homogeneous_coords.xy * flip_correction * proj_correction + vec2(0.5, 0.5); // do the lookup, using HW PCF and comparison return textureSampleCompare(t_shadow, sampler_shadow, light_local, i32(light_id), homogeneous_coords.z * proj_correction); } -const c_ambient: vec3 = vec3(0.05, 0.05, 0.05); -const c_max_lights: u32 = 10u; +let c_ambient: vec3 = vec3(0.05, 0.05, 0.05); +let c_max_lights: u32 = 10u; [[stage(fragment)]] fn fs_main(in: VertexOutput) -> [[location(0)]] vec4 { - const normal = normalize(in.world_normal); + let normal = normalize(in.world_normal); // accumulate color var color: vec3 = c_ambient; var i: u32 = 0u; @@ -87,12 +87,12 @@ fn fs_main(in: VertexOutput) -> [[location(0)]] vec4 { if (i >= min(u_globals.num_lights.x, c_max_lights)) { break; } - const light = s_lights.data[i]; + let light = s_lights.data[i]; // project into the light space - const shadow = fetch_shadow(i, light.proj * in.world_position); + let shadow = fetch_shadow(i, light.proj * in.world_position); // compute Lambertian diffuse term - const light_dir = normalize(light.pos.xyz - in.world_position.xyz); - const diffuse = max(0.0, dot(normal, light_dir)); + let light_dir = normalize(light.pos.xyz - in.world_position.xyz); + let diffuse = max(0.0, dot(normal, light_dir)); // add light contribution color = color + shadow * diffuse * light.color.xyz; continuing { diff --git a/wgpu/examples/skybox/shader.wgsl b/wgpu/examples/skybox/shader.wgsl index 1a5888ea2a..9d211eed52 100644 --- a/wgpu/examples/skybox/shader.wgsl +++ b/wgpu/examples/skybox/shader.wgsl @@ -20,9 +20,9 @@ var r_data: Data; [[stage(vertex)]] fn vs_sky([[builtin(vertex_index)]] vertex_index: u32) -> SkyOutput { // hacky way to draw a large triangle - const tmp1 = i32(vertex_index) / 2; - const tmp2 = i32(vertex_index) & 1; - const pos = vec4( + let tmp1 = i32(vertex_index) / 2; + let tmp2 = i32(vertex_index) & 1; + let pos = vec4( f32(tmp1) * 4.0 - 1.0, f32(tmp2) * 4.0 - 1.0, 1.0, @@ -30,8 +30,8 @@ fn vs_sky([[builtin(vertex_index)]] vertex_index: u32) -> SkyOutput { ); // transposition = inversion for this orthonormal matrix - const inv_model_view = transpose(mat3x3(r_data.view.x.xyz, r_data.view.y.xyz, r_data.view.z.xyz)); - const unprojected = r_data.proj_inv * pos; + let inv_model_view = transpose(mat3x3(r_data.view.x.xyz, r_data.view.y.xyz, r_data.view.z.xyz)); + let unprojected = r_data.proj_inv * pos; var out: SkyOutput; out.uv = inv_model_view * unprojected.xyz; @@ -69,10 +69,10 @@ fn fs_sky(in: SkyOutput) -> [[location(0)]] vec4 { [[stage(fragment)]] fn fs_entity(in: EntityOutput) -> [[location(0)]] vec4 { - const incident = normalize(in.view); - const normal = normalize(in.normal); - const reflected = incident - 2.0 * dot(normal, incident) * normal; + let incident = normalize(in.view); + let normal = normalize(in.normal); + let reflected = incident - 2.0 * dot(normal, incident) * normal; - const reflected_color = textureSample(r_texture, r_sampler, reflected); + let reflected_color = textureSample(r_texture, r_sampler, reflected); return vec4(0.1, 0.1, 0.1, 0.1) + 0.5 * reflected_color; } diff --git a/wgpu/examples/water/terrain.wgsl b/wgpu/examples/water/terrain.wgsl index 50f923610c..2af261bf4b 100644 --- a/wgpu/examples/water/terrain.wgsl +++ b/wgpu/examples/water/terrain.wgsl @@ -7,9 +7,9 @@ struct Uniforms { [[group(0), binding(0)]] var uniforms: Uniforms; -const light: vec3 = vec3(150.0, 70.0, 0.0); -const light_colour: vec3 = vec3(1.0, 0.98, 0.82); -const ambient: f32 = 0.2; +let light: vec3 = vec3(150.0, 70.0, 0.0); +let light_colour: vec3 = vec3(1.0, 0.98, 0.82); +let ambient: f32 = 0.2; struct VertexOutput { [[builtin(position)]] position: vec4; @@ -28,8 +28,8 @@ fn vs_main( out.position = uniforms.projection_view * vec4(position, 1.0); // https://www.desmos.com/calculator/nqgyaf8uvo - const normalized_light_direction = normalize(position - light); - const brightness_diffuse = clamp(dot(normalized_light_direction, normal), 0.2, 1.0); + let normalized_light_direction = normalize(position - light); + let brightness_diffuse = clamp(dot(normalized_light_direction, normal), 0.2, 1.0); out.colour = vec4(max((brightness_diffuse + ambient) * light_colour * colour.rgb, vec3(0.0, 0.0, 0.0)), colour.a); out.clip_dist = dot(vec4(position, 1.0), uniforms.clipping_plane); diff --git a/wgpu/examples/water/water.wgsl b/wgpu/examples/water/water.wgsl index 1e32908f95..0e69955bf2 100644 --- a/wgpu/examples/water/water.wgsl +++ b/wgpu/examples/water/water.wgsl @@ -7,13 +7,13 @@ struct Uniforms { }; [[group(0), binding(0)]] var uniforms: Uniforms; -const light_point: vec3 = vec3(150.0, 70.0, 0.0); -const light_colour: vec3 = vec3(1.0, 0.98, 0.82); -const one: vec4 = vec4(1.0, 1.0, 1.0, 1.0); +let light_point: vec3 = vec3(150.0, 70.0, 0.0); +let light_colour: vec3 = vec3(1.0, 0.98, 0.82); +let one: vec4 = vec4(1.0, 1.0, 1.0, 1.0); -const Y_SCL: f32 = 0.86602540378443864676372317075294; -const CURVE_BIAS: f32 = -0.1; -const INV_1_CURVE_BIAS: f32 = 1.11111111111; //1.0 / (1.0 + CURVE_BIAS); +let Y_SCL: f32 = 0.86602540378443864676372317075294; +let CURVE_BIAS: f32 = -0.1; +let INV_1_CURVE_BIAS: f32 = 1.11111111111; //1.0 / (1.0 + CURVE_BIAS); // // The following code to calculate simplex 3D @@ -32,34 +32,34 @@ fn taylorInvSqrt(r: vec4) -> vec4 { } fn snoise(v: vec3) -> f32 { - const C = vec2(1.0/6.0, 1.0/3.0); - const D = vec4(0.0, 0.5, 1.0, 2.0); + let C = vec2(1.0/6.0, 1.0/3.0); + let D = vec4(0.0, 0.5, 1.0, 2.0); // First corner //TODO: use the splat operations when available - const vCy = dot(v, C.yyy); + let vCy = dot(v, C.yyy); var i: vec3 = floor(v + vec3(vCy, vCy, vCy)); - const iCx = dot(i, C.xxx); - const x0 = v - i + vec3(iCx, iCx, iCx); + let iCx = dot(i, C.xxx); + let x0 = v - i + vec3(iCx, iCx, iCx); // Other corners - const g = step(x0.yzx, x0.xyz); - const l = (vec3(1.0, 1.0, 1.0) - g).zxy; - const i1 = min(g, l); - const i2 = max(g, l); + let g = step(x0.yzx, x0.xyz); + let l = (vec3(1.0, 1.0, 1.0) - g).zxy; + let i1 = min(g, l); + let i2 = max(g, l); // x0 = x0 - 0.0 + 0.0 * C.xxx; // x1 = x0 - i1 + 1.0 * C.xxx; // x2 = x0 - i2 + 2.0 * C.xxx; // x3 = x0 - 1.0 + 3.0 * C.xxx; - const x1 = x0 - i1 + C.xxx; - const x2 = x0 - i2 + C.yyy; // 2.0*C.x = 1/3 = C.y - const x3 = x0 - D.yyy; // -1.0+3.0*C.x = -0.5 = -D.y + let x1 = x0 - i1 + C.xxx; + let x2 = x0 - i2 + C.yyy; // 2.0*C.x = 1/3 = C.y + let x3 = x0 - D.yyy; // -1.0+3.0*C.x = -0.5 = -D.y // Permutations var temp: vec3 = 289.0 * one.xyz; i = modf(i, &temp); - const p = permute( + let p = permute( permute( permute(i.zzzz + vec4(0.0, i1.z, i2.z, 1.0)) + i.yyyy + vec4(0.0, i1.y, i2.y, 1.0)) @@ -67,29 +67,29 @@ fn snoise(v: vec3) -> f32 { // Gradients: 7x7 points over a square, mapped onto an octahedron. // The ring size 17*17 = 289 is close to a multiple of 49 (49*6 = 294) - const n_ = 0.142857142857;// 1.0/7.0 - const ns = n_ * D.wyz - D.xzx; + let n_ = 0.142857142857;// 1.0/7.0 + let ns = n_ * D.wyz - D.xzx; - const j = p - 49.0 * floor(p * ns.z * ns.z);// mod(p,7*7) + let j = p - 49.0 * floor(p * ns.z * ns.z);// mod(p,7*7) - const x_ = floor(j * ns.z); - const y_ = floor(j - 7.0 * x_);// mod(j,N) + let x_ = floor(j * ns.z); + let y_ = floor(j - 7.0 * x_);// mod(j,N) var x: vec4 = x_ *ns.x + ns.yyyy; var y: vec4 = y_ *ns.x + ns.yyyy; - const h = one - abs(x) - abs(y); + let h = one - abs(x) - abs(y); - const b0 = vec4(x.xy, y.xy); - const b1 = vec4(x.zw, y.zw); + let b0 = vec4(x.xy, y.xy); + let b1 = vec4(x.zw, y.zw); //vec4 s0 = vec4(lessThan(b0,0.0))*2.0 - one; //vec4 s1 = vec4(lessThan(b1,0.0))*2.0 - one; - const s0 = floor(b0)*2.0 + one; - const s1 = floor(b1)*2.0 + one; - const sh = -step(h, 0.0 * one); + let s0 = floor(b0)*2.0 + one; + let s1 = floor(b1)*2.0 + one; + let sh = -step(h, 0.0 * one); - const a0 = b0.xzyw + s0.xzyw*sh.xxyy; - const a1 = b1.xzyw + s1.xzyw*sh.zzww; + let a0 = b0.xzyw + s0.xzyw*sh.xxyy; + let a1 = b1.xzyw + s1.xzyw*sh.zzww; var p0: vec3 = vec3(a0.xy, h.x); var p1: vec3 = vec3(a0.zw, h.y); @@ -97,7 +97,7 @@ fn snoise(v: vec3) -> f32 { var p3: vec3 = vec3(a1.zw, h.w); //Normalise gradients - const norm = taylorInvSqrt(vec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3))); + let norm = taylorInvSqrt(vec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3))); p0 = p0 * norm.x; p1 = p1 * norm.y; p2 = p2 * norm.z; @@ -118,31 +118,31 @@ fn apply_distortion(pos: vec3) -> vec3 { //continuous movement. //TODO: we should be able to name them `sin` and `cos`. - const sn = uniforms.time_size_width.x; - const cs = uniforms.time_size_width.y; - const size = uniforms.time_size_width.z; + let sn = uniforms.time_size_width.x; + let cs = uniforms.time_size_width.y; + let size = uniforms.time_size_width.z; // Rotate 90 Z, Move Left Size / 2 perlin_pos = vec3(perlin_pos.y - perlin_pos.x - size, perlin_pos.x, perlin_pos.z); - const xcos = perlin_pos.x * cs; - const xsin = perlin_pos.x * sn; - const ycos = perlin_pos.y * cs; - const ysin = perlin_pos.y * sn; - const zcos = perlin_pos.z * cs; - const zsin = perlin_pos.z * sn; + let xcos = perlin_pos.x * cs; + let xsin = perlin_pos.x * sn; + let ycos = perlin_pos.y * cs; + let ysin = perlin_pos.y * sn; + let zcos = perlin_pos.z * cs; + let zsin = perlin_pos.z * sn; // Rotate Time Y - const perlin_pos_y = vec3(xcos + zsin, perlin_pos.y, -xsin + xcos); + let perlin_pos_y = vec3(xcos + zsin, perlin_pos.y, -xsin + xcos); // Rotate Time Z - const perlin_pos_z = vec3(xcos - ysin, xsin + ycos, perlin_pos.x); + let perlin_pos_z = vec3(xcos - ysin, xsin + ycos, perlin_pos.x); // Rotate 90 Y perlin_pos = vec3(perlin_pos.z - perlin_pos.x, perlin_pos.y, perlin_pos.x); // Rotate Time X - const perlin_pos_x = vec3(perlin_pos.x, ycos - zsin, ysin + zcos); + let perlin_pos_x = vec3(perlin_pos.x, ycos - zsin, ysin + zcos); // Sample at different places for x/y/z to get random-looking water. return vec3( @@ -155,14 +155,14 @@ fn apply_distortion(pos: vec3) -> vec3 { // Multiply the input by the scale values. fn make_position(original: vec2) -> vec4 { - const interpreted = vec3(original.x * 0.5, 0.0, original.y * Y_SCL); + let interpreted = vec3(original.x * 0.5, 0.0, original.y * Y_SCL); return vec4(apply_distortion(interpreted), 1.0); } // Create the normal, and apply the curve. Change the Curve Bias above. fn make_normal(a: vec3, b: vec3, c: vec3) -> vec3 { - const norm = normalize(cross(b - c, a - c)); - const center = (a + b + c) * (1.0 / 3.0); //TODO: use splat + let norm = normalize(cross(b - c, a - c)); + let center = (a + b + c) * (1.0 / 3.0); //TODO: use splat return (normalize(a - center) * CURVE_BIAS + norm) * INV_1_CURVE_BIAS; } @@ -175,7 +175,7 @@ fn calc_fresnel(view: vec3, normal: vec3) -> f32 { // Calculate the specular lighting. fn calc_specular(eye: vec3, normal: vec3, light: vec3) -> f32 { - const light_reflected = reflect(light, normal); + let light_reflected = reflect(light, normal); var specular: f32 = max(dot(eye, light_reflected), 0.0); specular = pow(specular, 10.0); return specular; @@ -193,25 +193,25 @@ fn vs_main( [[location(0)]] position: vec2, [[location(1)]] offsets: vec4, ) -> VertexOutput { - const p_pos = vec2(position); - const b_pos = make_position(p_pos + vec2(offsets.xy)); - const c_pos = make_position(p_pos + vec2(offsets.zw)); - const a_pos = make_position(p_pos); - const original_pos = vec4(p_pos.x * 0.5, 0.0, p_pos.y * Y_SCL, 1.0); + let p_pos = vec2(position); + let b_pos = make_position(p_pos + vec2(offsets.xy)); + let c_pos = make_position(p_pos + vec2(offsets.zw)); + let a_pos = make_position(p_pos); + let original_pos = vec4(p_pos.x * 0.5, 0.0, p_pos.y * Y_SCL, 1.0); - const vm = uniforms.view; - const transformed_pos = vm * a_pos; + let vm = uniforms.view; + let transformed_pos = vm * a_pos; //TODO: use vector splats for division - const water_pos = transformed_pos.xyz * (1.0 / transformed_pos.w); - const normal = make_normal((vm * a_pos).xyz, (vm * b_pos).xyz, (vm * c_pos).xyz); - const eye = normalize(-water_pos); - const transformed_light = vm * vec4(light_point, 1.0); + let water_pos = transformed_pos.xyz * (1.0 / transformed_pos.w); + let normal = make_normal((vm * a_pos).xyz, (vm * b_pos).xyz, (vm * c_pos).xyz); + let eye = normalize(-water_pos); + let transformed_light = vm * vec4(light_point, 1.0); var out: VertexOutput; out.f_Light = light_colour * calc_specular(eye, normal, normalize(water_pos.xyz - (transformed_light.xyz * (1.0 / transformed_light.w)))); out.f_Fresnel = calc_fresnel(eye, normal); - const gridpos = uniforms.projection * vm * original_pos; + let gridpos = uniforms.projection * vm * original_pos; out.f_WaterScreenPos = (0.5 * gridpos.xy * (1.0 / gridpos.w)) + vec2(0.5, 0.5); out.position = uniforms.projection * transformed_pos; @@ -219,34 +219,34 @@ fn vs_main( } -const water_colour: vec3 = vec3(0.0, 0.46, 0.95); -const zNear: f32 = 10.0; -const zFar: f32 = 400.0; +let water_colour: vec3 = vec3(0.0, 0.46, 0.95); +let zNear: f32 = 10.0; +let zFar: f32 = 400.0; [[group(0), binding(1)]] var reflection: texture_2d; [[group(0), binding(2)]] var terrain_depth_tex: texture_2d; [[group(0), binding(3)]] var colour_sampler: sampler; fn to_linear_depth(depth: f32) -> f32 { - const z_n: f32 = 2.0 * depth - 1.0; - const z_e: f32 = 2.0 * zNear * zFar / (zFar + zNear - z_n * (zFar - zNear)); + let z_n: f32 = 2.0 * depth - 1.0; + let z_e: f32 = 2.0 * zNear * zFar / (zFar + zNear - z_n * (zFar - zNear)); return z_e; } [[stage(fragment)]] fn fs_main(in: VertexOutput) -> [[location(0)]] vec4 { - const reflection_colour = textureSample(reflection, colour_sampler, in.f_WaterScreenPos.xy).xyz; + let reflection_colour = textureSample(reflection, colour_sampler, in.f_WaterScreenPos.xy).xyz; - const pixel_depth = to_linear_depth(in.position.z); - const normalized_coords = in.position.xy / vec2(uniforms.time_size_width.w, uniforms.viewport_height); - const terrain_depth = to_linear_depth(textureSample(terrain_depth_tex, colour_sampler, normalized_coords).r); + let pixel_depth = to_linear_depth(in.position.z); + let normalized_coords = in.position.xy / vec2(uniforms.time_size_width.w, uniforms.viewport_height); + let terrain_depth = to_linear_depth(textureSample(terrain_depth_tex, colour_sampler, normalized_coords).r); - const dist = terrain_depth - pixel_depth; - const clamped = pow(smoothStep(0.0, 1.5, dist), 4.8); + let dist = terrain_depth - pixel_depth; + let clamped = pow(smoothStep(0.0, 1.5, dist), 4.8); - const final_colour = in.f_Light + reflection_colour; - const t = smoothStep(1.0, 5.0, dist) * 0.2; //TODO: splat for mix()? - const depth_colour = mix(final_colour, water_colour, vec3(t, t, t)); + let final_colour = in.f_Light + reflection_colour; + let t = smoothStep(1.0, 5.0, dist) * 0.2; //TODO: splat for mix()? + let depth_colour = mix(final_colour, water_colour, vec3(t, t, t)); return vec4(depth_colour, clamped * (1.0 - in.f_Fresnel)); }