Browse Source

shader: make osg-prefixed inputs work, fix p3d_Material.metallic

rdb 5 years ago
parent
commit
51be04dfd3
3 changed files with 54 additions and 2 deletions
  1. 1 1
      panda/src/glstuff/glShaderContext_src.cxx
  2. 52 1
      panda/src/gobj/shader.cxx
  3. 1 0
      panda/src/gobj/shader.h

+ 1 - 1
panda/src/glstuff/glShaderContext_src.cxx

@@ -266,7 +266,7 @@ CLP(ShaderContext)(CLP(GraphicsStateGuardian) *glgsg, Shader *s) : ShaderContext
   _color_attrib_index = -1;
   _color_attrib_index = -1;
   _transform_table_index = -1;
   _transform_table_index = -1;
   _slider_table_index = -1;
   _slider_table_index = -1;
-  _frame_number_loc = -1;
+  _frame_number_loc = s->_frame_number_loc;
   _frame_number = -1;
   _frame_number = -1;
   _validated = !gl_validate_shaders;
   _validated = !gl_validate_shaders;
 
 

+ 52 - 1
panda/src/gobj/shader.cxx

@@ -2155,7 +2155,7 @@ bind_parameter(CPT_InternalName name, const ::ShaderType *type, int location) {
             continue;
             continue;
           }
           }
         } else if (member.name == "metallic") {
         } else if (member.name == "metallic") {
-          if (member.type == ::ShaderType::bool_type &&
+          if (member.type == ::ShaderType::bool_type ||
               member.type == ::ShaderType::float_type) {
               member.type == ::ShaderType::float_type) {
             bind._part[0] = SMO_attr_material2;
             bind._part[0] = SMO_attr_material2;
             bind._piece = SMP_row3x1;
             bind._piece = SMP_row3x1;
@@ -2318,6 +2318,57 @@ bind_parameter(CPT_InternalName name, const ::ShaderType *type, int location) {
 
 
     return report_parameter_error(name, type, "unrecognized parameter name");
     return report_parameter_error(name, type, "unrecognized parameter name");
   }
   }
+  else if (pieces[0] == "osg" && _language == SL_GLSL) {
+    if (!expect_num_words(name, type, 2)) {
+      return false;
+    }
+
+    // These inputs are supported by OpenSceneGraph.  We can support them as
+    // well, to increase compatibility.
+    ShaderMatSpec bind;
+    bind._id = arg_id;
+    bind._arg[0] = nullptr;
+    bind._arg[1] = nullptr;
+
+    if (pieces[1] == "ViewMatrix") {
+      bind._piece = SMP_whole;
+      bind._func = SMF_compose;
+      bind._part[0] = SMO_world_to_view;
+      bind._part[1] = SMO_view_to_apiview;
+    }
+    else if (pieces[1] == "InverseViewMatrix" || pieces[1] == "ViewMatrixInverse") {
+      bind._piece = SMP_whole;
+      bind._func = SMF_compose;
+      bind._part[0] = SMO_apiview_to_view;
+      bind._part[1] = SMO_view_to_world;
+    }
+    else if (pieces[1] == "FrameTime") {
+      bind._piece = SMP_row3x1;
+      bind._func = SMF_first;
+      bind._part[0] = SMO_frame_time;
+      bind._part[1] = SMO_identity;
+    }
+    else if (pieces[1] == "DeltaFrameTime") {
+      bind._piece = SMP_row3x1;
+      bind._func = SMF_first;
+      bind._part[0] = SMO_frame_delta;
+      bind._part[1] = SMO_identity;
+    }
+    else if (pieces[1] == "FrameNumber") {
+      if (type == ::ShaderType::int_type) {
+        _frame_number_loc = location;
+        return true;
+      } else {
+        return report_parameter_error(name, type, "expected int");
+      }
+    }
+    else {
+      return report_parameter_error(name, type, "unrecognized parameter name");
+    }
+
+    cp_add_mat_spec(bind);
+    return true;
+  }
 
 
   // Check for mstrans, wstrans, vstrans, cstrans, mspos, wspos, vspos, cspos
   // Check for mstrans, wstrans, vstrans, cstrans, mspos, wspos, vspos, cspos
   if (pieces[0].size() >= 5 &&
   if (pieces[0].size() >= 5 &&

+ 1 - 0
panda/src/gobj/shader.h

@@ -533,6 +533,7 @@ public:
   pvector<ShaderMatPart> _mat_parts;
   pvector<ShaderMatPart> _mat_parts;
   int _mat_deps = 0;
   int _mat_deps = 0;
   int _mat_cache_size = 0;
   int _mat_cache_size = 0;
+  int _frame_number_loc = -1;
 
 
   bool _error_flag;
   bool _error_flag;
   ShaderFile _text;
   ShaderFile _text;