Browse Source

shader: Add texconst_i shader input for Cg shaders to access TexGen constant

rdb 2 years ago
parent
commit
10f4c6bb21

+ 12 - 0
panda/src/display/graphicsStateGuardian.cxx

@@ -1175,6 +1175,18 @@ fetch_specified_part(Shader::ShaderMatInput part, InternalName *name,
       return &LMatrix4::zeros_mat();
       return &LMatrix4::zeros_mat();
     }
     }
   }
   }
+  case Shader::SMO_texconst_i: {
+    const TexGenAttrib *tga;
+    const TextureAttrib *ta;
+    if (_target_rs->get_attrib(ta) && _target_rs->get_attrib(tga) &&
+        index < ta->get_num_on_stages()) {
+      LVecBase3 value = tga->get_constant_value(ta->get_on_stage(index));
+      t.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, value[0], value[1], value[2], 1);
+      return &t;
+    } else {
+      return &LMatrix4::ident_mat();
+    }
+  }
   case Shader::SMO_tex_is_alpha_i: {
   case Shader::SMO_tex_is_alpha_i: {
     // This is a hack so we can support both F_alpha and other formats in the
     // This is a hack so we can support both F_alpha and other formats in the
     // default shader, to fix font rendering in GLES2
     // default shader, to fix font rendering in GLES2

+ 4 - 0
panda/src/glstuff/glCgShaderContext_src.cxx

@@ -483,6 +483,10 @@ set_state_and_transform(const RenderState *target_rs,
         target_rs->get_attrib(TexMatrixAttrib::get_class_slot())) {
         target_rs->get_attrib(TexMatrixAttrib::get_class_slot())) {
       altered |= Shader::SSD_tex_matrix;
       altered |= Shader::SSD_tex_matrix;
     }
     }
+    if (state_rs->get_attrib(TexGenAttrib::get_class_slot()) !=
+        target_rs->get_attrib(TexGenAttrib::get_class_slot())) {
+      altered |= Shader::SSD_tex_gen;
+    }
     _state_rs = target_rs;
     _state_rs = target_rs;
   }
   }
 
 

+ 4 - 0
panda/src/glstuff/glShaderContext_src.cxx

@@ -2131,6 +2131,10 @@ set_state_and_transform(const RenderState *target_rs,
         target_rs->get_attrib(TextureAttrib::get_class_slot())) {
         target_rs->get_attrib(TextureAttrib::get_class_slot())) {
       altered |= Shader::SSD_texture;
       altered |= Shader::SSD_texture;
     }
     }
+    if (state_rs->get_attrib(TexGenAttrib::get_class_slot()) !=
+        target_rs->get_attrib(TexGenAttrib::get_class_slot())) {
+      altered |= Shader::SSD_tex_gen;
+    }
     _state_rs = target_rs;
     _state_rs = target_rs;
   }
   }
 
 

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

@@ -494,6 +494,9 @@ cp_dependency(ShaderMatInput inp) {
   if (inp == SMO_tex_is_alpha_i || inp == SMO_texcolor_i) {
   if (inp == SMO_tex_is_alpha_i || inp == SMO_texcolor_i) {
     dep |= SSD_texture | SSD_frame;
     dep |= SSD_texture | SSD_frame;
   }
   }
+  if (inp == SMO_texconst_i) {
+    dep |= SSD_tex_gen;
+  }
 
 
   return dep;
   return dep;
 }
 }
@@ -1218,6 +1221,29 @@ compile_parameter(ShaderArgInfo &p, int *arg_dim) {
     return true;
     return true;
   }
   }
 
 
+  if (pieces[0] == "texconst") {
+    if ((!cp_errchk_parameter_words(p,2))||
+        (!cp_errchk_parameter_in(p)) ||
+        (!cp_errchk_parameter_uniform(p))||
+        (!cp_errchk_parameter_float(p,3,4))) {
+      return false;
+    }
+    ShaderMatSpec bind;
+    bind._id = p._id;
+    bind._piece = SMP_row3;
+    bind._func = SMF_first;
+    bind._part[0] = SMO_texconst_i;
+    bind._arg[0] = nullptr;
+    bind._part[1] = SMO_identity;
+    bind._arg[1] = nullptr;
+    bind._index = atoi(pieces[1].c_str());
+
+    cp_optimize_mat_spec(bind);
+    _mat_spec.push_back(bind);
+    _mat_deps |= bind._dep[0] | bind._dep[1];
+    return true;
+  }
+
   if (pieces[0] == "plane") {
   if (pieces[0] == "plane") {
     if ((!cp_errchk_parameter_words(p,2))||
     if ((!cp_errchk_parameter_words(p,2))||
         (!cp_errchk_parameter_in(p)) ||
         (!cp_errchk_parameter_in(p)) ||

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

@@ -214,6 +214,9 @@ public:
     // Color of an M_blend texture stage.
     // Color of an M_blend texture stage.
     SMO_texcolor_i,
     SMO_texcolor_i,
 
 
+    // Constant value of the TexGenAttrib of stage i.
+    SMO_texconst_i,
+
     SMO_INVALID
     SMO_INVALID
   };
   };
 
 
@@ -321,6 +324,7 @@ public:
     SSD_projection    = 0x800,
     SSD_projection    = 0x800,
     SSD_texture      = 0x1000,
     SSD_texture      = 0x1000,
     SSD_view_transform= 0x2000,
     SSD_view_transform= 0x2000,
+    SSD_tex_gen      = 0x4000,
   };
   };
 
 
   enum ShaderBug {
   enum ShaderBug {