PSX Shader Kit
https://twitter.com/PeacecrabVal

Interior model by Liron
https://twitter.com/LironHero
https://sketchfab.com/3d-models/ps1-phasmophobia-da1af845dd6643079b379f3018d451f5

Emulated PSX rendering features
•	Dithering
•	Color Banding
•	Retro vertex lighting
•	Fixed-point precision vertex snapping
•	Affine texture mapping
•	Triangle sorted rendering
•	Interlacing
	
Contents
•	PSX Post-process effect for Dithering and Color Banding.
•	Unlit and Vertex-Lit variants of the PSX shader. (Opaque, Transparent, Cutout)
	
Usage
Add the PSXShaderManager Behaviour to a GameObject to customize global settings for the PSX shaders.

Add the PSXPostProcessEffect Behaviour to a camera to enable the PSX-style image effects.
	
Settings
•	Color/Dither Depth: Amount of unique colors per color channel for the color banding/dither passes. eg. a setting of 16 simulates a 4-bit color depth.
•	Dithering Matrix Size: 4x4 provides a higher quality dither with more dithering patterns per block.
•	Vertex Grid Resolution: Simulates the fact that vertex transformations on the PSX were done with low precision fixed point math. Lower values increase the snapping effect.
•	Triangle Sorting Emulation: Simulates the PSX's lack of a depth buffer, requiring triangles to be sorted individually back to front. Enabling it makes the PSX shaders calculate depth per-triangle rather than per-pixel.
•	Retro Vertex Lighting: Custom vertex lighting with linear attenuation.
•	Retro Lighting Normal Factor: How much the lighting is affected by the angle of surfaces relative to the light. 0 means the lighting intensity is based entirely on the distance between a vertex and the light. 1 means the lighting intensity is based on the distance and also the angle between the light and the vertex normal.
•	Depth Debug View: makes the PSX Shaders render the custom per-triangle depth for debugging.
	
Triangle Sorting Customization
There isn't a single best solution for triangle sorting as it depends on the scene and camera setup. To customize the triangle sorting for your game, open PSX-Utils.cginc and change the function the PSX_TRIANGLE_SORTING_FUNC macro points to. These functions take in the 3 vertices of the triangle in object space and output the custom depth that should be written. By default, GetTriangleSortingDepth_ClosestVertexDepth is used by default but more are provided for testing, as well as a pre-made custom function template in GetTriangleSortingDepth_Custom.
	
Unfortunately this method is fairly limited compared to being able to actually sort triangles. Actual PS1 games were able to use pre-computed sorting lists and per-object rules compared to the completely generic math based approach here. The effect will almost always produce worse artifacts than actual PS1 games had.
	
Notes
The PSX object shaders will work best with scenes made with PS1 limitations in mind. The affine texture mapping and lack of a depth buffer made rendering less accurate the bigger the triangles were on the scene. Your scene should be sufficiently tessellated to make best use of the effects, otherwise they might be too distracting

The triangle sorting function used outputs custom depth in the same value range and distribution as an object rendered without this shader. This is to allow the mixing of PSX and non-PSX shaders in the scene. If that's not a consideration for your project, your own custom triangle sorting solution can be simplified by not having to follow that rule. The GetTriangleSortingDepth_LinearCenterDistanceDepth function is provided as an example of that.

The implementation for the shader variants is centralized in PSX-ShaderSrc.cginc and various features are toggled using #define preprocessor macros. That way, the creation of custom variants is simplified. You can #define your keywords before including PSX-ShaderSrc.cginc to toggle these features.