Command Palette

Search for a command to run...

Back to skills
skill № 34866

forge-pbr-shading

Add Cook-Torrance PBR shading with GGX, Schlick-GGX, and Schlick Fresnel to an SDL GPU project alongside forge_scene.h

FreeNo executable scripts
Nebulavenusby Nebulavenus★ 51 GitHub stars

Install forge-pbr-shading in Claude Code & Claude Desktop

Sign up to install this skill

Create a free account to reveal the install command and save the skill to your library.

  • Reveal the one-line install command
  • Save skills to your synced library
  • Get notified when skills update
Sign up freeI already have an account

About this skill

Add physically-based rendering to an SDL GPU project. Implements a Cook-Torrance microfacet BRDF fragment shader that uses the same texture bindings and uniform layout as forge_scene.h's built-in model pipeline, enabling side-by-side comparison with Blinn-Phong.

When to use

  • Replacing Blinn-Phong with physically-based shading
  • Adding metallic-roughness material support
  • Comparing different lighting models on the same geometry
  • Creating a custom pipeline that coexists with forge_scene.h

Key API calls

  • forge_scene_create_shader() — create vertex/fragment shaders from bytecode
  • SDL_CreateGPUGraphicsPipeline() — create custom pipeline matching model vertex layout
  • SDL_BindGPUFragmentSamplers() — bind per-material textures with fallbacks
  • SDL_PushGPUFragmentUniformData() — push material uniform data to fragment shader
  • forge_scene_load_model() — load pipeline-processed model
  • forge_scene_draw_model() — draw with built-in Blinn-Phong for comparison

Correct order

  1. Load model via forge_scene_load_model()
  2. Create PBR fragment shader from compiled bytecode
  3. Create vertex shader from scene_model_vert_spirv/dxil/msl (available via FORGE_SCENE_IMPLEMENTATION)
  4. Create pipeline with model vertex layout using sizeof(ForgeSceneModelVertex) for pitch and offsetof() for attribute offsets
  5. Release shaders after pipeline creation
  6. Per frame: bind custom pipeline, iterate model submeshes, push uniforms with overridden PBR parameters, bind textures, draw

Cook-Torrance BRDF components

/* GGX Normal Distribution */
float D = alpha2 / (PI * pow(NdotH * NdotH * (alpha2 - 1.0) + 1.0, 2.0));

/* Schlick-GGX Geometry (Smith method) */
float k = (roughness + 1.0) * (roughness + 1.0) / 8.0;
float G = (NdotV / (NdotV * (1-k) + k)) * (NdotL / (NdotL * (1-k) + k));

/* Schlick Fresnel */
float3 F = F0 + (1.0 - F0) * pow(1.0 - VdotH, 5.0);

/* Full specular: D * G * F / (4 * NdotV * NdotL) */
/* Energy-conserving diffuse: (1 - F) * (1 - metallic) * albedo / PI */

Common mistakes

  • F0 for metals must use albedo color — lerp(0.04, albedo, metallic), not a fixed 0.04 for all materials
  • alpha = roughness^2, not roughness — GGX uses squared roughness
  • k differs for direct vs IBL lighting — direct: (r+1)^2/8, IBL: r^2/2
  • Divide-by-zero guard — clamp NdotV above zero (e.g. 0.001) in the Cook-Torrance denominator
  • Diffuse must divide by pi — without this, the surface reflects more energy than it receives

Reference

See Lesson 51 — PBR Shading Model for the full implementation.

Full SKILL.md on GitHub

Allowed tools

Tools this skill is permitted to call.

No restriction — this skill can use any tool.

FAQ

What does the forge-pbr-shading skill do?

Add Cook-Torrance PBR shading with GGX, Schlick-GGX, and Schlick Fresnel to an SDL GPU project alongside forge_scene.h

How do I install the forge-pbr-shading skill?

Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.

Does the forge-pbr-shading skill run scripts?

No, this skill is instructions only (SKILL.md) with no executable scripts.

Related skills

Compare forge-pbr-shading with