[ad_1]
I setup easy single gentle supply lighting round campfire object.
Nonetheless, as might be seen, the transition between lightened space 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 major(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’ll take away
if (distance(lightSourcePos, pos.xy) > 0.3) {
lightIntensity = 1;
}
the lightened space will broaden and the transition will probably be a lot smoother. How do I interpolate gentle depth and obtain clean transition for smaller space?
[ad_2]