Browse Source

Add support for texmat_x parameters in shaders

rdb 16 years ago
parent
commit
b3d8d834d4
3 changed files with 30 additions and 2 deletions
  1. 8 2
      panda/src/display/graphicsStateGuardian.cxx
  2. 21 0
      panda/src/gobj/shader.cxx
  3. 1 0
      panda/src/gobj/shader.h

+ 8 - 2
panda/src/display/graphicsStateGuardian.cxx

@@ -1088,6 +1088,14 @@ fetch_specified_part(Shader::ShaderMatInput part, InternalName *name, LMatrix4f
     t = LMatrix4f(c[0],c[1],c[2],c[3],s[0],s[1],s[2],s[3],p[0],p[1],p[2],0,d[0],d[1],d[2],cutoff);
     return &t;
   }
+  case Shader::SMO_texmat_x: {
+    const TexMatrixAttrib *tma = DCAST(TexMatrixAttrib, _target_rs->get_attrib_def(TexMatrixAttrib::get_class_slot()));
+    int stagenr = atoi(name->get_name().c_str());
+    if (stagenr >= tma->get_num_stages()) {
+      return &LMatrix4f::ident_mat();
+    }
+    return &tma->get_mat(tma->get_stage(stagenr));
+  }
   case Shader::SMO_plane_x: {
     const NodePath &np = _target_shader->get_shader_input_nodepath(name);
     nassertr(!np.is_empty(), &LMatrix4f::zeros_mat());
@@ -1100,8 +1108,6 @@ fetch_specified_part(Shader::ShaderMatInput part, InternalName *name, LMatrix4f
     const ClipPlaneAttrib *cpa = DCAST(ClipPlaneAttrib, _target_rs->get_attrib_def(ClipPlaneAttrib::get_class_slot()));
     int planenr = atoi(name->get_name().c_str());
     if (planenr >= cpa->get_num_on_planes()) {
-      // The identity matrix happens to have 0,0,0,1 in the last row,
-      // which is exactly what we need, because that won't clip anything.
       return &LMatrix4f::zeros_mat();
     }
     const NodePath &np = cpa->get_on_plane(planenr);

+ 21 - 0
panda/src/gobj/shader.cxx

@@ -774,6 +774,27 @@ compile_parameter(const ShaderArgId  &arg_id,
     return true;
   }
 
+  if (pieces[0] == "texmat") {
+    if ((!cp_errchk_parameter_words(p,2))||
+        (!cp_errchk_parameter_in(p)) ||
+        (!cp_errchk_parameter_uniform(p))||
+        (!cp_errchk_parameter_float(p,16,16))) {
+      return false;
+    }
+    ShaderMatSpec bind;
+    bind._id = arg_id;
+    bind._piece = SMP_whole;
+    bind._func = SMF_first;
+    bind._part[0] = SMO_texmat_x;
+    bind._arg[0] = InternalName::make(pieces[1]);
+    bind._part[1] = SMO_identity;
+    bind._arg[1] = NULL;
+
+    cp_optimize_mat_spec(bind);
+    _mat_spec.push_back(bind);
+    return true;
+  }
+
   if (pieces[0] == "plane") {
     if ((!cp_errchk_parameter_words(p,2))||
         (!cp_errchk_parameter_in(p)) ||

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

@@ -78,6 +78,7 @@ public:
     SMO_plight_x,
     SMO_slight_x,
     SMO_satten_x,
+    SMO_texmat_x,
     SMO_plane_x,
     SMO_clipplane_x,