
# Objective - Implements a more efficient, GPU-driven (https://github.com/bevyengine/bevy/issues/1342) rendering pipeline based on meshlets. - Meshes are split into small clusters of triangles called meshlets, each of which acts as a mini index buffer into the larger mesh data. Meshlets can be compressed, streamed, culled, and batched much more efficiently than monolithic meshes.   # Misc * Future work: https://github.com/bevyengine/bevy/issues/11518 * Nanite reference: https://advances.realtimerendering.com/s2021/Karis_Nanite_SIGGRAPH_Advances_2021_final.pdf Two pass occlusion culling explained very well: https://medium.com/@mil_kru/two-pass-occlusion-culling-4100edcad501 --------- Co-authored-by: Ricky Taylor <rickytaylor26@gmail.com> Co-authored-by: vero <email@atlasdostal.com> Co-authored-by: François <mockersf@gmail.com> Co-authored-by: atlas dostal <rodol@rivalrebels.com>
63 lines
2.0 KiB
WebGPU Shading Language
63 lines
2.0 KiB
WebGPU Shading Language
#import bevy_pbr::{
|
|
pbr_functions::alpha_discard,
|
|
pbr_fragment::pbr_input_from_standard_material,
|
|
}
|
|
|
|
#ifdef PREPASS_PIPELINE
|
|
#import bevy_pbr::{
|
|
prepass_io::{VertexOutput, FragmentOutput},
|
|
pbr_deferred_functions::deferred_output,
|
|
}
|
|
#else
|
|
#import bevy_pbr::{
|
|
forward_io::{VertexOutput, FragmentOutput},
|
|
pbr_functions::{apply_pbr_lighting, main_pass_post_lighting_processing},
|
|
pbr_types::STANDARD_MATERIAL_FLAGS_UNLIT_BIT,
|
|
}
|
|
#endif
|
|
|
|
#ifdef MESHLET_MESH_MATERIAL_PASS
|
|
#import bevy_pbr::meshlet_visibility_buffer_resolve::resolve_vertex_output
|
|
#endif
|
|
|
|
@fragment
|
|
fn fragment(
|
|
#ifdef MESHLET_MESH_MATERIAL_PASS
|
|
@builtin(position) frag_coord: vec4<f32>,
|
|
#else
|
|
in: VertexOutput,
|
|
@builtin(front_facing) is_front: bool,
|
|
#endif
|
|
) -> FragmentOutput {
|
|
#ifdef MESHLET_MESH_MATERIAL_PASS
|
|
let in = resolve_vertex_output(frag_coord);
|
|
let is_front = true;
|
|
#endif
|
|
|
|
// generate a PbrInput struct from the StandardMaterial bindings
|
|
var pbr_input = pbr_input_from_standard_material(in, is_front);
|
|
|
|
// alpha discard
|
|
pbr_input.material.base_color = alpha_discard(pbr_input.material, pbr_input.material.base_color);
|
|
|
|
#ifdef PREPASS_PIPELINE
|
|
// write the gbuffer, lighting pass id, and optionally normal and motion_vector textures
|
|
let out = deferred_output(in, pbr_input);
|
|
#else
|
|
// in forward mode, we calculate the lit color immediately, and then apply some post-lighting effects here.
|
|
// in deferred mode the lit color and these effects will be calculated in the deferred lighting shader
|
|
var out: FragmentOutput;
|
|
if (pbr_input.material.flags & STANDARD_MATERIAL_FLAGS_UNLIT_BIT) == 0u {
|
|
out.color = apply_pbr_lighting(pbr_input);
|
|
} else {
|
|
out.color = pbr_input.material.base_color;
|
|
}
|
|
|
|
// apply in-shader post processing (fog, alpha-premultiply, and also tonemapping, debanding if the camera is non-hdr)
|
|
// note this does not include fullscreen postprocessing effects like bloom.
|
|
out.color = main_pass_post_lighting_processing(pbr_input, out.color);
|
|
#endif
|
|
|
|
return out;
|
|
}
|