From 46cae5956f8535a7b24372fec4911704a942e8a4 Mon Sep 17 00:00:00 2001 From: Aevyrie Date: Thu, 1 Jul 2021 19:28:44 +0000 Subject: [PATCH] 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. --- crates/bevy_pbr/src/render_graph/pbr_pipeline/pbr.frag | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/bevy_pbr/src/render_graph/pbr_pipeline/pbr.frag b/crates/bevy_pbr/src/render_graph/pbr_pipeline/pbr.frag index 74a6fac659..20745f7622 100644 --- a/crates/bevy_pbr/src/render_graph/pbr_pipeline/pbr.frag +++ b/crates/bevy_pbr/src/render_graph/pbr_pipeline/pbr.frag @@ -400,7 +400,12 @@ void main() { emissive.rgb *= texture(sampler2D(StandardMaterial_emissive_texture, StandardMaterial_emissive_texture_sampler), v_Uv).rgb; # endif - vec3 V = normalize(CameraPos.xyz - v_WorldPosition.xyz); + vec3 V; + if (ViewProj[3][3] != 1.0) { // If the projection is not orthographic + V = normalize(CameraPos.xyz - v_WorldPosition.xyz); // Only valid for a perpective projection + } else { + V = normalize(vec3(-ViewProj[0][2],-ViewProj[1][2],-ViewProj[2][2])); // Ortho view vec + } // Neubelt and Pettineo 2013, "Crafting a Next-gen Material Pipeline for The Order: 1886" float NdotV = max(dot(N, V), 1e-4);