From 535636ebed9cf8be3b4a38d550a241884f9d3702 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Wed, 28 Feb 2024 23:39:41 +0100 Subject: [PATCH] meh again --- crates/bevy_pbr/src/pbr_material.rs | 23 +++++++++++-------- crates/bevy_pbr/src/render/pbr_fragment.wgsl | 7 +++++- .../src/render/pbr_prepass_functions.wgsl | 8 ++++++- crates/bevy_pbr/src/render/pbr_types.wgsl | 10 +++++--- 4 files changed, 34 insertions(+), 14 deletions(-) diff --git a/crates/bevy_pbr/src/pbr_material.rs b/crates/bevy_pbr/src/pbr_material.rs index ca516d1a58db22..45208361cc858a 100644 --- a/crates/bevy_pbr/src/pbr_material.rs +++ b/crates/bevy_pbr/src/pbr_material.rs @@ -610,12 +610,12 @@ pub struct StandardMaterialUniform { /// Color white light takes after travelling through the attenuation distance underneath the material surface pub attenuation_color: Vec4, /// 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, + pub uv_transform_xy_axis: Vec4, + // /// 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, + pub uv_transform_translation: Vec4, + // pub padding: Vec2, /// Linear perceptual roughness, clamped to [0.089, 1.0] in the shader /// Defaults to minimum of 0.089 pub roughness: f32, @@ -752,10 +752,15 @@ impl AsBindGroupShaderType 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_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, + uv_transform_xy_axis: self + .uv_transform + .matrix2 + .x_axis + .extend(self.uv_transform.matrix2.y_axis.x) + .extend(self.uv_transform.matrix2.y_axis.y), + // uv_transform_y_axis: self.uv_transform.matrix2.y_axis, + uv_transform_translation: self.uv_transform.translation.extend(0.0).extend(0.0), + // padding: Vec2::ZERO, } } } diff --git a/crates/bevy_pbr/src/render/pbr_fragment.wgsl b/crates/bevy_pbr/src/render/pbr_fragment.wgsl index d36c25c7c9a86d..bcd0c201e6a327 100644 --- a/crates/bevy_pbr/src/render/pbr_fragment.wgsl +++ b/crates/bevy_pbr/src/render/pbr_fragment.wgsl @@ -81,7 +81,12 @@ fn pbr_input_from_standard_material( let NdotV = max(dot(pbr_input.N, pbr_input.V), 0.0001); #ifdef VERTEX_UVS - let uv_transform = affine2_to_square(pbr_bindings::material.uv_transform); + // let uv_transform = affine2_to_square(pbr_bindings::material.uv_transform); + let uv_transform = mat3x3( + vec3(pbr_bindings::material.uv_transform_xy.xy, 0.0), + vec3(pbr_bindings::material.uv_transform_xy.zw, 0.0), + vec3(pbr_bindings::material.uv_transform_translation, 0.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 bb4c3be1f03503..db68d04e6b0e08 100644 --- a/crates/bevy_pbr/src/render/pbr_prepass_functions.wgsl +++ b/crates/bevy_pbr/src/render/pbr_prepass_functions.wgsl @@ -19,7 +19,13 @@ fn prepass_alpha_discard(in: VertexOutput) { var output_color: vec4 = pbr_bindings::material.base_color; #ifdef VERTEX_UVS - let uv_transform = affine2_to_square(pbr_bindings::material.uv_transform); + // let uv_transform = affine2_to_square(pbr_bindings::material.uv_transform); + let uv_transform = mat3x3( + vec3(pbr_bindings::material.uv_transform_xy.xy, 0.0), + vec3(pbr_bindings::material.uv_transform_xy.zw, 0.0), + vec3(pbr_bindings::material.uv_transform_translation, 0.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 d02dce361e4755..d5e727e4f6308a 100644 --- a/crates/bevy_pbr/src/render/pbr_types.wgsl +++ b/crates/bevy_pbr/src/render/pbr_types.wgsl @@ -6,8 +6,10 @@ struct StandardMaterial { base_color: vec4, emissive: vec4, attenuation_color: vec4, - uv_transform: mat3x2, - padding: vec2, + uv_transform_xy: vec4, + uv_transform_translation: vec2, + padding_a: f32, + padding_b: f32, perceptual_roughness: f32, metallic: f32, reflectance: f32, @@ -79,7 +81,9 @@ 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 = mat3x2(1.0, 0.0, 0.0, 1.0, 0.0, 0.0); + // material.uv_transform = mat3x2(1.0, 0.0, 0.0, 1.0, 0.0, 0.0); + material.uv_transform_xy = vec4(1.0, 0.0, 1.0, 0.0,); + material.uv_transform_translation = vec2(0.0, 0.0); return material; }