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

How to get layer ID from the "begin script" [Solved]

Discussion in 'Programming' started by GoK, Nov 3, 2019.

Tags:
  1. GoK

    GoK Member

    Joined:
    Nov 3, 2019
    Posts:
    4
    Guys, sorry for my English, but I need your help.
    There are several layers in the room (their number and order can change at run-time). All layers should be drawn with the same shader, but with a different uniform parameter. Parameters are stored in the map (layer ID -> parameter).
    It is logical to use "layer_script_begin" to configure the shader before drawing the layer, but I can’t figure out how to get the ID of the current layer from a script to get the parameter from the map. Does anyone have any ideas?
     
  2. Azenris

    Azenris Member

    Joined:
    Oct 30, 2016
    Posts:
    71
    There is no built-in way to do it.

    Only way I can think of is to build your own list of layer ids, and use a global var to track which you are drawing and then increment it and reset it each step.
    Problem with that is you need to know if a layer will draw, so you will need wrappers for setting the layer visibility to add/remove it from your list etc...

    This is how I did it anyway, if there is a better way, I would like to know too.
     
    GoK likes this.
  3. GoK

    GoK Member

    Joined:
    Nov 3, 2019
    Posts:
    4
    Thanks for your reply!
    I guess building a list of ids is the best solution, but at least for now, I decided to hardcode a whole thing. It`s not pretty, it's giving me less freedom, but it works.
     
  4. IndianaBones

    IndianaBones Member

    Joined:
    Jul 5, 2016
    Posts:
    2,267
    I read somewhere you could just use the built-in variable "layer" to get the layer id within the begin and end scripts.

    I just tested it on my computer and it seems to work fine.
     
    Azenris and GoK like this.
  5. GoK

    GoK Member

    Joined:
    Nov 3, 2019
    Posts:
    4
    IT IS WORKING!
    Thank you a lot, IndianaBones, you solved my problem!
     
    IndianaBones likes this.
  6. Azenris

    Azenris Member

    Joined:
    Oct 30, 2016
    Posts:
    71
    That works ??? Was that a change ? How did I miss that?

    Oh well, guess I'll try it out too. ty
     
    IndianaBones likes this.
  7. Hyomoto

    Hyomoto Member

    Joined:
    Jul 7, 2016
    Posts:
    1,078
    It was a change, it seems, I use the method described before and manage a layer stack.
     

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