[Merged by Bors] - Array texture example#5077
[Merged by Bors] - Array texture example#5077superdump wants to merge 5 commits intobevyengine:mainfrom
Conversation
|
|
||
| // Create a new array texture asset from the loaded texture. | ||
| let array_layers = 4; | ||
| image.reinterpret_stacked_2d_as_array(array_layers); |
There was a problem hiding this comment.
It's a shame this can't be done up-front when loading the image.
There was a problem hiding this comment.
But I guess asset pipeline and metadata stuff will sort that out.
| for x in -5..=5 { | ||
| commands.spawn_bundle(MaterialMeshBundle { | ||
| mesh: mesh_handle.clone(), | ||
| material: material_handle.clone(), | ||
| transform: Transform::from_xyz(x as f32 + 0.5, 0.0, 0.0), | ||
| ..Default::default() | ||
| }); | ||
| } |
There was a problem hiding this comment.
I'm spawning these here so that they only exist when the asset has loaded. I think that was because otherwise a non-array-texture fallback image is attempted to be used for the binding due to how mesh_pipeline.get_image_texture() works.
This removes the dependency of pbr_functions.wgsl on the material binding.
3a2d2f2 to
26f8d1d
Compare
|
|
||
| // Prepare a 'processed' StandardMaterial by sampling all textures to resolve | ||
| // the material members | ||
| var pbr_input: PbrInput = pbr_input_new(); |
There was a problem hiding this comment.
Random thought (not necessary for this pr): maybe we should have a pbr_input_default() function that sets as much as possible "automatically". Hard to do for FragmentInput, given that it is defined per-shader. But we could at least auto-calculate is_orthographic. Maybe we could have a standardized struct for "normal" fragment inputs, which users pass in to pbr_input_default(standard_frag_input_here)? Again, definitely not something to do in this pr, but it feels like theres room for ux improvements here.
There was a problem hiding this comment.
I agree and want to iterate some more on this when I have time.
examples/shader/array_texture.rs
Outdated
| } | ||
|
|
||
| impl Material for ArrayTextureMaterial { | ||
| // fn vertex_shader(asset_server: &AssetServer) -> Option<Handle<Shader>> { |
There was a problem hiding this comment.
We should remove this comment. I don't like including "unnecessary" commented out code in examples.
|
bors r+ |
# Objective - Make the reusable PBR shading functionality a little more reusable - Add constructor functions for `StandardMaterial` and `PbrInput` structs to populate them with default values - Document unclear `PbrInput` members - Demonstrate how to reuse the bevy PBR shading functionality - The final important piece from #3969 as the initial shot at making the PBR shader code reusable in custom materials ## Solution - Add back and rework the 'old' `array_texture` example from pre-0.6. - Create a custom shader material - Use a single array texture binding and sampler for the material bind group - Use a shader that calls `pbr()` from the `bevy_pbr::pbr_functions` import - Spawn a row of cubes using the custom material - In the shader, select the array texture layer to sample by using the world position x coordinate modulo the number of array texture layers <img width="1392" alt="Screenshot 2022-06-23 at 12 28 05" src="https://user-images.githubusercontent.com/302146/175278593-2296f519-f577-4ece-81c0-d842283784a1.png"> Co-authored-by: Carter Anderson <mcanders1@gmail.com>
# Objective - Make the reusable PBR shading functionality a little more reusable - Add constructor functions for `StandardMaterial` and `PbrInput` structs to populate them with default values - Document unclear `PbrInput` members - Demonstrate how to reuse the bevy PBR shading functionality - The final important piece from bevyengine#3969 as the initial shot at making the PBR shader code reusable in custom materials ## Solution - Add back and rework the 'old' `array_texture` example from pre-0.6. - Create a custom shader material - Use a single array texture binding and sampler for the material bind group - Use a shader that calls `pbr()` from the `bevy_pbr::pbr_functions` import - Spawn a row of cubes using the custom material - In the shader, select the array texture layer to sample by using the world position x coordinate modulo the number of array texture layers <img width="1392" alt="Screenshot 2022-06-23 at 12 28 05" src="https://user-images.githubusercontent.com/302146/175278593-2296f519-f577-4ece-81c0-d842283784a1.png"> Co-authored-by: Carter Anderson <mcanders1@gmail.com>
# Objective - Make the reusable PBR shading functionality a little more reusable - Add constructor functions for `StandardMaterial` and `PbrInput` structs to populate them with default values - Document unclear `PbrInput` members - Demonstrate how to reuse the bevy PBR shading functionality - The final important piece from bevyengine#3969 as the initial shot at making the PBR shader code reusable in custom materials ## Solution - Add back and rework the 'old' `array_texture` example from pre-0.6. - Create a custom shader material - Use a single array texture binding and sampler for the material bind group - Use a shader that calls `pbr()` from the `bevy_pbr::pbr_functions` import - Spawn a row of cubes using the custom material - In the shader, select the array texture layer to sample by using the world position x coordinate modulo the number of array texture layers <img width="1392" alt="Screenshot 2022-06-23 at 12 28 05" src="https://user-images.githubusercontent.com/302146/175278593-2296f519-f577-4ece-81c0-d842283784a1.png"> Co-authored-by: Carter Anderson <mcanders1@gmail.com>
# Objective - Make the reusable PBR shading functionality a little more reusable - Add constructor functions for `StandardMaterial` and `PbrInput` structs to populate them with default values - Document unclear `PbrInput` members - Demonstrate how to reuse the bevy PBR shading functionality - The final important piece from bevyengine#3969 as the initial shot at making the PBR shader code reusable in custom materials ## Solution - Add back and rework the 'old' `array_texture` example from pre-0.6. - Create a custom shader material - Use a single array texture binding and sampler for the material bind group - Use a shader that calls `pbr()` from the `bevy_pbr::pbr_functions` import - Spawn a row of cubes using the custom material - In the shader, select the array texture layer to sample by using the world position x coordinate modulo the number of array texture layers <img width="1392" alt="Screenshot 2022-06-23 at 12 28 05" src="https://user-images.githubusercontent.com/302146/175278593-2296f519-f577-4ece-81c0-d842283784a1.png"> Co-authored-by: Carter Anderson <mcanders1@gmail.com>
Objective
StandardMaterialandPbrInputstructs to populate them with default valuesPbrInputmembersSolution
array_textureexample from pre-0.6.pbr()from thebevy_pbr::pbr_functionsimport