mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
Commit patch by nikolm to support AmbientLight shader inputs in GLSL
This commit is contained in:
parent
d447ec3bc6
commit
0fda35d88c
@ -1407,22 +1407,29 @@ fetch_specified_part(Shader::ShaderMatInput part, InternalName *name,
|
|||||||
static const CPT_InternalName IN_quadraticAttenuation("quadraticAttenuation");
|
static const CPT_InternalName IN_quadraticAttenuation("quadraticAttenuation");
|
||||||
|
|
||||||
if (attrib == IN_ambient) {
|
if (attrib == IN_ambient) {
|
||||||
#ifndef NDEBUG
|
|
||||||
Light *light = np.node()->as_light();
|
Light *light = np.node()->as_light();
|
||||||
nassertr(light != (Light *)NULL, &LMatrix4::ident_mat());
|
nassertr(light != (Light *)NULL, &LMatrix4::ident_mat());
|
||||||
#endif
|
if (np.node()->is_of_type(AmbientLight::get_class_type())) {
|
||||||
// Lights don't currently have an ambient color in Panda3D.
|
LColor c = light->get_color();
|
||||||
// We still have to support the attribute.
|
c.componentwise_mult(_light_color_scale);
|
||||||
t.set_row(3, LColor(0.0f, 0.0f, 0.0f, 1.0f));
|
t.set_row(3, c);
|
||||||
|
} else {
|
||||||
|
// Non-ambient lights don't currently have an ambient color in Panda3D.
|
||||||
|
t.set_row(3, LColor(0.0f, 0.0f, 0.0f, 1.0f));
|
||||||
|
}
|
||||||
return &t;
|
return &t;
|
||||||
|
|
||||||
} else if (attrib == IN_diffuse) {
|
} else if (attrib == IN_diffuse) {
|
||||||
Light *light = np.node()->as_light();
|
Light *light = np.node()->as_light();
|
||||||
nassertr(light != (Light *)NULL, &LMatrix4::ones_mat());
|
nassertr(light != (Light *)NULL, &LMatrix4::ones_mat());
|
||||||
|
if (np.node()->is_of_type(AmbientLight::get_class_type())) {
|
||||||
LColor c = light->get_color();
|
// Ambient light has no diffuse color.
|
||||||
c.componentwise_mult(_light_color_scale);
|
t.set_row(3, LColor(0.0f, 0.0f, 0.0f, 1.0f));
|
||||||
t.set_row(3, c);
|
} else {
|
||||||
|
LColor c = light->get_color();
|
||||||
|
c.componentwise_mult(_light_color_scale);
|
||||||
|
t.set_row(3, c);
|
||||||
|
}
|
||||||
return &t;
|
return &t;
|
||||||
|
|
||||||
} else if (attrib == IN_specular) {
|
} else if (attrib == IN_specular) {
|
||||||
@ -1432,7 +1439,11 @@ fetch_specified_part(Shader::ShaderMatInput part, InternalName *name,
|
|||||||
return &t;
|
return &t;
|
||||||
|
|
||||||
} else if (attrib == IN_position) {
|
} else if (attrib == IN_position) {
|
||||||
if (np.node()->is_of_type(DirectionalLight::get_class_type())) {
|
if (np.node()->is_of_type(AmbientLight::get_class_type())) {
|
||||||
|
// Ambient light has no position.
|
||||||
|
t = LMatrix4(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
|
||||||
|
return &t;
|
||||||
|
} else if (np.node()->is_of_type(DirectionalLight::get_class_type())) {
|
||||||
DirectionalLight *light;
|
DirectionalLight *light;
|
||||||
DCAST_INTO_R(light, np.node(), &LMatrix4::ident_mat());
|
DCAST_INTO_R(light, np.node(), &LMatrix4::ident_mat());
|
||||||
|
|
||||||
@ -1458,7 +1469,11 @@ fetch_specified_part(Shader::ShaderMatInput part, InternalName *name,
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else if (attrib == IN_halfVector) {
|
} else if (attrib == IN_halfVector) {
|
||||||
if (np.node()->is_of_type(DirectionalLight::get_class_type())) {
|
if (np.node()->is_of_type(AmbientLight::get_class_type())) {
|
||||||
|
// Ambient light has no half-vector.
|
||||||
|
t = LMatrix4(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
|
||||||
|
return &t;
|
||||||
|
} else if (np.node()->is_of_type(DirectionalLight::get_class_type())) {
|
||||||
DirectionalLight *light;
|
DirectionalLight *light;
|
||||||
DCAST_INTO_R(light, np.node(), &LMatrix4::ident_mat());
|
DCAST_INTO_R(light, np.node(), &LMatrix4::ident_mat());
|
||||||
|
|
||||||
@ -1490,19 +1505,25 @@ fetch_specified_part(Shader::ShaderMatInput part, InternalName *name,
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else if (attrib == IN_spotDirection) {
|
} else if (attrib == IN_spotDirection) {
|
||||||
LightLensNode *light;
|
if (np.node()->is_of_type(AmbientLight::get_class_type())) {
|
||||||
DCAST_INTO_R(light, np.node(), &LMatrix4::ident_mat());
|
// Ambient light has no spot direction.
|
||||||
Lens *lens = light->get_lens();
|
t.set_row(3, LVector3(0.0f, 0.0f, 0.0f));
|
||||||
nassertr(lens != (Lens *)NULL, &LMatrix4::ident_mat());
|
return &t;
|
||||||
|
} else {
|
||||||
|
LightLensNode *light;
|
||||||
|
DCAST_INTO_R(light, np.node(), &LMatrix4::ident_mat());
|
||||||
|
Lens *lens = light->get_lens();
|
||||||
|
nassertr(lens != (Lens *)NULL, &LMatrix4::ident_mat());
|
||||||
|
|
||||||
CPT(TransformState) transform =
|
CPT(TransformState) transform =
|
||||||
get_scene()->get_cs_world_transform()->compose(
|
get_scene()->get_cs_world_transform()->compose(
|
||||||
np.get_transform(_scene_setup->get_scene_root().get_parent()));
|
np.get_transform(_scene_setup->get_scene_root().get_parent()));
|
||||||
|
|
||||||
const LMatrix4 &light_mat = transform->get_mat();
|
const LMatrix4 &light_mat = transform->get_mat();
|
||||||
LVector3 dir = lens->get_view_vector() * light_mat;
|
LVector3 dir = lens->get_view_vector() * light_mat;
|
||||||
t.set_row(3, dir);
|
t.set_row(3, dir);
|
||||||
return &t;
|
return &t;
|
||||||
|
}
|
||||||
|
|
||||||
} else if (attrib == IN_spotCutoff) {
|
} else if (attrib == IN_spotCutoff) {
|
||||||
if (np.node()->is_of_type(Spotlight::get_class_type())) {
|
if (np.node()->is_of_type(Spotlight::get_class_type())) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user