Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | tyo |
I’m looking for a way to erase pixels when they’re exposed to light in the 2d shader processor. The idea is an “outline” on sprites that fades out in light, giving the sprite a more defined shadowy affect. This isn’t to replace an occluder, but to give sprites a bit more definition.
I’ve figured out how to get it to draw on the opposite side the light is shining and that looked nice at first but that breaks with multiple lights. You can see this affect working as intended in this tweet(I was listening to music, may or may not wanna mute, isn’t loud either way):
https://twitter.com/TyoTheCreator/status/1361212230105264128?s=19
Here that second light was an experiment in making a backlight - if you happen to have an elegant solution for that as well, I’m listening!
The funkyness can be seen in this image with two proper lights:
I can see why this is happening. My shader simply flips the light vector, so instead of drawing where the light shines, it draws in the opposite vector… meaning, if two lights shine, both vectors get drawn. However, I don’t know what to do about this. The Shadow properties of the Light processor didn’t seem to do anything for me, and I can’t think of a way to tell the shader to erase the pixels facing the light instead of drawing the pixels away from the light.
The shader itself is super simple:
shader_type canvas_item;
void fragment() {
// Get the vertex color or the color from the texture if set
vec4 finalColor = min(texture(TEXTURE, UV), COLOR);
COLOR = finalColor;
if(!AT_LIGHT_PASS) {
COLOR = vec4(0, 0, 0, 0);
}
}
void light()
{
LIGHT_VEC.x = -LIGHT_VEC.x;
LIGHT = COLOR + vec4(0,0,.5,2); //just makes it slightly bluer and defined
}
I appreciate any help anyone offers for this!
So far, all I’ve found is an alternative way to do my initial implementation without the need of a shader. It’s the same logic, though. I can use an “inverse” light texture and the “mask” light mode to make a light which “shines” from the edges of the texture and dims inwards. This leads to the same outcome, though. Since the pixels are being drawn and not erased, if two lights are made on either end of the sprite an almost full outline will show, rather than the desired effect of having almost no outline.
tyo | 2021-02-20 05:12