I setup simple single light source lighting around campfire object. However, as can be seen, the transition between lightened area and unlighted one is sharp.
The GLSL fragment shader code:
uniform vec2 screenSize;
uniform vec2 lightSourceSize;
uniform vec2 lightSourceCoords;
uniform float lightIntensityCap;
uniform sampler2D textureSample;
void main(void)
{
float horizontalDiff = -lightSourceSize.x / 2;
float verticalDiff = lightSourceSize.y;
float lightSourceX =
(lightSourceCoords.x - horizontalDiff) / screenSize.x * 2 - 1;
float lightSourceY =
(-lightSourceCoords.y - verticalDiff) / screenSize.y * 2 + 1;
vec2 lightSourcePos = vec2(lightSourceX, lightSourceY);
float lightIntensity = 1.0/distance(lightSourcePos, pos.xy);
if (lightIntensity >= lightIntensityCap) {
lightIntensity = lightIntensityCap;
}
if (lightIntensity <= 1) {
lightIntensity = 1;
}
if (distance(lightSourcePos, pos.xy) > 0.3) {
lightIntensity = 1;
}
vec4 lightCol = vec4(lightIntensity, lightIntensity, lightIntensity, 1.0);
fColor = texture(textureSample, fragmentUV).rgba * lightCol;
if (fColor.a <= 0){
discard;
}
}
If I will remove
if (distance(lightSourcePos, pos.xy) > 0.3) {
lightIntensity = 1;
}
the lightened area will expand and the transition will be much smoother. How do I interpolate light intensity and achieve smooth transition for smaller area?

