38 m_lightTexture = generateLightBubble(0.1f);
44 TexturePtr LightView::generateLightBubble(
float centerFactor)
46 const int bubbleRadius = 256;
47 const int centerRadius = bubbleRadius * centerFactor;
48 const int bubbleDiameter = bubbleRadius * 2;
51 for(
int x = 0; x < bubbleDiameter; ++x) {
52 for(
int y = 0; y < bubbleDiameter; ++y) {
53 const float radius = std::sqrt((bubbleRadius - x) * (bubbleRadius - x) + (bubbleRadius - y) * (bubbleRadius - y));
54 float intensity = stdext::clamp<float>((bubbleRadius - radius) /
static_cast<float>(bubbleRadius - centerRadius), 0.0f, 1.0f);
57 intensity *= intensity;
58 const uint8_t colorByte = intensity * 0xB4;
60 uint8_t pixel[4] = { colorByte, colorByte, colorByte, 0xff };
61 lightImage->setPixel(x, y, pixel);
77 m_globalLight = light;
87 const float brightnessLevel = light.
intensity > 1 ? 0.7 : 0.2f;
88 const float brightness = brightnessLevel + (intensity /
static_cast<float>(
MAX_LIGHT_INTENSITY)) * brightnessLevel;
90 color.
setRed(color.
rF() * brightness);
96 if(prevSource.
center == center && prevSource.
color == color && prevSource.
radius == radius)
102 source.
color = color;
104 m_lightMap.push_back(source);
107 void LightView::drawGlobalLight(
const Light& light)
111 color.
setRed(color.
rF() * brightness);
119 void LightView::drawLightSource(
const Point& center,
const Color& color,
int radius)
124 const Rect dest =
Rect(center -
Point(radius, radius),
Size(radius * 2, radius * 2));
131 m_lightbuffer->
resize(size);
141 m_lightbuffer->
bind();
144 drawGlobalLight(m_globalLight);
150 drawLightSource(source.center, source.color, source.radius);
158 m_lightbuffer->
draw(dest, src);