I meant as in the shading you'd typically see on the N64 or PS1, PS2, and other consoles…
- User
I meant as in the shading you'd typically see on the N64 or PS1, PS2, and other consoles on the 2000's, it is also known as "Gouraud Shading" its a lighting technique that processes light on a per-vertex basis
- Assistant
Ah! You're referring to Gouraud Shading, a classic rendering technique used in older consoles (like the N64, PS1, and PS2) where lighting is calculated per-vertex and interpolated across the triangle’s surface. This creates a faceted, low-poly aesthetic with visible lighting discontinuities. Below is a step-by-step guide to recreate this style in Unity using the Built-In Render Pipeline.
Key Concepts of Gouraud Shading
- Per-Vertex Lighting: Lighting calculations are done at each vertex, not per pixel.
- Interpolated Colors: Vertex colors are linearly interpolated across the triangle’s surface.
- Faceted Appearance: Sharp lighting transitions mimic the look of low-poly models and limited GPU capabilities.
Shader Code: Gouraud Shading in Unity
Here’s a custom shader that replicates Gouraud shading:
Shader "Custom/GouraudShading" { Properties { _Color ("Base Color", Color) = (1, 1, 1, 1) _SpecularColor ("Specular Color", Color) = (1, 1, 1, 1) _Shininess ("Shininess", Float) = 10 } SubShader { Tags { "RenderType"="Opaque" } LOD 200 Pass { Name "FORWARD" Tags { "LightMode" = "ForwardBase" } CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" #include "Lighting.cginc" float4 _Color; float4 _SpecularColor; float _Shininess; struct appdata { float4 vertex : POSITION; float3 normal : NORMAL; }; struct v2f { float4 pos : SV_POSITION; fixed4 color : COLOR; // Interpolated vertex color }; // Vertex Shader v2f vert(appdata v) { v2f o; // Transform vertex to world space float3 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz; // Transform normal to world space float3 worldNormal = UnityObjectToWorldNormal(v.normal); // Get light direction (assuming directional light) float3 lightDir = _WorldSpaceLightPos0.xyz; // Normalize vectors worldNormal = normalize(worldNormal); lightDir = normalize(lightDir); // Diffuse lighting (Lambertian reflectance) float diff = max(0, dot(worldNormal, lightDir)); float3 diffuse = diff * _LightColor0.rgb; // Specular lighting (Blinn-Phong approximation) float3 viewDir = normalize(_WorldSpaceCameraPos - worldPos); float3 halfDir = normalize(lightDir + viewDir); float spec = pow(max(0, dot(worldNormal, halfDir)), _Shininess); float3 specular = spec * _SpecularColor.rgb; // Combine lighting components float3 finalLighting = (diffuse + specular) * _Color.rgb; // Output interpolated color o.color = float4(finalLighting, 1.0); o.pos = UnityObjectToClipPos(v.vertex); return o; } // Fragment Shader fixed4 frag(v2f i) : SV_Target { return i.color; // Use interpolated vertex color } ENDCG } } FallBack "Diffuse" }
How It Works
-
Vertex Shader (
vert):- Calculates diffuse and specular lighting at each vertex using the normal and light direction.
- Combines the base color (
_Color) with the computed lighting. - Outputs the final vertex color (
o.color), which is interpolated across the triangle.
-
Fragment Shader (
frag):- Simply outputs the interpolated color from the vertex shader (
i.color), creating the Gouraud-shaded look.
- Simply outputs the interpolated color from the vertex shader (
Visual Characteristics
- Faceted Lighting: Sharp transitions between triangle faces due to per-vertex lighting.
- Low-Poly Aesthetic: Best visible on models with few polygons (e.g., a low-poly sphere).
- Specular Highlights: Positioned at vertices, creating a "blocky" highlight effect.
Setup in Unity
-
Create the Shader:
- Save the code above as
GouraudShading.shader. - Create a new material and assign the shader to it.
- Save the code above as
-
Apply to a Model:
- Use a low-poly model (or enable
Wireframemode in the scene view for debugging). - Adjust
_Color,_SpecularColor, and_Shininessin the material inspector.
- Use a low-poly model (or enable
-
Lighting:
- Ensure a directional light is present in the scene.
- Gouraud shading works best with simple lighting setups.
Tips for Authentic Retro Look
- Disable Anti-Aliasing: Go to
Edit > Project Settings > Qualityand set Anti-Aliasing toNone. - Use Low-Poly Models: High-poly meshes will look smoother and lose the Gouraud effect.
- Add Screen-Space Effects: Use post-processing like pixelation or scanlines for extra retro flair.
Why This Mimics N64/PS1 Shading
- Hardware Limitations: Older GPUs couldn’t compute per-pixel lighting, so they relied on per-vertex calculations.
- Interpolation Artifacts: The visible seams between triangles are a hallmark of Gouraud shading.
- Simplified Lighting: Diffuse and specular highlights are calculated in a way that matches early 3D pipelines.
By using this shader, you’ll achieve the iconic look of 90s/2000s 3D graphics while leveraging Unity’s flexibility for modern development! 🎮
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.