Double threshold light ramps ignore t1 and l1
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Panda3D |
Fix Released
|
Undecided
|
rdb |
Bug Description
As described in this thread on the forums:
https:/
double threshold light ramps (LightRampAttri
Looking at the source code, I think this is actually a bug in panda/src/
In lightRampAttrib.cxx of Panda3D 1.8.1, the function LightRampAttrib
---8<---8<---8<---
CPT(
make_
LightRamp
attrib->_mode = LRT_single_
attrib-
attrib-
attrib-
attrib-
return return_new(attrib);
}
---8<---8<---8<---
Note that the attrib mode is set as LRT_single_
Hence, to fix this,
attrib->_mode = LRT_single_
should be changed to
attrib->_mode = LRT_double_
The rest is ok as-is.
Additionally, reading through ShaderGenerator
---8<---8<---8<---
case LightRampAttrib
{
text << "\t // Double-threshold light ramp\n";
text << "\t float lr_in = dot(tot_
text << "\t float lr_out = " << l0 << "\n";
text << "\t if (lr_in > " << t0 << ") lr_out=" << l1 << ";\n";
text << "\t if (lr_in > " << t1 << ") lr_out=" << l2 << ";\n";
text << "\t tot_diffuse = tot_diffuse * (lr_out / lr_in);\n";
}
---8<---8<---8<---
LightRampAttrib only has two levels available (according to lightRampAttrib.h and lightRampAttrib.I - see the array allocations and the functions LightRampAttrib
Hence, with the code quoted here, the light level will drop to black when the input is above t1.
To fix this, I propose the following, adapting the approach of the single threshold mode (where the "low" value is always 0.0):
---8<---8<---8<---
case LightRampAttrib
{
text << "\t // Double-threshold light ramp\n";
text << "\t float lr_in = dot(tot_
text << "\t float lr_out = 0.0\n";
text << "\t if (lr_in > " << t0 << ") lr_out=" << l0 << ";\n";
text << "\t if (lr_in > " << t1 << ") lr_out=" << l1 << ";\n";
text << "\t tot_diffuse = tot_diffuse * (lr_out / lr_in);\n";
}
---8<---8<---8<---
The only changes are in the levels: 0.0 for less than t0, l0 for between t0 and t1, and l1 for greater than t1. This version matches the Python API documentation for makeDoubleThres
I can prepare a proper patch if necessary.
Changed in panda3d: | |
status: | Fix Committed → Fix Released |
Furthermore, the line
text << "\t float lr_out = " << l0 << "\n";
as also its proposed replacement
text << "\t float lr_out = 0.0\n";
is missing the final semicolon before the \n in the generated code. It should be:
text << "\t float lr_out = 0.0;\n";
After applying these modifications to my local copy of panda sources, the double light ramp shading started working.