3D Math – Always a Single Plane to Cut Three 3D Objects in Half with Borsuk-Ulam Theorem – by Zach Star

June 28, 2021

Borsuk-Ulam Theorem

3D Math


Title:
A surprising topological proof – Why you can always cut three objects in half with a single plane

By:
Zach Star


Youtube – Information

Description:
Proving that any set of n n-dimensional objects can be cut in half by n-1 dimensional object (i.e. 3 3D objects can be cut in half by a 2D plane).


Overview

This was just a fun and interesting mathematical proof I came across. Using the Borsuk-Ulam Theorem at its core, it proves how any set of 3 3D objects can be cut in half (by volume) by some 2D plane. It then expands that to show that this works for any n amount of n-dimensional objects, which are then divided by an object with n-1 dimensions.

Borsuk-Ulam Theorem

This can be read up on here at the corresponding wikipedia page:

Wikipedia – Borsuk-Ulam Theorem

This states: “every continuous function from an n-sphere into Euclidean n-space maps some pair of antipodal points to the same point”. The simple explanations they use to show how it is used is that in the 2D case, there must exist at least 2 points around the equator with the same temperature, and in the 3D case, there must exist at least 2 points in the entirety of Earth that have the same temperature and pressure. Another key note is this is only true assuming all parameters vary continuously in space.

Expanding to Proof on Dividing Objects

To apply this to the concept they were investigating, they start with the 2D example since it is easier to visualize, and will eventually lead to the same foundational concepts used for any n-dimensional case. They begin with a unit circle, and show how the tangent to every point around the circle accounts for every possible slope in this space and how any of those lines can be used to cut any shape in half by area.

The key to using the Borsuk-Ulam Theorem in this case is that they need to assign a value to that point on the circle. To do so, they use the distance between the two parallel lines that are cutting the two shapes in half. Because they want to find antipodal points which are equivalent, they create a signed distance system. The sign of the distance is based on the normal of the point on the unit circle. If that normal points towards shape #1, it is positive, and if it points towards shape #2, it is negative. They do this because there is only one case where the positive and opposite of a value is equal, and that’s when it is 0. This proves that the 0 value will exist, and a distance of 0 between the two lines indicates they are the same line cutting both shapes in half.

Summary

Honestly I was mostly just interested in the concept that there’s always at least 1 plane that can cut up to 3 3D objects in half, and was not fully connecting the dots on all the steps through the process for actually proving this to be true. Just learning about the Borsuk-Ulam Theorem in itself was very interesting, and seeing some of the unexpected cases it can be used to help prove was pretty eye opening. I did want to check it out because I thought it would be a fun concept to explore with a small Unity project to create a puzzle-like game centered around this concept, while also providing some background information on some of these concepts and theorems.

via Blogger http://stevelilleyschool.blogspot.com/2021/06/3d-math-always-single-plane-to-cut.html

Unity Shader Graph – Signed Distance Fields – Update with Subgraph Fix

June 24, 2021

Shader Graph

Unity


Title:
Drawing Boxes and Rectangles in URP Shader Graph with 2D SDFs! 2021.1 | Unity Game Dev Tutorial

By:
Ned Makes Games


Youtube – Tutorial

Description:
Exploration into calculating signed distance fields and using them with Unity’s Shader Graph.


Title:
Rectangle SDFs and Procedural Bricks! Video Production Stream | Unity Game Dev Livestream

By:
Ned Makes Games 2


Youtube – Tutorial

Description:
The full stream which most of the previous tutorial is pulled from. Useful for any more in depth questions of previous tutorial.


Overview

When I visited this tutorial yesterday I ran into an issue with Unity 2021.1.3 that working with subgraphs was extremely bugged and error prone. I had seen online that later versions potentially fixed the issue, so I download the latest version, 2021.1.12, and this did indeed fix the issue for me, making this tutorial much easier to follow along with.

This tutorial was mostly just looking at the subgraphs and shader graphs they built and following along to build them out myself. This was at least a decent learning experience at getting familiar with the work flow of setting up subgraphs for your shader graphs, as well as just using a lot of the math nodes.

Helper Scripts to Show Off Shader

Along with building the shader, they made two simple scripts to make the shader a bit interactive and more flexible.

SetPoints

This class was responsible for letting the user move the two points dictating the general length of the rectangle shape by just clicking and dragging. This however did not work immediately, as they were using a helper class named MousePointer I did not use.

I was able to get a similar result by replacing their process of getting the point:


var p = MousePointer.GetWorldPosition(Camera.main);



