# Fishes

UsingÂ **Graphics.DrawMeshInstancedIndirect** so that I can calculate the fish positions with compute shader.

The moving tails are just vertex displacements in shader. Rotation are also done in the rendering shader.

Below is the look-at matrix that takes the normalized velocity to be the rotation, and to be the forward axis.

# ComputeShader.SetFloats()

Originally I have in

**C#**

_floatArray = new float[2]; _floatArray[0] = 1f; _floatArray[1] = 0.5f;

**Compute Shader**

`float FloatArray[2];`

And useÂ ComputeShader.SetFloats() to pass the values from C# to Compute Shader**.
**Reading the values in Compute Shader, I found that

**only FloatArray[0] has the value**. SoÂ FloatArray[1] will equals to 0.

Unity dev (Marton E.) replied me that:

# Deform MeshCollider with Compute Shader

If you want to do something like this:

In **C#** : You need a for loop which

-> iterates a few ten-thousands vertices, and then

-> for each vertex, you need to calculate the distance between each bead…

All these instructions are run 1 by 1 on CPU. You can imagine the time needed for this.

——–

But with **compute shader**, those several ten-thousands iterations can be done “at the same time” in GPU (it depends how you setup the data). And the result data will be transferred back to CPU, and directly apply to Mesh.vertices array.

And this is what you can see in this video, the fps stays above 70.

# Indirect Compute Shader

Direct means CPU give something to GPU

Indirectmeans CPU tells GPU to get something in GPU

# Maths Link

Opengl Math Cheatsheet

http://www.opengl-tutorial.org/miscellaneous/math-cheatsheet/

Visualization of Math Physics

http://www.falstad.com/mathphysics.html

A very good tutorial about linear algebra, it visualises the concepts!

Matrix (GLSL)

http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/

# SRP studies

**Overview**

https://docs.unity3d.com/2017.2/Documentation/Manual/ScriptableRenderPipeline.html#APIOverview

Unity C++ code |
C#/shader code (MIT open source) |

Culling Render set of objects with filter/sort/params/batch Internal graphics platform abstraction |
Camera setup Light setup Shadows setup Frame render pass structure & logicShader/compute code |