mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-29 16:20:11 -04:00
pgraph: fix precision issues with Color(Scale)Attrib quantization
This commit is contained in:
parent
c43d9b5002
commit
fac82e6dca
@ -133,17 +133,17 @@ get_hash_impl() const {
|
||||
}
|
||||
|
||||
/**
|
||||
* Quantizes the color color to the nearest multiple of 1000, just to prevent
|
||||
* Quantizes the flat color to the nearest multiple of 1024, just to prevent
|
||||
* runaway accumulation of only slightly-different ColorAttribs.
|
||||
*/
|
||||
void ColorAttrib::
|
||||
quantize_color() {
|
||||
switch (_type) {
|
||||
case T_flat:
|
||||
_color[0] = cfloor(_color[0] * 1000.0f + 0.5f) * 0.001f;
|
||||
_color[1] = cfloor(_color[1] * 1000.0f + 0.5f) * 0.001f;
|
||||
_color[2] = cfloor(_color[2] * 1000.0f + 0.5f) * 0.001f;
|
||||
_color[3] = cfloor(_color[3] * 1000.0f + 0.5f) * 0.001f;
|
||||
_color[0] = cfloor(_color[0] * 1024.0f + 0.5f) / 1024.0f;
|
||||
_color[1] = cfloor(_color[1] * 1024.0f + 0.5f) / 1024.0f;
|
||||
_color[2] = cfloor(_color[2] * 1024.0f + 0.5f) / 1024.0f;
|
||||
_color[3] = cfloor(_color[3] * 1024.0f + 0.5f) / 1024.0f;
|
||||
break;
|
||||
|
||||
case T_off:
|
||||
|
@ -230,15 +230,15 @@ invert_compose_impl(const RenderAttrib *other) const {
|
||||
}
|
||||
|
||||
/**
|
||||
* Quantizes the color scale to the nearest multiple of 1000, just to prevent
|
||||
* Quantizes the color scale to the nearest multiple of 1024, just to prevent
|
||||
* runaway accumulation of only slightly-different ColorScaleAttribs.
|
||||
*/
|
||||
void ColorScaleAttrib::
|
||||
quantize_scale() {
|
||||
_scale[0] = cfloor(_scale[0] * 1000.0f + 0.5f) * 0.001f;
|
||||
_scale[1] = cfloor(_scale[1] * 1000.0f + 0.5f) * 0.001f;
|
||||
_scale[2] = cfloor(_scale[2] * 1000.0f + 0.5f) * 0.001f;
|
||||
_scale[3] = cfloor(_scale[3] * 1000.0f + 0.5f) * 0.001f;
|
||||
_scale[0] = cfloor(_scale[0] * 1024.0f + 0.5f) / 1024.0f;
|
||||
_scale[1] = cfloor(_scale[1] * 1024.0f + 0.5f) / 1024.0f;
|
||||
_scale[2] = cfloor(_scale[2] * 1024.0f + 0.5f) / 1024.0f;
|
||||
_scale[3] = cfloor(_scale[3] * 1024.0f + 0.5f) / 1024.0f;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user