Download

How to set global texture for all materials

In Unity we have this: http://docs.unity3d.com/ScriptReference/Shader.SetGlobalTexture.html

You can broadcast a 1d,2d,3d texture or render target texture to all shaders (or materials as you would call them in UE4). You can then sample a texture of specified type and name. For example you can do this in code:
Shader.SetGlobalTexture(“MyTextureName”, textureObject);

In the shader you then sample texture called MyTextureName.
Is there anything similar inside UE4 API?

What I am trying to do is to broadcast screen-space texture to all materials and sample it. I want to change this texture at runtime (update it’s contents, swap it). I imagine that it should be possible to set up a dummy Texture Sampler that points to a texture with specified name and in C++ I should broadcast the texture with the same name.

There’s not really any need to approach this differently from a regular texture. Simply create a render target in the editor and reference this in your material instead of a regular texture. You can then write to this texture at runtime and all materials will update.

I guess it would be nice if they would add Texture functionality to Material Parameter Collections, but it’s not supported

While true in general, that is not needed in the case varfare describes as a single render texture would suffice.

I thought about Material Parameter Collection but it does not support textures (but it would be nice if it could!). But yea, render target will work perfectly in my situation.

How about Shader.SetGlobalMatix?

I have some precomputed(in C++) matrix(a lot) and I want to make in available in .usf material file and do some dot products to get my result.

Any idea of how to go about to achieve this?