
The problem is that all the points(quad meshes) are faced toward their local Z axis.Īs it has always suggested, it’s better to use quaternion rotation rather than simple Euler angles x,y,z. _scale in worldPos matrix is referred to the whole object scale, but the _step in scale matrix is the scale of each point.Īt this point, we can generate our Point Cloud, and we can move and rotate all of them. Then, I transformed them back into their local position and applied each point's scale. After that, I rotated the coordinates using rotationMatrix.ĥ. Then, I transferred the point to its local origin by localPosNegativematrix.Ĥ.

second, I set our points to their world position(position of analogous vertex * scale of all points) + whole point cloud world position with worldPos matrix.ģ. First, I declared rotationMatrix by multiplying all other three matrices based on the axes.Ģ.We should multiply out matrices in a specific order. To access buffers and pass the desired data, we need to add a Custom Function node and write some HLSL code in it. To access buffers in Shader Graphs, you need some extra nodes that you can find in my PointCloud repository also, you can find all the implementations and a deeper understanding in this article. In this project, Unity’s Shader Graph is used. Thus we must adjust them using a vertex shader. It means that they are in the same position and don’t have any extra components to adjust. _Positions is our buffer float3 position = _Positions Īs I mentioned, this method draws the same mesh multiple times using GPU instancing. For more information about DrawMeshInstancedProcedural, you can check Unity documentation. Here a default quad mesh is passed to instantiate as our points also a material, bound, and the number of instances. Now it’s time to use Unity graphic API to draw instance meshes. We don’t need any special implementation in our Compute Shader in the current step as we want to pass data and show them without any effect. positionsBuffer = new ComputeBuffer(vertices.Lenght,3*4) positionsBuffer.SetData(vertices) As every vertex position consists of 3 floats (4 Byte data each), we set 12 Byte in the size parameter. We should declare the buffer length and size of each data in bytes. Use a computer shader to make VFX for points(optional).įirst of all, we need a buffer to store our vertices’ positions.In the vertex shader, we use the vertex position (also UV and normals for other adjustments) to place each point correctly.With APIs that Unity gave us, draw procedural geometry as the same number as vertices count.

We can get vertices data in any form we prefer, but I got them directly from the mesh. If you have another script altering the velocity, like a charachter controller, you CANNOT set the speed from this script, you will need to pass the speedReductionFactor to your Charachter controller, and update the velocity there using it and the Input logic, i'll leave that to you.
