-
Notifications
You must be signed in to change notification settings - Fork 87
Add Screen-Space Global Illumination (SSGI) with configurable quality tiers #286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
7823ba6
f38c689
f364113
3d34303
964efed
a9af2da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,95 @@ | ||||||
| /* | ||||||
| Screen-Space Global Illumination (SSGI) / Ray-Traced Indirect Lighting | ||||||
| Approximates path-traced indirect diffuse lighting using screen-space ray marching. | ||||||
| Traces rays from each fragment in random hemisphere directions to gather | ||||||
| indirect light bounces from nearby surfaces visible on screen. | ||||||
| */ | ||||||
|
|
||||||
| vec3 CosWeightedHemisphereDir(vec3 normal, float xi1, float xi2) { | ||||||
| float r = sqrt(xi1); | ||||||
| float phi = 6.28318530718 * xi2; | ||||||
|
|
||||||
| vec3 sampleDir = vec3( | ||||||
| r * cos(phi), | ||||||
| r * sin(phi), | ||||||
| sqrt(max(1.0 - xi1, 0.0)) | ||||||
| ); | ||||||
|
|
||||||
| vec3 up = abs(normal.y) < 0.999 ? vec3(0.0, 1.0, 0.0) : vec3(1.0, 0.0, 0.0); | ||||||
| vec3 tangent = normalize(cross(up, normal)); | ||||||
| vec3 bitangent = cross(normal, tangent); | ||||||
|
|
||||||
| return tangent * sampleDir.x + bitangent * sampleDir.y + normal * sampleDir.z; | ||||||
| } | ||||||
|
|
||||||
| float DoScreenSpaceGlobalIllumination( | ||||||
| vec3 viewPos, vec3 normalM, float z0, float linearZ0, float dither, | ||||||
| out vec3 giColor | ||||||
| ) { | ||||||
| giColor = vec3(0.0); | ||||||
|
|
||||||
| if (z0 < 0.56 || z0 > 0.9999) return 0.0; // 0.56 = hand/entity depth cutoff used throughout the pack | ||||||
|
|
||||||
| #if RT_SUNLIGHT_QUALITY == 1 | ||||||
| const int samples = 2; | ||||||
| const int steps = 6; | ||||||
| #elif RT_SUNLIGHT_QUALITY == 2 | ||||||
| const int samples = 3; | ||||||
| const int steps = 8; | ||||||
| #else | ||||||
| const int samples = 4; | ||||||
| const int steps = 12; | ||||||
| #endif | ||||||
|
|
||||||
| float radius = RT_GI_RADIUS; | ||||||
| float invSteps = 1.0 / float(steps); | ||||||
| float thicknessThreshold = radius * 0.15 * invSteps; | ||||||
| float totalWeight = 0.0; | ||||||
| vec3 totalGI = vec3(0.0); | ||||||
|
|
||||||
| for (int i = 0; i < samples; i++) { | ||||||
| float xi1 = fract(dither + float(i) * 0.618033988); | ||||||
| float xi2 = fract(dither * 1.414 + float(i) * 0.381966); | ||||||
|
|
||||||
| vec3 sampleDir = CosWeightedHemisphereDir(normalM, xi1, xi2); | ||||||
| vec3 viewDir = mat3(gbufferModelView) * sampleDir; | ||||||
|
||||||
| vec3 viewDir = mat3(gbufferModelView) * sampleDir; | |
| vec3 viewDir = sampleDir; |
There was a problem hiding this comment.
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_TRACINGis 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 likeRT_SSGI_QUALITYorSSGI_QUALITYto accurately reflect its purpose. This inconsistency also appears in shaders.properties (line 50) and could confuse future developers.