bevy/assets/shaders/custom.wgsl
Nibor62 7b686b5031 Fix custom_shader_pipelined example shader (#2992)
## Objective

Looking though the new pipelined example I stumbled on an issue with the example shader :

```
Oct 20 12:38:44.891  INFO bevy_render2::renderer: AdapterInfo { name: "Intel(R) UHD Graphics 620 (KBL GT2)", vendor: 32902, device: 22807, device_type: IntegratedGpu, backend: Vulkan }
Oct 20 12:38:44.894  INFO naga:🔙:spv::writer: Skip function Some("fetch_point_shadow")    
Oct 20 12:38:44.894  INFO naga:🔙:spv::writer: Skip function Some("fetch_directional_shadow")    
Oct 20 12:38:44.898 ERROR wgpu::backend::direct: Handling wgpu errors as fatal by default    
thread 'main' panicked at 'wgpu error: Validation Error

Caused by:
    In Device::create_shader_module
    Global variable [1] 'view' is invalid
    Type isn't compatible with the storage class
```

## Solution

added `<uniform>` here and there.
Note : my current mastery of shaders is about 2 days old, so this still kinda look likes wizardry
2021-10-25 19:02:36 +00:00

46 lines
944 B
WebGPU Shading Language

[[block]]
struct View {
view_proj: mat4x4<f32>;
projection: mat4x4<f32>;
world_position: vec3<f32>;
};
[[group(0), binding(0)]]
var<uniform> view: View;
[[block]]
struct Mesh {
transform: mat4x4<f32>;
};
[[group(2), binding(0)]]
var<uniform> mesh: Mesh;
struct Vertex {
[[location(0)]] position: vec3<f32>;
[[location(1)]] normal: vec3<f32>;
[[location(2)]] uv: vec2<f32>;
};
struct VertexOutput {
[[builtin(position)]] clip_position: vec4<f32>;
};
[[stage(vertex)]]
fn vertex(vertex: Vertex) -> VertexOutput {
let world_position = mesh.transform * vec4<f32>(vertex.position, 1.0);
var out: VertexOutput;
out.clip_position = view.view_proj * world_position;
return out;
}
[[block]]
struct CustomMaterial {
color: vec4<f32>;
};
[[group(1), binding(0)]]
var<uniform> material: CustomMaterial;
[[stage(fragment)]]
fn fragment() -> [[location(0)]] vec4<f32> {
return material.color;
}