From da59bbd028a102e03d338f2ee72ad860dcf4e9a5 Mon Sep 17 00:00:00 2001 From: DGriffin91 <33357138+DGriffin91@users.noreply.github.com> Date: Wed, 29 Jun 2022 02:48:46 +0000 Subject: [PATCH] Move texture sample out of branch in prepare_normal (#5129) # Objective This fixes https://github.com/bevyengine/bevy/issues/5127 ## Solution - Moved texture sample out of branch in `prepare_normal()`. Co-authored-by: DGriffin91 --- crates/bevy_pbr/src/render/pbr_functions.wgsl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/bevy_pbr/src/render/pbr_functions.wgsl b/crates/bevy_pbr/src/render/pbr_functions.wgsl index b389801b61b46..f35d2a3d6b375 100644 --- a/crates/bevy_pbr/src/render/pbr_functions.wgsl +++ b/crates/bevy_pbr/src/render/pbr_functions.wgsl @@ -41,13 +41,13 @@ fn prepare_normal( #ifdef VERTEX_TANGENTS #ifdef STANDARDMATERIAL_NORMAL_MAP // Nt is the tangent-space normal. - var Nt: vec3; + var Nt = textureSample(normal_map_texture, normal_map_sampler, uv).rgb; if ((standard_material_flags & STANDARD_MATERIAL_FLAGS_TWO_COMPONENT_NORMAL_MAP) != 0u) { // Only use the xy components and derive z for 2-component normal maps. - Nt = vec3(textureSample(normal_map_texture, normal_map_sampler, uv).rg * 2.0 - 1.0, 0.0); + Nt = vec3(Nt.rg * 2.0 - 1.0, 0.0); Nt.z = sqrt(1.0 - Nt.x * Nt.x - Nt.y * Nt.y); } else { - Nt = textureSample(normal_map_texture, normal_map_sampler, uv).rgb * 2.0 - 1.0; + Nt = Nt * 2.0 - 1.0; } // Normal maps authored for DirectX require flipping the y component if ((standard_material_flags & STANDARD_MATERIAL_FLAGS_FLIP_NORMAL_MAP_Y) != 0u) {