Developer Diary, Game

PSX Inspired Shader


For last few days (amongst other things), I’ve been working on the PSX shader to simulate that distortion you often see in PSX games. The goal is to use this shader to help add a layer of creepiness to the environment through the shader.

So before I did anything, I did a quick search on “PSX Shader” on Google to see what would come up. I ended up coming across a few forum posts which pointed me in the direction of Affine Transformations.

After doing a little bit of a deeper search, I came across a basic shader which simulated the effect, but wasn’t exactly ideal for what we were trying to do. So I spent a few hours experimenting to try and understand what was going on and come up with our own.

And I did it! But it did have some problems.

The same Affine shader creating different distortions based on the number of vertices in the mesh.

The same Affine shader creating different distortions based on the number of vertices in the mesh.

One of the problems with the shader was when in first person view, the textures underneath the player would become extremely distorted. So I ended up adding a cut-off value which determines when to blend between Affine Transformed UVs, and normal UVs to help remove the distortion underneath the player.

Distortion effect underneath the player, without and with UV blending.

Distortion effect underneath the player, without and with UV blending.

It kind of makes a nice sense of normality around the player, while everything else is distorted and feels like it’s moving.

I also added vertex snapping into the shader to simulate PSX fixed precision. I used a single float value which indicates how many increments there are per unit, and rounds each vertex axis to the nearest increment.

Simulated Vertex Precision on a ... sphere?!

Simulated Vertex Precision on a … sphere?!

Sliding the value back and forth also creates a pretty neat effect causing the vertices to move around and shake. Which we might incorporate into gameplay some how.

Sliding the vertex precision back and forth makes the room look like it's breathing!

Sliding the vertex precision back and forth makes the room look like it’s breathing!

Once I got the base shader, I wrote variations which add Vertex Coloring and support for Unity Lighting, which will allow us to create interesting lighting and set the mood. And to save time on writing too much shader code, I wrote it in a Surface Shader.

Affecting the Lightmap UVs to create distorted looking UVs.

Affecting the Lightmap UVs to create distorted looking UVs.

After testing it a little further, I was pretty happy with the results. The final result is a nice distortion effect to create a slightly creepy environment.


Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Ko-fi Coffee

Comments for this post are closed.