-
Notifications
You must be signed in to change notification settings - Fork 0
Vertex data packing #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c7b7e34
Add material boilerplate
CuddlyBunion341 602b3ed
Update material
CuddlyBunion341 981aab6
wip
CuddlyBunion341 6573839
Do sth
CuddlyBunion341 62d1cb8
Make material that doesn't crash
CuddlyBunion341 e8ad7c7
Attempt vertex
CuddlyBunion341 b06fb34
wip
CuddlyBunion341 6ecb00d
Attempt update material
CuddlyBunion341 226b143
fix boilerplate
CuddlyBunion341 5c2e7d4
clean up boilerplate
CuddlyBunion341 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#define_import_path bevy_pbr::my_material | ||
|
||
#import bevy_pbr::mesh_view_bindings | ||
#import bevy_pbr::mesh_bindings | ||
#import bevy_pbr::forward_io::VertexOutput | ||
#import bevy_render::maths::affine3_to_square | ||
|
||
struct MyExtensionMaterial { | ||
quantize_steps: u32, | ||
}; | ||
|
||
@group(2) @binding(100) | ||
var<uniform> my_extension: MyExtensionMaterial; | ||
|
||
fn quantize_position(position: vec3<f32>, steps: u32) -> vec3<f32> { | ||
if (steps > 0u) { | ||
let step_size = 1.0 / f32(steps); | ||
return floor(position / step_size) * step_size; | ||
} | ||
return position; | ||
} | ||
|
||
@vertex | ||
fn vertex( | ||
@location(0) position: vec3<f32>, | ||
@location(1) normal: vec3<f32>, | ||
@location(2) uv: vec2<f32>, | ||
@builtin(instance_index) instance_index: u32, | ||
) -> VertexOutput { | ||
var out: VertexOutput; | ||
|
||
let model_affine = mesh_bindings::mesh[instance_index].world_from_local; | ||
let model = affine3_to_square(model_affine); | ||
|
||
let world_position = model * vec4<f32>(position, 1.0); | ||
|
||
var quantized_position = world_position; | ||
let quantized_xyz = quantize_position(world_position.xyz, my_extension.quantize_steps); | ||
quantized_position.x = quantized_xyz.x; | ||
quantized_position.y = quantized_xyz.y; | ||
quantized_position.z = quantized_xyz.z; | ||
|
||
out.position = mesh_view_bindings::view.clip_from_world * quantized_position; | ||
|
||
out.world_position = world_position; | ||
|
||
out.world_normal = (model * vec4<f32>(normal, 0.0)).xyz; | ||
|
||
out.uv = uv; | ||
|
||
return out; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use crate::prelude::*; | ||
use bevy::{ | ||
color::palettes::css::RED, | ||
pbr::MaterialExtension, | ||
reflect::Reflect, | ||
render::render_resource::{AsBindGroup, ShaderRef}, | ||
}; | ||
|
||
const SHADER_ASSET_PATH: &str = "shaders/my_material.wgsl"; | ||
|
||
#[derive(Asset, AsBindGroup, Reflect, Debug, Clone)] | ||
pub struct MyExtension { | ||
#[uniform(100)] | ||
pub quantize_steps: u32, | ||
} | ||
|
||
impl MaterialExtension for MyExtension { | ||
fn vertex_shader() -> ShaderRef { | ||
SHADER_ASSET_PATH.into() | ||
} | ||
} | ||
|
||
pub fn create_base_material( | ||
texture_handle: Handle<Image>, | ||
) -> ExtendedMaterial<StandardMaterial, MyExtension> { | ||
ExtendedMaterial { | ||
base: StandardMaterial { | ||
opaque_render_method: OpaqueRendererMethod::Auto, | ||
perceptual_roughness: 0.5, | ||
reflectance: 0.0, | ||
unlit: false, | ||
specular_transmission: 0.0, | ||
base_color_texture: Some(texture_handle), | ||
..default() | ||
}, | ||
extension: MyExtension { quantize_steps: 12 }, | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Define Type Alias for the material