mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 20:53:53 +00:00
Add view transform to view uniform (#3885)
(cherry picked from commit de943381bd2a8b242c94db99e6c7bbd70006d7c3) # Objective The view uniform lacks view transform information. The inverse transform is currently provided but this is not sufficient if you do not have access to an `inverse` function (such as in WGSL). ## Solution Grab the view transform, put it in the view uniform, use the same matrix to compute the inverse as well.
This commit is contained in:
parent
1e049a651b
commit
56b0e88b53
3 changed files with 6 additions and 1 deletions
|
@ -1,5 +1,6 @@
|
||||||
struct View {
|
struct View {
|
||||||
view_proj: mat4x4<f32>;
|
view_proj: mat4x4<f32>;
|
||||||
|
view: mat4x4<f32>;
|
||||||
inverse_view: mat4x4<f32>;
|
inverse_view: mat4x4<f32>;
|
||||||
projection: mat4x4<f32>;
|
projection: mat4x4<f32>;
|
||||||
world_position: vec3<f32>;
|
world_position: vec3<f32>;
|
||||||
|
|
|
@ -86,6 +86,7 @@ pub struct ExtractedView {
|
||||||
#[derive(Clone, AsStd140)]
|
#[derive(Clone, AsStd140)]
|
||||||
pub struct ViewUniform {
|
pub struct ViewUniform {
|
||||||
view_proj: Mat4,
|
view_proj: Mat4,
|
||||||
|
view: Mat4,
|
||||||
inverse_view: Mat4,
|
inverse_view: Mat4,
|
||||||
projection: Mat4,
|
projection: Mat4,
|
||||||
world_position: Vec3,
|
world_position: Vec3,
|
||||||
|
@ -145,10 +146,12 @@ fn prepare_view_uniforms(
|
||||||
view_uniforms.uniforms.clear();
|
view_uniforms.uniforms.clear();
|
||||||
for (entity, camera) in views.iter() {
|
for (entity, camera) in views.iter() {
|
||||||
let projection = camera.projection;
|
let projection = camera.projection;
|
||||||
let inverse_view = camera.transform.compute_matrix().inverse();
|
let view = camera.transform.compute_matrix();
|
||||||
|
let inverse_view = view.inverse();
|
||||||
let view_uniforms = ViewUniformOffset {
|
let view_uniforms = ViewUniformOffset {
|
||||||
offset: view_uniforms.uniforms.push(ViewUniform {
|
offset: view_uniforms.uniforms.push(ViewUniform {
|
||||||
view_proj: projection * inverse_view,
|
view_proj: projection * inverse_view,
|
||||||
|
view,
|
||||||
inverse_view,
|
inverse_view,
|
||||||
projection,
|
projection,
|
||||||
world_position: camera.transform.translation,
|
world_position: camera.transform.translation,
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
struct View {
|
struct View {
|
||||||
view_proj: mat4x4<f32>;
|
view_proj: mat4x4<f32>;
|
||||||
|
view: mat4x4<f32>;
|
||||||
inverse_view: mat4x4<f32>;
|
inverse_view: mat4x4<f32>;
|
||||||
projection: mat4x4<f32>;
|
projection: mat4x4<f32>;
|
||||||
world_position: vec3<f32>;
|
world_position: vec3<f32>;
|
||||||
|
|
Loading…
Reference in a new issue