diff options
author | 2023-09-14 13:58:36 -0700 | |
---|---|---|
committer | 2023-11-14 11:31:44 +0100 | |
commit | 781ef1f94c4859aeeb852f801b72be095b8ff82b (patch) | |
tree | 63e2678eca11dd41c26a40633c04341fd795d733 /examples/custom_shader/src/shaders/depth.wgsl | |
parent | 817f72868746461891ca4e74473c555f3b5c5703 (diff) | |
download | iced-781ef1f94c4859aeeb852f801b72be095b8ff82b.tar.gz iced-781ef1f94c4859aeeb852f801b72be095b8ff82b.tar.bz2 iced-781ef1f94c4859aeeb852f801b72be095b8ff82b.zip |
Added support for custom shader widget for iced_wgpu backend.
Diffstat (limited to 'examples/custom_shader/src/shaders/depth.wgsl')
-rw-r--r-- | examples/custom_shader/src/shaders/depth.wgsl | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/examples/custom_shader/src/shaders/depth.wgsl b/examples/custom_shader/src/shaders/depth.wgsl new file mode 100644 index 00000000..a3f7e5ec --- /dev/null +++ b/examples/custom_shader/src/shaders/depth.wgsl @@ -0,0 +1,48 @@ +var<private> positions: array<vec2<f32>, 6> = array<vec2<f32>, 6>( + vec2<f32>(-1.0, 1.0), + vec2<f32>(-1.0, -1.0), + vec2<f32>(1.0, -1.0), + vec2<f32>(-1.0, 1.0), + vec2<f32>(1.0, 1.0), + vec2<f32>(1.0, -1.0) +); + +var<private> uvs: array<vec2<f32>, 6> = array<vec2<f32>, 6>( + vec2<f32>(0.0, 0.0), + vec2<f32>(0.0, 1.0), + vec2<f32>(1.0, 1.0), + vec2<f32>(0.0, 0.0), + vec2<f32>(1.0, 0.0), + vec2<f32>(1.0, 1.0) +); + +@group(0) @binding(0) var depth_sampler: sampler; +@group(0) @binding(1) var depth_texture: texture_2d<f32>; + +struct Output { + @builtin(position) position: vec4<f32>, + @location(0) uv: vec2<f32>, +} + +@vertex +fn vs_main(@builtin(vertex_index) v_index: u32) -> Output { + var out: Output; + + out.position = vec4<f32>(positions[v_index], 0.0, 1.0); + out.uv = uvs[v_index]; + + return out; +} + +@fragment +fn fs_main(input: Output) -> @location(0) vec4<f32> { + let depth = textureSample(depth_texture, depth_sampler, input.uv).r; + + if (depth > .9999) { + discard; + } + + let c = 1.0 - depth; + + return vec4<f32>(c, c, c, 1.0); +} |