Shader graph: Rigid body animation using vertex animation textures

Using Unity 2019.2.1f1, LWRP 6.9.1 and Shader Graph 6.9.1. You can get the article’s code and shaders here.

I saw two Youtube talks (The Illusion of Motion: Making Magic with Textures in the Vertex Shader, Unleashing Houdini for AAA Mobile Games Production – MIGS) about using specially encoded textures in the vertex shader to animate mesh. Both talks use Houdini to generate animations and because I don’t have Houdini, I decided to do everything in Unity.

The whole castle is the single mesh, in which recorded physics simulation.

Overview of example

Creating vertex animation consists of the following steps:

  1. Selecting the target
  2. Recording positions and rotations
  3. Combining meshes into single saving pivots and mesh ids
  4. Encoding position and rotation textures
  5. Using special shader that decodes these textures
Read More »

Shader graph: Force shield with hits

Using Unity 2019.2.1f1, LWRP 6.9.1 and Shader Graph 6.9.1. You can get the article’s code and shaders here.

I saw the tweet by Cyanilux and found out that Shader Graph’s Custom Node now supports arrays. So I decided to finish my Shield shader, for which I wrote a double-sided mesh generator previously. Also, Cyanilux already posted his shader breakdown.

As the mesh for the shield, I use double-sided mesh generated from Unity’s built-in sphere. I described the Depth intersection part of the shader graph in this article.

Simple shield

Click to view full graph
Read More »

Shader graph: Scan effect

Using Unity 2019.2.1f1, LWRP 6.9.1 and Shader Graph 6.9.1. You can get the article’s code and shaders here.

Scan effect shader uses depth intersection to determine where to render the scan object’s mesh.

Depth intersection

When the camera renders a scene, it creates Depth texture, writing in it all opaque objects. Using this texture, you can get distance from scene geometry to camera. Scene Depth Node provides access to the Depth Texture in several different sampling modes. (For LWRP to access Depth texture, it must be enabled in the Pipeline Asset)

When you render your object, you can get the fragment’s distance from camera and compare it to the distance to scene geometry. The main trick is to compare Scene Depth node output and Position/Screen Position node output in the same space.(comparing value A in range 0..1 with value B in range near… far plane won’t make any sense.)

Read More »

Shader graph: Dissolve effect

Unity 2019.2.1f1, LWRP 6.9.1 and Shader Graph 6.9.1. You can get the article’s code and shaders here.

Dissolve effect used for gradual appearing/disappearing of characters, force shields, etc.

Opaque

In opaque rendering mode, this effect uses a texture, that is usually generated noise, as the mask to discard pixels.

Discarding means that for every fragment of your mesh, you sample the discarding mask. Take a value from any mask’s channel (for example, red) of the sample and compare it against the DissolveValue. If the value in the channel is less than the DissolveValue, then this pixel is excluded from rendering, otherwise it’s rendered.

DissolveValue is the value that controls the visibility of the object. This value is in the range from 0 to 1, where 0 is the fully visible object, and 1 is fully invisible (all fragments were discarded). Also, the value of any texture channel is in the range of 0 to 1.

Read More »

Double-sided mesh generator

I wanted to create the simple double-sided force field shader but stumbled upon a problem with the double-sided rendering of transparent objects.

You can see that the Cull Off shader has some artifacts. On the other hand, the double-sided mesh with the Cull Back shader doesn’t have these artifacts.

I’ve decided to do some research about the ways to render objects from both sides. I want to look into how they work with transparent objects and what approaches can be used in LWRP.

There are several ways to render meshes from both sides:

  1. A single-pass Cull Off shader with normals flip on VFACE, if lighting is needed
  2. Two-pass shader, the first pass with Cull Front, the second with Cull Back
  3. Two Materials Basic material and material with Cull Front and flipped normals
  4. Double-sided mesh

All variants except the fourth require shader modifications. The second and the third variants are not supported by LWRP at all, because it doesn’t support the two pass shaders, at least not without some or another magic.

Read More »

Setup and double payoff

Warning: spoilers for MCU’s Capitan Marvel, MCU’s Avengers, Netflix’s Jessica Jones season two and rubikanon’s Extinction.

You set up something early in a story, and later you pay off this setup, preferably in some unexpected way. Also if there is a big interval between setup and payoff, you should remind your readers about the setup. This is a basic yet powerful tool of a writer. Some of the ways to make this tool more powerful are playing with expectations and making a double payoff.

Two ways of creating a basic setup/payoff
Read More »