[Custom SRP] How to use Unity features?

Update:

If you are using 2019.1+, you might notice there is a big change to the SRP APIs.
I’ve created a new repository and you can grab here. Much cleaner and minimal.

https://github.com/cinight/CustomSRP

 


 

May-14-2018 gif

Screen Shot 2018-06-02 at 22.16.24

SRPFlowScreen Shot 2018-05-12 at 18.52.43

(My playground pipeline)

Here lists out exact what codes enable the Unity feature when making our custom SRP.

*Note that my codes may not be perfectly optimised, but the concept itself won’t change.
(!) Alert: Below information might be outdated. I stopped updating this note after 2018.x releases.

Indicators:
icon_script In pipeline code
icon_shader In shader code
✅ Doesn’t need to specifically care about it in codes. Write the codes as usual.

Continue reading “[Custom SRP] How to use Unity features?”

StungaLab – 21³ Cubic Animation Tech Note

Me and a few of my friends (StungaLab) decided to create this animation from last year and I’m responsible for all Unity things – setup / shaders / tools / plug-ins etc. I didn’t help a lot as I have my full-time job in UK so most of the work are actually done by the 2 amazing 3D artists Felix Yin-Zhen Chu and Shadow Chi-Ho Wong, also 2D part by Carol Tsz-Ching Ng. It is the first time for us all to put ourselves into such a big production — target at high quality, massive amounts of assets, and short time-frame, (esp. ) lack of knowledge of using Unity (they are almost the first time Unity user). The final animation really surprised me.

 

I only have mobile game development experience in the past so there was no way for me to grab so many plug-ins and use so many expensive graphics features in any projects. So I had no idea how to correctly set things up for a project like this. Glad that I work in Unity and the knowledge I gained supported me a good start.

Note: Not everything shown in this blog are being used. But they are the stuff I worked on so I hope to keep them here as a log.

Continue reading “StungaLab – 21³ Cubic Animation Tech Note”

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.

float4 ApplyRotation (float4 v, float3 rotation)
{
	// Create LookAt matrix
	float3 up = float3(0,1,0);
	
	float3 zaxis = rotation;
	float3 xaxis = normalize(cross(up, zaxis));
	float3 yaxis = cross(zaxis, xaxis);

	float4x4 lookatMatrix = {
		xaxis.x, yaxis.x, zaxis.x, 0,
		xaxis.y, yaxis.y, zaxis.y, 0,
		xaxis.z, yaxis.z, zaxis.z, 0,
		0, 0, 0, 1
	};
	
	return mul(lookatMatrix,v);
}
Screen Shot 2018-02-01 at 23.14.24
Continue reading “Fishes”

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:

Continue reading “ComputeShader.SetFloats()”

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.

Update: This can be done much faster using AsyncGPUReadback. Visit here for example: https://github.com/cinight/MinimalCompute