- Home /
Simple mesh deformation : Mesh.vertices or vertex shader with displacement texture ?
Hello, I have a simple "2D grid" that I want to deform and I have implemented this by modifying vertices positions and applying them to the Mesh via Mesh.vertices and that works well.
But wouldn't be better to calculate positions and save them to a texture that a vertex shader will read to move the vertices ?
In both cases, some data must be send from the CPU to the GPU (vertices in the first case and texture in the second) so I don't know if one solution is better than the other or even if there is another better solution to do that ?
Thanks
Is it possible to do the "calculate positions" step in the GPU ins$$anonymous$$d of the CPU?
I don't think it's possible because deformation needs to store data for its calculation. Unless there is a way to store data in shader (it's for mobile so at least compatible with OpenGL ES 2.0) ?
Answer by kalanadis · Jul 28, 2017 at 01:23 AM
hope this helps https://myunitynotes.wordpress.com/2014/11/11/magic-candle-deforming-object-with-unity-shader/ in this deforming data is stored in vertices.
Thanks but the deformation data is not constant so I can't use this method. But $$anonymous$$esh.vertices do the job, it was just to know if using a displacement texture ins$$anonymous$$d was a better option.
Actually if you check the shader deformation data is not a constant.In the above shader deformation data is sent thru variables to the shader, inside the shader it uses vertex data to filter and apply the data from the script.
Yes but my deformation data is actually +- 1300 floats so I can't pass it as variables to the shader because there is a limit of 1024 uniforms (When I pass an array of size X with setFloatArray, it's considered as X uniforms float, in fact it's considered as X * 4 uniforms float, I don't know if it's a bug from Unity ?).
Your answer
Follow this Question
Related Questions
Raycast on mesh deformed by shader 0 Answers
How does appdata_base work? 0 Answers
How to set float or float4 UV in Mesh. 1 Answer
How to get a sphere surface with a solid angle through script? 1 Answer
Mesh Clipping / Cross Sections 1 Answer