Adding PBR lighting to the shader_instancing
example
#11410
-
Hi all, I'm interested in using GPU instancing to render fields of grass (upwards of a million blades of grass at a time), and I have managed to implement some simple rendering of exactly that by building off of the @fragment
fn fragment(
in: VertexOutput,
@builtin(front_facing) is_front: bool,
) -> @location(0) vec4<f32> {
#ifdef VERTEX_COLORS
let pbr_input = pbr_input_from_standard_material(in, is_front);
return apply_pbr_lighting(pbr_input);
#else
return vec4<f32>(0.3, 0.8, 0.1, 1.0);
#endif
} The first issue I ran into was the following:
I was able to figure out (correct me if I'm wrong) that this was due to the grass blade mesh using the same bind group (1) as the what the shader thinks the standard material should be bound to. I was able to solve this by removing the descriptor
.vertex
.shader_defs
.push("MESH_BINDGROUP_1".into()); I also changed type DrawCustom = (
SetItemPipeline,
SetMeshViewBindGroup<0>,
SetMeshBindGroup<2>,
DrawMeshInstanced,
); But now I am receiving the following error, and I've been struggling to understand/fix this for some time now:
Any help/advice would be greatly appreciated! Maybe I am just missing something obvious here. Like I said, I am a bit fuzzy on my knowledge of the rendering pipeline, and honestly I've been having a hard time finding good resources online to learn. Thanks in advance 😃 |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 8 replies
-
Don't look at bevy main. Bind group numbers moved around recently. Make sure you look at bevy 0.12's code https://github.com/bevyengine/bevy/blob/release-0.12.1/examples/shader/shader_instancing.rs |
Beta Was this translation helpful? Give feedback.
-
I have figured it out. For anyone else who has a similar issue: the problem is |
Beta Was this translation helpful? Give feedback.
-
Hey! |
Beta Was this translation helpful? Give feedback.
-
Interesting! I can render 1.5 million blades easy on laptop at +300fps, and even on Android low end device at ~20fps. I'll try applying fragment shader at some point too like you do. I create a custom material:
And spawn it with:
My shader is thus more or less:
|
Beta Was this translation helpful? Give feedback.
-
Another grass solution that slipped under my radar - https://github.com/jadedbay/bevy_procedural_grass Looks neat! |
Beta Was this translation helpful? Give feedback.
I have figured it out. For anyone else who has a similar issue: the problem is
wgpu
cannot create "skip" a bindgroup. In my case, bindgroup 0 is used for the vertex data, and bindgroup 2 is used for the mesh uniform data.wgpu
doesn't like this as bindgroup 1 is unused. So to make it work, I am now using bindgroup 1 for a PBR material uniform (which I was already planning on doing since I want PBR lighting on my mesh instances).