Skip to content

Commit 51be04d

Browse files
committed
shader: make osg-prefixed inputs work, fix p3d_Material.metallic
1 parent 9e453f6 commit 51be04d

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

panda/src/glstuff/glShaderContext_src.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ CLP(ShaderContext)(CLP(GraphicsStateGuardian) *glgsg, Shader *s) : ShaderContext
266266
_color_attrib_index = -1;
267267
_transform_table_index = -1;
268268
_slider_table_index = -1;
269-
_frame_number_loc = -1;
269+
_frame_number_loc = s->_frame_number_loc;
270270
_frame_number = -1;
271271
_validated = !gl_validate_shaders;
272272

panda/src/gobj/shader.cxx

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2155,7 +2155,7 @@ bind_parameter(CPT_InternalName name, const ::ShaderType *type, int location) {
21552155
continue;
21562156
}
21572157
} else if (member.name == "metallic") {
2158-
if (member.type == ::ShaderType::bool_type &&
2158+
if (member.type == ::ShaderType::bool_type ||
21592159
member.type == ::ShaderType::float_type) {
21602160
bind._part[0] = SMO_attr_material2;
21612161
bind._piece = SMP_row3x1;
@@ -2318,6 +2318,57 @@ bind_parameter(CPT_InternalName name, const ::ShaderType *type, int location) {
23182318

23192319
return report_parameter_error(name, type, "unrecognized parameter name");
23202320
}
2321+
else if (pieces[0] == "osg" && _language == SL_GLSL) {
2322+
if (!expect_num_words(name, type, 2)) {
2323+
return false;
2324+
}
2325+
2326+
// These inputs are supported by OpenSceneGraph. We can support them as
2327+
// well, to increase compatibility.
2328+
ShaderMatSpec bind;
2329+
bind._id = arg_id;
2330+
bind._arg[0] = nullptr;
2331+
bind._arg[1] = nullptr;
2332+
2333+
if (pieces[1] == "ViewMatrix") {
2334+
bind._piece = SMP_whole;
2335+
bind._func = SMF_compose;
2336+
bind._part[0] = SMO_world_to_view;
2337+
bind._part[1] = SMO_view_to_apiview;
2338+
}
2339+
else if (pieces[1] == "InverseViewMatrix" || pieces[1] == "ViewMatrixInverse") {
2340+
bind._piece = SMP_whole;
2341+
bind._func = SMF_compose;
2342+
bind._part[0] = SMO_apiview_to_view;
2343+
bind._part[1] = SMO_view_to_world;
2344+
}
2345+
else if (pieces[1] == "FrameTime") {
2346+
bind._piece = SMP_row3x1;
2347+
bind._func = SMF_first;
2348+
bind._part[0] = SMO_frame_time;
2349+
bind._part[1] = SMO_identity;
2350+
}
2351+
else if (pieces[1] == "DeltaFrameTime") {
2352+
bind._piece = SMP_row3x1;
2353+
bind._func = SMF_first;
2354+
bind._part[0] = SMO_frame_delta;
2355+
bind._part[1] = SMO_identity;
2356+
}
2357+
else if (pieces[1] == "FrameNumber") {
2358+
if (type == ::ShaderType::int_type) {
2359+
_frame_number_loc = location;
2360+
return true;
2361+
} else {
2362+
return report_parameter_error(name, type, "expected int");
2363+
}
2364+
}
2365+
else {
2366+
return report_parameter_error(name, type, "unrecognized parameter name");
2367+
}
2368+
2369+
cp_add_mat_spec(bind);
2370+
return true;
2371+
}
23212372

23222373
// Check for mstrans, wstrans, vstrans, cstrans, mspos, wspos, vspos, cspos
23232374
if (pieces[0].size() >= 5 &&

panda/src/gobj/shader.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@ class EXPCL_PANDA_GOBJ Shader : public TypedWritableReferenceCount {
533533
pvector<ShaderMatPart> _mat_parts;
534534
int _mat_deps = 0;
535535
int _mat_cache_size = 0;
536+
int _frame_number_loc = -1;
536537

537538
bool _error_flag;
538539
ShaderFile _text;

0 commit comments

Comments
 (0)