with my replacement:


var p = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, distanceToPlane));

distanceToPlane was a value the user could put in that is the distance from the camera to the flat plane the camera is facing to test the shader. As long as the exact same distance is put there for the z-value of ScreenToWorldPoint, the points moving correlate exactly with where the user is dragging them.

RectangleThicknessByScrollWheel

This class lets the user control the thickness, or width, of the rectangle with the scroll wheel. This class directly worked as shown.

General Notes with Scripts Interacting with ShaderGraph Properties

Integrating the scripts with the Shader Graph properties was actually pretty easy. It worked similarly to working with the Animator in Unity. You just use methods like SetFloat() and give it two parameters where one is the exact string name of the property you want to set, and the second is the value you are passing in to said property. It is worth noting this was just accessed through the Material, there was no strange Shader Graph object that needed to exist or anything like that.

An example of my implementation of the tutorial can be seen below.


Unity Shader Graph: SDF Rainbow Pulse from Tutorial by NedMakesGames from Steve Lilley on Vimeo.

Video Example of my Following of the Pulse Shader in the Ned Makes Games Tutorial

via Blogger http://stevelilleyschool.blogspot.com/2021/06/unity-shader-graph-signed-distance_24.html

Unity Shader Graph – Signed Distance Fields and Subgraph Errors

June 23, 2021

Shader Graph

Unity


Title:
Drawing Boxes and Rectangles in URP Shader Graph with 2D SDFs! 2021.1 | Unity Game Dev Tutorial

By:
Ned Makes Games


Youtube – Tutorial

Description:
Exploration into calculating signed distance fields and using them with Unity’s Shader Graph.


Overview

This shader tutorial quickly explores calculating signed distance fields and using that for interesting effects. These effects were built in HLSL in the tutorial video originally, but they also show how these can be implemented with Unity’s Shader Graph system. I wanted to use the Shader Graph approach, but unfortunately I found that Unity’s Shader Graph Subgraphs have some major issues.

Signed Distance Fields (SDFs)

Signed Distance Fields (SDFs): calculate the distance from any arbitrary point to a specific shape

Principles of Calculating

To start, they look at an example using a rectangle whose center is at the origin (0, 0).

First, they find the distance from the point, p, to the center of the rectangle, which is just the length of the Vector2 p because the center is at the origin.

Then, using the symmetry of the rectangle, the absolute value of point, p, and the half dimensions of the rectangle are used to determine the distance of the point to any corner of the rectangle.

To get the positive results, they find the vector between the absolute value of point, p, and the corner of the rectangle and find the length of this vector after converting any negative components to 0.

Since the core of an SDF is that it is signed, meaning that a point inside the shape returns a negative value and a point outside the shape returns a positive value, they expand it to deal with negative distances. The vector, d, which is that from the absolute value of point, p, to the corner of the rectangle is only inside of the shape when both components of d are negative.

Assuming both components of d are negative, the result from the previous step already results in 0, so they can add a secondary component to this that returns a negative result in this case. By using min(max(d.x, d.y), 0) they can find this distance because a point within the rectangle must be closer to one wall or the other, or they are identical values. This is why there also is no rounded effect within the rectangle.

Moving the rectangle’s center from the origin just requires an additional offset argument.

Then, rotation requires another argument, and requires rotational matrix math (something I covered in my investigation to changing vector spaces).

Unity Problem with Subgraphs

While following along to mimic their Shader Graphs, I came across a Unity issue working in Sub Graphs especially. When creating properties and moving those property nodes around, Unity consistently runs in ArgumentNullException errors which completely shut the graph down and prevent any further progress until it is closed and reopened. Apparently Unity versions 2021.2 and up may work better with this, so I will have to look into more Unity versions in the future.

via Blogger http://stevelilleyschool.blogspot.com/2021/06/unity-shader-graph-signed-distance.html

Modding Monster Train – Editing Name of Champion Tutorial

June 22, 2021

Modding

Monster Train


Title:
Monster Train – Shiny Mark mades mods

By:
Good Shepherd Entertainment


Youtube – Tutorial #1

Description:
Extremely basic introduction to setting up a C# project for modding Monster Train (slightly outdated).


Overview

This was an introductory tutorial mostly meant to help you learn how to setup a C# project to mod Monster Train. It has however become slightly deprecated since the DLC was launched, however it did lead to me gaining a better grasp on the logging system for debugging.

Following Tutorial

