-
Notifications
You must be signed in to change notification settings - Fork 199
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
Add material_tilemap_layout #460
Conversation
Maybe we should add a field to the material in the |
@rparrett Done |
Co-authored-by: Rob Parrett <robparrett@gmail.com>
Co-authored-by: Rob Parrett <robparrett@gmail.com>
Could you run |
@rparrett Maybe add a way to control the brightness? |
@rparrett Yeah, sure |
I think as long as we're giving working code to users we don't need to go nuts in this PR. |
The example now errors in webgl2 builds. This diff fixes it. diff --git a/examples/custom_shader.rs b/examples/custom_shader.rs
index f279ebe..361cb80 100644
--- a/examples/custom_shader.rs
+++ b/examples/custom_shader.rs
@@ -10,7 +10,10 @@ mod helpers;
#[uuid = "31575692-a956-4762-98e2-5d457f552d0a"]
pub struct MyMaterial {
#[uniform(0)]
- brightness: f32
+ brightness: f32,
+ // webgl2 requires 16 byte alignment
+ #[uniform(0)]
+ _padding: Vec3,
}
impl MaterialTilemap for MyMaterial {
@@ -27,7 +30,8 @@ fn startup(
commands.spawn(Camera2dBundle::default());
let my_material_handle = materials.add(MyMaterial {
- brightness: 0.5
+ brightness: 0.5,
+ ..default()
});
let texture_handle: Handle<Image> = asset_server.load("tiles.png"); |
Oops sorry, the shader needs to be updated too: diff --git a/assets/custom_shader.wgsl b/assets/custom_shader.wgsl
index 7eb4ece..bbf11f9 100644
--- a/assets/custom_shader.wgsl
+++ b/assets/custom_shader.wgsl
@@ -2,8 +2,13 @@
#import bevy_ecs_tilemap::vertex_output MeshVertexOutput
#import bevy_sprite::mesh2d_view_bindings globals
+struct MyMaterial {
+ brightness: f32,
+ _padding: vec3<f32>
+};
+
@group(3) @binding(0)
-var<uniform> brightness: f32;
+var<uniform> material: MyMaterial;
fn hsv2rgb(c: vec3<f32>) -> vec3<f32>
{
@@ -17,5 +22,5 @@ fn fragment(in: MeshVertexOutput) -> @location(0) vec4<f32> {
let color = process_fragment(in);
let hsv = vec3(abs(sin(globals.time)), 1.0, 1.0);
- return vec4((color.rgb + hsv2rgb(hsv)) * brightness, color.a);
+ return vec4((color.rgb + hsv2rgb(hsv)) * material.brightness, color.a);
} |
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.
Thanks!
Fixes #455
Note that you must set the group index of a uniform to 3, like this:
It's not obvious and there are no docs about that