Skip to content

Add PBR rendering pipeline: GGX BRDF, Fresnel, tone mapping, environment sky#26

Merged
lienardale merged 8 commits into
masterfrom
claude/game-engine-rendering-eIHws
Mar 26, 2026
Merged

Add PBR rendering pipeline: GGX BRDF, Fresnel, tone mapping, environment sky#26
lienardale merged 8 commits into
masterfrom
claude/game-engine-rendering-eIHws

Conversation

@lienardale

Copy link
Copy Markdown
Owner

Upgrade miniRT toward an offline renderer with physically-based rendering:

  • PBR materials: metallic-roughness workflow with GGX/Cook-Torrance BRDF
    and Schlick Fresnel approximation (ft_pbr.c)
  • New material properties: metal:, rough:, emit: parsed from .rt files
  • ACES filmic tone mapping replaces simple gamma for HDR support (ft_argb.c)
  • Environment sky lighting with gradient hemisphere (ft_env.c)
  • Path tracer upgraded with Russian Roulette termination, emissive materials,
    and PBR-aware direct lighting
  • PBR shading integrated into interactive Phong renderer (ft_light.c)
  • PBR showcase scene (scenes/pbr_showcase.rt)

All 174 tests pass (452 assertions, 0 failures).

https://claude.ai/code/session_011AkHu1jxvYRN9F9pGfuF7f

claude added 8 commits March 25, 2026 23:34
…ent sky

Upgrade miniRT toward an offline renderer with physically-based rendering:

- PBR materials: metallic-roughness workflow with GGX/Cook-Torrance BRDF
  and Schlick Fresnel approximation (ft_pbr.c)
- New material properties: metal:, rough:, emit: parsed from .rt files
- ACES filmic tone mapping replaces simple gamma for HDR support (ft_argb.c)
- Environment sky lighting with gradient hemisphere (ft_env.c)
- Path tracer upgraded with Russian Roulette termination, emissive materials,
  and PBR-aware direct lighting
- PBR shading integrated into interactive Phong renderer (ft_light.c)
- PBR showcase scene (scenes/pbr_showcase.rt)

All 174 tests pass (452 assertions, 0 failures).

https://claude.ai/code/session_011AkHu1jxvYRN9F9pGfuF7f
… tool

- Fix clang-format issues in ft_light.c, ft_pathtrace.c, ft_pbr.c
- Regenerate all 19 regression reference BMPs for ACES tone mapping
- Add renders_preview/ with PNG versions of all renders for PR review
- Add tools/bmp_to_png.py script to automate BMP->PNG conversion

https://claude.ai/code/session_011AkHu1jxvYRN9F9pGfuF7f
Two issues caused existing scenes to lose colors and lighting:

1. Default roughness was 0.5, which activated PBR shading on ALL shapes
   even without explicit PBR properties. Fixed: default roughness = 0.0,
   so PBR is opt-in only (via metal:/rough: in .rt files).

2. ACES tone mapping was applied to all renders, compressing the standard
   Phong pipeline's [0,255] output. Fixed: ACES only activates for path
   tracing (HDR); standard rendering keeps the original gamma correction.

All 19 regression references are now pixel-identical to the pre-PBR originals.

https://claude.ai/code/session_011AkHu1jxvYRN9F9pGfuF7f
- Fix upside-down renders: remove rot_z=-1 (180° roll) from new_shapes.rt
  and pbr_showcase.rt camera orientations
- Add 'E' scene directive to enable environment sky gradient background
  (opt-in, existing scenes unchanged)
- Standard renderer returns sky color for ray misses when E is set
- Redesign new_shapes.rt: camera at elevated position looking down,
  objects well-spaced, two lights, sky background
- Redesign pbr_showcase.rt: 3 rows (dielectric, metallic, mixed shapes),
  elevated overview camera, sky background, 1920x1080

18 unchanged regression scenes remain pixel-identical to originals.

https://claude.ai/code/session_011AkHu1jxvYRN9F9pGfuF7f
New test file tests/test_pbr.c with 25 tests (76 assertions) covering:
- ft_fresnel_schlick: head-on, grazing, 45deg, negative clamp, metal
- ft_env_sky: zenith, horizon, down, below-clamp directions
- ft_material_default: all 13 field defaults including new PBR fields
- ft_reflect_ray: straight-on and 45-degree reflection
- ft_refract_ray: normal incidence and total internal reflection
- ft_parse_material: metal:, rough:, emit:, combined, vel: keywords
- ft_pbr_shade: head-on dielectric, backface, metallic
- ft_light PBR branch: metallic/roughness triggers PBR path
- ft_trace_ray_recursive: env sky miss vs black miss

Coverage: 53.1% lines (1451/2735), 62.5% functions (150/240)
Total test suite: 199 tests, 528 assertions, 0 failures

https://claude.ai/code/session_011AkHu1jxvYRN9F9pGfuF7f
New scene:
- scenes/materials.rt: showcases ALL material properties in 3 rows:
  row 1 (spec, refl, trans+ior glass, trans+ior diamond),
  row 2 (PBR metal chrome/brushed/rough, glossy plastic),
  row 3 (emissive box, metallic+reflective cylinder, transparent cone)

Fix post-42 scenes to follow guidelines (elevated camera, sky background):
- quadrics.rt: remove rot_z=-1, add E, elevated camera
- new_shapes.rt: remove rot_z=-1, add E, elevated camera
- benchmark.rt: remove rot_z=1, add E, elevated camera at z=60
- dof_test.rt: add E for sky background
- motion_blur.rt: add E for sky background
- taurus.rt: add E for sky background
- cathedral_ruins.rt: add E for sky background

Original 42 project scenes (cylinder, exemple, inside_*, lights, objects,
square, tiny, triangle, error) left unchanged.

https://claude.ai/code/session_011AkHu1jxvYRN9F9pGfuF7f
Re-rendered saves/ for scenes with camera/sky fixes:
- new_shapes, quadrics, taurus (camera rot_z fix + E directive)
- benchmark (camera fix + E directive)

New saves/ for scenes that were missing:
- materials, pbr_showcase, dof_test, motion_blur, benchmark

Updated renders_preview/ PNGs from all 20 saves/ + 19 regression refs.
Cathedral render in progress (~1h at 2560x1440), will update separately.

https://claude.ai/code/session_011AkHu1jxvYRN9F9pGfuF7f
Scene fixes:
- quadrics.rt: spread objects wider (x=-8 to 8), camera higher (y=14)
  and further (z=24), pitch 0.15 for proper overhead view
- new_shapes.rt: spread objects wider (x=-12 to 12, 2 z-planes),
  camera at (0,14,28) with pitch 0.15

Documentation:
- skills/camera-and-rendering.md: add "Post-42 Scene Generation Rules"
  section with drone-view camera formula, sky background, object layout,
  and PBR material properties table
- CLAUDE.md: add "Development Workflow" section requiring lint/test/
  regression on every iteration, saves/ and renders_preview/ updates
  when scenes change

Updated saves/ and renders_preview/ for both changed scenes.
Lint OK, 199 tests pass, 19/19 regression pass.

https://claude.ai/code/session_011AkHu1jxvYRN9F9pGfuF7f
@lienardale
lienardale merged commit 35339bf into master Mar 26, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants