SetGlobalTexture ?

Hello,

I’ve been trying to inject global data to a shader without any luck so far.
I’m working on a Tile based game and I want automatic blending between the different terrain type.
For that I created a shader that do this terrain type edge detection using a texture representing the status of the map (each pixel represent a color of the terrain type).

My object using that shader get instanciated and rather than injecting the texture on each instance (and update it individually) I have to use
Shader.SetGlobalTexture(“_Tilemap”, TileTexture);
And in the shader I declare:
uniform sampler2D _Tilemap;

However this doesn’t seems to do anything on the shader, they all keep their Tilemap property null =^(

Any idea, help , thoughts please ?

Thank you,

Nanorock

It should work normally. Maybe your setup is wrong or there is something else going wrong somewhere else.
Try to set “_Tilemap” as a property and try setting the texture manually to see if it works or not.

If I set it it manually yes it does work =^/

I’m in deferred rendering, I don’t know if that could be an issue. The SetGlobalTexture data is cached also isn’t it ? (I don’t need to set it in an update method ?)

Doesn’t matter per-se where you set it. You wanna set it just before first being used in a rendered frame, and then re-set it only when you’re actually changing the texture. SetGlobalTexture totally works fine, it’s a simple functionality that basically pretty much everyone uses all the time, you most likely have a coding bug in there somewhere preventing your texture from reaching your executed shader code path.

I finally found the issue !

If you expose a global variable in the shader through properties it breaks the whole global workflow for this shader.
My global texture wasn’t exposed but the Width/Height which are global were exposed.
As soon as I removed them from the Property block the whole stuff started to work !
I confirmed that in a test project.

I wonder if I should report that as a bug with my test scene.

1 Like

Now that you mention it… now I do remember that oddity :smile: not sure I would class it as a bug, a global uniform shouldn’t be exposed as a per-material property logically speaking. Your setglobal call still works but after you do so, the material sets its own uniform prerender most likely, so your global value gets lost.

Hum, but I didn’t exposed the texture, that was exposing my float that made my texture and the floats not work ~~
A single expose of one of the global var make all of them null, so this might be considered as I bug ^^’
But I’m glad I finally found it ~(^.^)~