Uploaded March 2018 | Updated November 2026, 52 minutes ago
Let's add wind! The goal is to make snow "flow" across the land over time and create drifts from indentations. It also makes filling in the holes left behind by people or things in the snow more dynamic than just rising back up! Now it has direction and is a lot more dynamic.
For this test we're going to only solve this for linear wind across the X axis. We'll sample from both sides of the current position and use two simple rules to determine how snow flows in our environment.
1. If the place the snow is coming from has more snow than the current position than move some of the snow from the previous position to the current one.
2. If the place the snow is going towards has less snow than the current position than remove some snow from the current position.
This causes snow to "drift" across the ground over time, almost as if it's smeared across the ground by a brush. The effect is really cool! For a proof of concept I'd say it worked out well.
Apologies for the crunchy audio. I tried to fix it but there wasn't much to work with unfortunately.
Join the World of Zero Discord channel: discord.gg/hU5Kq2u
Let's add wind! The goal is to make snow "flow" across the land over time and create drifts from indentations. It also makes filling in the holes left behind by people or things in the snow more dynamic than just rising back up! Now it has direction and is a lot more dynamic.
For this test we're going to only solve this for linear wind across the X axis. We'll sample from both sides of the current position and use two simple rules to determine how snow flows in our environment.
1. If the place the snow is coming from has more snow than the current position than move some of the snow from the previous position to the current one.
2. If the place the snow is going towards has less snow than the current position than remove some snow from the current position.
This causes snow to "drift" across the ground over time, almost as if it's smeared across the ground by a brush. The effect is really cool! For a proof of concept I'd say it worked out well.
Apologies for the crunchy audio. I tried to fix it but there wasn't much to work with unfortunately.
Join the World of Zero Discord channel: discord.gg/hU5Kq2u
![Correcting Lighting on our Grid Snapped Vertex Shader with Geometry Shaders
Lets fix our grid snapped vertex custom shader by introducing some improved lighting. Because were manipulating our objects geometry inside our shader the normals that are used to calculate lighting are incorrect. This causes objects to appear oddly smooth and lighting effects to look very different from what youd expect based on the geometry you see. We cant just correct the normals of each vertex because doing that would still cause the normal value to be interpolated along each of the triangles of our mesh (causing a smoothing effect). To resolve this were going to implement a geometry shader which allows us to dynamically recreate the mesh inside our shader so we can provide data that can be tweaked to our needs.
If present a geometry shader occurs after an a vertex shader but before the fragment shader following one of these two paths:
```mermaid
graph LR;
vert([Vertex Shader])
geom([Geometry Shader])
frag([Fragment Shader])
vert v2g ˃geom
geom g2f ˃frag
vert v2f ˃frag
```
It is not necessary for a geometry shader to recreate the same geometry that was passed in. The output can be completely modified to introduce additional information (weve used that capability in our [Grass Shader](https://youtu.be/b2AlyCNbYmY)). In this case our needs are simpler though, we are going to be using the geometry shader to isolate each triangle of our mesh. Doing this means that we can avoid interpolation caused by multiple triangles sharing a vertices without having to make those modification in our original mesh beforehand. This allows our shader to be compatible with any shape instead of just meshes specifically designed for this effect.
Our geometry shader recreates each triangle and assigns all the vertices of that triangle a unique normal so the face has uniform lighting. We also calculate the diffuse lighting we use inside of the geometry shader and pass that information along to the fragment shader. The geometry shader were using looks like this (assuming our vertex shader provides world space coordinates):
```shader
[maxvertexcount(3)]
void geom(triangle v2g IN[3], inout TriangleStream˂g2f˃ triStream)
{
float3 lightPosition = _WorldSpaceLightPos0;
float3 v0 = IN[0].pos.xyz;
float3 v1 = IN[1].pos.xyz;
float3 v2 = IN[2].pos.xyz;
float3 normal = normalize(cross(v0 - v1, v1 - v2));
float lightStrength = (dot(lightPosition, normal) + 1) / 2;
g2f OUT;
OUT.norm = normal;
OUT.lightStrength = lightStrength;
OUT.pos = mul(UNITY_MATRIX_VP, IN[0].pos);
triStream.Append(OUT);
OUT.pos = mul(UNITY_MATRIX_VP, IN[1].pos);
triStream.Append(OUT);
OUT.pos = mul(UNITY_MATRIX_VP, IN[2].pos);
triStream.Append(OUT);
}
```
***
My intro to exploring Geometry Shaders: https://youtu.be/HY6qFbmbij8
My video covering implementing diffuse lighting in more detail: https://youtu.be/4XfXOEDzBx4
A collection of other visual effects weve built: https://www.youtube.com/watch?v=l_2uGpjBMl4&list=PLEwYhelKHmig6ttzH0nRL3OOQsGLtVrtX
Watch the entire series where we explore this concept of snapping vertices to a grid: https://www.youtube.com/watch?v=e8NItqF_9hQ&list=PLEwYhelKHmiixWR3Tn5dYt1iUlSCL6OFq
Join the World of Zero Discord Server: https://discord.gg/hU5Kq2u Correcting Lighting on our Grid Snapped Vertex Shader with Geometry Shaders](https://i.ytimg.com/vi/VC-v874C5xQ/mqdefault.jpg)


. This retrieves a `MonoBehavior` from any `GameObject` in our scene which matches the type were searching for. This search method is not the final solution well end up using later in development, but for testing right now its more than enough to get us what we want. We can use the reference we retrieve to replace the actual instantiation, effectively moving the parts of the code we want into a separate place.
To make things a little easier and to make sure our new component is more useful well still do some of the lifting in the Asteroids code. This includes calculating the rotation and world position of each new Chunk of the Asteroid. We do this so that the controller we built can be used to generate brand new Asteroids and not just create debris from existing ones.
There is still a bit more to do to get a fully functioning destruction system (we dont track health yet for example), but this gets us to a place where object destruction and creation works reliably well.
The base subdivision destruction system was built in a Live Stream which you can find here: https://youtu.be/POVJ-QIyygE
Join the World of Zero Discord Server: https://discord.gg/hU5Kq2u Creating a Subchunk Spawner for Asteroids VR](https://i.ytimg.com/vi/VaGI6j_4e7Y/mqdefault.jpg)




![I Learn How To Make Bash Flip Tables When I Break Things
Lets take a look at how to customize a `bash` shell. Well be making our shell print a table flip whenever the last command failed. In order to customize your prompt you can overwrite the `PS1` environment variable.
To see what your current prompt is set to you can run `echo $PS1`
The table flip script looks like this:
```bash
table_flip() {
if [[ $? 0 ]]; then
echo
else
echo (╯°□°)╯︵ ┻━┻
fi
}
```
Here is a tool that can help you customize your prompt more easily: http://ezprompt.net/
The ArchLinux wiki goes into much more detail about prompt customization: https://wiki.archlinux.org/index.php/Bash/Prompt_customization#Bash_escape_sequences
Join the World of Zero Discord Server: https://discord.gg/hU5Kq2u I Learn How To Make Bash Flip Tables When I Break Things](https://i.ytimg.com/vi/XUOti_9WgaM/mqdefault.jpg)

 class that provides some helper functions to make this easier.
The first thing to do is define a set of planes we can use to describe the view of our camera. This is called a frustum and is the white box-like gizmo you see in Unitys scene editor when you select a `Camera`. The frustum defines your cameras view and we can take advantage of this to test if objects are inside or outside of the bounds we calculate.
In order to calculate the frustum planes well want to run `GeometryUtility.CalculateFrustumPlanes(...)` and pass in the camera we want to calculate the Frustum of. In our quick example well use `Camera.main` to grab the main camera in our scene.
Once weve calculated the camera frustum planes we can provide those to the `GeometryUtility.TestPlanesAABB(...)` method to test if the bounding box we provide is inside or outside of the planes we calculated earlier. This method returns true if the bounding box provided overlaps with or is inside of the `Plane[]` boundaries. In this case were testing if a bounding box overlaps or is inside of the cameras viewport.
To get the bounds of an object you can use the `Collider.bounds` field. This calculates a world space axis-aligned bounding box for the collider and returns it to you so you can reference it in your object. The bounds are always a box aligned to the XYZ planes but are supported on all types of `Collider` in Unity.
Once youve passed your bounds into the test function you can use that to perform your behavior for objects in or out of view. This can be used to freeze objects when they come into view (like the Doctor Who Angels) or to move/delete an object when it gets out of sight (like some gibs you only want to be cleaned up when the player looks away). Theres a lot of different uses for functions like this!
The code Im using in this example has an `Update` that looks like this:
```csharp
var bounds = collider.bounds;
cameraFrustum = GeometryUtility.CalculateFrustumPlanes(camera);
if (GeometryUtility.TestPlanesAABB(cameraFrustum, bounds))
{
renderer.sharedMaterial.color = Color.green;
}
else
{
renderer.sharedMaterial.color = Color.red;
}
```
You can learn more about dot product here: https://youtu.be/8cZo-c-f1yc
***
Join the World of Zero Discord Server: https://discord.gg/hU5Kq2u Detect Objects in Your Camera View - Unity Geometry Utilities](https://i.ytimg.com/vi/XrqesjfcitU/mqdefault.jpg)