Skip to content

Commit

Permalink
bump gi_clipmaps !
Browse files Browse the repository at this point in the history
  • Loading branch information
e2002e committed May 6, 2024
1 parent bb0ff6d commit 73b557f
Show file tree
Hide file tree
Showing 211 changed files with 9,602 additions and 3,277 deletions.
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root = true

[*]
charset = utf-8
tab_width = 4
indent_style = tab

[*.py]
indent_size = 4
tab_width = 4
indent_style = space
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"editor.detectIndentation": false,
"editor.tabSize": 4,
"editor.insertSpaces": false
"editor.insertSpaces": false,
"[python]": {
"editor.insertSpaces": true
},
}
}
6 changes: 6 additions & 0 deletions Shaders/custom_mat_presets/custom_mat_deferred.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ void main() {
float specular = 1.0;
uint materialId = 0;
vec3 emissionCol = vec3(0.0);
float ior = 1.450;
float opacity = 1.0;

// Store in gbuffer (see layout table above)
fragColor[GBUF_IDX_0] = vec4(n.xy, roughness, packFloatInt16(metallic, materialId));
Expand All @@ -48,4 +50,8 @@ 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
}
99 changes: 50 additions & 49 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 @@ -233,15 +236,15 @@ void main() {
if (g2.b < 0.5) {
envl = envl;
} else {
envl = vec3(1.0);
envl = vec3(0.0);
}
#endif

#ifdef _EnvTex
envl /= PI;
#endif
#else
vec3 envl = vec3(1.0);
vec3 envl = vec3(0.0);
#endif

#ifdef _Rad
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
5 changes: 2 additions & 3 deletions Shaders/ssr_pass/ssr_pass.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ vec3 hitCoord;
float depth;

const int numBinarySearchSteps = 7;
const int maxSteps = 18;
const int maxSteps = int(ceil(1.0 / ssrRayStep) * ssrSearchDist);

vec2 getProjectedCoord(const vec3 hit) {
vec4 projectedCoord = P * vec4(hit, 1.0);
Expand All @@ -45,7 +45,6 @@ float getDeltaDepth(const vec3 hit) {

vec4 binarySearch(vec3 dir) {
float ddepth;
vec3 start = hitCoord;
for (int i = 0; i < numBinarySearchSteps; i++) {
dir *= 0.5;
hitCoord -= dir;
Expand Down Expand Up @@ -93,7 +92,7 @@ void main() {

vec3 viewNormal = V3 * n;
vec3 viewPos = getPosView(viewRay, d, cameraProj);
vec3 reflected = normalize(reflect(viewPos, viewNormal));
vec3 reflected = reflect(normalize(viewPos), viewNormal);
hitCoord = viewPos;

#ifdef _CPostprocess
Expand Down
106 changes: 106 additions & 0 deletions Shaders/ssrefr_pass/ssrefr_pass.frag.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#version 450

#include "compiled.inc"
#include "std/math.glsl"
#include "std/gbuffer.glsl"

uniform sampler2D tex;
uniform sampler2D tex1;
uniform sampler2D gbufferD;
uniform sampler2D gbuffer0;
uniform sampler2D gbufferD1;
uniform sampler2D gbuffer_refraction; // ior\opacity
uniform mat4 P;
uniform mat3 V3;
uniform vec2 cameraProj;

in vec3 viewRay;
in vec2 texCoord;
out vec4 fragColor;

vec3 hitCoord;
float depth;

const int numBinarySearchSteps = 7;
const int maxSteps = int(ceil(1.0 / ss_refractionRayStep) * ss_refractionSearchDist);

vec2 getProjectedCoord(const vec3 hit) {
vec4 projectedCoord = P * vec4(hit, 1.0);
projectedCoord.xy /= projectedCoord.w;
projectedCoord.xy = projectedCoord.xy * 0.5 + 0.5;
#ifdef _InvY
projectedCoord.y = 1.0 - projectedCoord.y;
#endif
return projectedCoord.xy;
}

float getDeltaDepth(const vec3 hit) {
depth = textureLod(gbufferD1, getProjectedCoord(hit), 0.0).r * 2.0 - 1.0;
vec3 viewPos = getPosView(viewRay, depth, cameraProj);
return viewPos.z - hit.z;
}

vec4 binarySearch(vec3 dir) {
float ddepth;
for (int i = 0; i < numBinarySearchSteps; i++) {
dir *= 0.5;
hitCoord -= dir;
ddepth = getDeltaDepth(hitCoord);
if (ddepth < 0.0) hitCoord += dir;
}
if (abs(ddepth) > ss_refractionSearchDist / 500) return vec4(0.0);
return vec4(getProjectedCoord(hitCoord), 0.0, 1.0);
}

vec4 rayCast(vec3 dir) {
float ddepth;
dir *= ss_refractionRayStep;
for (int i = 0; i < maxSteps; i++) {
hitCoord += dir;
ddepth = getDeltaDepth(hitCoord);
if (ddepth > 0.0) return binarySearch(dir);
}
return vec4(0.0);
}

void main() {
vec4 g0 = textureLod(gbuffer0, texCoord, 0.0);
float roughness = g0.z;
vec4 gr = textureLod(gbuffer_refraction, texCoord, 0.0);
float ior = gr.x;
float opac = gr.y;

float d = textureLod(gbufferD, texCoord, 0.0).r * 2.0 - 1.0;

if (d == 1.0 || ior == 1.0 || opac == 1.0) {
fragColor.rgb = textureLod(tex1, texCoord, 0.0).rgb;
return;
}

vec2 enc = g0.rg;
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);
vec3 refracted = refract(normalize(viewPos), viewNormal, 1.0 / ior);
hitCoord = viewPos;

vec3 dir = refracted * (1.0 - rand(texCoord) * ss_refractionJitter * roughness) * 2.0;

vec4 coords = rayCast(dir);
vec2 deltaCoords = abs(vec2(0.5, 0.5) - coords.xy);
float screenEdgeFactor = clamp(1.0 - (deltaCoords.x + deltaCoords.y), 0.0, 1.0);

float refractivity = 1.0;

float intensity = pow(refractivity, ss_refractionFalloffExp) * screenEdgeFactor * clamp((ss_refractionSearchDist - length(viewPos - hitCoord)) * (1.0 / ss_refractionSearchDist), 0.0, 1.0) * coords.w;

intensity = clamp(intensity, 0.0, 1.0);
vec3 refractionCol = textureLod(tex1, coords.xy, 0.0).rgb;
refractionCol = clamp(refractionCol, 0.0, 1.0);
vec3 color = textureLod(tex, texCoord.xy, 0.0).rgb;
fragColor.rgb = mix(refractionCol * intensity, color, opac);
}
Loading

0 comments on commit 73b557f

Please sign in to comment.