Skip to content

Commit 072f2e1

Browse files
committed
Move texture sample out of branch in prepare_normal (#5129)
# Objective This fixes #5127 ## Solution - Moved texture sample out of branch in `prepare_normal()`. Co-authored-by: DGriffin91 <github@dgdigital.net>
1 parent 510ce5e commit 072f2e1

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

crates/bevy_pbr/src/render/pbr_functions.wgsl

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ fn prepare_normal(
4141
#ifdef VERTEX_TANGENTS
4242
#ifdef STANDARDMATERIAL_NORMAL_MAP
4343
// Nt is the tangent-space normal.
44-
var Nt: vec3<f32>;
44+
var Nt = textureSample(normal_map_texture, normal_map_sampler, uv).rgb;
4545
if ((standard_material_flags & STANDARD_MATERIAL_FLAGS_TWO_COMPONENT_NORMAL_MAP) != 0u) {
4646
// Only use the xy components and derive z for 2-component normal maps.
47-
Nt = vec3<f32>(textureSample(normal_map_texture, normal_map_sampler, uv).rg * 2.0 - 1.0, 0.0);
47+
Nt = vec3<f32>(Nt.rg * 2.0 - 1.0, 0.0);
4848
Nt.z = sqrt(1.0 - Nt.x * Nt.x - Nt.y * Nt.y);
4949
} else {
50-
Nt = textureSample(normal_map_texture, normal_map_sampler, uv).rgb * 2.0 - 1.0;
50+
Nt = Nt * 2.0 - 1.0;
5151
}
5252
// Normal maps authored for DirectX require flipping the y component
5353
if ((standard_material_flags & STANDARD_MATERIAL_FLAGS_FLIP_NORMAL_MAP_Y) != 0u) {

0 commit comments

Comments
 (0)