• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Shaders Creating multiple simple light sources using shaders

D

Dudeless

Guest
Hi,

I have written a shader code that creates a ball of non-darkness (I don't know how else I should put this) around one of my objects. You can see it in this picture below:
Untitled.png
To do that, I created a completely black, rectangle object (whose size is the same room's) and put it on a layer above everything. Then, I wrote this code in the fragment shader (and wrote the necessary codes to the "draw" event):

GML:
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
varying vec2 v_vPosition;

uniform float x_player;
uniform float y_player;




void main()
{
    gl_FragColor = v_vColour * texture2D( gm_BaseTexture, v_vTexcoord );
    gl_FragColor = vec4(gl_FragColor.rgb,(abs(distance(vec2(x_player,y_player),v_vPosition)/512.0)));
}
Until now, there is no problem. It works as it should. But I want to add multiple light sources (like torches etc.) which create "balls of non-darkness" simultaneously. But I couldn't figure out a way. I am very new at writing shader codes, so I would be very glad if you could help me with this.
Thanks in advance~
 

kburkhart84

Firehammer Games
You could also forget the shader and just use surfaces the way this was done before we even got access to shaders. There are plenty of tutorials out there on the technique.
 
Top