How can I set an sampler globally for all models

Here, I need an cube map to be used as environment reflection source and ambient lighting source.
setting it up on every single model file will be very inconvenient and impractical, e.g. what if I’ve to change it on the fly?
The first thing pop into my head is to use render.enable_texture, unfortunately, it works only with render textures.
The second though bring me to render.constant_buffer, but it’s not clear if it accept texture at all, with little try and error, I found that resource API is not available in render script context, thus close this path.
seems the last resort I may have is setting it on every single model component before they appear on screen, I have not try this yet, but the document said it has only texture0 property, and I wonder if I can bind other sampler with go.set.

Is there any official, clean method to do this? setting common sampler for every models in the scene?

I don’t have an answer for you but @sven or @Andreas_Tadic should be able to answer this.

You will in a near future be able to set component textures, materials and more.
See the notes regarding this in this post: Defold 1.2.118 has been released

2 Likes

Thanks for replying!

According to the wording of release note, If I’m interpreting it correctly, this release make the third method, e.g. setting texture on game object spawn possible, do I get it right?

Please consider adding ability to setting texture in render.constant_buffer, because this is common use case for all kind of image base illumination technique.And this is also open up the possibility for adding global look up tables, such as toning/wrapping.

Being able to dynamically set materials will be so good! Maybe in the future implement something like glslify so shaders can be more easily built in components.

2 Likes

Yes, you can set the texture through the api using go.set property functions. It’s still not determined exactly what release will include this, but it’s in a very near future.
I’ll add a ticket regarding your idea of being able to setting the texture through constant buffers.

I have try resource.set and no luck, seems we’ve to wait for later release. :frowning:
On the other hand, not only modifying texture in runtime bothers me, but also enumerating/selecting components. As I’ve to enumerate every model in the scene and setting cube map for them, I find no trivial way to do this, and force to name every single model ‘#model’. This works, but has its limitation, no other model name can be used, no more than 1 model can be attach to a game object. Enumeration API for components should be helpful here, something like GetComponentsByKind/GetComponentsInChildren. This kind of API can make component script more reusable.

1 Like

resource.set should already work. It’s also used in the camera example we have.

What I need is setting a cube map, I leave it empty on the model, and try to set it on component script init. It said resource not found