Skip to content

Add Screen-Space Global Illumination (SSGI) with configurable quality tiers#286

Open
Noa3 wants to merge 6 commits intoComplementaryDevelopment:mainfrom
Noa3:main
Open

Add Screen-Space Global Illumination (SSGI) with configurable quality tiers#286
Noa3 wants to merge 6 commits intoComplementaryDevelopment:mainfrom
Noa3:main

Conversation

@Noa3
Copy link

@Noa3 Noa3 commented Feb 13, 2026

Adds a screen-space path tracing approximation for indirect diffuse lighting. Rays are marched in screen space from each fragment along cosine-weighted hemisphere directions to gather light bounces from nearby visible surfaces.
New option: RT_SUNLIGHT_TRACING

Quality tiers: OFF / Low (2 rays, 6 steps) / Medium (3 rays, 8 steps) / High (4 rays, 12 steps)
RT_GI_STRENGTH: Intensity slider (25–200%)
RT_GI_RADIUS: Ray march distance (1.0–8.0 blocks)

Core implementation (lib/lighting/screenSpaceGI.glsl)

Cosine-weighted hemisphere sampling with golden-ratio-based quasi-random sequences
Depth-aware intersection with thickness threshold to reject back-face hits
Uses texelFetch and precomputed invSteps/farMinusNear to minimize per-fragment work

Integration

Injected in deferred1.glsl after SSAO, before PBR reflections — reuses linearZ0 when SSAO/outlines already computed it
shaders.properties: new RT_LIGHTING_SETTINGS submenu under Lighting, profile defaults (OFF through High, Low for VeryHigh, Medium for Ultra), slider registration
en_US.lang: display names and descriptions for all three settings

Minor cleanup

shadowSampling.glsl: sqrt(x*x + y*y) → length(xy)

Copilot AI and others added 4 commits February 13, 2026 20:16
- New lib/lighting/screenSpaceGI.glsl with SSGI implementation
- New RT_SUNLIGHT_TRACING option (OFF/Low/Medium/High quality)
- New RT_GI_STRENGTH and RT_GI_RADIUS configurable settings
- Integrated into deferred1.glsl after SSAO pass
- Added RT_LIGHTING_SETTINGS submenu to Lighting Settings
- Added language strings for all new options
- Profile defaults: OFF for Potato-High, Low for VeryHigh, Medium for Ultra

Co-authored-by: Noa3 <8495084+Noa3@users.noreply.github.com>
Co-authored-by: Noa3 <8495084+Noa3@users.noreply.github.com>
Add Screen-Space Global Illumination (SSGI) with configurable quality tiers
Copilot AI review requested due to automatic review settings February 13, 2026 20:41
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds Screen-Space Global Illumination (SSGI) to approximate indirect diffuse lighting through screen-space ray marching. The implementation traces multiple rays per fragment along cosine-weighted hemisphere directions to gather light bounces from nearby visible surfaces.

Changes:

  • Adds SSGI with three quality tiers (Low: 2 rays/6 steps, Medium: 3 rays/8 steps, High: 4 rays/12 steps) plus configurable strength and radius sliders
  • Integrates SSGI into deferred1.glsl after SSAO and before PBR reflections, with optimizations to reuse linearZ0 when available
  • Updates shader properties, language files, and profile defaults (OFF for most profiles, Low for VeryHigh, Medium for Ultra)

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
shaders/shaders.properties Adds RT_SUNLIGHT_TRACING to all quality profiles, creates RT_LIGHTING_SETTINGS submenu, registers new sliders
shaders/lib/common.glsl Defines RT_SUNLIGHT_TRACING, RT_GI_STRENGTH, RT_GI_RADIUS options and enables SSGI_ENABLED when tracing is active
shaders/program/deferred1.glsl Integrates SSGI call after SSAO, transforms world normals to view space, applies GI with configurable strength
shaders/lib/lighting/screenSpaceGI.glsl Implements cosine-weighted hemisphere sampling and depth-aware ray marching with thickness threshold intersection testing
shaders/lib/lighting/shadowSampling.glsl Refactors distance calculation to use length() for improved readability
shaders/lang/en_US.lang Adds localized strings for RT_LIGHTING_SETTINGS menu and all three SSGI options

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

#define SSAO_I 100 //[0 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 110 120 130 140 150 160 170 180 190 200 220 240 260 280 300]
#define VANILLAAO_I 100 //[0 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 110 120 130 140 150 160 170 180 190 200 220 240 260 280 300]

#define RT_SUNLIGHT_TRACING 0 //[0 1 2 3]
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The define name RT_SUNLIGHT_TRACING is misleading and inconsistent with the feature it controls. This setting controls Screen-Space Global Illumination (SSGI) quality, not sunlight tracing. The name should be changed to something like RT_SSGI_QUALITY or SSGI_QUALITY to accurately reflect its purpose. This inconsistency also appears in shaders.properties (line 50) and could confuse future developers.

Suggested change
#define RT_SUNLIGHT_TRACING 0 //[0 1 2 3]
#define RT_SSGI_QUALITY 0 //[0 1 2 3]
// Backwards compatibility alias for legacy configs/shaders
#define RT_SUNLIGHT_TRACING RT_SSGI_QUALITY

Copilot uses AI. Check for mistakes.
float xi2 = fract(dither * 1.414 + float(i) * 0.381966);

vec3 sampleDir = CosWeightedHemisphereDir(normalM, xi1, xi2);
vec3 viewDir = mat3(gbufferModelView) * sampleDir;
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect coordinate space transformation. The sampleDir returned from CosWeightedHemisphereDir is already in view space (it's constructed in the tangent space of normalM, which is a view-space normal). Applying mat3(gbufferModelView) here incorrectly transforms it a second time. This line should simply be vec3 viewDir = sampleDir; or the transformation should be removed. This bug will cause rays to be traced in incorrect directions, significantly affecting the visual quality and correctness of the SSGI effect.

Suggested change
vec3 viewDir = mat3(gbufferModelView) * sampleDir;
vec3 viewDir = sampleDir;

Copilot uses AI. Check for mistakes.
@Noa3
Copy link
Author

Noa3 commented Feb 13, 2026

@copilot open a new pull request to apply changes based on the comments in this thread

@EminGT
Copy link
Member

EminGT commented Feb 13, 2026

Now this looks really interesting. Thank you very much for your contribution :) I will check this out in more detail when I get some other higher priority things finished

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.

3 participants