Precompute srgb to linear values to array
This commit is contained in:
parent
6071d2f983
commit
feb1667acc
@ -223,10 +223,9 @@ SkidMarks::SkidMarkQuads::SkidMarkQuads(const Vec3 &left,
|
||||
|
||||
if (CVS->isDefferedEnabled())
|
||||
{
|
||||
video::SColorf tmp(m_start_color);
|
||||
m_start_color.setRed(SP::srgbToLinear(tmp.r));
|
||||
m_start_color.setGreen(SP::srgbToLinear(tmp.g));
|
||||
m_start_color.setBlue(SP::srgbToLinear(tmp.b));
|
||||
m_start_color.setRed(SP::srgb255ToLinear(m_start_color.getRed()));
|
||||
m_start_color.setGreen(SP::srgb255ToLinear(m_start_color.getGreen()));
|
||||
m_start_color.setBlue(SP::srgb255ToLinear(m_start_color.getBlue()));
|
||||
}
|
||||
|
||||
add(left, right, normal, 0.0f);
|
||||
|
@ -150,6 +150,36 @@ inline uint8_t srgbToLinear(float color_srgb)
|
||||
}
|
||||
return uint8_t(irr::core::clamp(ret, 0, 255));
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
inline uint8_t srgb255ToLinear(unsigned color_srgb_255)
|
||||
{
|
||||
static unsigned srgb_linear_map[256] =
|
||||
{
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2,
|
||||
2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4,
|
||||
4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7,
|
||||
7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11,
|
||||
11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16,
|
||||
16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 22, 22,
|
||||
23, 23, 24, 24, 25, 26, 26, 27, 27, 28, 29, 29,
|
||||
30, 31, 31, 32, 33, 33, 34, 35, 36, 36, 37, 38,
|
||||
38, 39, 40, 41, 42, 42, 43, 44, 45, 46, 47, 47,
|
||||
48, 49, 50, 51, 52, 53, 54, 55, 55, 56, 57, 58,
|
||||
59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 70, 71,
|
||||
72, 73, 74, 75, 76, 77, 78, 80, 81, 82, 83, 84,
|
||||
85, 87, 88, 89, 90, 92, 93, 94, 95, 97, 98, 99,
|
||||
101, 102, 103, 105, 106, 107, 109, 110, 112, 113, 114, 116,
|
||||
117, 119, 120, 122, 123, 125, 126, 128, 129, 131, 132, 134,
|
||||
135, 137, 139, 140, 142, 144, 145, 147, 148, 150, 152, 153,
|
||||
155, 157, 159, 160, 162, 164, 166, 167, 169, 171, 173, 175,
|
||||
176, 178, 180, 182, 184, 186, 188, 190, 192, 193, 195, 197,
|
||||
199, 201, 203, 205, 207, 209, 211, 213, 215, 218, 220, 222,
|
||||
224, 226, 228, 230, 232, 235, 237, 239, 241, 243, 245, 248,
|
||||
250, 252, 255
|
||||
};
|
||||
return uint8_t(srgb_linear_map[color_srgb_255]);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
inline uint8_t linearToSrgb(float color_linear)
|
||||
|
@ -206,10 +206,9 @@ void SPMeshBuffer::uploadGLMesh()
|
||||
video::SColor vc = m_vertices[i].m_color;
|
||||
if (CVS->isDefferedEnabled())
|
||||
{
|
||||
video::SColorf tmp(vc);
|
||||
vc.setRed(srgbToLinear(tmp.r));
|
||||
vc.setGreen(srgbToLinear(tmp.g));
|
||||
vc.setBlue(srgbToLinear(tmp.b));
|
||||
vc.setRed(srgb255ToLinear(vc.getRed()));
|
||||
vc.setGreen(srgb255ToLinear(vc.getGreen()));
|
||||
vc.setBlue(srgb255ToLinear(vc.getBlue()));
|
||||
}
|
||||
memcpy(ptr + v_size + offset, &vc, 4);
|
||||
offset += 4;
|
||||
|
@ -236,9 +236,9 @@ std::shared_ptr<video::IImage> SPTexture::getTextureImage() const
|
||||
#endif
|
||||
if (m_undo_srgb && !use_tex_compress)
|
||||
{
|
||||
data[i * 4] = srgbToLinear(data[i * 4] / 255.0f);
|
||||
data[i * 4 + 1] = srgbToLinear(data[i * 4 + 1] / 255.0f);
|
||||
data[i * 4 + 2] = srgbToLinear(data[i * 4 + 2] / 255.0f);
|
||||
data[i * 4] = srgb255ToLinear(data[i * 4]);
|
||||
data[i * 4 + 1] = srgb255ToLinear(data[i * 4 + 1]);
|
||||
data[i * 4 + 2] = srgb255ToLinear(data[i * 4 + 2]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -33,21 +33,21 @@ STKTextBillboard::STKTextBillboard(const video::SColor& color_top,
|
||||
: ISceneNode(parent, mgr, id, position,
|
||||
core::vector3df(0.0f, 0.0f, 0.0f), size)
|
||||
{
|
||||
using namespace SP;
|
||||
m_color_top = color_top;
|
||||
if (CVS->isDefferedEnabled())
|
||||
{
|
||||
video::SColorf tmp(m_color_top);
|
||||
m_color_top.setRed(SP::srgbToLinear(tmp.r));
|
||||
m_color_top.setGreen(SP::srgbToLinear(tmp.g));
|
||||
m_color_top.setBlue(SP::srgbToLinear(tmp.b));
|
||||
m_color_top.setRed(srgb255ToLinear(m_color_top.getRed()));
|
||||
m_color_top.setGreen(srgb255ToLinear(m_color_top.getGreen()));
|
||||
m_color_top.setBlue(srgb255ToLinear(m_color_top.getBlue()));
|
||||
}
|
||||
m_color_bottom = color_bottom;
|
||||
if (CVS->isDefferedEnabled())
|
||||
{
|
||||
video::SColorf tmp(m_color_bottom);
|
||||
m_color_bottom.setRed(SP::srgbToLinear(tmp.r));
|
||||
m_color_bottom.setGreen(SP::srgbToLinear(tmp.g));
|
||||
m_color_bottom.setBlue(SP::srgbToLinear(tmp.b));
|
||||
m_color_bottom.setRed(srgb255ToLinear(m_color_bottom.getRed()));
|
||||
m_color_bottom.setGreen(srgb255ToLinear(m_color_bottom.getGreen()));
|
||||
m_color_bottom.setBlue(srgb255ToLinear(m_color_bottom.getBlue()));
|
||||
}
|
||||
static_assert(sizeof(GLTB) == 20, "Wrong compiler padding");
|
||||
} // STKTextBillboard
|
||||
|
@ -54,10 +54,9 @@ RubberBand::RubberBand(Plunger *plunger, AbstractKart *kart)
|
||||
video::SColor color(77, 179, 0, 0);
|
||||
if (CVS->isDefferedEnabled())
|
||||
{
|
||||
video::SColorf tmp(color);
|
||||
color.setRed(SP::srgbToLinear(tmp.r));
|
||||
color.setGreen(SP::srgbToLinear(tmp.g));
|
||||
color.setBlue(SP::srgbToLinear(tmp.b));
|
||||
color.setRed(SP::srgb255ToLinear(color.getRed()));
|
||||
color.setGreen(SP::srgb255ToLinear(color.getGreen()));
|
||||
color.setBlue(SP::srgb255ToLinear(color.getBlue()));
|
||||
}
|
||||
m_dy_dc = std::make_shared<SP::SPDynamicDrawCall>
|
||||
(scene::EPT_TRIANGLE_STRIP, SP::getSPShader("unlit"),
|
||||
|
Loading…
x
Reference in New Issue
Block a user