Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions wgpu/examples/cube/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,17 @@ impl framework::Example for Example {
},
count: None,
},
// color
wgpu::BindGroupLayoutEntry {
binding: 2,
visibility: wgpu::ShaderStages::FRAGMENT,
ty: wgpu::BindingType::Buffer {
ty: wgpu::BufferBindingType::Uniform,
has_dynamic_offset: false,
min_binding_size: None,
},
count: None,
},
],
});
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
Expand Down Expand Up @@ -224,6 +235,12 @@ impl framework::Example for Example {
usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
});

let color_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
label: Some("Color Buffer"),
contents: bytemuck::cast_slice(glam::Vec4::new(1.0, 0.0, 0.0, 1.0).as_ref()),
usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
});

// Create bind group
let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
layout: &bind_group_layout,
Expand All @@ -236,6 +253,10 @@ impl framework::Example for Example {
binding: 1,
resource: wgpu::BindingResource::TextureView(&texture_view),
},
wgpu::BindGroupEntry {
binding: 2,
resource: color_buffer.as_entire_binding(),
},
],
label: None,
});
Expand Down
11 changes: 8 additions & 3 deletions wgpu/examples/cube/shader.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@ fn vs_main(
@binding(1)
var r_color: texture_2d<u32>;

@group(0) @binding(2)
var<uniform> u_color: vec4<f32>;

@fragment
fn fs_main(vertex: VertexOutput) -> @location(0) vec4<f32> {
let tex = textureLoad(r_color, vec2<i32>(vertex.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);
// let tex = textureLoad(r_color, vec2<i32>(vertex.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);

return u_color;
}

@fragment
Expand Down