Update to upstream naga

This commit is contained in:
João Capucho 2022-01-22 15:34:44 +00:00 committed by Dzmitry Malyshau
parent 83d0d16177
commit dcd07f0391
26 changed files with 207 additions and 175 deletions

2
Cargo.lock generated
View File

@ -1039,7 +1039,7 @@ dependencies = [
[[package]]
name = "naga"
version = "0.8.0"
source = "git+https://github.com/JCapucho/naga?branch=glsl-out-push-constants-v2#c60d70eddf99d5858747d0a7823ab79c8cd0d019"
source = "git+https://github.com/gfx-rs/naga?rev=81dc674#81dc67402a743b4dc6b2d24c0d306cd18799238b"
dependencies = [
"bit-set",
"bitflags",

View File

@ -18,7 +18,6 @@ default-members = ["wgpu", "wgpu-hal", "wgpu-info"]
[patch."https://github.com/gfx-rs/naga"]
#naga = { path = "../naga" }
naga = { git = "https://github.com/JCapucho/naga", branch = "glsl-out-push-constants-v2" }
[patch."https://github.com/zakarumych/gpu-descriptor"]
#gpu-descriptor = { path = "../gpu-descriptor/gpu-descriptor" }

View File

@ -4,11 +4,12 @@ const numbers = [1, 4, 3, 295];
const device = await adapter.requestDevice();
const shaderCode = `[[block]]
const shaderCode = `@block
struct PrimeIndices {
data: [[stride(4)]] array<u32>;
data: @stride(4) array<u32>;
}; // this is used as both input and output for convenience
[[group(0), binding(0)]]
@group(0)
@binding(0)
var<storage, read_write> v_indices: PrimeIndices;
// The Collatz Conjecture states that for any integer n:
// If n is even, n = n/2
@ -37,8 +38,9 @@ fn collatz_iterations(n_base: u32) -> u32{
}
return i;
}
[[stage(compute), workgroup_size(1)]]
fn main([[builtin(global_invocation_id)]] global_id: vec3<u32>) {
@stage(compute)
@workgroup_size(1)
fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
v_indices.data[global_id.x] = collatz_iterations(v_indices.data[global_id.x]);
}`;

View File

@ -1,3 +1,4 @@
[[stage(compute), workgroup_size(1)]]
@stage(compute)
@workgroup_size(1)
fn main() {
}

View File

@ -1,5 +1,5 @@
[[stage(vertex)]]
fn vs_main([[builtin(vertex_index)]] vertex_index: u32) -> [[builtin(position)]] vec4<f32> {
@stage(vertex)
fn vs_main(@builtin(vertex_index) vertex_index: u32) -> @builtin(position) vec4<f32> {
// hacky way to draw a large triangle
let tmp1 = i32(vertex_index) / 2;
let tmp2 = i32(vertex_index) & 1;
@ -10,7 +10,7 @@ fn vs_main([[builtin(vertex_index)]] vertex_index: u32) -> [[builtin(position)]]
return vec4<f32>(pos, 0.0, 1.0);
}
[[stage(fragment)]]
fn fs_main() -> [[location(0)]] vec4<f32> {
@stage(fragment)
fn fs_main() -> @location(0) vec4<f32> {
return vec4<f32>(1.0, 1.0, 1.0, 1.0);
}

View File

@ -1,11 +1,13 @@
struct InOutBuffer {
data: [[stride(4)]] array<u32>;
data: @stride(4) array<u32>;
};
[[group(0), binding(0)]]
@group(0)
@binding(0)
var<storage, read_write> buffer: InOutBuffer;
[[stage(compute), workgroup_size(1)]]
fn main([[builtin(global_invocation_id)]] global_id: vec3<u32>) {
@stage(compute)
@workgroup_size(1)
fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
buffer.data[global_id.x] = buffer.data[global_id.x] + global_id.x;
}

View File

@ -1,6 +1,7 @@
[[group(0), binding(0)]] var tex: texture_2d<f32>;
[[group(0), binding(1)]] var tex_storage: texture_storage_2d<rgba8uint, write>;
@group(0) @binding(0) var tex: texture_2d<f32>;
@group(0) @binding(1) var tex_storage: texture_storage_2d<rgba8uint, write>;
[[stage(compute), workgroup_size(1)]]
fn main([[builtin(global_invocation_id)]] global_id: vec3<u32>) {
@stage(compute)
@workgroup_size(1)
fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
}

View File

@ -38,7 +38,7 @@ thiserror = "1"
[dependencies.naga]
git = "https://github.com/gfx-rs/naga"
rev = "a1840be"
rev = "81dc674"
#version = "0.8"
features = ["span", "validate", "wgsl-in"]

View File

@ -82,14 +82,14 @@ js-sys = { version = "0.3" }
[dependencies.naga]
git = "https://github.com/gfx-rs/naga"
rev = "a1840be"
rev = "81dc674"
#version = "0.8"
# DEV dependencies
[dev-dependencies.naga]
git = "https://github.com/gfx-rs/naga"
rev = "a1840be"
rev = "81dc674"
#version = "0.8"
features = ["wgsl-in"]

View File

@ -9,20 +9,22 @@ struct Locals {
color: u32;
};
[[group(0), binding(0)]]
@group(0)
@binding(0)
var<uniform> globals: Globals;
[[group(1), binding(0)]]
@group(1)
@binding(0)
var<uniform> locals: Locals;
struct VertexOutput {
[[builtin(position)]] position: vec4<f32>;
[[location(0)]] tex_coords: vec2<f32>;
[[location(1)]] color: vec4<f32>;
@builtin(position) position: vec4<f32>;
@location(0) tex_coords: vec2<f32>;
@location(1) color: vec4<f32>;
};
[[stage(vertex)]]
fn vs_main([[builtin(vertex_index)]] vi: u32) -> VertexOutput {
@stage(vertex)
fn vs_main(@builtin(vertex_index) vi: u32) -> VertexOutput {
let tc = vec2<f32>(f32(vi & 1u), 0.5 * f32(vi & 2u));
let offset = vec2<f32>(tc.x * globals.size.x, tc.y * globals.size.y);
let pos = globals.mvp * vec4<f32>(locals.position + offset, 0.0, 1.0);
@ -30,12 +32,14 @@ fn vs_main([[builtin(vertex_index)]] vi: u32) -> VertexOutput {
return VertexOutput(pos, tc, color);
}
[[group(0), binding(1)]]
@group(0)
@binding(1)
var texture: texture_2d<f32>;
[[group(0), binding(2)]]
@group(0)
@binding(2)
var sam: sampler;
[[stage(fragment)]]
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
@stage(fragment)
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
return in.color * textureSampleLevel(texture, sam, in.tex_coords, 0.0);
}

View File

@ -136,20 +136,20 @@ env_logger = "0.8"
[dependencies.naga]
git = "https://github.com/gfx-rs/naga"
rev = "a1840be"
rev = "81dc674"
#version = "0.8"
optional = true
# used to test all the example shaders
[dev-dependencies.naga]
git = "https://github.com/gfx-rs/naga"
rev = "a1840be"
rev = "81dc674"
#version = "0.8"
features = ["wgsl-in"]
[target.'cfg(target_arch = "wasm32")'.dependencies.naga]
git = "https://github.com/gfx-rs/naga"
rev = "a1840be"
rev = "81dc674"
#version = "0.8"
features = ["wgsl-out"]

View File

@ -14,16 +14,17 @@ struct SimParams {
};
struct Particles {
particles : [[stride(16)]] array<Particle>;
particles : @stride(16) array<Particle>;
};
[[group(0), binding(0)]] var<uniform> params : SimParams;
[[group(0), binding(1)]] var<storage, read> particlesSrc : Particles;
[[group(0), binding(2)]] var<storage, read_write> particlesDst : Particles;
@group(0) @binding(0) var<uniform> params : SimParams;
@group(0) @binding(1) var<storage, read> particlesSrc : Particles;
@group(0) @binding(2) var<storage, read_write> particlesDst : 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<u32>) {
@stage(compute)
@workgroup_size(64)
fn main(@builtin(global_invocation_id) global_invocation_id: vec3<u32>) {
let total = arrayLength(&particlesSrc.particles);
let index = global_invocation_id.x;
if (index >= total) {

View File

@ -1,9 +1,9 @@
[[stage(vertex)]]
@stage(vertex)
fn main_vs(
[[location(0)]] particle_pos: vec2<f32>,
[[location(1)]] particle_vel: vec2<f32>,
[[location(2)]] position: vec2<f32>,
) -> [[builtin(position)]] vec4<f32> {
@location(0) particle_pos: vec2<f32>,
@location(1) particle_vel: vec2<f32>,
@location(2) position: vec2<f32>,
) -> @builtin(position) vec4<f32> {
let angle = -atan2(particle_vel.x, particle_vel.y);
let pos = vec2<f32>(
position.x * cos(angle) - position.y * sin(angle),
@ -12,7 +12,7 @@ fn main_vs(
return vec4<f32>(pos + particle_pos, 0.0, 1.0);
}
[[stage(fragment)]]
fn main_fs() -> [[location(0)]] vec4<f32> {
@stage(fragment)
fn main_fs() -> @location(0) vec4<f32> {
return vec4<f32>(1.0, 1.0, 1.0, 1.0);
}

View File

@ -1,22 +1,22 @@
[[stage(vertex)]]
fn vs_main([[builtin(vertex_index)]] vertex_index: u32) -> [[builtin(position)]] vec4<f32> {
@stage(vertex)
fn vs_main(@builtin(vertex_index) vertex_index: u32) -> @builtin(position) vec4<f32> {
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<f32>(x, y, 0.0, 1.0);
}
[[stage(fragment)]]
fn fs_main_red() -> [[location(0)]] vec4<f32> {
@stage(fragment)
fn fs_main_red() -> @location(0) vec4<f32> {
return vec4<f32>(1.0, 0.0, 0.0, 1.0);
}
[[stage(fragment)]]
fn fs_main_blue() -> [[location(0)]] vec4<f32> {
@stage(fragment)
fn fs_main_blue() -> @location(0) vec4<f32> {
return vec4<f32>(0.13, 0.31, 0.85, 1.0); // cornflower blue in linear space
}
[[stage(fragment)]]
fn fs_main_white() -> [[location(0)]] vec4<f32> {
@stage(fragment)
fn fs_main_white() -> @location(0) vec4<f32> {
return vec4<f32>(1.0, 1.0, 1.0, 1.0);
}

View File

@ -1,10 +1,10 @@
struct VertexOutput {
[[builtin(position)]] position: vec4<f32>;
[[location(0)]] tex_coords: vec2<f32>;
@builtin(position) position: vec4<f32>;
@location(0) tex_coords: vec2<f32>;
};
[[stage(vertex)]]
fn vs_main([[builtin(vertex_index)]] vertex_index: u32) -> VertexOutput {
@stage(vertex)
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;
@ -13,12 +13,14 @@ fn vs_main([[builtin(vertex_index)]] vertex_index: u32) -> VertexOutput {
return output;
}
[[group(0), binding(0)]]
@group(0)
@binding(0)
var r_color: texture_2d<f32>;
[[group(0), binding(1)]]
@group(0)
@binding(1)
var r_sampler: sampler;
[[stage(fragment)]]
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
@stage(fragment)
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
return textureSample(r_color, r_sampler, in.tex_coords);
}
}

View File

@ -1,18 +1,19 @@
struct VertexOutput {
[[location(0)]] tex_coord: vec2<f32>;
[[builtin(position)]] position: vec4<f32>;
@location(0) tex_coord: vec2<f32>;
@builtin(position) position: vec4<f32>;
};
struct Locals {
transform: mat4x4<f32>;
};
[[group(0), binding(0)]]
@group(0)
@binding(0)
var<uniform> r_locals: Locals;
[[stage(vertex)]]
@stage(vertex)
fn vs_main(
[[location(0)]] position: vec4<f32>,
[[location(1)]] tex_coord: vec2<f32>,
@location(0) position: vec4<f32>,
@location(1) tex_coord: vec2<f32>,
) -> VertexOutput {
var out: VertexOutput;
out.tex_coord = tex_coord;
@ -20,17 +21,18 @@ fn vs_main(
return out;
}
[[group(0), binding(1)]]
@group(0)
@binding(1)
var r_color: texture_2d<u32>;
[[stage(fragment)]]
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
@stage(fragment)
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
let tex = textureLoad(r_color, vec2<i32>(in.tex_coord * 256.0), 0);
let v = f32(tex.x) / 255.0;
return vec4<f32>(1.0 - (v * 5.0), 1.0 - (v * 15.0), 1.0 - (v * 50.0), 1.0);
}
[[stage(fragment)]]
fn fs_wire() -> [[location(0)]] vec4<f32> {
@stage(fragment)
fn fs_wire() -> @location(0) vec4<f32> {
return vec4<f32>(0.0, 0.5, 0.0, 0.5);
}

View File

@ -1,8 +1,9 @@
struct PrimeIndices {
data: [[stride(4)]] array<u32>;
data: @stride(4) array<u32>;
}; // this is used as both input and output for convenience
[[group(0), binding(0)]]
@group(0)
@binding(0)
var<storage, read_write> v_indices: PrimeIndices;
// The Collatz Conjecture states that for any integer n:
@ -34,7 +35,8 @@ fn collatz_iterations(n_base: u32) -> u32{
return i;
}
[[stage(compute), workgroup_size(1)]]
fn main([[builtin(global_invocation_id)]] global_id: vec3<u32>) {
@stage(compute)
@workgroup_size(1)
fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
v_indices.data[global_id.x] = collatz_iterations(v_indices.data[global_id.x]);
}

View File

@ -1,11 +1,11 @@
[[stage(vertex)]]
fn vs_main([[builtin(vertex_index)]] in_vertex_index: u32) -> [[builtin(position)]] vec4<f32> {
@stage(vertex)
fn vs_main(@builtin(vertex_index) in_vertex_index: u32) -> @builtin(position) vec4<f32> {
let x = f32(i32(in_vertex_index) - 1);
let y = f32(i32(in_vertex_index & 1u) * 2 - 1);
return vec4<f32>(x, y, 0.0, 1.0);
}
[[stage(fragment)]]
fn fs_main() -> [[location(0)]] vec4<f32> {
@stage(fragment)
fn fs_main() -> @location(0) vec4<f32> {
return vec4<f32>(1.0, 0.0, 0.0, 1.0);
}

View File

@ -1,10 +1,10 @@
struct VertexOutput {
[[builtin(position)]] position: vec4<f32>;
[[location(0)]] tex_coords: vec2<f32>;
@builtin(position) position: vec4<f32>;
@location(0) tex_coords: vec2<f32>;
};
[[stage(vertex)]]
fn vs_main([[builtin(vertex_index)]] vertex_index: u32) -> VertexOutput {
@stage(vertex)
fn vs_main(@builtin(vertex_index) vertex_index: u32) -> VertexOutput {
var out: VertexOutput;
let x = i32(vertex_index) / 2;
let y = i32(vertex_index) & 1;
@ -21,12 +21,14 @@ fn vs_main([[builtin(vertex_index)]] vertex_index: u32) -> VertexOutput {
return out;
}
[[group(0), binding(0)]]
@group(0)
@binding(0)
var r_color: texture_2d<f32>;
[[group(0), binding(1)]]
@group(0)
@binding(1)
var r_sampler: sampler;
[[stage(fragment)]]
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
@stage(fragment)
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
return textureSample(r_color, r_sampler, in.tex_coords);
}

View File

@ -1,16 +1,17 @@
struct VertexOutput {
[[builtin(position)]] position: vec4<f32>;
[[location(0)]] tex_coords: vec2<f32>;
@builtin(position) position: vec4<f32>;
@location(0) tex_coords: vec2<f32>;
};
struct Locals {
transform: mat4x4<f32>;
};
[[group(0), binding(0)]]
@group(0)
@binding(0)
var<uniform> r_data: Locals;
[[stage(vertex)]]
fn vs_main([[builtin(vertex_index)]] vertex_index: u32) -> VertexOutput {
@stage(vertex)
fn vs_main(@builtin(vertex_index) vertex_index: u32) -> VertexOutput {
let pos = vec2<f32>(
100.0 * (1.0 - f32(vertex_index & 2u)),
1000.0 * f32(vertex_index & 1u)
@ -21,12 +22,14 @@ fn vs_main([[builtin(vertex_index)]] vertex_index: u32) -> VertexOutput {
return out;
}
[[group(0), binding(1)]]
@group(0)
@binding(1)
var r_color: texture_2d<f32>;
[[group(0), binding(2)]]
@group(0)
@binding(2)
var r_sampler: sampler;
[[stage(fragment)]]
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
@stage(fragment)
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
return textureSample(r_color, r_sampler, in.tex_coords);
}

View File

@ -1,12 +1,12 @@
struct VertexOutput {
[[location(0)]] color: vec4<f32>;
[[builtin(position)]] position: vec4<f32>;
@location(0) color: vec4<f32>;
@builtin(position) position: vec4<f32>;
};
[[stage(vertex)]]
@stage(vertex)
fn vs_main(
[[location(0)]] position: vec2<f32>,
[[location(1)]] color: vec4<f32>,
@location(0) position: vec2<f32>,
@location(1) color: vec4<f32>,
) -> VertexOutput {
var out: VertexOutput;
out.position = vec4<f32>(position, 0.0, 1.0);
@ -14,7 +14,7 @@ fn vs_main(
return out;
}
[[stage(fragment)]]
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
@stage(fragment)
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
return in.color;
}

View File

@ -3,7 +3,8 @@ struct Globals {
num_lights: vec4<u32>;
};
[[group(0), binding(0)]]
@group(0)
@binding(0)
var<uniform> u_globals: Globals;
struct Entity {
@ -11,24 +12,25 @@ struct Entity {
color: vec4<f32>;
};
[[group(1), binding(0)]]
@group(1)
@binding(0)
var<uniform> u_entity: Entity;
[[stage(vertex)]]
fn vs_bake([[location(0)]] position: vec4<i32>) -> [[builtin(position)]] vec4<f32> {
@stage(vertex)
fn vs_bake(@location(0) position: vec4<i32>) -> @builtin(position) vec4<f32> {
return u_globals.view_proj * u_entity.world * vec4<f32>(position);
}
struct VertexOutput {
[[builtin(position)]] proj_position: vec4<f32>;
[[location(0)]] world_normal: vec3<f32>;
[[location(1)]] world_position: vec4<f32>;
@builtin(position) proj_position: vec4<f32>;
@location(0) world_normal: vec3<f32>;
@location(1) world_position: vec4<f32>;
};
[[stage(vertex)]]
@stage(vertex)
fn vs_main(
[[location(0)]] position: vec4<i32>,
[[location(1)]] normal: vec4<i32>,
@location(0) position: vec4<i32>,
@location(1) normal: vec4<i32>,
) -> VertexOutput {
let w = u_entity.world;
let world_pos = u_entity.world * vec4<f32>(position);
@ -48,7 +50,7 @@ struct Light {
};
struct Lights {
data: [[stride(96)]] array<Light>;
data: @stride(96) array<Light>;
};
// Used when storage types are not supported
@ -56,13 +58,17 @@ struct LightsWithoutStorage {
data: array<Light, 10>;
};
[[group(0), binding(1)]]
@group(0)
@binding(1)
var<storage, read> s_lights: Lights;
[[group(0), binding(1)]]
@group(0)
@binding(1)
var<uniform> u_lights: LightsWithoutStorage;
[[group(0), binding(2)]]
@group(0)
@binding(2)
var t_shadow: texture_depth_2d_array;
[[group(0), binding(3)]]
@group(0)
@binding(3)
var sampler_shadow: sampler_comparison;
fn fetch_shadow(light_id: u32, homogeneous_coords: vec4<f32>) -> f32 {
@ -81,8 +87,8 @@ fn fetch_shadow(light_id: u32, homogeneous_coords: vec4<f32>) -> f32 {
let c_ambient: vec3<f32> = vec3<f32>(0.05, 0.05, 0.05);
let c_max_lights: u32 = 10u;
[[stage(fragment)]]
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
@stage(fragment)
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
let normal = normalize(in.world_normal);
// accumulate color
var color: vec3<f32> = c_ambient;
@ -101,8 +107,8 @@ fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
}
// The fragment entrypoint used when storage buffers are not available for the lights
[[stage(fragment)]]
fn fs_main_without_storage(in: VertexOutput) -> [[location(0)]] vec4<f32> {
@stage(fragment)
fn fs_main_without_storage(in: VertexOutput) -> @location(0) vec4<f32> {
let normal = normalize(in.world_normal);
var color: vec3<f32> = c_ambient;
for(var i = 0u; i < min(u_globals.num_lights.x, c_max_lights); i += 1u) {
@ -115,4 +121,4 @@ fn fs_main_without_storage(in: VertexOutput) -> [[location(0)]] vec4<f32> {
color += shadow * diffuse * light.color.xyz;
}
return vec4<f32>(color, 1.0) * u_entity.color;
}
}

View File

@ -1,6 +1,6 @@
struct SkyOutput {
[[builtin(position)]] position: vec4<f32>;
[[location(0)]] uv: vec3<f32>;
@builtin(position) position: vec4<f32>;
@location(0) uv: vec3<f32>;
};
struct Data {
@ -13,11 +13,12 @@ struct Data {
// camera position
cam_pos: vec4<f32>;
};
[[group(0), binding(0)]]
@group(0)
@binding(0)
var<uniform> r_data: Data;
[[stage(vertex)]]
fn vs_sky([[builtin(vertex_index)]] vertex_index: u32) -> SkyOutput {
@stage(vertex)
fn vs_sky(@builtin(vertex_index) vertex_index: u32) -> SkyOutput {
// hacky way to draw a large triangle
let tmp1 = i32(vertex_index) / 2;
let tmp2 = i32(vertex_index) & 1;
@ -39,15 +40,15 @@ fn vs_sky([[builtin(vertex_index)]] vertex_index: u32) -> SkyOutput {
}
struct EntityOutput {
[[builtin(position)]] position: vec4<f32>;
[[location(1)]] normal: vec3<f32>;
[[location(3)]] view: vec3<f32>;
@builtin(position) position: vec4<f32>;
@location(1) normal: vec3<f32>;
@location(3) view: vec3<f32>;
};
[[stage(vertex)]]
@stage(vertex)
fn vs_entity(
[[location(0)]] pos: vec3<f32>,
[[location(1)]] normal: vec3<f32>,
@location(0) pos: vec3<f32>,
@location(1) normal: vec3<f32>,
) -> EntityOutput {
var out: EntityOutput;
out.normal = normal;
@ -56,18 +57,20 @@ fn vs_entity(
return out;
}
[[group(0), binding(1)]]
@group(0)
@binding(1)
var r_texture: texture_cube<f32>;
[[group(0), binding(2)]]
@group(0)
@binding(2)
var r_sampler: sampler;
[[stage(fragment)]]
fn fs_sky(in: SkyOutput) -> [[location(0)]] vec4<f32> {
@stage(fragment)
fn fs_sky(in: SkyOutput) -> @location(0) vec4<f32> {
return textureSample(r_texture, r_sampler, in.uv);
}
[[stage(fragment)]]
fn fs_entity(in: EntityOutput) -> [[location(0)]] vec4<f32> {
@stage(fragment)
fn fs_entity(in: EntityOutput) -> @location(0) vec4<f32> {
let incident = normalize(in.view);
let normal = normalize(in.normal);
let reflected = incident - 2.0 * dot(normal, incident) * normal;

View File

@ -3,7 +3,8 @@ struct Uniforms {
clipping_plane: vec4<f32>;
};
[[group(0), binding(0)]]
@group(0)
@binding(0)
var<uniform> uniforms: Uniforms;
let light = vec3<f32>(150.0, 70.0, 0.0);
@ -11,17 +12,17 @@ let light_colour = vec3<f32>(1.0, 0.98, 0.82);
let ambient = 0.2;
struct VertexOutput {
[[builtin(position)]] position: vec4<f32>;
[[location(0)]] colour: vec4<f32>;
@builtin(position) position: vec4<f32>;
@location(0) colour: vec4<f32>;
// Comment this out if using user-clipping planes:
[[location(1)]] clip_dist: f32;
@location(1) clip_dist: f32;
};
[[stage(vertex)]]
@stage(vertex)
fn vs_main(
[[location(0)]] position: vec3<f32>,
[[location(1)]] normal: vec3<f32>,
[[location(2)]] colour: vec4<f32>,
@location(0) position: vec3<f32>,
@location(1) normal: vec3<f32>,
@location(2) colour: vec4<f32>,
) -> VertexOutput {
var out: VertexOutput;
out.position = uniforms.projection_view * vec4<f32>(position, 1.0);
@ -35,10 +36,11 @@ fn vs_main(
return out;
}
[[stage(fragment), early_depth_test]]
@stage(fragment)
@early_depth_test
fn fs_main(
in: VertexOutput,
) -> [[location(0)]] vec4<f32> {
) -> @location(0) vec4<f32> {
// Comment this out if using user-clipping planes:
if(in.clip_dist < 0.0) {
discard;

View File

@ -4,7 +4,7 @@ struct Uniforms {
time_size_width: vec4<f32>;
viewport_height: f32;
};
[[group(0), binding(0)]] var<uniform> uniforms: Uniforms;
@group(0) @binding(0) var<uniform> uniforms: Uniforms;
let light_point = vec3<f32>(150.0, 70.0, 0.0);
let light_colour = vec3<f32>(1.0, 0.98, 0.82);
@ -181,16 +181,16 @@ fn calc_specular(eye: vec3<f32>, normal: vec3<f32>, light: vec3<f32>) -> f32 {
}
struct VertexOutput {
[[builtin(position)]] position: vec4<f32>;
[[location(0)]] f_WaterScreenPos: vec2<f32>;
[[location(1)]] f_Fresnel: f32;
[[location(2)]] f_Light: vec3<f32>;
@builtin(position) position: vec4<f32>;
@location(0) f_WaterScreenPos: vec2<f32>;
@location(1) f_Fresnel: f32;
@location(2) f_Light: vec3<f32>;
};
[[stage(vertex)]]
@stage(vertex)
fn vs_main(
[[location(0)]] position: vec2<i32>,
[[location(1)]] offsets: vec4<i32>,
@location(0) position: vec2<i32>,
@location(1) offsets: vec4<i32>,
) -> VertexOutput {
let p_pos = vec2<f32>(position);
let b_pos = make_position(p_pos + vec2<f32>(offsets.xy));
@ -222,9 +222,9 @@ let water_colour = vec3<f32>(0.0, 0.46, 0.95);
let zNear = 10.0;
let zFar = 400.0;
[[group(0), binding(1)]] var reflection: texture_2d<f32>;
[[group(0), binding(2)]] var terrain_depth_tex: texture_2d<f32>;
[[group(0), binding(3)]] var colour_sampler: sampler;
@group(0) @binding(1) var reflection: texture_2d<f32>;
@group(0) @binding(2) var terrain_depth_tex: texture_2d<f32>;
@group(0) @binding(3) var colour_sampler: sampler;
fn to_linear_depth(depth: f32) -> f32 {
let z_n = 2.0 * depth - 1.0;
@ -232,8 +232,8 @@ fn to_linear_depth(depth: f32) -> f32 {
return z_e;
}
[[stage(fragment)]]
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
@stage(fragment)
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
let reflection_colour = textureSample(reflection, colour_sampler, in.f_WaterScreenPos.xy).xyz;
let pixel_depth = to_linear_depth(in.position.z);

View File

@ -2,17 +2,17 @@ struct Indices {
arr: array<u32>;
}; // this is used as both input and output for convenience
[[group(0), binding(0)]]
@group(0) @binding(0)
var<storage, read_write> indices: Indices;
[[stage(vertex)]]
fn vs_main([[builtin(instance_index)]] instance: u32, [[builtin(vertex_index)]] index: u32) -> [[builtin(position)]] vec4<f32> {
@stage(vertex)
fn vs_main(@builtin(instance_index) instance: u32, @builtin(vertex_index) index: u32) -> @builtin(position) vec4<f32> {
let idx = instance * 3u + index;
indices.arr[idx] = idx;
return vec4<f32>(0.0, 0.0, 0.0, 1.0);
}
[[stage(fragment)]]
fn fs_main() -> [[location(0)]] vec4<f32> {
@stage(fragment)
fn fs_main() -> @location(0) vec4<f32> {
return vec4<f32>(0.0);
}