38 m_lightTexture = generateLightBubble(0.1f);
43 TexturePtr LightView::generateLightBubble(
float centerFactor)
45 int bubbleRadius = 256;
46 int centerRadius = bubbleRadius * centerFactor;
47 int bubbleDiameter = bubbleRadius * 2;
50 for(
int x = 0; x < bubbleDiameter; x++) {
51 for(
int y = 0; y < bubbleDiameter; y++) {
52 float radius = std::sqrt((bubbleRadius - x)*(bubbleRadius - x) + (bubbleRadius - y)*(bubbleRadius - y));
53 float intensity = stdext::clamp<float>((bubbleRadius - radius) / (
float)(bubbleRadius - centerRadius), 0.0f, 1.0f);
56 intensity = intensity * intensity;
57 uint8_t colorByte = intensity * 0xff;
59 uint8_t pixel[4] = {colorByte,colorByte,colorByte,0xff};
60 lightImage->setPixel(x, y, pixel);
76 m_globalLight = light;
87 color.
setRed(color.
rF() * brightness);
93 if(prevSource.
center == center && prevSource.
color == color && prevSource.
radius == radius)
101 m_lightMap.push_back(source);
104 void LightView::drawGlobalLight(
const Light& light)
108 color.
setRed(color.
rF() * brightness);
115 void LightView::drawLightSource(
const Point& center,
const Color& color,
int radius)
127 m_lightbuffer->
resize(size);
133 m_lightbuffer->
bind();
135 drawGlobalLight(m_globalLight);
139 drawLightSource(source.center, source.color, source.radius);
142 m_lightbuffer->
draw(dest, src);