I am a decent coder, but shaders make me cry, so I’m giving in to the Unity Forums for help.
My Issue:
I’m using a water shader (FX-Water4) to generate water and waves. I want to be able to generate a heightmap for the waves WITHIN the shader. Then, use a script to access the height of the waves at a particular point. I have been informed that this is possible, but have looked at hundreds of articles and cannot find any example code of generating a rendertexture from a shader.
So, put simply, how do I take vertex data in the shader, let’s say, the height of each vertex, and output a texture / rendertexture as a heightmap.
To do this, you’d need to send your shader with the heightmap values to a renderTexture before you send it into your final render pipeline. Typically, you would use the Graphics.Blit() function to do this:
Did you try implementing a ComputeShader allready? They are kind of like the Unity Api for writing, modifying and reading data from your gpu, that’s probably the easiest way to achieve what you want. They also work together well with RenderTextures, you can basically map a RenderTexture to a shader variable and then modify it inside.
The best source of ocean shaders I know of is Loading... - look for any of the renderers that use a “Get Heights” function and they seem to do what you’re describing.
Thanks, There is only one project there that has a "Get Heights" method, and it doesn't compile due to errors. Plus, those projects use scripts to simulate the waves and the Get Heights performs a lookup - unless I've missed something. Plus, this doesn't really answer my question if it is possible to output vertex heights to a image via a shader. Thanks anyway
bump. Anyone got ANY ideas at all?
– verenion