This tutorial is rather straight forward, but even this had its fair share of issues. One of the first major blocks I ran into and resolved was how strict Harmony is with some of the ways it interacts with the base game code. Specifically, the __result parameters used in the Postfix() methods specifically require EXACTLY 2 underscores before ‘result’. This is actually just part of their system of naming conventions, and is further explained in other Monster Train modding documentation.

The other issue I encountered is that one of the renaming conventions was not working. I was able to change the name on the card (the CardState change), however changing the name while the unit was in the train (the CharacterData change) was not performing as expected. I was able to find through logging that the method being called was indeed returning the string “Hornbreaker Prince” and my system was identifying that, but for whatever reason the result was not changing the ‘in train name’. My suspicion is that an updated underlying system is actually returning the name of the unit back to ‘Hornbreaker Prince’ and it also needs to be changed somewhere else, but I am unsure where that would be.

Either way, changing the name of a card can be done in better ways so this issue does not particularly need resolved. Some others mentioned going through Monster Train’s localization system to find a better place to change the name of a card.

Confirming Updated DLC as Error

To check that this was not just an error in my code or program, I downloaded the existing mod created in the above mentioned tutorial (as it is available in the Steam Workshop). Sure enough, even though it is seen working in the old video, the download of that mod had the same result as my mod. The name on the card was changed to ‘Frank’ but the name on the unit in the train was still ‘Hornbreaker Prince’.

Fig. 1: Showing Side by Side of Where the Name Change Worked and Did Not Work

via Blogger http://stevelilleyschool.blogspot.com/2021/06/modding-monster-train-editing-name-of.html

Modding Monster Train – Basics and Introduction

June 21, 2021

Modding

Monster Train


Title:
Monster Train – Shiny Mark mades mods

By:
Good Shepherd Entertainment


Youtube – Tutorial #1

Description:
Extremely basic introduction to setting up a C# project for modding Monster Train (slightly outdated).


Title:
Monster Train Modding Card Creation Tutorial Mod

By:
Good Shepherd Entertainment


Youtube – Tutorial #2

Description:
Introduction to using the Trainworks API, a modding tool for Monster Train geared towards adding new content.


Title:
Getting Started with Trainworks Modding Tools

By:
KittenAqua


Github – Wiki

Description:
More detailed and indepth documentation on properly setting up a C# project for modding Monster Train as well as examples for modding various content.


Overview

Monster Train is a game I have played a lot and really enjoyed, and it recently put out some modding support in the last year. Being a Unity-based game, I figured I could use some of my Unity and C# knowledge to take a crack at modding in some content of my own to play around with and possibly add to the community.

It is not the most straight forward process, and there was recently a large DLC added to the game that makes parts of the old modding tutorials different or completely obsolete, but I still think there enough to sift through to make a base for starting a mod going. I think there is also a decently strong community that would appreciate some mod content since it is rather lacking, so it could also just be a nice place to implement some game design practices and create some new stuff for others to play with.

via Blogger http://stevelilleyschool.blogspot.com/2021/06/modding-monster-train-basics-and.html

Unity Shader Graph – Liquid Effect by Gabriel Aguiar Prod.

June 18, 2021

Shader Graph

Unity


Title:
Unity Shader Graph – Liquid Effect Tutorial

By:
Gabriel Aguiar Prod.


Youtube – Tutorial

Description:
Quick shader graph tutorial exploring interesting effects of moving shader based on psuedo-physics.


Overview

This shader tutorial looked like a great way to extend my knowledge on Unity’s shader graph since it appears to have some neat and unique mechanics. The fact that the shader is responding to the changes in position and rotation of the object explore ways to have shaders follow physics-like rules to create effects visually that can mimic for physical phenomena. Many of this user’s tutorials also include setting up the initial models, but I think this effect can work decently with other simple shapes I can easily make with ProBuilder.

via Blogger http://stevelilleyschool.blogspot.com/2021/06/unity-shader-graph-liquid-effect-by.html

Unity Shader Graph – Grid Shader by UGuruz

June 16, 2021

Shader Graph

Unity


Title:
Grid Shader in Unity LWRP – Shader Graph Tutorial

By:
UGuruz


Youtube – Tutorial #3

Description:
Experimenting with tiling and the rectangle node in Unity Shader Graph to create a Tron-like glowing grid pattern.


My Final Grid Shader Graph (w/ Color Change Addition)


Overview

Following my exploration of Unity’s shader graph, I did this tutorial by UGuruz on creating a grid shader similar to what you see in Tron. I really liked the effect so I continued it slightly further by adding a color changing effect over time, as can be seen in my examples provided.

Learnings from Tutorial

