diff --git a/player/tests/data/zero-init-buffer-for-binding.wgsl b/player/tests/data/zero-init-buffer-for-binding.wgsl index 0dae384f05..acf2417c7f 100644 --- a/player/tests/data/zero-init-buffer-for-binding.wgsl +++ b/player/tests/data/zero-init-buffer-for-binding.wgsl @@ -1,9 +1,9 @@ @group(0) @binding(0) -var buffer: array; +var buf: array; @compute @workgroup_size(1) fn main(@builtin(global_invocation_id) global_id: vec3) { - buffer[global_id.x] = buffer[global_id.x] + global_id.x; + buf[global_id.x] = buf[global_id.x] + global_id.x; } diff --git a/wgpu-hal/examples/halmark/shader.wgsl b/wgpu-hal/examples/halmark/shader.wgsl index 70385cbf29..60aac686b8 100644 --- a/wgpu-hal/examples/halmark/shader.wgsl +++ b/wgpu-hal/examples/halmark/shader.wgsl @@ -34,12 +34,12 @@ fn vs_main(@builtin(vertex_index) vi: u32) -> VertexOutput { @group(0) @binding(1) -var texture: texture_2d; +var tex: texture_2d; @group(0) @binding(2) var sam: sampler; @fragment -fn fs_main(in: VertexOutput) -> @location(0) vec4 { - return in.color * textureSampleLevel(texture, sam, in.tex_coords, 0.0); +fn fs_main(vertex: VertexOutput) -> @location(0) vec4 { + return vertex.color * textureSampleLevel(tex, sam, vertex.tex_coords, 0.0); } diff --git a/wgpu/examples/conservative-raster/upscale.wgsl b/wgpu/examples/conservative-raster/upscale.wgsl index 93390ed7b8..e456aba608 100644 --- a/wgpu/examples/conservative-raster/upscale.wgsl +++ b/wgpu/examples/conservative-raster/upscale.wgsl @@ -7,10 +7,10 @@ struct VertexOutput { fn vs_main(@builtin(vertex_index) vertex_index: u32) -> VertexOutput { 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; - return output; + var result: VertexOutput; + result.position = vec4(x, -y, 0.0, 1.0); + result.tex_coords = vec2(x + 1.0, y + 1.0) * 0.5; + return result; } @group(0) @@ -21,6 +21,6 @@ var r_color: texture_2d; var r_sampler: sampler; @fragment -fn fs_main(in: VertexOutput) -> @location(0) vec4 { - return textureSample(r_color, r_sampler, in.tex_coords); +fn fs_main(vertex: VertexOutput) -> @location(0) vec4 { + return textureSample(r_color, r_sampler, vertex.tex_coords); } diff --git a/wgpu/examples/cube/shader.wgsl b/wgpu/examples/cube/shader.wgsl index d345f8093c..5d106494ea 100644 --- a/wgpu/examples/cube/shader.wgsl +++ b/wgpu/examples/cube/shader.wgsl @@ -15,10 +15,10 @@ fn vs_main( @location(0) position: vec4, @location(1) tex_coord: vec2, ) -> VertexOutput { - var out: VertexOutput; - out.tex_coord = tex_coord; - out.position = r_locals.transform * position; - return out; + var result: VertexOutput; + result.tex_coord = tex_coord; + result.position = r_locals.transform * position; + return result; } @group(0) @@ -26,8 +26,8 @@ fn vs_main( var r_color: texture_2d; @fragment -fn fs_main(in: VertexOutput) -> @location(0) vec4 { - let tex = textureLoad(r_color, vec2(in.tex_coord * 256.0), 0); +fn fs_main(vertex: VertexOutput) -> @location(0) vec4 { + let tex = textureLoad(r_color, vec2(vertex.tex_coord * 256.0), 0); let v = f32(tex.x) / 255.0; return vec4(1.0 - (v * 5.0), 1.0 - (v * 15.0), 1.0 - (v * 50.0), 1.0); } diff --git a/wgpu/examples/mipmap/blit.wgsl b/wgpu/examples/mipmap/blit.wgsl index 76e5f44933..c293e51c73 100644 --- a/wgpu/examples/mipmap/blit.wgsl +++ b/wgpu/examples/mipmap/blit.wgsl @@ -5,20 +5,20 @@ struct VertexOutput { @vertex fn vs_main(@builtin(vertex_index) vertex_index: u32) -> VertexOutput { - var out: VertexOutput; + var result: VertexOutput; let x = i32(vertex_index) / 2; let y = i32(vertex_index) & 1; let tc = vec2( f32(x) * 2.0, f32(y) * 2.0 ); - out.position = vec4( + result.position = vec4( tc.x * 2.0 - 1.0, 1.0 - tc.y * 2.0, 0.0, 1.0 ); - out.tex_coords = tc; - return out; + result.tex_coords = tc; + return result; } @group(0) @@ -29,6 +29,6 @@ var r_color: texture_2d; var r_sampler: sampler; @fragment -fn fs_main(in: VertexOutput) -> @location(0) vec4 { - return textureSample(r_color, r_sampler, in.tex_coords); +fn fs_main(vertex: VertexOutput) -> @location(0) vec4 { + return textureSample(r_color, r_sampler, vertex.tex_coords); } diff --git a/wgpu/examples/mipmap/draw.wgsl b/wgpu/examples/mipmap/draw.wgsl index 804e43d1b4..f3b4cde580 100644 --- a/wgpu/examples/mipmap/draw.wgsl +++ b/wgpu/examples/mipmap/draw.wgsl @@ -16,10 +16,10 @@ fn vs_main(@builtin(vertex_index) vertex_index: u32) -> VertexOutput { 100.0 * (1.0 - f32(vertex_index & 2u)), 1000.0 * f32(vertex_index & 1u) ); - var out: VertexOutput; - out.tex_coords = 0.05 * pos + vec2(0.5, 0.5); - out.position = r_data.transform * vec4(pos, 0.0, 1.0); - return out; + var result: VertexOutput; + result.tex_coords = 0.05 * pos + vec2(0.5, 0.5); + result.position = r_data.transform * vec4(pos, 0.0, 1.0); + return result; } @group(0) @@ -30,6 +30,6 @@ var r_color: texture_2d; var r_sampler: sampler; @fragment -fn fs_main(in: VertexOutput) -> @location(0) vec4 { - return textureSample(r_color, r_sampler, in.tex_coords); +fn fs_main(vertex: VertexOutput) -> @location(0) vec4 { + return textureSample(r_color, r_sampler, vertex.tex_coords); } diff --git a/wgpu/examples/msaa-line/shader.wgsl b/wgpu/examples/msaa-line/shader.wgsl index 4a6023cdfd..687bb5718d 100644 --- a/wgpu/examples/msaa-line/shader.wgsl +++ b/wgpu/examples/msaa-line/shader.wgsl @@ -8,13 +8,13 @@ fn vs_main( @location(0) position: vec2, @location(1) color: vec4, ) -> VertexOutput { - var out: VertexOutput; - out.position = vec4(position, 0.0, 1.0); - out.color = color; - return out; + var result: VertexOutput; + result.position = vec4(position, 0.0, 1.0); + result.color = color; + return result; } @fragment -fn fs_main(in: VertexOutput) -> @location(0) vec4 { - return in.color; +fn fs_main(vertex: VertexOutput) -> @location(0) vec4 { + return vertex.color; } diff --git a/wgpu/examples/shadow/shader.wgsl b/wgpu/examples/shadow/shader.wgsl index 6a8d607df7..d6d272750c 100644 --- a/wgpu/examples/shadow/shader.wgsl +++ b/wgpu/examples/shadow/shader.wgsl @@ -34,11 +34,11 @@ fn vs_main( ) -> VertexOutput { 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; - out.proj_position = u_globals.view_proj * world_pos; - return out; + var result: VertexOutput; + result.world_normal = mat3x3(w.x.xyz, w.y.xyz, w.z.xyz) * vec3(normal.xyz); + result.world_position = world_pos; + result.proj_position = u_globals.view_proj * world_pos; + return result; } // fragment shader @@ -79,16 +79,16 @@ let c_ambient: vec3 = vec3(0.05, 0.05, 0.05); let c_max_lights: u32 = 10u; @fragment -fn fs_main(in: VertexOutput) -> @location(0) vec4 { - let normal = normalize(in.world_normal); +fn fs_main(vertex: VertexOutput) -> @location(0) vec4 { + let normal = normalize(vertex.world_normal); // accumulate color var color: vec3 = c_ambient; for(var i = 0u; i < min(u_globals.num_lights.x, c_max_lights); i += 1u) { let light = s_lights[i]; // project into the light space - let shadow = fetch_shadow(i, light.proj * in.world_position); + let shadow = fetch_shadow(i, light.proj * vertex.world_position); // compute Lambertian diffuse term - let light_dir = normalize(light.pos.xyz - in.world_position.xyz); + let light_dir = normalize(light.pos.xyz - vertex.world_position.xyz); let diffuse = max(0.0, dot(normal, light_dir)); // add light contribution color += shadow * diffuse * light.color.xyz; @@ -99,15 +99,15 @@ fn fs_main(in: VertexOutput) -> @location(0) vec4 { // The fragment entrypoint used when storage buffers are not available for the lights @fragment -fn fs_main_without_storage(in: VertexOutput) -> @location(0) vec4 { - let normal = normalize(in.world_normal); +fn fs_main_without_storage(vertex: VertexOutput) -> @location(0) vec4 { + let normal = normalize(vertex.world_normal); var color: vec3 = c_ambient; for(var i = 0u; i < min(u_globals.num_lights.x, c_max_lights); i += 1u) { // This line is the only difference from the entrypoint above. It uses the lights // uniform instead of the lights storage buffer let light = u_lights[i]; - let shadow = fetch_shadow(i, light.proj * in.world_position); - let light_dir = normalize(light.pos.xyz - in.world_position.xyz); + let shadow = fetch_shadow(i, light.proj * vertex.world_position); + let light_dir = normalize(light.pos.xyz - vertex.world_position.xyz); let diffuse = max(0.0, dot(normal, light_dir)); color += shadow * diffuse * light.color.xyz; } diff --git a/wgpu/examples/skybox/shader.wgsl b/wgpu/examples/skybox/shader.wgsl index b441c2eaa7..fcc8caf3ff 100644 --- a/wgpu/examples/skybox/shader.wgsl +++ b/wgpu/examples/skybox/shader.wgsl @@ -33,10 +33,10 @@ fn vs_sky(@builtin(vertex_index) vertex_index: u32) -> SkyOutput { 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; - out.position = pos; - return out; + var result: SkyOutput; + result.uv = inv_model_view * unprojected.xyz; + result.position = pos; + return result; } struct EntityOutput { @@ -50,11 +50,11 @@ fn vs_entity( @location(0) pos: vec3, @location(1) normal: vec3, ) -> EntityOutput { - var out: EntityOutput; - out.normal = normal; - out.view = pos - r_data.cam_pos.xyz; - out.position = r_data.proj * r_data.view * vec4(pos, 1.0); - return out; + var result: EntityOutput; + result.normal = normal; + result.view = pos - r_data.cam_pos.xyz; + result.position = r_data.proj * r_data.view * vec4(pos, 1.0); + return result; } @group(0) @@ -65,14 +65,14 @@ var r_texture: texture_cube; var r_sampler: sampler; @fragment -fn fs_sky(in: SkyOutput) -> @location(0) vec4 { - return textureSample(r_texture, r_sampler, in.uv); +fn fs_sky(vertex: SkyOutput) -> @location(0) vec4 { + return textureSample(r_texture, r_sampler, vertex.uv); } @fragment -fn fs_entity(in: EntityOutput) -> @location(0) vec4 { - let incident = normalize(in.view); - let normal = normalize(in.normal); +fn fs_entity(vertex: EntityOutput) -> @location(0) vec4 { + let incident = normalize(vertex.view); + let normal = normalize(vertex.normal); let reflected = incident - 2.0 * dot(normal, incident) * normal; let reflected_color = textureSample(r_texture, r_sampler, reflected).rgb; diff --git a/wgpu/examples/water/terrain.wgsl b/wgpu/examples/water/terrain.wgsl index f1c2a6eb53..e5a19d7b29 100644 --- a/wgpu/examples/water/terrain.wgsl +++ b/wgpu/examples/water/terrain.wgsl @@ -24,27 +24,27 @@ fn vs_main( @location(1) normal: vec3, @location(2) colour: vec4, ) -> VertexOutput { - var out: VertexOutput; - out.position = uniforms.projection_view * vec4(position, 1.0); + var result: VertexOutput; + result.position = uniforms.projection_view * vec4(position, 1.0); // https://www.desmos.com/calculator/nqgyaf8uvo 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); - return out; + result.colour = vec4(max((brightness_diffuse + ambient) * light_colour * colour.rgb, vec3(0.0, 0.0, 0.0)), colour.a); + result.clip_dist = dot(vec4(position, 1.0), uniforms.clipping_plane); + return result; } @fragment @early_depth_test fn fs_main( - in: VertexOutput, + vertex: VertexOutput, ) -> @location(0) vec4 { // Comment this out if using user-clipping planes: - if(in.clip_dist < 0.0) { + if(vertex.clip_dist < 0.0) { discard; } - return vec4(in.colour.xyz, 1.0); + return vec4(vertex.colour.xyz, 1.0); } diff --git a/wgpu/examples/water/water.wgsl b/wgpu/examples/water/water.wgsl index 61653dd02b..121e805b65 100644 --- a/wgpu/examples/water/water.wgsl +++ b/wgpu/examples/water/water.wgsl @@ -206,15 +206,15 @@ fn vs_main( 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); + var result: VertexOutput; + result.f_Light = light_colour * calc_specular(eye, normal, normalize(water_pos.xyz - (transformed_light.xyz * (1.0 / transformed_light.w)))); + result.f_Fresnel = calc_fresnel(eye, normal); let gridpos = uniforms.projection * vm * original_pos; - out.f_WaterScreenPos = (0.5 * gridpos.xy * (1.0 / gridpos.w)) + vec2(0.5, 0.5); + result.f_WaterScreenPos = (0.5 * gridpos.xy * (1.0 / gridpos.w)) + vec2(0.5, 0.5); - out.position = uniforms.projection * transformed_pos; - return out; + result.position = uniforms.projection * transformed_pos; + return result; } @@ -234,19 +234,19 @@ fn to_linear_depth(depth: f32) -> f32 { } @fragment -fn fs_main(in: VertexOutput) -> @location(0) vec4 { - let reflection_colour = textureSample(reflection, colour_sampler, in.f_WaterScreenPos.xy).xyz; +fn fs_main(vertex: VertexOutput) -> @location(0) vec4 { + let reflection_colour = textureSample(reflection, colour_sampler, vertex.f_WaterScreenPos.xy).xyz; - 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 pixel_depth = to_linear_depth(vertex.position.z); + let normalized_coords = vertex.position.xy / vec2(uniforms.time_size_width.w, uniforms.viewport_height); let terrain_depth = to_linear_depth(textureSample(terrain_depth_tex, depth_sampler, normalized_coords).r); let dist = terrain_depth - pixel_depth; let clamped = pow(smoothstep(0.0, 1.5, dist), 4.8); - let final_colour = in.f_Light + reflection_colour; + let final_colour = vertex.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)); + return vec4(depth_colour, clamped * (1.0 - vertex.f_Fresnel)); }