fog-related shader inputs

This commit is contained in:
rdb 2011-10-08 13:25:51 +00:00
parent 5e98a7d91e
commit d86356f122
5 changed files with 59 additions and 0 deletions

View File

@ -54,6 +54,7 @@
#include "colorAttrib.h"
#include "colorScaleAttrib.h"
#include "clipPlaneAttrib.h"
#include "fogAttrib.h"
#include <algorithm>
#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]);
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());

View File

@ -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();

View File

@ -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();

View File

@ -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;

View File

@ -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 {