Learning Shaders: The Comprehensive Panda3D GLSL Laboratory
An end-to-end curriculum and interactive laboratory for learning real-time Computer Graphics and GLSL shaders using Python and the Panda3D game engine.
The repository spans from bare-minimum programmable pipeline foundations to advanced Physically Based Rendering (PBR), Cook-Torrance microfacet BRDFs, procedural vertex wave simulations, dynamic atmospheric skydomes, multi-layer terrain texture splatting, and complete real-time water shaders with offscreen render-to-texture (RTT) reflections and refractions.
Every individual shader lesson is isolated inside its own dedicated sub-directory with its runnable Python driver, GLSL vertex and fragment shaders, and an in-depth lesson README.md tutorial.
🗂️ Curriculum & Module Index
The repository is organized into 10 structured, progressive modules containing 56 self-contained shader lessons:
| # |
Module Directory |
Focus & Core Techniques |
Key Mathematical Models |
| 01 |
01-minimal-shaders |
GLSL program structure, MVP matrix transform, vertex attributes, uniforms, texture sampling, alpha testing, UV distortion. |
$\mathbf{v}_{\text{clip}} = \mathbf{M}_{\text{MVP}} \cdot \mathbf{v}$ |
| 02 |
02-vertex-deformations |
Procedural vertex shader displacement, sine waves, directional waves, height-dependent torsional twists, normal extrusion, radial explosions. |
$y' = y + \sin(x\omega + ts)A, \quad \mathbf{R}_{\text{twist}}(z)$ |
| 03 |
03-lambert-lighting |
Matte surface reflectance, Johann Heinrich Lambert’s cosine law, ambient light fill, material base color modulation, textured diffuse shading. |
$I = \max(\mathbf{N} \cdot \mathbf{L}, 0.0) + k_a$ |
| 04 |
04-phong-lighting |
Bui Tuong Phong’s classical illumination model: Ambient, Diffuse, and view-dependent Specular highlights via reflection vectors. |
$I_{\text{spec}} = \max(\mathbf{R} \cdot \mathbf{V}, 0)^\alpha$ |
| 05 |
05-blinn-phong-lighting |
Jim Blinn’s halfway vector formulation ($\mathbf{H}$), localized 3D point lights, inverse-square physical distance attenuation. |
$I_{\text{spec}} = \max(\mathbf{N} \cdot \mathbf{H}, 0)^\beta, \quad \frac{1}{d^2}$ |
| 06 |
06-legacy-pipeline |
GLSL emulations of OpenGL 1.x / 2.x fixed-function pipeline: unlit/shadeless, texture stage modulation, directional lights, linear & exponential depth fog. |
$f = e^{-(\text{density} \cdot d)}$ |
| 07 |
07-pbr-pipeline |
Modern Physically Based Rendering (PBR) metallic-roughness workflow, Cook-Torrance microfacet BRDF, GGX distribution, Schlick geometry & Fresnel, MER texture unpacking. |
$f_r = \frac{D \cdot F \cdot G}{4(\mathbf{N}\cdot\mathbf{L})(\mathbf{N}\cdot\mathbf{V})}$ |
| 08 |
08-sky-rendering |
Cubic static skyboxes, hemispherical panoramic skydomes, and dynamic atmospheric skies with animated scrolling clouds and solar day/night tracking. |
$\text{mix}(\mathbf{C}_{\text{horizon}}, \mathbf{C}_{\text{zenith}}, h)$ |
| 09 |
09-legacy-terrain-water |
Multi-texture terrain splatting, lake basin placement, DuDv flow distortion, normal mapped ripple glints, Fresnel mixing, dual RTT reflection/refraction, soft depth shoreline edges. |
$F(\theta), \quad \Delta z = z_{\text{terr}} - z_{\text{water}}$ |
| 10 |
10-pbr-terrain-water |
Physically based landscape splatting, Cook-Torrance water reflections, dielectric Fresnel ($F_0 = 0.02$), microfacet sun streaks, and underwater light absorption (Beer-Lambert law). |
$\mathbf{T}(d) = e^{-\boldsymbol{\sigma}_a \cdot d}$ |
🚀 Quick start
Prerequisites
- Python 3.8+ installed on your system.
- An OpenGL 3.2+ Core Profile capable GPU.
1. Installation
Clone this repository and create a virtual environment:
git clone https://github.com/ShivamKR12/Learning-Shaders.git
cd Learning-Shaders
Create and activate a virtual environment:
# Windows (PowerShell):
python -m venv venv
.\venv\Scripts\Activate.ps1
# Linux / macOS:
python3 -m venv venv
source venv/bin/activate
Install requirements:
pip install -r requirements.txt
2. Running Individual Lessons
Every lesson lives in its own dedicated sub-directory with all needed shaders, assets, camera controls, and configurations. Navigate into any lesson folder to run it:
# Minimal programmable pipeline demo
cd 01-minimal-shaders/01-working-shader
python Minimal-Working-Shader.py
# Phong specular reflections
cd ../../04-phong-lighting/02-diffuse-ambient-specular
python Phong-Diffuse+Ambient+Specular-Lighting.py
# Cook-Torrance PBR BRDF
cd ../../07-pbr-pipeline/04-cook-torrance-brdf
python Pbr-CookTorranceBrdf-Lighting.py
# Dynamic Skydome with cloud animation
cd ../../08-sky-rendering/03-dynamic-skydome
python ShadelessSky-DynamicSkydome-Rendering.py
# Advanced real-time water simulation
cd ../../09-legacy-terrain-water/05-reflection-and-refraction
python LegacyTerrain-ReflectionAndRefraction-Rendering.py
🕹️ Global Camera & Viewport Controls
All interactive 3D demos are equipped with a Blender-style free-fly camera controller (cam.py):
| Input |
Action |
| W / S |
Fly Camera Forward / Backward |
| A / D |
Strafe Camera Left / Right |
| Q / E |
Move Camera Down / Up vertically |
| Hold RMB + Move Mouse |
Free-fly Mouse Look (pitch and yaw rotation) |
| Esc |
Release Mouse Pointer / Unlock cursor |
🛠️ Repository Layout
Learning-Shaders/
├── 01-minimal-shaders/ # Basic GLSL pipeline, uniforms, textures, discard
│ ├── 01-working-shader/
│ ├── 02-pass-through/
│ ├── 03-tint/
│ ├── 04-pulse/
│ ├── 05-texture/
│ ├── 06-alpha-cutoff/
│ └── 07-uv-distortion/
├── 02-vertex-deformations/ # GPU vertex animations, waves, twists, pulses
│ ├── 01-y-wave/
│ ├── 02-directional-wave/
│ ├── 03-height-twist/
│ ├── 04-normal-pulse/
│ └── 05-radial-explosion/
├── 03-lambert-lighting/ # Matte diffuse Lambertian cosine reflectance
│ ├── 01-diffuse/
│ ├── 02-diffuse-ambient/
│ ├── 03-diffuse-ambient-base-color/
│ └── 04-diffuse-ambient-texture/
├── 04-phong-lighting/ # Glossy specular highlights via reflection vectors
│ ├── 01-diffuse-specular/
│ ├── 02-diffuse-ambient-specular/
│ ├── 03-diffuse-ambient-specular-base-color/
│ └── 04-diffuse-ambient-specular-texture/
├── 05-blinn-phong-lighting/ # Halfway vector formulation & 3D point lights
│ ├── 01-point-light/
│ └── 02-directional-halfway/
├── 06-legacy-pipeline/ # Fixed-function pipeline emulation & hardware fog
│ ├── 01-scene-setup/
│ ├── 02-shadeless-rendering/
│ ├── 03-ambient-lighting/
│ ├── 04-diffuse-lighting/
│ ├── 05-specular-lighting/
│ ├── 06-texture/
│ └── 07-fog/
├── 07-pbr-pipeline/ # Physically Based Rendering & Cook-Torrance BRDF
│ ├── 01-scene-setup/
│ ├── 02-shadeless-rendering/
│ ├── 03-ambient-lighting/
│ ├── 04-cook-torrance-brdf/
│ ├── 05-texture/
│ ├── 06-fog/
│ └── 07-mer-map/
├── 08-sky-rendering/ # Static skyboxes, skydomes, and dynamic skies
│ ├── 01-static-skybox/
│ ├── 02-static-skydome/
│ └── 03-dynamic-skydome/
├── 09-legacy-terrain-water/ # Terrain splatting, DuDv water, RTT reflections
│ ├── 01-scene-setup/
│ ├── 02-texture-splatting/
│ ├── 03-water-plane/
│ ├── 04-water-shader/
│ ├── 05-reflection-and-refraction/
│ ├── 06-distortion/
│ ├── 07-normal-mapping/
│ ├── 08-fresnel/
│ └── 09-soft-edges/
├── 10-pbr-terrain-water/ # PBR terrain splatting, microfacet water, Beer's law
│ ├── 01-scene-setup/
│ ├── 02-texture-splatting/
│ ├── 03-water-plane/
│ ├── 04-water-shader/
│ ├── 05-reflection-and-refraction/
│ ├── 06-distortion/
│ ├── 07-normal-mapping/
│ └── 08-fresnel/
├── models/ # Shared 3D models (glTF/egg), terrain, textures, maps
├── cam.py # Blender-style free-fly camera module
├── Config.prc # Panda3D runtime configuration
├── requirements.txt # Python dependencies (panda3d)
├── RoadMap.md # Complete pedagogical roadmap & learning syllabus
├── GLSL-Grammer-Rules.md # Desktop GLSL syntax and grammar specification
├── GLSL_ES-Grammer-Rules.md # Embedded Systems GLSL ES syntax rules
└── README.md # Root documentation and laboratory index
📚 Supplementary Documentation
RoadMap.md: Step-by-step 16-stage learning curriculum from beginner to advanced shader authoring.
GLSL-Grammer-Rules.md: Detailed reference guide on GLSL variables, types, swizzling, vector operations, and built-in functions.
GLSL_ES-Grammer-Rules.md: Reference guide covering OpenGL ES qualifiers, precision statements, and mobile GPU constraints.
📜 Credits & Tech Stack
- Game Engine: Panda3D
- Shading Language: OpenGL Shading Language (GLSL 1.50 / GLSL ES 3.00)
- Programming Language: Python 3
评论