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

GoK

Member
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?
 

Azenris

Member
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.
 
  • Like
Reactions: GoK

GoK

Member
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.
 

Azenris

Member
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.
That works ??? Was that a change ? How did I miss that?

Oh well, guess I'll try it out too. ty
 
Top