fix(renderer): merge IBL into group(3) to stay within max_bind_groups limit of 4
wgpu's default max_bind_groups is 4 (groups 0-3), but the PBR shader was using group(4) for BRDF LUT bindings. This merges IBL bindings into the shadow bind group (group 3) at binding slots 3-4, removes the standalone IBL bind group layout/creation, and updates all examples accordingly. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -79,51 +79,4 @@ impl IblResources {
|
||||
}
|
||||
}
|
||||
|
||||
/// Bind group layout for group(4):
|
||||
/// binding 0 — texture_2d<f32> (filterable)
|
||||
/// binding 1 — sampler (filtering)
|
||||
pub fn bind_group_layout(device: &wgpu::Device) -> wgpu::BindGroupLayout {
|
||||
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
||||
label: Some("IblBindGroupLayout"),
|
||||
entries: &[
|
||||
wgpu::BindGroupLayoutEntry {
|
||||
binding: 0,
|
||||
visibility: wgpu::ShaderStages::FRAGMENT,
|
||||
ty: wgpu::BindingType::Texture {
|
||||
multisampled: false,
|
||||
view_dimension: wgpu::TextureViewDimension::D2,
|
||||
sample_type: wgpu::TextureSampleType::Float { filterable: true },
|
||||
},
|
||||
count: None,
|
||||
},
|
||||
wgpu::BindGroupLayoutEntry {
|
||||
binding: 1,
|
||||
visibility: wgpu::ShaderStages::FRAGMENT,
|
||||
ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering),
|
||||
count: None,
|
||||
},
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
pub fn create_bind_group(
|
||||
&self,
|
||||
device: &wgpu::Device,
|
||||
layout: &wgpu::BindGroupLayout,
|
||||
) -> wgpu::BindGroup {
|
||||
device.create_bind_group(&wgpu::BindGroupDescriptor {
|
||||
label: Some("IblBindGroup"),
|
||||
layout,
|
||||
entries: &[
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 0,
|
||||
resource: wgpu::BindingResource::TextureView(&self.brdf_lut_view),
|
||||
},
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 1,
|
||||
resource: wgpu::BindingResource::Sampler(&self.brdf_lut_sampler),
|
||||
},
|
||||
],
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ pub fn create_pbr_pipeline(
|
||||
texture_layout: &wgpu::BindGroupLayout,
|
||||
material_layout: &wgpu::BindGroupLayout,
|
||||
shadow_layout: &wgpu::BindGroupLayout,
|
||||
ibl_layout: &wgpu::BindGroupLayout,
|
||||
) -> wgpu::RenderPipeline {
|
||||
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
|
||||
label: Some("PBR Shader"),
|
||||
@@ -17,7 +16,7 @@ pub fn create_pbr_pipeline(
|
||||
|
||||
let layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
||||
label: Some("PBR Pipeline Layout"),
|
||||
bind_group_layouts: &[camera_light_layout, texture_layout, material_layout, shadow_layout, ibl_layout],
|
||||
bind_group_layouts: &[camera_light_layout, texture_layout, material_layout, shadow_layout],
|
||||
immediate_size: 0,
|
||||
});
|
||||
|
||||
|
||||
@@ -48,9 +48,8 @@ struct ShadowUniform {
|
||||
@group(3) @binding(0) var t_shadow: texture_depth_2d;
|
||||
@group(3) @binding(1) var s_shadow: sampler_comparison;
|
||||
@group(3) @binding(2) var<uniform> shadow: ShadowUniform;
|
||||
|
||||
@group(4) @binding(0) var t_brdf_lut: texture_2d<f32>;
|
||||
@group(4) @binding(1) var s_brdf_lut: sampler;
|
||||
@group(3) @binding(3) var t_brdf_lut: texture_2d<f32>;
|
||||
@group(3) @binding(4) var s_brdf_lut: sampler;
|
||||
|
||||
struct VertexInput {
|
||||
@location(0) position: vec3<f32>,
|
||||
|
||||
@@ -78,6 +78,24 @@ impl ShadowMap {
|
||||
},
|
||||
count: None,
|
||||
},
|
||||
// binding 3: BRDF LUT texture
|
||||
wgpu::BindGroupLayoutEntry {
|
||||
binding: 3,
|
||||
visibility: wgpu::ShaderStages::FRAGMENT,
|
||||
ty: wgpu::BindingType::Texture {
|
||||
multisampled: false,
|
||||
view_dimension: wgpu::TextureViewDimension::D2,
|
||||
sample_type: wgpu::TextureSampleType::Float { filterable: true },
|
||||
},
|
||||
count: None,
|
||||
},
|
||||
// binding 4: BRDF LUT sampler
|
||||
wgpu::BindGroupLayoutEntry {
|
||||
binding: 4,
|
||||
visibility: wgpu::ShaderStages::FRAGMENT,
|
||||
ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering),
|
||||
count: None,
|
||||
},
|
||||
],
|
||||
})
|
||||
}
|
||||
@@ -87,6 +105,8 @@ impl ShadowMap {
|
||||
device: &wgpu::Device,
|
||||
layout: &wgpu::BindGroupLayout,
|
||||
shadow_uniform_buffer: &wgpu::Buffer,
|
||||
brdf_lut_view: &wgpu::TextureView,
|
||||
brdf_lut_sampler: &wgpu::Sampler,
|
||||
) -> wgpu::BindGroup {
|
||||
device.create_bind_group(&wgpu::BindGroupDescriptor {
|
||||
label: Some("Shadow Bind Group"),
|
||||
@@ -104,6 +124,14 @@ impl ShadowMap {
|
||||
binding: 2,
|
||||
resource: shadow_uniform_buffer.as_entire_binding(),
|
||||
},
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 3,
|
||||
resource: wgpu::BindingResource::TextureView(brdf_lut_view),
|
||||
},
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 4,
|
||||
resource: wgpu::BindingResource::Sampler(brdf_lut_sampler),
|
||||
},
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user