Browse Source

fog-related shader inputs

rdb 14 years ago
parent
commit
d86356f122

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

@@ -54,6 +54,7 @@
 #include "colorAttrib.h"
 #include "colorAttrib.h"
 #include "colorScaleAttrib.h"
 #include "colorScaleAttrib.h"
 #include "clipPlaneAttrib.h"
 #include "clipPlaneAttrib.h"
+#include "fogAttrib.h"
 
 
 #include <algorithm>
 #include <algorithm>
 #include <limits.h>
 #include <limits.h>
@@ -1042,6 +1043,27 @@ fetch_specified_part(Shader::ShaderMatInput part, InternalName *name, LMatrix4f
     t = LMatrix4f(0,0,0,0,0,0,0,0,0,0,0,0,cs[0],cs[1],cs[2],cs[3]);
     t = LMatrix4f(0,0,0,0,0,0,0,0,0,0,0,0,cs[0],cs[1],cs[2],cs[3]);
     return &t;
     return &t;
   }
   }
+  case Shader::SMO_attr_fog: {
+    const FogAttrib *target_fog = DCAST(FogAttrib, _target_rs->get_attrib_def(FogAttrib::get_class_slot()));
+    Fog *fog = target_fog->get_fog();
+    if (fog == (Fog*) NULL) {
+      return &LMatrix4f::ones_mat();
+    }
+    float start, end;
+    fog->get_linear_range(start, end);
+    t = LMatrix4f(0,0,0,0,0,0,0,0,0,0,0,0,fog->get_exp_density(),start,end,1.0f/(end-start));
+    return &t;
+  }
+  case Shader::SMO_attr_fogcolor: {
+    const FogAttrib *target_fog = DCAST(FogAttrib, _target_rs->get_attrib_def(FogAttrib::get_class_slot()));
+    Fog *fog = target_fog->get_fog();
+    if (fog == (Fog*) NULL) {
+      return &LMatrix4f::ones_mat();
+    }
+    LVecBase4f c = fog->get_color();
+    t = LMatrix4f(0,0,0,0,0,0,0,0,0,0,0,0,c[0],c[1],c[2],c[3]);
+    return &t;
+  }
   case Shader::SMO_alight_x: {
   case Shader::SMO_alight_x: {
     const NodePath &np = _target_shader->get_shader_input_nodepath(name);
     const NodePath &np = _target_shader->get_shader_input_nodepath(name);
     nassertr(!np.is_empty(), &LMatrix4f::zeros_mat());
     nassertr(!np.is_empty(), &LMatrix4f::zeros_mat());

+ 3 - 0
panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx

@@ -3352,6 +3352,9 @@ set_state_and_transform(const RenderState *target,
     //PStatTimer timer(_draw_set_state_fog_pcollector);
     //PStatTimer timer(_draw_set_state_fog_pcollector);
     do_issue_fog();
     do_issue_fog();
     _state_mask.set_bit(fog_slot);
     _state_mask.set_bit(fog_slot);
+    if (_current_shader_context) {
+      _current_shader_context->issue_parameters(this, Shader::SSD_fog);
+    }
   }
   }
 
 
   int scissor_slot = ScissorAttrib::get_class_slot();
   int scissor_slot = ScissorAttrib::get_class_slot();

+ 5 - 0
panda/src/glstuff/glGraphicsStateGuardian_src.cxx

@@ -7334,6 +7334,11 @@ set_state_and_transform(const RenderState *target,
     //PStatTimer timer(_draw_set_state_fog_pcollector);
     //PStatTimer timer(_draw_set_state_fog_pcollector);
     do_issue_fog();
     do_issue_fog();
     _state_mask.set_bit(fog_slot);
     _state_mask.set_bit(fog_slot);
+#ifndef OPENGLES_1
+    if (_current_shader_context) {
+      _current_shader_context->issue_parameters(this, Shader::SSD_fog);
+    }
+#endif
   }
   }
 
 
   int scissor_slot = ScissorAttrib::get_class_slot();
   int scissor_slot = ScissorAttrib::get_class_slot();

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

@@ -406,6 +406,9 @@ cp_dependency(ShaderMatInput inp) {
   if (inp == SMO_attr_colorscale) {
   if (inp == SMO_attr_colorscale) {
     dep |= SSD_colorscale;
     dep |= SSD_colorscale;
   }
   }
+  if (inp == SMO_attr_fog || inp == SMO_attr_fogcolor) {
+    dep |= SSD_fog;
+  }
   if ((inp == SMO_model_to_view)||
   if ((inp == SMO_model_to_view)||
       (inp == SMO_view_to_model)) {
       (inp == SMO_view_to_model)) {
     dep |= SSD_transform;
     dep |= SSD_transform;
@@ -801,6 +804,28 @@ compile_parameter(const ShaderArgId        &arg_id,
       bind._arg[0] = NULL;
       bind._arg[0] = NULL;
       bind._part[1] = SMO_identity;
       bind._part[1] = SMO_identity;
       bind._arg[1] = NULL;
       bind._arg[1] = NULL;
+    } else if (pieces[1] == "fog") {
+      if (!cp_errchk_parameter_float(p,3,4)) {
+        return false;
+      }
+      bind._id = arg_id;
+      bind._piece = SMP_row3;
+      bind._func = SMF_first;
+      bind._part[0] = SMO_attr_fog;
+      bind._arg[0] = NULL;
+      bind._part[1] = SMO_identity;
+      bind._arg[1] = NULL;
+    } else if (pieces[1] == "fogcolor") {
+      if (!cp_errchk_parameter_float(p,3,4)) {
+        return false;
+      }
+      bind._id = arg_id;
+      bind._piece = SMP_row3;
+      bind._func = SMF_first;
+      bind._part[0] = SMO_attr_fogcolor;
+      bind._arg[0] = NULL;
+      bind._part[1] = SMO_identity;
+      bind._arg[1] = NULL;
     } else {
     } else {
       cp_report_error(p,"Unknown attr parameter.");
       cp_report_error(p,"Unknown attr parameter.");
       return false;
       return false;

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

@@ -150,6 +150,9 @@ public:
 
 
     SMO_apiclip_x_to_view,
     SMO_apiclip_x_to_view,
     SMO_view_to_apiclip_x,
     SMO_view_to_apiclip_x,
+
+    SMO_attr_fog,
+    SMO_attr_fogcolor,
     
     
     SMO_INVALID
     SMO_INVALID
   };
   };
@@ -224,6 +227,7 @@ public:
     SSD_colorscale    =  8,
     SSD_colorscale    =  8,
     SSD_material      = 16,
     SSD_material      = 16,
     SSD_shaderinputs  = 32,
     SSD_shaderinputs  = 32,
+    SSD_fog           = 64,
   };
   };
 
 
   enum ShaderBug {
   enum ShaderBug {