From d86356f122032a8f1c9e525fea1f9ad3c3b858d1 Mon Sep 17 00:00:00 2001 From: rdb Date: Sat, 8 Oct 2011 13:25:51 +0000 Subject: [PATCH] fog-related shader inputs --- panda/src/display/graphicsStateGuardian.cxx | 22 ++++++++++++++++ panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx | 3 +++ .../glstuff/glGraphicsStateGuardian_src.cxx | 5 ++++ panda/src/gobj/shader.cxx | 25 +++++++++++++++++++ panda/src/gobj/shader.h | 4 +++ 5 files changed, 59 insertions(+) diff --git a/panda/src/display/graphicsStateGuardian.cxx b/panda/src/display/graphicsStateGuardian.cxx index 467af4f47a..c2a2c28df9 100644 --- a/panda/src/display/graphicsStateGuardian.cxx +++ b/panda/src/display/graphicsStateGuardian.cxx @@ -54,6 +54,7 @@ #include "colorAttrib.h" #include "colorScaleAttrib.h" #include "clipPlaneAttrib.h" +#include "fogAttrib.h" #include #include @@ -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]); 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: { const NodePath &np = _target_shader->get_shader_input_nodepath(name); nassertr(!np.is_empty(), &LMatrix4f::zeros_mat()); diff --git a/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx b/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx index 6525b6685f..6a1ecc4180 100755 --- a/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx +++ b/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx @@ -3352,6 +3352,9 @@ set_state_and_transform(const RenderState *target, //PStatTimer timer(_draw_set_state_fog_pcollector); do_issue_fog(); _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(); diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index e3edf546b1..8ba707fc52 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -7334,6 +7334,11 @@ set_state_and_transform(const RenderState *target, //PStatTimer timer(_draw_set_state_fog_pcollector); do_issue_fog(); _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(); diff --git a/panda/src/gobj/shader.cxx b/panda/src/gobj/shader.cxx index 5ff10a84c8..de3d45a78f 100755 --- a/panda/src/gobj/shader.cxx +++ b/panda/src/gobj/shader.cxx @@ -406,6 +406,9 @@ cp_dependency(ShaderMatInput inp) { if (inp == SMO_attr_colorscale) { dep |= SSD_colorscale; } + if (inp == SMO_attr_fog || inp == SMO_attr_fogcolor) { + dep |= SSD_fog; + } if ((inp == SMO_model_to_view)|| (inp == SMO_view_to_model)) { dep |= SSD_transform; @@ -801,6 +804,28 @@ compile_parameter(const ShaderArgId &arg_id, bind._arg[0] = NULL; bind._part[1] = SMO_identity; 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 { cp_report_error(p,"Unknown attr parameter."); return false; diff --git a/panda/src/gobj/shader.h b/panda/src/gobj/shader.h index 16b58b90a8..604146486f 100755 --- a/panda/src/gobj/shader.h +++ b/panda/src/gobj/shader.h @@ -150,6 +150,9 @@ public: SMO_apiclip_x_to_view, SMO_view_to_apiclip_x, + + SMO_attr_fog, + SMO_attr_fogcolor, SMO_INVALID }; @@ -224,6 +227,7 @@ public: SSD_colorscale = 8, SSD_material = 16, SSD_shaderinputs = 32, + SSD_fog = 64, }; enum ShaderBug {