|
allegro 5 - 2d lightning - opengl |
davidemo89
Member #14,215
April 2012
|
Hello everyone. yeah search in Google blah blah, I whave tried for three long weeks before opening a topic here. I'm really desperate. Any suggestion with a little example or a link worth an article I can read? thank you everyone for the help and sorry for my bad English |
jmasterx
Member #11,410
October 2009
|
Have you considered doing it with shaders and glsl? Agui GUI API -> https://github.com/jmasterx/Agui |
davidemo89
Member #14,215
April 2012
|
ok it's impressive. Now I have to look to some article on how to implement this. I have found this I think it's ok to start I'm having big big big difficult making something. Any help or code example? IThe only thing I did was a easy tint Edit: NEWS! I've added successfully a blur effect |
jmasterx
Member #11,410
October 2009
|
Although it's for 3D, there is some useful info here http://www.lighthouse3d.com/tutorials/glsl-tutorial/?pipeline More good info here: The idea of a fragment shader is that each time you go to draw something with it on, This was the code for the light in that YouTube video I showed you: 1uniform vec2 lightpos;
2uniform vec3 lightColor;
3uniform float screenHeight;
4uniform vec3 lightAttenuation;
5uniform float radius;
6
7uniform sampler2D texture;
8
9void main()
10{
11 vec2 pixel=gl_FragCoord.xy;
12 pixel.y=screenHeight-pixel.y;
13 vec2 aux=lightpos-pixel;
14 float distance=length(aux);
15 float attenuation=1.0/(lightAttenuation.x+lightAttenuation.y*distance+lightAttenuation.z*distance*distance);
16 vec4 color=vec4(attenuation,attenuation,attenuation,1.0)*vec4(lightColor,1.0);
17 gl_FragColor = color;//*texture2D(texture,gl_TexCoord[0].st);
18}
The uniform variables can be modified by your program using an API. Next, he makes a vec2 (a Point if you will) that corresponds to the pixel Y value on the screen. A formula is then used to figure out the color of that pixel and the pixel is set. At that point it is just math and you just need to understand lighting math. As a simple example, if I wanted to create a spotlight that emitted from pixel A with a radius of 20 px, then I would simply get the distance between pixel A and B and would multiply the color of B by a brightness factor determined by how close I am. So if I'm 30 px away, I multiply it by 0. If I'm 1 pix away, I might multiply it by 3 making the pixel 3 times as bright. If you want omniscient light, you can just make it so the minimum multiplier is something like 0.5 . Agui GUI API -> https://github.com/jmasterx/Agui |
davidemo89
Member #14,215
April 2012
|
I love you. |
jmasterx
Member #11,410
October 2009
|
Sure Glad it helps. Agui GUI API -> https://github.com/jmasterx/Agui |
|