From 1da793b822b3a78a6b75728680ebf94cc61c9837 Mon Sep 17 00:00:00 2001 From: luboslenco Date: Mon, 2 Dec 2019 14:45:31 +0100 Subject: [PATCH] Cleanup --- Shaders/std/clusters.glsl | 17 ----- Shaders/std/denoise.glsl | 56 -------------- Shaders/std/dof.glsl | 75 ------------------- Shaders/std/normals.glsl | 31 -------- Shaders/std/shadows.glsl | 149 -------------------------------------- Shaders/std/skinning.glsl | 29 -------- Shaders/std/ssrs.glsl | 37 ---------- 7 files changed, 394 deletions(-) delete mode 100644 Shaders/std/clusters.glsl delete mode 100644 Shaders/std/denoise.glsl delete mode 100644 Shaders/std/dof.glsl delete mode 100644 Shaders/std/normals.glsl delete mode 100644 Shaders/std/shadows.glsl delete mode 100644 Shaders/std/skinning.glsl delete mode 100644 Shaders/std/ssrs.glsl diff --git a/Shaders/std/clusters.glsl b/Shaders/std/clusters.glsl deleted file mode 100644 index 9da7a450..00000000 --- a/Shaders/std/clusters.glsl +++ /dev/null @@ -1,17 +0,0 @@ - -const int maxLights = 16; -const int maxLightsCluster = 4; // Ensure fast loop unroll before going higher -const float clusterNear = 3.0; -const vec3 clusterSlices = vec3(16, 16, 16); - -int getClusterI(vec2 tc, float viewz, vec2 cameraPlane) { - int sliceZ = 0; - float cnear = clusterNear + cameraPlane.x; - if (viewz >= cnear) { - float z = log(viewz - cnear + 1.0) / log(cameraPlane.y - cnear + 1.0); - sliceZ = int(z * (clusterSlices.z - 1)) + 1; - } - return int(tc.x * clusterSlices.x) + - int(int(tc.y * clusterSlices.y) * clusterSlices.x) + - int(sliceZ * clusterSlices.x * clusterSlices.y); -} diff --git a/Shaders/std/denoise.glsl b/Shaders/std/denoise.glsl deleted file mode 100644 index 8ab8095e..00000000 --- a/Shaders/std/denoise.glsl +++ /dev/null @@ -1,56 +0,0 @@ -//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -// Copyright (c) 2018-2019 Michele Morrone -// All rights reserved. -// -// https://michelemorrone.eu - https://BrutPitt.com -// -// me@michelemorrone.eu - brutpitt@gmail.com -// twitter: @BrutPitt - github: BrutPitt -// -// https://github.com/BrutPitt/glslSmartDeNoise/ -// -// This software is distributed under the terms of the BSD 2-Clause license -//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -#ifndef _DENOISE_GLSL_ -#define _DENOISE_GLSL_ - -#define INV_SQRT_OF_2PI 0.39894228040143267793994605993439 -#define INV_PI 0.31830988618379067153776752674503 - -vec4 smartDeNoise(sampler2D tex, vec2 uv, float sigma, float kSigma, float threshold) { - float radius = round(kSigma*sigma); - float radQ = radius * radius; - - float invSigmaQx2 = .5 / (sigma * sigma); // 1.0 / (sigma^2 * 2.0) - float invSigmaQx2PI = INV_PI * invSigmaQx2; // 1.0 / (sqrt(PI) * sigma) - - float invThresholdSqx2 = .5 / (threshold * threshold); // 1.0 / (sigma^2 * 2.0) - float invThresholdSqrt2PI = INV_SQRT_OF_2PI / threshold; // 1.0 / (sqrt(2*PI) * sigma) - - vec4 centrPx = texture(tex,uv); - - float zBuff = 0.0; - vec4 aBuff = vec4(0.0); - vec2 size = vec2(textureSize(tex, 0)); - - for(float x=-radius; x <= radius; x++) { - float pt = sqrt(radQ-x*x); // pt = yRadius: have circular trend - for(float y=-pt; y <= pt; y++) { - vec2 d = vec2(x,y)/size; - - float blurFactor = exp( -dot(d , d) * invSigmaQx2 ) * invSigmaQx2; - - vec4 walkPx = texture(tex,uv+d); - - vec4 dC = walkPx-centrPx; - float deltaFactor = exp( -dot(dC, dC) * invThresholdSqx2) * invThresholdSqrt2PI * blurFactor; - - zBuff += deltaFactor; - aBuff += deltaFactor*walkPx; - } - } - return aBuff/zBuff; -} - -#endif diff --git a/Shaders/std/dof.glsl b/Shaders/std/dof.glsl deleted file mode 100644 index 7dfeb983..00000000 --- a/Shaders/std/dof.glsl +++ /dev/null @@ -1,75 +0,0 @@ -// DoF with bokeh GLSL shader by Martins Upitis (martinsh) (devlog-martinsh.blogspot.com) -// Creative Commons Attribution 3.0 Unported License - -#include "../std/math.glsl" - -// const float compoDOFDistance = 10.0; // Focal distance value in meters -// const float compoDOFLength = 160.0; // Focal length in mm 18-200 -// const float compoDOFFstop = 128.0; // F-stop value - -const int samples = 6; // Samples on the first ring -const int rings = 6; // Ring count -const vec2 focus = vec2(0.5, 0.5); -const float coc = 0.11; // Circle of confusion size in mm (35mm film = 0.03mm) -const float maxblur = 1.0; -const float threshold = 0.5; // Highlight threshold -const float gain = 2.0; // Highlight gain -const float bias = 0.5; // Bokeh edge bias -const float fringe = 0.7; // Bokeh chromatic aberration/fringing -const float namount = 0.0001; // Dither amount - -vec3 color(vec2 coords, const float blur, const sampler2D tex, const vec2 texStep) { - vec3 col = vec3(0.0); - col.r = textureLod(tex, coords + vec2(0.0, 1.0) * texStep * fringe * blur, 0.0).r; - col.g = textureLod(tex, coords + vec2(-0.866, -0.5) * texStep * fringe * blur, 0.0).g; - col.b = textureLod(tex, coords + vec2(0.866, -0.5) * texStep * fringe * blur, 0.0).b; - - const vec3 lumcoeff = vec3(0.299, 0.587, 0.114); - float lum = dot(col.rgb, lumcoeff); - float thresh = max((lum - threshold) * gain, 0.0); - return col + mix(vec3(0.0), col, thresh * blur); -} - -vec3 dof(const vec2 texCoord, const float gdepth, const sampler2D tex, const sampler2D gbufferD, const vec2 texStep, const vec2 cameraProj) { - float depth = linearize(gdepth, cameraProj); - // const float fDepth = compoDOFDistance; - float fDepth = linearize(textureLod(gbufferD, focus, 0.0).r * 2.0 - 1.0, cameraProj); // Autofocus - - const float f = compoDOFLength; // Focal length in mm - const float d = fDepth * 1000.0; // Focal plane in mm - float o = depth * 1000.0; // Depth in mm - float a = (o * f) / (o - f); - float b = (d * f) / (d - f); - float c = (d - f) / (d * compoDOFFstop * coc); - float blur = abs(a - b) * c; - blur = clamp(blur, 0.0, 1.0); - - vec2 noise = rand2(texCoord) * namount * blur; - float w = (texStep.x) * blur * maxblur + noise.x; - float h = (texStep.y) * blur * maxblur + noise.y; - vec3 col = vec3(0.0); - if (blur < 0.05) { - col = textureLod(tex, texCoord, 0.0).rgb; - } - else { - col = textureLod(tex, texCoord, 0.0).rgb; - float s = 1.0; - int ringsamples; - - for (int i = 1; i <= rings; ++i) { - ringsamples = i * samples; - for (int j = 0 ; j < ringsamples; ++j) { - float step = PI2 / float(ringsamples); - float pw = (cos(float(j) * step) * float(i)); - float ph = (sin(float(j) * step) * float(i)); - float p = 1.0; - // if (pentagon) p = penta(vec2(pw, ph)); - col += color(texCoord + vec2(pw * w, ph * h), blur, tex, texStep) * mix(1.0, (float(i)) / (float(rings)), bias) * p; - s += 1.0 * mix(1.0, (float(i)) / (float(rings)), bias) * p; - } - } - col /= s; - } - return col; -} - diff --git a/Shaders/std/normals.glsl b/Shaders/std/normals.glsl deleted file mode 100644 index 9927a9f2..00000000 --- a/Shaders/std/normals.glsl +++ /dev/null @@ -1,31 +0,0 @@ -// http://www.thetenthplanet.de/archives/1180 -mat3 cotangentFrame(const vec3 n, const vec3 p, const vec2 duv1, const vec2 duv2) { - // Get edge vectors of the pixel triangle - vec3 dp1 = dFdx(p); - vec3 dp2 = dFdy(p); - - // Solve the linear system - vec3 dp2perp = cross(dp2, n); - vec3 dp1perp = cross(n, dp1); - vec3 t = dp2perp * duv1.x + dp1perp * duv2.x; - vec3 b = dp2perp * duv1.y + dp1perp * duv2.y; - - // Construct a scale-invariant frame - float invmax = inversesqrt(max(dot(t, t), dot(b, b))); - return mat3(t * invmax, b * invmax, n); -} - -mat3 cotangentFrame(const vec3 n, const vec3 p, const vec2 texCoord) { - return cotangentFrame(n, p, dFdx(texCoord), dFdy(texCoord)); -} - -// vec3 perturbNormal(vec3 n, vec3 v, vec2 texCoord) { - // Assume N, the interpolated vertex normal and V, the view vector (vertex to eye) - // vec3 map = texture(snormal, texCoord).xyz * (255.0 / 127.0) - (128.0 / 127.0); -// WITH_NORMALMAP_2CHANNEL - // map.z = sqrt(1.0 - dot(map.xy, map.xy)); -// WITH_NORMALMAP_GREEN_UP - // map.y = -map.y; - // mat3 TBN = cotangentFrame(n, -v, texCoord); - // return normalize(TBN * map); -// } diff --git a/Shaders/std/shadows.glsl b/Shaders/std/shadows.glsl deleted file mode 100644 index 88e25874..00000000 --- a/Shaders/std/shadows.glsl +++ /dev/null @@ -1,149 +0,0 @@ -#ifndef _SHADOWS_GLSL_ -#define _SHADOWS_GLSL_ - -#ifdef _CSM -const int shadowmapCascades = 1; -uniform vec4 casData[shadowmapCascades * 4 + 4]; -#endif - -#ifdef _SMSizeUniform -uniform vec2 smSizeUniform; -#endif - -const vec2 shadowmapSize = vec2(0, 0); - -float PCF(sampler2DShadow shadowMap, const vec2 uv, const float compare, const vec2 smSize) { - float result = texture(shadowMap, vec3(uv + (vec2(-1.0, -1.0) / smSize), compare)); - result += texture(shadowMap, vec3(uv + (vec2(-1.0, 0.0) / smSize), compare)); - result += texture(shadowMap, vec3(uv + (vec2(-1.0, 1.0) / smSize), compare)); - result += texture(shadowMap, vec3(uv + (vec2(0.0, -1.0) / smSize), compare)); - result += texture(shadowMap, vec3(uv, compare)); - result += texture(shadowMap, vec3(uv + (vec2(0.0, 1.0) / smSize), compare)); - result += texture(shadowMap, vec3(uv + (vec2(1.0, -1.0) / smSize), compare)); - result += texture(shadowMap, vec3(uv + (vec2(1.0, 0.0) / smSize), compare)); - result += texture(shadowMap, vec3(uv + (vec2(1.0, 1.0) / smSize), compare)); - return result / 9.0; -} - -float lpToDepth(vec3 lp, const vec2 lightProj) { - lp = abs(lp); - float zcomp = max(lp.x, max(lp.y, lp.z)); - zcomp = lightProj.x - lightProj.y / zcomp; - return zcomp * 0.5 + 0.5; -} - -float PCFCube(samplerCubeShadow shadowMapCube, const vec3 lp, vec3 ml, const float bias, const vec2 lightProj, const vec3 n) { - const float shadowmapCubePcfSize = 0.001; - const float s = shadowmapCubePcfSize; // TODO: incorrect... - float compare = lpToDepth(lp, lightProj) - bias * 1.5; - ml = ml + n * bias * 20; - #ifdef HLSL - ml.y = -ml.y; - #endif - float result = texture(shadowMapCube, vec4(ml, compare)); - result += texture(shadowMapCube, vec4(ml + vec3(s, s, s), compare)); - result += texture(shadowMapCube, vec4(ml + vec3(-s, s, s), compare)); - result += texture(shadowMapCube, vec4(ml + vec3(s, -s, s), compare)); - result += texture(shadowMapCube, vec4(ml + vec3(s, s, -s), compare)); - result += texture(shadowMapCube, vec4(ml + vec3(-s, -s, s), compare)); - result += texture(shadowMapCube, vec4(ml + vec3(s, -s, -s), compare)); - result += texture(shadowMapCube, vec4(ml + vec3(-s, s, -s), compare)); - result += texture(shadowMapCube, vec4(ml + vec3(-s, -s, -s), compare)); - return result / 9.0; -} - -float shadowTest(sampler2DShadow shadowMap, const vec3 lPos, const float shadowsBias) { - #ifdef _SMSizeUniform - vec2 smSize = smSizeUniform; - #else - const vec2 smSize = shadowmapSize; - #endif - if (lPos.x < 0.0 || lPos.y < 0.0 || lPos.x > 1.0 || lPos.y > 1.0) return 1.0; - return PCF(shadowMap, lPos.xy, lPos.z - shadowsBias, smSize); -} - -#ifdef _CSM -mat4 getCascadeMat(const float d, out int casi, out int casIndex) { - const int c = shadowmapCascades; - - // Get cascade index - // TODO: use bounding box slice selection instead of sphere - const vec4 ci = vec4(float(c > 0), float(c > 1), float(c > 2), float(c > 3)); - // int ci; - // if (d < casData[c * 4].x) ci = 0; - // else if (d < casData[c * 4].y) ci = 1 * 4; - // else if (d < casData[c * 4].z) ci = 2 * 4; - // else ci = 3 * 4; - // Splits - vec4 comp = vec4( - float(d > casData[c * 4].x), - float(d > casData[c * 4].y), - float(d > casData[c * 4].z), - float(d > casData[c * 4].w)); - casi = int(min(dot(ci, comp), c)); - - // Get cascade mat - casIndex = casi * 4; - - return mat4( - casData[casIndex ], - casData[casIndex + 1], - casData[casIndex + 2], - casData[casIndex + 3]); - - // if (casIndex == 0) return mat4(casData[0], casData[1], casData[2], casData[3]); - // .. -} - -float shadowTestCascade(sampler2DShadow shadowMap, const vec3 eye, const vec3 p, const float shadowsBias) { - #ifdef _SMSizeUniform - vec2 smSize = smSizeUniform * vec2(shadowmapCascades, 1.0); - #else - const vec2 smSize = shadowmapSize * vec2(shadowmapCascades, 1.0); - #endif - const int c = shadowmapCascades; - float d = distance(eye, p); - - int casi; - int casIndex; - mat4 LWVP = getCascadeMat(d, casi, casIndex); - - vec4 lPos = LWVP * vec4(p, 1.0); - lPos.xyz /= lPos.w; - - float visibility = 1.0; - if (lPos.w > 0.0) visibility = PCF(shadowMap, lPos.xy, lPos.z - shadowsBias, smSize); - - // Blend cascade - // https://github.com/TheRealMJP/Shadows - const float blendThres = 0.15; - float nextSplit = casData[c * 4][casi]; - float splitSize = casi == 0 ? nextSplit : nextSplit - casData[c * 4][casi - 1]; - float splitDist = (nextSplit - d) / splitSize; - if (splitDist <= blendThres && casi != c - 1) { - int casIndex2 = casIndex + 4; - mat4 LWVP2 = mat4( - casData[casIndex2 ], - casData[casIndex2 + 1], - casData[casIndex2 + 2], - casData[casIndex2 + 3]); - - vec4 lPos2 = LWVP2 * vec4(p, 1.0); - lPos2.xyz /= lPos2.w; - float visibility2 = 1.0; - if (lPos2.w > 0.0) visibility2 = PCF(shadowMap, lPos2.xy, lPos2.z - shadowsBias, smSize); - - float lerpAmt = smoothstep(0.0, blendThres, splitDist); - return mix(visibility2, visibility, lerpAmt); - } - return visibility; - - // Visualize cascades - // if (ci == 0) albedo.rgb = vec3(1.0, 0.0, 0.0); - // if (ci == 4) albedo.rgb = vec3(0.0, 1.0, 0.0); - // if (ci == 8) albedo.rgb = vec3(0.0, 0.0, 1.0); - // if (ci == 12) albedo.rgb = vec3(1.0, 1.0, 0.0); -} -#endif - -#endif diff --git a/Shaders/std/skinning.glsl b/Shaders/std/skinning.glsl deleted file mode 100644 index 090a782c..00000000 --- a/Shaders/std/skinning.glsl +++ /dev/null @@ -1,29 +0,0 @@ -// Geometric Skinning with Approximate Dual Quaternion Blending, Kavan -// Based on https://github.com/tcoppex/aer-engine/blob/master/demos/aura/data/shaders/Skinning.glsl -const int skinMaxBones = 50; -uniform vec4 skinBones[skinMaxBones * 2]; - -void getSkinningDualQuat(const ivec4 bone, vec4 weight, out vec4 A, inout vec4 B) { - // Retrieve the real and dual part of the dual-quaternions - ivec4 bonei = bone * 2; - mat4 matA = mat4( - skinBones[bonei.x], - skinBones[bonei.y], - skinBones[bonei.z], - skinBones[bonei.w]); - mat4 matB = mat4( - skinBones[bonei.x + 1], - skinBones[bonei.y + 1], - skinBones[bonei.z + 1], - skinBones[bonei.w + 1]); - // Handles antipodality by sticking joints in the same neighbourhood - // weight.xyz *= sign(matA[3] * mat3x4(matA)).xyz; - weight.xyz *= sign(matA[3] * matA).xyz; - // Apply weights - A = matA * weight; // Real part - B = matB * weight; // Dual part - // Normalize - float invNormA = 1.0 / length(A); - A *= invNormA; - B *= invNormA; -} diff --git a/Shaders/std/ssrs.glsl b/Shaders/std/ssrs.glsl deleted file mode 100644 index bb21003a..00000000 --- a/Shaders/std/ssrs.glsl +++ /dev/null @@ -1,37 +0,0 @@ -#include "../std/gbuffer.glsl" - -uniform mat4 VP; - -vec2 getProjectedCoord(vec3 hitCoord) { - vec4 projectedCoord = VP * vec4(hitCoord, 1.0); - projectedCoord.xy /= projectedCoord.w; - projectedCoord.xy = projectedCoord.xy * 0.5 + 0.5; - #ifdef HLSL - projectedCoord.y = 1.0 - projectedCoord.y; - #endif - return projectedCoord.xy; -} - -float getDeltaDepth(vec3 hitCoord, sampler2D gbufferD, mat4 invVP, vec3 eye) { - vec2 texCoord = getProjectedCoord(hitCoord); - float depth = textureLod(gbufferD, texCoord, 0.0).r * 2.0 - 1.0; - vec3 wpos = getPos2(invVP, depth, texCoord); - float d1 = length(eye - wpos); - float d2 = length(eye - hitCoord); - return d1 - d2; -} - -float traceShadowSS(vec3 dir, vec3 hitCoord, sampler2D gbufferD, mat4 invVP, vec3 eye) { - dir *= ssrsRayStep; - // for (int i = 0; i < maxSteps; i++) { - hitCoord += dir; - if (getDeltaDepth(hitCoord, gbufferD, invVP, eye) > 0.0) return 0.6; - hitCoord += dir; - if (getDeltaDepth(hitCoord, gbufferD, invVP, eye) > 0.0) return 0.7; - hitCoord += dir; - if (getDeltaDepth(hitCoord, gbufferD, invVP, eye) > 0.0) return 0.8; - hitCoord += dir; - if (getDeltaDepth(hitCoord, gbufferD, invVP, eye) > 0.0) return 0.9; - //} - return 1.0; -}