Skip to content

Commit

Permalink
Merge pull request #3012 from e2002e/gi_clipmaps
Browse files Browse the repository at this point in the history
Gi clipmaps
  • Loading branch information
luboslenco authored May 10, 2024
2 parents 1b27bf2 + cbd03a4 commit 63a3171
Show file tree
Hide file tree
Showing 39 changed files with 2,981 additions and 481 deletions.
2 changes: 1 addition & 1 deletion Shaders/custom_mat_presets/custom_mat_deferred.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void main() {
#ifdef _EmissionShaded
fragColor[GBUF_IDX_EMISSION] = vec4(emissionCol, 0.0);
#endif

#ifdef _SSRefraction
fragColor[GBUF_IDX_REFRACTION] = vec4(ior, opacity, 0.0, 0.0);
#endif
Expand Down
95 changes: 48 additions & 47 deletions Shaders/deferred_light/deferred_light.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#ifdef _Irr
#include "std/shirr.glsl"
#endif
#ifdef _VoxelAOvar
#ifdef _VoxelShadow
#include "std/conetrace.glsl"
#endif
#ifdef _SSS
Expand All @@ -21,22 +21,25 @@
uniform sampler2D gbufferD;
uniform sampler2D gbuffer0;
uniform sampler2D gbuffer1;

#ifdef _gbuffer2
uniform sampler2D gbuffer2;
#endif
#ifdef _EmissionShaded
uniform sampler2D gbufferEmission;
#endif

#ifdef _VoxelAOvar
uniform sampler3D voxels;
#ifdef _VoxelGI
uniform sampler2D voxels_diffuse;
uniform sampler2D voxels_specular;
#endif
#ifdef _VoxelGITemporal
uniform sampler3D voxelsLast;
uniform float voxelBlend;
#ifdef _VoxelAOvar
uniform sampler2D voxels_ao;
#endif
#ifdef _VoxelGICam
uniform vec3 eyeSnap;
#ifdef _VoxelShadow
uniform float clipmaps[voxelgiClipmapCount * 10];
uniform sampler3D voxels;
uniform sampler3D voxelsSDF;
#endif

uniform float envmapStrength;
Expand Down Expand Up @@ -273,26 +276,31 @@ void main() {

envl.rgb *= envmapStrength * occspec.x;

#ifdef _VoxelAOvar

#ifdef _VoxelGICam
vec3 voxpos = (p - eyeSnap) / voxelgiHalfExtents;
#else
vec3 voxpos = p / voxelgiHalfExtents;
#endif

#ifndef _VoxelAONoTrace
#ifdef _VoxelGITemporal
envl.rgb *= 1.0 - (traceAO(voxpos, n, voxels) * voxelBlend +
traceAO(voxpos, n, voxelsLast) * (1.0 - voxelBlend));
#else
envl.rgb *= 1.0 - traceAO(voxpos, n, voxels);
#endif
#endif
#ifdef _VoxelGI
fragColor.rgb = textureLod(voxels_diffuse, texCoord, 0.0).rgb * voxelgiDiff * albedo;
if(roughness < 1.0 && occspec.y > 0.0)
fragColor.rgb += textureLod(voxels_specular, texCoord, 0.0).rgb * voxelgiRefl * occspec.y;
#endif

#ifdef _VoxelAOvar
envl.rgb *= 1.0 - textureLod(voxels_ao, texCoord, 0.0).r;
#endif

#ifndef _VoxelGI
fragColor.rgb = envl;
#endif
// Show voxels
// vec3 origin = vec3(texCoord * 2.0 - 1.0, 0.99);
// vec3 direction = vec3(0.0, 0.0, -1.0);
// vec4 color = vec4(0.0f);
// for(uint step = 0; step < 400 && color.a < 0.99f; ++step) {
// vec3 point = origin + 0.005 * step * direction;
// color += (1.0f - color.a) * textureLod(voxels, point * 0.5 + 0.5, 0);
// }
// fragColor.rgb += color.rgb;

// Show SSAO
// fragColor.rgb = texture(ssaotex, texCoord).rrr;

#ifdef _SSAO
// #ifdef _RTGI
Expand Down Expand Up @@ -320,19 +328,6 @@ void main() {
#endif
#endif

// Show voxels
// vec3 origin = vec3(texCoord * 2.0 - 1.0, 0.99);
// vec3 direction = vec3(0.0, 0.0, -1.0);
// vec4 color = vec4(0.0f);
// for(uint step = 0; step < 400 && color.a < 0.99f; ++step) {
// vec3 point = origin + 0.005 * step * direction;
// color += (1.0f - color.a) * textureLod(voxels, point * 0.5 + 0.5, 0);
// }
// fragColor.rgb += color.rgb;

// Show SSAO
// fragColor.rgb = texture(ssaotex, texCoord).rrr;

#ifdef _Sun
vec3 sh = normalize(v + sunDir);
float sdotNH = max(0.0, dot(n, sh));
Expand Down Expand Up @@ -373,12 +368,10 @@ void main() {
#endif
#endif

#ifdef _VoxelAOvar
#ifdef _VoxelShadow
svisibility *= 1.0 - traceShadow(voxels, voxpos, sunDir);
svisibility *= 1.0 - traceShadow(p, n, voxels, voxelsSDF, sunDir, clipmaps);
#endif
#endif


#ifdef _SSRS
// vec2 coords = getProjectedCoord(hitCoord);
// vec2 deltaCoords = abs(vec2(0.5, 0.5) - coords.xy);
Expand Down Expand Up @@ -440,10 +433,10 @@ void main() {
#ifdef _Spot
, true, spotData.x, spotData.y, spotDir, spotData.zw, spotRight
#endif
#ifdef _VoxelAOvar
#ifdef _VoxelShadow
, voxels, voxpos
#endif
, voxels
, voxelsSDF
, clipmaps
#endif
#ifdef _MicroShadowing
, occspec.x
Expand Down Expand Up @@ -500,10 +493,10 @@ void main() {
, vec2(lightsArray[li * 3].w, lightsArray[li * 3 + 1].w) // scale
, lightsArraySpot[li * 2 + 1].xyz // right
#endif
#ifdef _VoxelAOvar
#ifdef _VoxelShadow
, voxels, voxpos
#endif
, voxels
, voxelsSDF
, clipmaps
#endif
#ifdef _MicroShadowing
, occspec.x
Expand All @@ -515,5 +508,13 @@ void main() {
}
#endif // _Clusters

/*
#ifdef _VoxelRefract
if(opac < 1.0) {
vec3 refraction = traceRefraction(p, n, voxels, v, ior, roughness, eye) * voxelgiRefr;
fragColor.rgb = mix(refraction, fragColor.rgb, opac);
}
#endif
*/
fragColor.a = 1.0; // Mark as opaque
}
12 changes: 6 additions & 6 deletions Shaders/deferred_light/deferred_light.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@
"name": "eye",
"link": "_cameraPosition"
},
{
"name": "eyeSnap",
"link": "_cameraPositionSnap",
"ifdef": ["_VoxelGICam"]
},
{
"name": "voxelBlend",
"link": "_voxelBlend",
"ifdef": ["_VoxelGITemporal"]
"ifdef": ["_VoxelTemporal"]
},
{
"name": "eyeLook",
"link": "_cameraLook"
},
{
"name": "clipmaps",
"link": "_clipmaps",
"ifdef": ["VoxelShadow"]
},
{
"name": "invVP",
"link": "_inverseViewProjectionMatrix"
Expand Down
2 changes: 1 addition & 1 deletion Shaders/smaa_blend_weight/smaa_blend_weight.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ vec4 SMAABlendingWeightCalculationPS(vec2 texcoord, vec2 pixcoord,
// one of the boundaries is enough.
weights.rg = SMAACalculateDiagWeights(texcoord, e, subsampleIndices);

// We give priority to diagonals, so if we find a diagonal we skip
// We give piority to diagonals, so if we find a diagonal we skip
// horizontal/vertical processing.
//SMAA_BRANCH
if (weights.r == -weights.g) { // weights.r + weights.g == 0.0
Expand Down
1 change: 1 addition & 0 deletions Shaders/ssrefr_pass/ssrefr_pass.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ void main() {
vec3 n;
n.z = 1.0 - abs(enc.x) - abs(enc.y);
n.xy = n.z >= 0.0 ? enc.xy : octahedronWrap(enc.xy);
n = normalize(n);

vec3 viewNormal = V3 * n;
vec3 viewPos = getPosView(viewRay, d, cameraProj);
Expand Down
Loading

0 comments on commit 63a3171

Please sign in to comment.