Legacy GM Polygon based lighting [Solved]

JaimitoEs

Member
I am very interested in creating a lighting system like the one offered by the Ubi Art framework. Here are some screenshots of the concept:


As you can see, the lighting is executed only in the first layer, while the background seems to be a fog effect.

If you look at the textures of the character and platforms, they have an ambient color applied. When these are in the position of the mesh, they are illuminated with the parameters of said mesh.

Rayman legends uses only 2 textures for lighting:


You can see the information in the minute 11:00...
I imagine that the textures of this layer are drawn by passing them a shader that determines the area of these polygons, according to this explanatory video of the engine, they use per vertex lighting, but I cannot understand how to pass the information of the polygon and illuminate only the places where the mesh is situated. It would be something similar to mesh shading but vice versa, where the polygon is responsible for saying which parts light up and which ones do not. Any information you can give on the subject is appreciated. Thanks for reading and your patience.
 
Last edited:

JaimitoEs

Member
I have started doing experiments with my editor, a controller stores the texture data, running the shader in one pass and drawing the family of objects. But as you can see, it is based on the point of light. I can create a mesh, but I don't know how to associate that mesh to make it a light emitter.


The goal to be achieved is to convert this buffer into a light emitter:


I assume that I need to normalize the coordinates of the vertices, pass it through the vertex shader but ... How do I calculate the color blending of the textures based on the triagulation of the mesh? Do I need to pass vertices data and define a matrix in the vertex shader?

I show you a visual example, according to the image below ... An idea can be to define a vector that represents the ambient lighting, pass the data of a mesh that represents the light and dim the sides of our polygon. This can be done by calculating from the vertex shader?
 
Last edited:

RujiK

Member
At a glance, I don't think they are using vertexes/mesh coordinates in the vertex shader for the lighting. Since the lighting is 2D with some fake 3D elements, there is no need for complex vertex/matrix equations and the effect could be done completely in the fragment shader.

I SUSPECT they are using this method:

1. Draw your light buffer/light mesh to a separate screen surface as an absolute red or black. Inside the mesh is red, outside is black. (Call this surface surf_light)
2. Draw unlit_texture with LIT_TEXTURE ADDED ON BY A MULTIPLE OF SURF_LIGHT.
3. Done.

Pseudo code:
Code:
gl_fragcolor = unlit_color + lit_color*surf_light.r

Or, an alternative if your lit_texture has your unlit_texture baked in (IE: It's not just black and white)
Code:
gl_fragcolor = unlit_color*(1.0 - surf_light.r) + lit_color*surf_light.r

This should be lightning fast as there are no distance checks or conditions needed in the shader. The downside is you will need to pass a few textures into the shader so mobile performance may be an issue.

To get smoother lighting cutoffs, I would blur surf_light before using it to multiply the lit_texture.
 
Last edited:

JaimitoEs

Member
At a glance, I don't think they are using vertexes/mesh coordinates in the vertex shader for the lighting. Since the lighting is 2D with some fake 3D elements, there is no need for complex vertex/matrix equations and the effect could be done completely in the fragment shader.

I SUSPECT they are using this method:

1. Draw your light buffer/light mesh to a separate screen surface as an absolute red or black. Inside the mesh is red, outside is black. (Call this surface surf_light)
2. Draw unlit_texture with LIT_TEXTURE ADDED ON BY A MULTIPLE OF SURF_LIGHT.
3. Done.

Pseudo code:
Code:
gl_fragcolor = unlit_color + lit_color*surf_light.r

Or, an alternative if your lit_texture has your unlit_texture baked in (IE: It's not just black and white)
Code:
gl_fragcolor = unlit_color*(1.0 - surf_light.r) + lit_color*surf_light.r

This should be lightning fast as there are no distance checks or conditions needed in the shader. The downside is you will need to pass a few textures into the shader so mobile performance may be an issue.

To get smoother lighting cutoffs, I would blur surf_light before using it to multiply the lit_texture.
Hey! Thanks for comment! Yes, you are right, they use the fragment shader to multiply the texture in black and white, which looks like a heightmap, but in this case I think they use it as an emitting ambient map when it is not affected by the light. I will start testing with the help you have given me, I wanted to avoid using surfaces, but this also helps me clarify my doubts. Again, thank you very much!!
 
Last edited:

JaimitoEs

Member
Ok, today I did a test based on @Mike 's tutorial DYNAMIC RENDERING MASKS, thank you very much! and without using surfaces... All is done with vertex buffers and these have an emissive map for lighting...Now I have to see if I can modify the drawing, combine this technique with the shader and try to create a good lighting. From the little I have been able to prove, it seems to work very fast and would be a way to light our stage freely without worrying about surfaces and coordinates.


Edit:

Although we can configure in which way our Gpu draws, I still haven't found a way to illuminate the buffer ... yes, now it makes holes ...:bash:maybe it can be useful, maybe it has the answer in front of me ... I don't know ...:bash::):):(
 
Last edited:

JaimitoEs

Member
It´s 4:46 and i´m very tired, but, there is a screenshot with some fails and...easter eggs...:D i will explain soon the technique..The lights are 3d, the lights contain a shader, the lights can be the ambient, the lights can be mapped, you don´t need surfaces, and you don´t need normal maps and stages...Try to found the good ones...:p i´ll upload more images to see in depth..

It is not finished yet, but I have finally found the lighting I wanted and it is probably the in-build lighting system included in DarkSpine...
:)

The elements react to the light according to the depth of these ... If an element is at a lower depth than the light, the outline of our sprite will illuminate relative to the position and direction of the light , upper depth illuminate the clear pixels bumping the asset, Rim lighting ...

You can create a Masked light! Without using the alphablend destroy.. If you look the terrain on the back, you can see a substracted hole in the terrain, based on the masked texture, transforming the appearance of the vertex buffer...

This is an example removing a filter, you can see the ilumitation of sprites, calculated by the "vertex surface" depending on depth..

Look at the player's feet and eyes, the sprite that represents the light is a hybrid that acts different from a simple mask. Look at the word "Good", you will see that although the mask that composes the light does not touch the image, it lights up giving a 3d effect to our assets ... all this without the need for a texture map, and gives a very nice result.. What do you think ??

The same image reducing the ambient light....What is your opinion? Would you like to have this kind of lighting for your game?

Animating and switching the light to see diferences...
 
Last edited:

JaimitoEs

Member
Finished lighting system .... works in the same way as the famous video game ...

It works with vertex buffers and is extremely fast. The lights can be textured and animated. The resolution can be increased depending on how many vertices our mesh has.

 
Top