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

This commit is contained in:
rdb 2023-01-13 17:01:20 +01:00
parent 21347bb2d5
commit 10f4c6bb21
5 changed files with 50 additions and 0 deletions

View File

@ -1175,6 +1175,18 @@ fetch_specified_part(Shader::ShaderMatInput part, InternalName *name,
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: {
// This is a hack so we can support both F_alpha and other formats in the
// default shader, to fix font rendering in GLES2

View File

@ -483,6 +483,10 @@ set_state_and_transform(const RenderState *target_rs,
target_rs->get_attrib(TexMatrixAttrib::get_class_slot())) {
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;
}

View File

@ -2131,6 +2131,10 @@ set_state_and_transform(const RenderState *target_rs,
target_rs->get_attrib(TextureAttrib::get_class_slot())) {
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;
}

View File

@ -494,6 +494,9 @@ cp_dependency(ShaderMatInput inp) {
if (inp == SMO_tex_is_alpha_i || inp == SMO_texcolor_i) {
dep |= SSD_texture | SSD_frame;
}
if (inp == SMO_texconst_i) {
dep |= SSD_tex_gen;
}
return dep;
}
@ -1218,6 +1221,29 @@ compile_parameter(ShaderArgInfo &p, int *arg_dim) {
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 ((!cp_errchk_parameter_words(p,2))||
(!cp_errchk_parameter_in(p)) ||

View File

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