3
\$\begingroup\$

I have a visibility mesh made by raycasting:

https://my.mixtape.moe/omjlgr.webm

Right now, I'm using a shader to color the mesh white and fall off with distance and radius (the texCoord in this case is the same as the current vertex position):

uniform vec2 lightPosition;
uniform vec4 lightColor;
uniform float lightRadius;

void main()
{
    float distance = gl_TexCoord[0].xy - lightPosition;

    float lightPower = 1 - length(distance) / lightRadius;

    gl_FragColor = lightColor * lightPower;
}

However, as you can see, this light is all white. What I want to happen, is to shade the sprites themselves fullbright. Right now, to apply an ambient light color, I set the color of every tile to the color.

So if I have an ambient color of (70, 70, 70), and a light of (255, 255, 255), I want the center of the light to have a fullbright sprite (as if you set the color if it to white), and the tiles at the very edge of the light and further to be the ambient color. To explain further, if my map is fullbright (e.g. ambient color pure white), white lights wouldn't be visible.

How would I change my shader / add another shader to accomplish this effect?

\$\endgroup\$
1
\$\begingroup\$

One way to accomplish this is to use the shader to render something like a light map. You create a grayscale image which can then be used in other shaders as a mask. Moreover, this way you can enhance the light effect by applying some blur or other filters.

\$\endgroup\$
0
\$\begingroup\$

Why not just add ambient into your equation?

uniform vec3 ambient;
...
gl_FragColor = lightColor * lightPower + vec4(ambient, 1.0);
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.