+1

Retro Shader

Corjn 8 years ago updated 8 years ago 2

Hi,

Do you think it is possible to do a retro shader with shader forge, a bit like this : https://github.com/keijiro/Retro3D ? Like the shader used for the ps1

It's using pixel snaping as a vertex offset I guess, and has some distortions over the uv's

Thanks in advance for adivces !

+1

Sorry I'm really bad at coding and shaders are really hard. I made a lot of reasearch and I managed to achieve what I want by tweaking the code part of "Pixel Snap" included in the shader forge settings.
But, It's kind of boring to remake this operation anything I change something with shader forge. That's why I really want to do it inside the node editor.
I think I can achieve this using UNITY MATRIX P and UNITY MATRIX MV, I already tried that with the code node, but it's not working. How can have these inside shader forge ?

+1

Hey,

I managed to adapt the Keijiro code and convert, I guess, any shader forge code to a retro shader.
Unfortunatly I did that by code editing and did not figured out how to do it with nodes.

If you are interested, here are the steps:





Note that for debug purpose, this was tested with the default untouched shader forge pbr.


Alos note that you should repeat each operation on every pass in your code (Forward, Forward Delta, Meta)

1-In your shader forge geometry settings, check "Show 2D sprite pixel snap option in material" (better if you want a bool for activate/deactivate the pixel snap. But know that this bool won't work anymore and will have to remain checked if you go beyond the point "7" on this tuto)

2-Open your shader forge shader code

4-Search for "o.pos = UnityPixelSnap(o.pos);" and replace it with :

float4 wp = mul(UNITY_MATRIX_MV, v.vertex);
wp.xyz = floor(wp.xyz * _GeoRes) / _GeoRes;
float4 sp = mul(UNITY_MATRIX_P, wp);
o.pos = sp;


5-In the properties of your shader, paste :

_GeoRes("Geometric Resolution", Float) = 40


6-Before struct VertexInput, paste :

uniform float _GeoRes;


Now you are done with retro pixel snaping.
If you want your retro shader in a even more "glitchy" aestethic, that is to say you also want the uv displacement of the retro shader, you should do that:


7-Search for "float2 texcoord0 : TEXCOORD0;" an replace it by "float3 texcoord0 : TEXCOORD0;"

8-Search for "float2 uv0" an replace it by "float3 uv0"

9-Paste this after the freshly added "o.pos = sp;" :

float2 uv = TRANSFORM_TEX(v.texcoord0, _MainTex);
o.uv0 = float3(uv * sp.w, sp.w);


10-Paste this after the frag function. (You can search "float4 frag(VertexOutput i)") :

float2 uv = i.uv0.xy / i.uv0.z;


11-Search for "tex2D" and just after replace "i.uv.0" by "uv"


Done !



There is no shadow pass to follow the vertex offset, I tried to add one, but doing that is way too glitchy (imo). That's why the original one by keijiro is unlit I think. Anyway, you can bypass that problem with baked shadows, or set the cast shadow of mesh renderer to "off" (and still have the lit and normal map, and fog, things that the original from keijiro does not have) .
Of course, if someone finds a way to do that directly with shader forge, I would be happy to try :)