Browse Source

Correct scaling and normalizations of binormals and tangents in generated shaders

rdb 10 years ago
parent
commit
6d0e4c2662
1 changed files with 4 additions and 2 deletions
  1. 4 2
      panda/src/pgraphnodes/shaderGenerator.cxx

+ 4 - 2
panda/src/pgraphnodes/shaderGenerator.cxx

@@ -713,6 +713,8 @@ synthesize_shader(const RenderState *rs) {
     text << "\t uniform float4x4 trans_model_to_view,\n";
     eye_position_freg = alloc_freg();
     text << "\t out float4 l_eye_position : " << eye_position_freg << ",\n";
+  } else if ((_lighting || _out_aux_normal) && (_map_index_normal >= 0 && _auto_normal_on)) {
+    text << "\t uniform float4x4 trans_model_to_view,\n";
   }
   if (_need_eye_normal) {
     eye_normal_freg = alloc_freg();
@@ -784,9 +786,9 @@ synthesize_shader(const RenderState *rs) {
     text << "\t l_color = vtx_color;\n";
   }
   if ((_lighting || _out_aux_normal) && (_map_index_normal >= 0 && _auto_normal_on)) {
-    text << "\t l_tangent.xyz = mul((float3x3)tpose_view_to_model, vtx_" << tangent_input << ".xyz);\n";
+    text << "\t l_tangent.xyz = normalize(mul((float3x3)trans_model_to_view, vtx_" << tangent_input << ".xyz));\n";
     text << "\t l_tangent.w = 0;\n";
-    text << "\t l_binormal.xyz = mul((float3x3)tpose_view_to_model, -vtx_" << binormal_input << ".xyz);\n";
+    text << "\t l_binormal.xyz = normalize(mul((float3x3)trans_model_to_view, -vtx_" << binormal_input << ".xyz));\n";
     text << "\t l_binormal.w = 0;\n";
   }
   if (_shadows && _auto_shadow_on) {