Runtime generated RenderTexture as Displacement map weird behavior

Hey.

I’m using a compute shader to generate a displacement map at runtime. In order to write to a RenderTexture in a compute shader you need to assign some flag* to it before creating it and this (as far as I know) can only be done via scripting. So I’m stuck at creating it at runtime.

Now if I apply that texture as a diffuse to a material it works as one would expect it to, brilliant!

But if I try to use it as a displacement map it results in all kind of undefined behavior which is kind of funny in it’s own way… Sometimes you get nothing and sometimes it seems like an instant wave generator.

Sometimes it also draws a couple of frames correctly when you hit play or stop.

I also double checked that RenderTexture is supposed work and does work as a displacement map, just not the runtime generated I suppose.

Anyone able to shed some light on this?

Edit: The flag is RenderTexture.enableRandomWrite. Could also be the root of the problem?

I believe it has something to do with the order of the rendering pipeline.

One workaround I am using is to double buffer two RenderTextures.