Using a Fraction node with a Tiling & Offset node is an effective way to give you standard expected tiling and offset results. I however had some strange effects because of interactions with the UVs of the models. The base UVs of just a standard Unity cube did not tile effectively for me, so I tried using Unity’s ProBuilder to make a basic cube since that also gave me easy access to modifying UVs if necessary. This gave me much more consistent results similar to those in the tutorial, since I wanted to avoid the step of modifying UVs in Blender.

They mentioned the shader would only work well on flat surfaces, but I at least wanted to test on another surface to see what the result would be and see if I could improve it. That’s why I included a sphere in the environment. It immediately gave very strange results as expected, but I found that grouping faces together through the ProBuilder tool helped give a better result, as this allows it to treat the many faces of a sphere similar to a single large face. This concept works well with a basic tiling pattern like I used here.

I did end up using World type UVs to get a decent visual result on everything, especially the sphere. While this gave something very close to what is desired, it is still a somewhat strange appearance when viewed from some angles as this inherently treats the positioning in world space as the coordinates for applying the shader. I still need to investigate the UV types and UVs in general though to get a better understanding of how to control them.



Unity Shader Graph: Tutorial by UGuruz with Color Change Addition from Steve Lilley on Vimeo.

Video Example of the Grid Shader Result with Color Change Addition

via Blogger http://stevelilleyschool.blogspot.com/2021/06/unity-shader-graph-grid-shader-by-uguruz.html

Unity Shader Graph Examples and Tutorials

June 10, 2021

Shader Graph

Unity


Title:
FORCE FIELD in Unity – SHADER GRAPH

By:
Brackeys


Youtube – Tutorial #1

Description:
A quick introduction to shader graph in Unity making a transparent force field with glowing edges.


Title:
ART 200: Creating an energy Shader in Shader Graph in Unity

By:
Casey Farina


Youtube – Tutorial #2

Description:
An introduction to using noise effects in Unity Shader Graph to create a glowing generic energy effect.


Title:
Grid Shader in Unity LWRP – Shader Graph Tutorial

By:
UGuruz


Youtube – Tutorial #3

Description:
Experimenting with tiling and the rectangle node in Unity Shader Graph to create a Tron-like glowing grid pattern.


Title:
Unity Shader Graph Tutorials – Youtube Playlist

By:
Gabriel Aguiar Prod.


Youtube – Playlist #1

Description:
This user creates tons of VFX tutorials for games, and has delved into Unity’s Shader Graph, giving great examples of quick but well done effects.


Title:
Unity Shader Graph – Ice Tutorial

By:
Gabriel Aguiar Prod.


Youtube – Tutorial #4

Description:
Creates a stylized glowing, transparent ice shader to use for crystaline ice formations.


Title:
Unity Shader Graph – Shield Effect Tutorial

By:
Gabriel Aguiar Prod.


Youtube – Tutorial #5

Description:
Similar to Brackeys force field tutorial, but covers extra steps to push the effect over the edge.


Title:
Shader Graph fundamentals in Unity

By:
PabloMakes


Youtube – Tutorial #6

Description:
General coverage of a lot of commonly used nodes and tools within Unity’s Shader Graph.


Source: Unity.com

Overview

I wanted a quick way to apply some interesting effects and looks to different models I work with in my sample projects, and making cool materials and shaders seemed like a perfect tool for that. You can get some neat effects without too much effort, and as you make these tools they are easily applicable over multiple projects and give me a tool to use over and over again.

Coding shaders in HLSL for Unity can be a bit tricky, so meeting them in the middle and working with Unity’s Shader Graph was a good compromise for me. This could give me results even quicker without sacrificing too much for what I will be doing. As such, I gathered this large source of resources for learning and exploring Unity’s Shader Graph system.

Quick Notes

URP vs HDRP

HDRP is for more high end games and devices (PC, XBOX, PS) but is more demanding. URP is better for 2D projects in general, and is made to be more accessible and less demanding.

URP vs Deprecated LWRP

Many resources, including some of these tutorials, used Unity’s Light Weight Render Pipeline (LWRP). This has already been phased out and replaced by the Universal Render Pipeline (URP). So it is generally safe to use the URP system if a tutorial or example uses the LWRP.

PBR Graphs Replaced with Lit Shader Graphs

Some of these old tutorials also use PBR graphs, which have also been phased out already. They can be replaced with Lit Shader Graphs. The PBR master node within the graph has also been broken up and replaced in newer Unity projects by two nodes, a Fragment node and a Vertex node (makes it more similar to shader coding).

