-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
220 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,220 @@ | ||
From 1af35586dc918d380455e0a50a029e04cdd276f9 Mon Sep 17 00:00:00 2001 | ||
From: =?UTF-8?q?Fran=C3=A7ois?= <[email protected]> | ||
Date: Wed, 28 Feb 2024 23:25:11 +0100 | ||
Subject: [PATCH 1/4] use 2 vec4 instead of a mat3x3 | ||
|
||
--- | ||
crates/bevy_pbr/src/pbr_material.rs | 16 ++++++++++++---- | ||
crates/bevy_pbr/src/render/pbr_fragment.wgsl | 6 +++++- | ||
.../src/render/pbr_prepass_functions.wgsl | 6 +++++- | ||
crates/bevy_pbr/src/render/pbr_types.wgsl | 6 ++++-- | ||
4 files changed, 26 insertions(+), 8 deletions(-) | ||
|
||
diff --git a/crates/bevy_pbr/src/pbr_material.rs b/crates/bevy_pbr/src/pbr_material.rs | ||
index 3231cb8df5d6d..0a9f4e210f18d 100644 | ||
--- a/crates/bevy_pbr/src/pbr_material.rs | ||
+++ b/crates/bevy_pbr/src/pbr_material.rs | ||
@@ -1,6 +1,6 @@ | ||
use bevy_asset::Asset; | ||
use bevy_color::Alpha; | ||
-use bevy_math::{Affine2, Mat3, Vec4}; | ||
+use bevy_math::{Affine2, Vec2, Vec4}; | ||
use bevy_reflect::{std_traits::ReflectDefault, Reflect}; | ||
use bevy_render::{ | ||
mesh::MeshVertexBufferLayoutRef, render_asset::RenderAssets, render_resource::*, | ||
@@ -608,8 +608,13 @@ pub struct StandardMaterialUniform { | ||
pub emissive: Vec4, | ||
/// Color white light takes after travelling through the attenuation distance underneath the material surface | ||
pub attenuation_color: Vec4, | ||
- /// The transform applied to the UVs corresponding to ATTRIBUTE_UV_0 on the mesh before sampling. Default is identity. | ||
- pub uv_transform: Mat3, | ||
+ /// The x-axis of the mat2 of the transform applied to the UVs corresponding to ATTRIBUTE_UV_0 on the mesh before sampling. Default is [1, 0]. | ||
+ pub uv_transform_x_axis: Vec2, | ||
+ /// The y-axis of the mat2 of the transform applied to the UVs corresponding to ATTRIBUTE_UV_0 on the mesh before sampling. Default is [0, 1]. | ||
+ pub uv_transform_y_axis: Vec2, | ||
+ /// The translation of the transform applied to the UVs corresponding to ATTRIBUTE_UV_0 on the mesh before sampling. Default is [0, 0]. | ||
+ pub uv_transform_translation: Vec2, | ||
+ pub padding: Vec2, | ||
/// Linear perceptual roughness, clamped to [0.089, 1.0] in the shader | ||
/// Defaults to minimum of 0.089 | ||
pub roughness: f32, | ||
@@ -746,7 +751,10 @@ impl AsBindGroupShaderType<StandardMaterialUniform> for StandardMaterial { | ||
lightmap_exposure: self.lightmap_exposure, | ||
max_relief_mapping_search_steps: self.parallax_mapping_method.max_steps(), | ||
deferred_lighting_pass_id: self.deferred_lighting_pass_id as u32, | ||
- uv_transform: self.uv_transform.into(), | ||
+ uv_transform_x_axis: self.uv_transform.matrix2.x_axis, | ||
+ uv_transform_y_axis: self.uv_transform.matrix2.y_axis, | ||
+ uv_transform_translation: self.uv_transform.translation, | ||
+ padding: Vec2::ZERO, | ||
} | ||
} | ||
} | ||
diff --git a/crates/bevy_pbr/src/render/pbr_fragment.wgsl b/crates/bevy_pbr/src/render/pbr_fragment.wgsl | ||
index 07b37c3b46962..40bbfe7d72845 100644 | ||
--- a/crates/bevy_pbr/src/render/pbr_fragment.wgsl | ||
+++ b/crates/bevy_pbr/src/render/pbr_fragment.wgsl | ||
@@ -73,7 +73,11 @@ fn pbr_input_from_standard_material( | ||
let NdotV = max(dot(pbr_input.N, pbr_input.V), 0.0001); | ||
|
||
#ifdef VERTEX_UVS | ||
- let uv_transform = pbr_bindings::material.uv_transform; | ||
+ let uv_transform = mat3x3<f32>( | ||
+ vec3<f32>(pbr_bindings::material.uv_transform_xy_axys.xy, 0.0), | ||
+ vec3<f32>(pbr_bindings::material.uv_transform_xy_axys.zw, 0.0), | ||
+ vec3<f32>(pbr_bindings::material.uv_transform_translation.xy, 1.0), | ||
+ ); | ||
var uv = (uv_transform * vec3(in.uv, 1.0)).xy; | ||
|
||
#ifdef VERTEX_TANGENTS | ||
diff --git a/crates/bevy_pbr/src/render/pbr_prepass_functions.wgsl b/crates/bevy_pbr/src/render/pbr_prepass_functions.wgsl | ||
index edf08a5cb2909..3fa0c736b3183 100644 | ||
--- a/crates/bevy_pbr/src/render/pbr_prepass_functions.wgsl | ||
+++ b/crates/bevy_pbr/src/render/pbr_prepass_functions.wgsl | ||
@@ -18,7 +18,11 @@ fn prepass_alpha_discard(in: VertexOutput) { | ||
var output_color: vec4<f32> = pbr_bindings::material.base_color; | ||
|
||
#ifdef VERTEX_UVS | ||
- let uv_transform = pbr_bindings::material.uv_transform; | ||
+ let uv_transform = mat3x3<f32>( | ||
+ vec3<f32>(pbr_bindings::material.uv_transform_xy_axys.xy, 0.0), | ||
+ vec3<f32>(pbr_bindings::material.uv_transform_xy_axys.zw, 0.0), | ||
+ vec3<f32>(pbr_bindings::material.uv_transform_translation.xy, 1.0), | ||
+ ); | ||
let uv = (uv_transform * vec3(in.uv, 1.0)).xy; | ||
if (pbr_bindings::material.flags & pbr_types::STANDARD_MATERIAL_FLAGS_BASE_COLOR_TEXTURE_BIT) != 0u { | ||
output_color = output_color * textureSampleBias(pbr_bindings::base_color_texture, pbr_bindings::base_color_sampler, uv, view.mip_bias); | ||
diff --git a/crates/bevy_pbr/src/render/pbr_types.wgsl b/crates/bevy_pbr/src/render/pbr_types.wgsl | ||
index 5ecc6e893e0e2..8e6d39bbe2069 100644 | ||
--- a/crates/bevy_pbr/src/render/pbr_types.wgsl | ||
+++ b/crates/bevy_pbr/src/render/pbr_types.wgsl | ||
@@ -6,7 +6,8 @@ struct StandardMaterial { | ||
base_color: vec4<f32>, | ||
emissive: vec4<f32>, | ||
attenuation_color: vec4<f32>, | ||
- uv_transform: mat3x3<f32>, | ||
+ uv_transform_xy_axys: vec4<f32>, | ||
+ uv_transform_translation: vec4<f32>, | ||
perceptual_roughness: f32, | ||
metallic: f32, | ||
reflectance: f32, | ||
@@ -78,7 +79,8 @@ fn standard_material_new() -> StandardMaterial { | ||
material.max_relief_mapping_search_steps = 5u; | ||
material.deferred_lighting_pass_id = 1u; | ||
// scale 1, translation 0, rotation 0 | ||
- material.uv_transform = mat3x3<f32>(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0); | ||
+ material.uv_transform_xy_axys = vec4<f32>(1.0, 0.0, 0.0, 0.1); | ||
+ material.uv_transform_translation = vec4<f32>(0.0, 0.0, 0.0, 0.0); | ||
|
||
return material; | ||
} | ||
|
||
From 142a559c901d67d73c3d73998e6ae86d5cd9f5d7 Mon Sep 17 00:00:00 2001 | ||
From: =?UTF-8?q?Fran=C3=A7ois?= <[email protected]> | ||
Date: Sat, 2 Mar 2024 00:30:56 +0100 | ||
Subject: [PATCH 2/4] spelling | ||
|
||
--- | ||
crates/bevy_pbr/src/render/pbr_fragment.wgsl | 4 ++-- | ||
crates/bevy_pbr/src/render/pbr_prepass_functions.wgsl | 4 ++-- | ||
crates/bevy_pbr/src/render/pbr_types.wgsl | 4 ++-- | ||
3 files changed, 6 insertions(+), 6 deletions(-) | ||
|
||
diff --git a/crates/bevy_pbr/src/render/pbr_fragment.wgsl b/crates/bevy_pbr/src/render/pbr_fragment.wgsl | ||
index 40bbfe7d72845..f40b4c9d1af13 100644 | ||
--- a/crates/bevy_pbr/src/render/pbr_fragment.wgsl | ||
+++ b/crates/bevy_pbr/src/render/pbr_fragment.wgsl | ||
@@ -74,8 +74,8 @@ fn pbr_input_from_standard_material( | ||
|
||
#ifdef VERTEX_UVS | ||
let uv_transform = mat3x3<f32>( | ||
- vec3<f32>(pbr_bindings::material.uv_transform_xy_axys.xy, 0.0), | ||
- vec3<f32>(pbr_bindings::material.uv_transform_xy_axys.zw, 0.0), | ||
+ vec3<f32>(pbr_bindings::material.uv_transform_xy_axes.xy, 0.0), | ||
+ vec3<f32>(pbr_bindings::material.uv_transform_xy_axes.zw, 0.0), | ||
vec3<f32>(pbr_bindings::material.uv_transform_translation.xy, 1.0), | ||
); | ||
var uv = (uv_transform * vec3(in.uv, 1.0)).xy; | ||
diff --git a/crates/bevy_pbr/src/render/pbr_prepass_functions.wgsl b/crates/bevy_pbr/src/render/pbr_prepass_functions.wgsl | ||
index 3fa0c736b3183..112a2d098065c 100644 | ||
--- a/crates/bevy_pbr/src/render/pbr_prepass_functions.wgsl | ||
+++ b/crates/bevy_pbr/src/render/pbr_prepass_functions.wgsl | ||
@@ -19,8 +19,8 @@ fn prepass_alpha_discard(in: VertexOutput) { | ||
|
||
#ifdef VERTEX_UVS | ||
let uv_transform = mat3x3<f32>( | ||
- vec3<f32>(pbr_bindings::material.uv_transform_xy_axys.xy, 0.0), | ||
- vec3<f32>(pbr_bindings::material.uv_transform_xy_axys.zw, 0.0), | ||
+ vec3<f32>(pbr_bindings::material.uv_transform_xy_axes.xy, 0.0), | ||
+ vec3<f32>(pbr_bindings::material.uv_transform_xy_axes.zw, 0.0), | ||
vec3<f32>(pbr_bindings::material.uv_transform_translation.xy, 1.0), | ||
); | ||
let uv = (uv_transform * vec3(in.uv, 1.0)).xy; | ||
diff --git a/crates/bevy_pbr/src/render/pbr_types.wgsl b/crates/bevy_pbr/src/render/pbr_types.wgsl | ||
index 8e6d39bbe2069..00e14630a15d1 100644 | ||
--- a/crates/bevy_pbr/src/render/pbr_types.wgsl | ||
+++ b/crates/bevy_pbr/src/render/pbr_types.wgsl | ||
@@ -6,7 +6,7 @@ struct StandardMaterial { | ||
base_color: vec4<f32>, | ||
emissive: vec4<f32>, | ||
attenuation_color: vec4<f32>, | ||
- uv_transform_xy_axys: vec4<f32>, | ||
+ uv_transform_xy_axes: vec4<f32>, | ||
uv_transform_translation: vec4<f32>, | ||
perceptual_roughness: f32, | ||
metallic: f32, | ||
@@ -79,7 +79,7 @@ fn standard_material_new() -> StandardMaterial { | ||
material.max_relief_mapping_search_steps = 5u; | ||
material.deferred_lighting_pass_id = 1u; | ||
// scale 1, translation 0, rotation 0 | ||
- material.uv_transform_xy_axys = vec4<f32>(1.0, 0.0, 0.0, 0.1); | ||
+ material.uv_transform_xy_axes = vec4<f32>(1.0, 0.0, 0.0, 0.1); | ||
material.uv_transform_translation = vec4<f32>(0.0, 0.0, 0.0, 0.0); | ||
|
||
return material; | ||
|
||
From 7cf4a5f889a7ce3e7e885ca74f02cbebf9bb4f14 Mon Sep 17 00:00:00 2001 | ||
From: =?UTF-8?q?Fran=C3=A7ois?= <[email protected]> | ||
Date: Sat, 2 Mar 2024 00:32:07 +0100 | ||
Subject: [PATCH 3/4] comment | ||
|
||
--- | ||
crates/bevy_pbr/src/pbr_material.rs | 1 + | ||
1 file changed, 1 insertion(+) | ||
|
||
diff --git a/crates/bevy_pbr/src/pbr_material.rs b/crates/bevy_pbr/src/pbr_material.rs | ||
index 0a9f4e210f18d..b43c09cc5859a 100644 | ||
--- a/crates/bevy_pbr/src/pbr_material.rs | ||
+++ b/crates/bevy_pbr/src/pbr_material.rs | ||
@@ -614,6 +614,7 @@ pub struct StandardMaterialUniform { | ||
pub uv_transform_y_axis: Vec2, | ||
/// The translation of the transform applied to the UVs corresponding to ATTRIBUTE_UV_0 on the mesh before sampling. Default is [0, 0]. | ||
pub uv_transform_translation: Vec2, | ||
+ /// Needed for alignement, otherwise some versions of DX12 crash | ||
pub padding: Vec2, | ||
/// Linear perceptual roughness, clamped to [0.089, 1.0] in the shader | ||
/// Defaults to minimum of 0.089 | ||
|
||
From 4f1c1753d6994695bbce6bbe3b737fcd0300bd81 Mon Sep 17 00:00:00 2001 | ||
From: =?UTF-8?q?Fran=C3=A7ois?= <[email protected]> | ||
Date: Sat, 2 Mar 2024 07:05:54 +0100 | ||
Subject: [PATCH 4/4] Update pbr_material.rs | ||
|
||
Co-authored-by: Jan Hohenheim <[email protected]> | ||
--- | ||
crates/bevy_pbr/src/pbr_material.rs | 2 +- | ||
1 file changed, 1 insertion(+), 1 deletion(-) | ||
|
||
diff --git a/crates/bevy_pbr/src/pbr_material.rs b/crates/bevy_pbr/src/pbr_material.rs | ||
index b43c09cc5859a..b342cfbb8b1e3 100644 | ||
--- a/crates/bevy_pbr/src/pbr_material.rs | ||
+++ b/crates/bevy_pbr/src/pbr_material.rs | ||
@@ -614,7 +614,7 @@ pub struct StandardMaterialUniform { | ||
pub uv_transform_y_axis: Vec2, | ||
/// The translation of the transform applied to the UVs corresponding to ATTRIBUTE_UV_0 on the mesh before sampling. Default is [0, 0]. | ||
pub uv_transform_translation: Vec2, | ||
- /// Needed for alignement, otherwise some versions of DX12 crash | ||
+ /// Needed for alignment, otherwise some versions of DX12 crash | ||
pub padding: Vec2, | ||
/// Linear perceptual roughness, clamped to [0.089, 1.0] in the shader | ||
/// Defaults to minimum of 0.089 |