فهرست منبع

Add roughness and metallic to p3d_Material struct

rdb 10 سال پیش
والد
کامیت
1d098b0099
3فایلهای تغییر یافته به همراه36 افزوده شده و 0 حذف شده
  1. 11 0
      panda/src/display/graphicsStateGuardian.cxx
  2. 22 0
      panda/src/glstuff/glShaderContext_src.cxx
  3. 3 0
      panda/src/gobj/shader.h

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

@@ -1067,6 +1067,17 @@ fetch_specified_part(Shader::ShaderMatInput part, InternalName *name,
                   spc[0],spc[1],spc[2],spc[3]);
                   spc[0],spc[1],spc[2],spc[3]);
     return &t;
     return &t;
   }
   }
+  case Shader::SMO_attr_material2: {
+    const MaterialAttrib *target_material = (const MaterialAttrib *)
+      _target_rs->get_attrib_def(MaterialAttrib::get_class_slot());
+    if (target_material->is_off()) {
+      t = LMatrix4(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1);
+      return &t;
+    }
+    Material *m = target_material->get_material();
+    t.set_row(3, LVecBase4(m->get_metallic(), 0, 0, m->get_roughness()));
+    return &t;
+  }
   case Shader::SMO_attr_color: {
   case Shader::SMO_attr_color: {
     const ColorAttrib *target_color = (const ColorAttrib *)
     const ColorAttrib *target_color = (const ColorAttrib *)
       _target_rs->get_attrib_def(ColorAttrib::get_class_slot());
       _target_rs->get_attrib_def(ColorAttrib::get_class_slot());

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

@@ -954,6 +954,28 @@ reflect_uniform(int i, char *name_buffer, GLsizei name_buflen) {
         _shader->_mat_spec.push_back(bind);
         _shader->_mat_spec.push_back(bind);
         _shader->_mat_deps |= bind._dep[0];
         _shader->_mat_deps |= bind._dep[0];
         return;
         return;
+
+      } else if (noprefix == "Material.roughness") {
+        if (param_type != GL_FLOAT) {
+          GLCAT.error()
+            << "p3d_Material.roughness should be float\n";
+        }
+        bind._part[0] = Shader::SMO_attr_material2;
+        bind._piece = Shader::SMP_cell15;
+        _shader->_mat_spec.push_back(bind);
+        _shader->_mat_deps |= bind._dep[0];
+        return;
+
+      } else if (noprefix == "Material.metallic") {
+        if (param_type != GL_FLOAT && param_type != GL_BOOL) {
+          GLCAT.error()
+            << "p3d_Material.metallic should be bool or float\n";
+        }
+        bind._part[0] = Shader::SMO_attr_material2;
+        bind._piece = Shader::SMP_row3x1;
+        _shader->_mat_spec.push_back(bind);
+        _shader->_mat_deps |= bind._dep[0];
+        return;
       }
       }
     }
     }
     if (noprefix == "ColorScale") {
     if (noprefix == "ColorScale") {

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

@@ -194,6 +194,9 @@ public:
 
 
     SMO_inv_texmat_i,
     SMO_inv_texmat_i,
 
 
+    // Additional properties for PBR materials
+    SMO_attr_material2,
+
     SMO_INVALID
     SMO_INVALID
   };
   };