-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[Merged by Bors] - Add animate shaders example #1765
Conversation
examples/shader/animate_shader.rs
Outdated
|
||
// Spawn a camera | ||
commands.spawn_bundle(PerspectiveCameraBundle { | ||
transform: Transform::from_xyz(0.0, 0.0, -8.0).looking_at(Vec3::ZERO, -Vec3::Y), |
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.
Regarding: -Vec3::Y
, without the minus, the colours are flipped.
I was expecting to have red on the left and blue on right, but it's the opposite. The same happened to me when just drawing the UVs in the fragment shader directly ( gl_FragColor = vec4(v_Uv, 0.0, 1.0);
). You get black ( 0,0 coords ) on the top right corner instead of bottom left.
Where in my code in this example i should fix it, if not via this -Vec3::Y
? Thanks a lot
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.
Using a 2d camera fixed it (and i increase the Quad size).
With .looking_at(Vec3::ZERO, Vec3::Y)
and a 3d camera it's definitely upside down. flip: true
/ false
on the Quad doesn't fix it. Is it worth an issue or is there another bug in the example?
In my opinion the current example is correct, but please let me have your feedback.
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.
In the last commit i have reverted it to using a 3D camera, with Transform::from_xyz(0.0, 0.0, 8.0).looking_at(Vec3::ZERO, Vec3::Y)
. So positive Z and Quad::new
without flipping works.
In my opinion this should be clear enough for users.
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.
7ce6fcb
to
8510ff6
Compare
8510ff6
to
c6171a4
Compare
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.
Very good example! Very clear and teaches something very commonly desired (such as when people want to do Shadertoy-like things in Bevy).
Added single_mut because this doesn't make sense with more than one query result (or zero results). Additionally, I renamed TimeComponent to TimeUniform because I don't want to encourage the XComponent naming convention. |
Nice work! I agree that this is super useful. Long term we'll want Bevy to provide built in time support for shaders, but this is a good stop gap measure (and is also just generally educational). |
bors r+ |
This PR adds an example on how to animate a shader by passing the global `time.seconds_since_startup()` to a component, and accessing that component inside the shader. Hopefully this is the current proper solution, please let me know if it should be solved in another way. Co-authored-by: Carter Anderson <[email protected]>
Pull request successfully merged into main. Build succeeded: |
This PR adds an example on how to animate a shader by passing the global `time.seconds_since_startup()` to a component, and accessing that component inside the shader. Hopefully this is the current proper solution, please let me know if it should be solved in another way. Co-authored-by: Carter Anderson <[email protected]>
This PR adds an example on how to animate a shader by passing the global
time.seconds_since_startup()
to a component, and accessing that component inside the shader.Hopefully this is the current proper solution, please let me know if it should be solved in another way.