1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

GM:S 1.4 Polygon based lighting [Solved]

Discussion in 'Advanced Programming Discussion' started by JaimitoEs, Nov 9, 2019.

  1. JaimitoEs

    JaimitoEs Member

    Joined:
    Aug 9, 2016
    Posts:
    174
    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:
    [​IMG]

    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:
    [​IMG]
    [​IMG]

    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: Nov 10, 2019
  2. JaimitoEs

    JaimitoEs Member

    Joined:
    Aug 9, 2016
    Posts:
    174
    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.
    [​IMG]

    The goal to be achieved is to convert this buffer into a light emitter:
    [​IMG]

    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?
    [​IMG]
     
    Last edited: Nov 10, 2019
    Nocturne likes this.
  3. RujiK

    RujiK Member

    Joined:
    Jun 21, 2016
    Posts:
    174
    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: Nov 11, 2019
    JaimitoEs likes this.
  4. JaimitoEs

    JaimitoEs Member

    Joined:
    Aug 9, 2016
    Posts:
    174
    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: Nov 11, 2019
    RujiK likes this.
  5. JaimitoEs

    JaimitoEs Member

    Joined:
    Aug 9, 2016
    Posts:
    174
    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.

    [​IMG]
    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::):):(
    [​IMG]
     
    Last edited: Nov 12, 2019
  6. JaimitoEs

    JaimitoEs Member

    Joined:
    Aug 9, 2016
    Posts:
    174
    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..
    [​IMG]
    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...
    :)
    [​IMG]
    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 ...
    [​IMG]
    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...
    [​IMG]
    This is an example removing a filter, you can see the ilumitation of sprites, calculated by the "vertex surface" depending on depth..
    [​IMG]
    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 ??
    [​IMG]
    The same image reducing the ambient light....What is your opinion? Would you like to have this kind of lighting for your game?
    [​IMG]

    Animating and switching the light to see diferences...
    [​IMG]
     
    Last edited: Nov 20, 2019
    Bart and Nocturne like this.
  7. JaimitoEs

    JaimitoEs Member

    Joined:
    Aug 9, 2016
    Posts:
    174
    Adding the polygon light:
    [​IMG]
    The light can be scaled:
    [​IMG]
     
    Last edited: Nov 25, 2019
    Fanatrick and jackquake like this.
  8. JaimitoEs

    JaimitoEs Member

    Joined:
    Aug 9, 2016
    Posts:
    174
    Finished lighting system .... works in the same way as the famous video game ...
    [​IMG]
    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.

    [​IMG]
     
    Bart and Nocturne like this.
  9. JaimitoEs

    JaimitoEs Member

    Joined:
    Aug 9, 2016
    Posts:
    174
    The final look with 2 shapes and 1 ambient light...
    [​IMG]
    Taking the control of meshes and tweaking the light area. The fade direction is relative, starting from the centroid polygon.
    [​IMG]
    You can fake a shadow area, look how the player reacts:
    [​IMG]
    [​IMG]
     
    Last edited: Dec 4, 2019 at 10:58 AM
    shortbread likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice