Skip to content

Commit 46cae59

Browse files
committed
Fix view vector in pbr frag to work in ortho (#2370)
# Objective Fixes #2369 ## Solution Use the view forward direction for all frags when using ortho view.
1 parent afb3323 commit 46cae59

File tree

1 file changed

+6
-1
lines changed
  • crates/bevy_pbr/src/render_graph/pbr_pipeline

1 file changed

+6
-1
lines changed

crates/bevy_pbr/src/render_graph/pbr_pipeline/pbr.frag

+6-1
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,12 @@ void main() {
400400
emissive.rgb *= texture(sampler2D(StandardMaterial_emissive_texture, StandardMaterial_emissive_texture_sampler), v_Uv).rgb;
401401
# endif
402402

403-
vec3 V = normalize(CameraPos.xyz - v_WorldPosition.xyz);
403+
vec3 V;
404+
if (ViewProj[3][3] != 1.0) { // If the projection is not orthographic
405+
V = normalize(CameraPos.xyz - v_WorldPosition.xyz); // Only valid for a perpective projection
406+
} else {
407+
V = normalize(vec3(-ViewProj[0][2],-ViewProj[1][2],-ViewProj[2][2])); // Ortho view vec
408+
}
404409
// Neubelt and Pettineo 2013, "Crafting a Next-gen Material Pipeline for The Order: 1886"
405410
float NdotV = max(dot(N, V), 1e-4);
406411

0 commit comments

Comments
 (0)