via Blogger http://stevelilleyschool.blogspot.com/2021/06/unity-shader-graph-examples-and.html

Game Project: Flying Game – Part 5 – Projectile and Environment Interaction (Part 2)

June 8, 2021

Flying Game

Projectile


Overview

I wanted to have the player projectile add force to objects that it came in contact with. This originally was just to prevent strange occurrences where originally if the player hit obstacles sitting on top of others, nothing would happen since the only force moving them at all was gravity. This additional force adds some extra displacement to make sure that whenever any objects are hit, there is some dramatic impact.

Voxelized Environment Obstacles Update

IDestructible Interface Update for Voxel Obstacle Element Class

This interface is implemented by the individual voxel obstacles. It originally just had a Destroyed() method, but with this update I wanted to add a secondary method to deal with simply being hit at all, so I added a Damaged() method. I then also renamed the Destroyed() method to EndLife() since it may not necessarily be destroyed when its job is done.

Internal Hit Cooldown Timer

Because the objects were receiving forces from various angles and running into other elements, sometimes objects could quickly be pushed slightly out of the projectile and then be hit again by the same projectile and receive another boost in force applied. To prevent this, I added an internal hit cooldown timer to the individual elements so that they would not react again until a certain time had passed. This will most likely be set to a relatively low time (i.e. <1s), but as can be seen in the test video a timer of about 10s is used just to check its validity.


Video: Sonic Boom Projectile and Obstacle Internal Timer

via Blogger http://stevelilleyschool.blogspot.com/2021/06/game-project-flying-game-part-5.html

Game Project: Flying Game: Sonic Boost – Part 4 – Projectile and Environment Interaction

June 2, 2021

Flying Game

Projectile


Overview

I was trying to think of ideas on how to add an extra mechanic to the flying controller that ties in with a fast and agile moving controller, and thought of tying in some type of sonic boom effect. With this, I thought creating an expanding projectile from the player after boosting could be an interesting way to generate these projectiles. I then explored a few ways to have the projectile interact with the environment and came across a relatively simple one that provides some fun feedback.

Sonic Boom Projectile

Everything about the projectile is rather simple. The projectile is generated when the player performs a fully charged boost. It then expands at some growth rate (dictated by the projectile controller on the player) up until some maximum size (dictated in the same location). As it encounters objects with an IDestructible interface, it will cause them to perform their Destroyed() method.

This gives a pretty cool effect that at least has a minimal basis in real world physics. It also makes tight turns and effective direction changes tied to a boost more satisfying when performed properly. It does have a major flaw currently however in that a majority of the action is normally happening behind the player, so they do not get to witness it most of the time. This is a pretty severe drawback that I will need to investigate some solutions to.

Voxelized Environment Obstacles

I initially liked the idea of creating targets or obstacles that could be destroyed by this growing sonic boom that would deteriorate as the sonic boom moved into it, as opposed to a more general game approach where contact would just do damage and destroys the entire object as a whole. This led me to making a bit more voxelized targets, which were made up of several chunks instead of just being a single large mesh.

To begin, I created a Voxel Obstacle script which is the overall container of a full obstacle made of several voxelized elements. This script just holds 3 dimensional values and builds out a solid cube/rectangular solid based on those dimensions.

The elements that make up the full obstacles are just simple prefab cubes for now, with a VoxelObstacleElement script. That script implements the IDestructible interface just so they have a Destroyed() method for the projectile to interact with.

Initially I had these elements have their gameobjects destroyed on impact with the projectile just to test the interactions. This was an ok approach, and gave the deteriorating effect I wanted that was at least more fun than the whole area exploding immdeiately on impact. However, I explored a more physics-based approach that looked a lot more satisfying. I simply turned the elements’ rigid body component from kinematic to non-kinematic to effectively enabled their physics. This gave a fun tumbling and physics-y effect for the individual blocks as they interacted with the projectile.

This is a decent spot for most of the elements of this small game project, and I think the next step is just building out a better level to test the individual mechanics in. I would also like to add a bit more to the projectile/environment interaction just to make it a bit more impactful. I would also like to remove the strange interaction of hitting the blocks from above, as without any additional force, they don’t really move since they really start by moving downward with gravity being the only force acting on them.

Sonic Boost – Projectile Tests and Environment Voxel Interactions from Steve Lilley on Vimeo.


Video: Sonic Boom Projectile and Obstacle Destruction Showcase (1st and 2nd Iteration)

via Blogger http://stevelilleyschool.blogspot.com/2021/06/game-project-flying-game-sonic-boost.html