Skip to content

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

Open
Noa3 wants to merge 1 commit intoComplementaryDevelopment:mainfrom
Noa3:SSGI
Open

Add Screen-Space Global Illumination (SSGI) with configurable quality tiers#287
Noa3 wants to merge 1 commit intoComplementaryDevelopment:mainfrom
Noa3:SSGI

Conversation

@Noa3
Copy link

@Noa3 Noa3 commented Feb 19, 2026

i deleted the old fork because i fucked too much with it around, this is the backup and same changes as #286

Changes:

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 review requested due to automatic review settings February 19, 2026 06:11
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 pull request adds Screen-Space Global Illumination (SSGI) to the Complementary Shaders pack, providing an approximation of indirect diffuse lighting through screen-space ray marching. The implementation introduces configurable quality tiers and allows users to adjust the strength and radius of the global illumination effect.

Changes:

  • Added SSGI implementation with 4 quality tiers (OFF, Low, Medium, High) using different ray and step counts
  • Integrated SSGI into the deferred rendering pipeline after SSAO
  • Added configuration options for SSGI quality, strength, and radius with profile-specific defaults
  • Minor cleanup replacing manual distance calculation with built-in length() function

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/lib/lighting/screenSpaceGI.glsl New file implementing SSGI with cosine-weighted hemisphere sampling and depth-aware ray marching
shaders/program/deferred1.glsl Integration of SSGI into deferred rendering pass with conditional compilation
shaders/lib/common.glsl Added RT_SUNLIGHT_TRACING, RT_GI_STRENGTH, and RT_GI_RADIUS defines with SSGI_ENABLED conditional
shaders/shaders.properties Added RT_SUNLIGHT_TRACING to profiles, created RT_LIGHTING_SETTINGS submenu, registered sliders
shaders/lang/en_US.lang Added localization strings for SSGI settings and descriptions
shaders/lib/lighting/shadowSampling.glsl Refactored distance calculation to use built-in length() function

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

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 19, 2026

Choose a reason for hiding this comment

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

Coordinate space transformation error: sampleDir is already in view space after being generated by CosWeightedHemisphereDir (which works in the normal's tangent space), but line 55 incorrectly applies gbufferModelView again. Since normalM is already in view space (transformed at line 236 of deferred1.glsl), the hemisphere sampling produces view-space directions. Applying gbufferModelView again would transform from view space to... an undefined space. Line 55 should be removed, and sampleDir should be used directly as viewDir.

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

Copilot uses AI. Check for mistakes.
#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 19, 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 for a Screen-Space Global Illumination feature. The setting doesn't trace sunlight specifically—it traces indirect diffuse lighting from all visible surfaces. Consider renaming to RT_GI_QUALITY, SSGI_QUALITY, or similar to accurately reflect what this setting controls. The same applies to RT_SUNLIGHT_QUALITY at line 493 of common.glsl.

Suggested change
#define RT_SUNLIGHT_TRACING 0 //[0 1 2 3]
#define RT_GI_QUALITY 0 //[0 1 2 3]
#define RT_SUNLIGHT_TRACING RT_GI_QUALITY // Backwards compatibility: deprecated, use RT_GI_QUALITY

Copilot uses AI. Check for mistakes.
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.

1 participant

Comments