Mithila Games
GRAPHICS SHADERS 2026-09-28 • 5 MIN READ

Writing Custom Shaders: Demystifying Vertex, Fragment & Screen-Space Distortion

MG
Divyanshu Priyadarshi Mithila Games Studio
Writing Custom Shaders: Demystifying Vertex, Fragment & Screen-Space Distortion

Step-by-step introduction to writing custom shader math: UV coordinates, sin-wave vertex displacements, and screen-space chromatic aberration.

Shaders are not magic—they are simply mathematical functions executed in parallel across thousands of GPU cores. Mastering vertex and fragment shader mathematics allows technical artists to create breathtaking water ripples, forcefields, dissolving shields, and stylized post-processing effects with near-zero CPU overhead.

1. The Graphics Pipeline: Vertex vs Fragment

2. Writing a Water Vertex Wave Shader (Godot Shader Language)

shader_type spatial;

uniform float wave_speed : hint_range(0.1, 5.0) = 1.5;
uniform float wave_height : hint_range(0.0, 2.0) = 0.3;
uniform float wave_frequency : hint_range(0.1, 10.0) = 2.0;

void vertex() {
    // Calculate wave displacement along the Y-axis using sinusoidal UV math
    float wave = sin((VERTEX.x * wave_frequency) + (TIME * wave_speed)) 
               * cos((VERTEX.z * wave_frequency) + (TIME * wave_speed));
    
    VERTEX.y += wave * wave_height;
    
    // Recalculate normal vectors so lighting aligns with displaced surface
    NORMAL = normalize(vec3(
        -cos((VERTEX.x * wave_frequency) + (TIME * wave_speed)) * wave_height,
        1.0,
        -sin((VERTEX.z * wave_frequency) + (TIME * wave_speed)) * wave_height
    ));
}

void fragment() {
    ALBEDO = vec3(0.05, 0.35, 0.65); // Deep ocean cyan
    ROUGHNESS = 0.1;                  // Mirror-like reflections
    METALLIC = 0.0;
}
TOPICS: #shaders#glsl#hlsl#graphics#vfx#math
TRANSMISSION CONCLUDED

More Studio Devlogs & Technical Reports

Explore tutorials on Godot 4, Blender 3D pipelines, GTA 6 architectural breakdowns, and anti-cheat.

VIEW ALL 44 DEVLOGS →