Hi,
i am generating my own Perlin Noise functions and methods, different from the ones shipped with Unity. With that noise texture i use it as a heightmap for the mesh ground of an environment. So far, so good.
The problem arises when i want to update/animate the texture. If the texture is below 32*32 array i get a decent 40 FPS, but if i lift the value a bit the framerate starts to drop drammatically.
In an attempt to make it more scalable and performant i have considered two options:
- (1) either start trying to parallelize the code in CSharp so that, for example, any “row” computation belongs to a different Thread/Task.
- (2) generate the noise directly in the shader, thus, taking advantage of the already fit parallel architecture of the render pipeline in the GPU.
I am writing because i wanna try option (2) (even if i have little to none experience writing shaders in Cg).
So, here comes my question: i am having troubles trying to find a way to write a value from one / functions to a texture in the shader.
I am presuming i wouldnt need a two pass shader, since the computed value can be used on-the-fly in the same pass.
My problem, is that i dont know how to write/store directly to the _MainTex within the shader, without doing the math in the C Sharp/Monobehaviour script and sending it back to the Material’s _MainTex. Which seems to be the problem when i try to generate random grids greater than 64 * 64 cells.
After writing to the texture, i would use a sampler2D to get the value and apply the height to the function.
This problem can be synthesized asking the following question: ÂżBest performant way to keep a texture of a material updated with new values?
Thanks in advance,
JC