1. Hey! Guest! The 35th GMC Jam will take place between November 28th, 12:00 UTC - December 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

GM:S 1.4 Polygon based lighting.

Discussion in 'Advanced Programming Discussion' started by JaimitoEs, Nov 9, 2019 at 12:43 PM.

  1. JaimitoEs

    JaimitoEs Member

    Joined:
    Aug 9, 2016
    Posts:
    156
    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 at 8:48 PM
  2. JaimitoEs

    JaimitoEs Member

    Joined:
    Aug 9, 2016
    Posts:
    156
    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 at 11:38 PM
    Nocturne likes this.
  3. RujiK

    RujiK Member

    Joined:
    Jun 21, 2016
    Posts:
    172
    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 at 3:19 AM
    JaimitoEs likes this.
  4. JaimitoEs

    JaimitoEs Member

    Joined:
    Aug 9, 2016
    Posts:
    156
    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 at 1:10 PM
    RujiK likes this.
  5. JaimitoEs

    JaimitoEs Member

    Joined:
    Aug 9, 2016
    Posts:
    156
    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 at 4:25 PM
    RujiK 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