From 71929bd32f3efb17ecbda88b26fefa3b0ca12769 Mon Sep 17 00:00:00 2001 From: Lubos Lenco Date: Mon, 20 Nov 2017 12:38:35 +0100 Subject: [PATCH] Shaders clean up --- .../blur_edge_pass/blur_edge_pass.frag.glsl | 16 +- .../blur_gaus_pass/blur_gaus_pass.frag.glsl | 2 - Shaders/debug_normals/debug_normals.frag.glsl | 1 - .../deferred_indirect.frag.glsl | 1 - .../deferred_light/deferred_light.frag.glsl | 14 +- Shaders/deferred_light/deferred_light.json | 10 - .../deferred_light_quad.frag.glsl | 14 +- .../deferred_light_quad.json | 10 - Shaders/pt_trace_pass/pt_material.json | 15 -- Shaders/pt_trace_pass/pt_trace_pass.frag.glsl | 197 ---------------- Shaders/pt_trace_pass/pt_trace_pass.json | 27 --- Shaders/pt_trace_pass/pt_trace_pass.vert.glsl | 27 --- Shaders/std/shadows.glsl | 45 ++-- Shaders/std/shadows_csm.glsl | 167 -------------- Shaders/std/shadows_pcss.glsl | 218 ------------------ Shaders/world/world.frag.glsl | 19 -- blender/arm/make_renderer.py | 2 - blender/arm/make_renderpath.py | 3 + blender/arm/make_world.py | 7 - blender/arm/material/make_mesh.py | 51 ++-- blender/arm/props.py | 2 +- blender/arm/props_renderpath.py | 2 +- blender/arm/props_ui.py | 6 +- blender/arm/write_data.py | 5 - 24 files changed, 57 insertions(+), 804 deletions(-) delete mode 100644 Shaders/pt_trace_pass/pt_material.json delete mode 100644 Shaders/pt_trace_pass/pt_trace_pass.frag.glsl delete mode 100755 Shaders/pt_trace_pass/pt_trace_pass.json delete mode 100755 Shaders/pt_trace_pass/pt_trace_pass.vert.glsl delete mode 100755 Shaders/std/shadows_csm.glsl delete mode 100755 Shaders/std/shadows_pcss.glsl diff --git a/Shaders/blur_edge_pass/blur_edge_pass.frag.glsl b/Shaders/blur_edge_pass/blur_edge_pass.frag.glsl index fbf1a4bc..7dba4687 100644 --- a/Shaders/blur_edge_pass/blur_edge_pass.frag.glsl +++ b/Shaders/blur_edge_pass/blur_edge_pass.frag.glsl @@ -17,7 +17,6 @@ in vec2 texCoord; out vec4 fragColor; const float blurWeights[5] = float[] (0.227027, 0.1945946, 0.1216216, 0.054054, 0.016216); -// const float blurWeights[10] = float[] (0.132572, 0.125472, 0.106373, 0.08078, 0.05495, 0.033482, 0.018275, 0.008934, 0.003912, 0.001535); const float discardThreshold = 0.95; float doBlur(const float blurWeight, const int pos, const vec3 nor, const vec2 texCoord) { @@ -44,17 +43,10 @@ void main() { fragColor.r = texture(tex, tc).r * blurWeights[0]; float weight = blurWeights[0]; - // for (int i = 1; i < 10; i++) { - weight += doBlur(blurWeights[1], 1, nor, tc); - weight += doBlur(blurWeights[2], 2, nor, tc); - weight += doBlur(blurWeights[3], 3, nor, tc); - weight += doBlur(blurWeights[4], 4, nor, tc); - // weight += doBlur(blurWeights[5], 5, nor, tc); - // weight += doBlur(blurWeights[6], 6, nor, tc); - // weight += doBlur(blurWeights[7], 7, nor, tc); - // weight += doBlur(blurWeights[8], 8, nor, tc); - // weight += doBlur(blurWeights[9], 9, nor, tc); - // } + weight += doBlur(blurWeights[1], 1, nor, tc); + weight += doBlur(blurWeights[2], 2, nor, tc); + weight += doBlur(blurWeights[3], 3, nor, tc); + weight += doBlur(blurWeights[4], 4, nor, tc); fragColor = vec4(fragColor.r / weight); // SSAO only } \ No newline at end of file diff --git a/Shaders/blur_gaus_pass/blur_gaus_pass.frag.glsl b/Shaders/blur_gaus_pass/blur_gaus_pass.frag.glsl index bdf9668a..e10d57a5 100644 --- a/Shaders/blur_gaus_pass/blur_gaus_pass.frag.glsl +++ b/Shaders/blur_gaus_pass/blur_gaus_pass.frag.glsl @@ -14,8 +14,6 @@ uniform vec2 screenSize; in vec2 texCoord; out vec4 fragColor; -// const float weight[5] = float[] (0.227027, 0.1945946, 0.1216216, 0.054054, 0.016216); -// const float weight[8] = float[] (0.197448, 0.174697, 0.120999, 0.065602, 0.02784, 0.009246, 0.002403, 0.000489); const float weight[10] = float[] (0.132572, 0.125472, 0.106373, 0.08078, 0.05495, 0.033482, 0.018275, 0.008934, 0.003912, 0.001535); void main() { diff --git a/Shaders/debug_normals/debug_normals.frag.glsl b/Shaders/debug_normals/debug_normals.frag.glsl index ae7500fb..429e4a50 100755 --- a/Shaders/debug_normals/debug_normals.frag.glsl +++ b/Shaders/debug_normals/debug_normals.frag.glsl @@ -6,7 +6,6 @@ precision mediump float; #include "../compiled.glsl" #include "../std/gbuffer.glsl" -// getNor() uniform sampler2D tex; diff --git a/Shaders/deferred_indirect/deferred_indirect.frag.glsl b/Shaders/deferred_indirect/deferred_indirect.frag.glsl index 34f8b789..47e42484 100644 --- a/Shaders/deferred_indirect/deferred_indirect.frag.glsl +++ b/Shaders/deferred_indirect/deferred_indirect.frag.glsl @@ -85,7 +85,6 @@ void main() { #ifdef _InvY // D3D float depth = texture(gbufferD, texCoord).r * 2.0 - 1.0; #else - // TODO: Firefox throws transform loop error even when no depth write is performed float depth = (1.0 - g0.a) * 2.0 - 1.0; #endif vec3 p = getPos(eye, eyeLook, viewRay, depth, cameraProj); diff --git a/Shaders/deferred_light/deferred_light.frag.glsl b/Shaders/deferred_light/deferred_light.frag.glsl index 6bc9bb05..c1614661 100644 --- a/Shaders/deferred_light/deferred_light.frag.glsl +++ b/Shaders/deferred_light/deferred_light.frag.glsl @@ -17,11 +17,7 @@ precision mediump float; #include "../std/ltc.glsl" #endif #ifndef _NoShadows - #ifdef _PCSS - #include "../std/shadows_pcss.glsl" - #else #include "../std/shadows.glsl" - #endif #endif #ifdef _DFRS #include "../std/sdf.glsl" @@ -49,10 +45,6 @@ uniform sampler2D gbuffer1; #ifndef _NoShadows //!uniform sampler2D shadowMap; //!uniform samplerCube shadowMapCube; - #ifdef _PCSS - //!uniform sampler2D snoise; - //!uniform float lampSizeUV; - #endif #endif #ifdef _DFRS //!uniform sampler3D sdftex; @@ -141,11 +133,7 @@ void main() { // vec4 lPos = LWVP * vec4(p + noff, 1.0); vec4 lPos = LWVP * vec4(p, 1.0); if (lPos.w > 0.0) { - #ifdef _PCSS - visibility = PCSS(lPos.xy, lPos.z - shadowsBias); - #else - visibility = shadowTest(lPos.xyz / lPos.w, shadowsBias); - #endif + visibility = shadowTest(lPos.xyz / lPos.w, shadowsBias, shadowmapSize); } } else if (lightShadow == 2) { // Cube diff --git a/Shaders/deferred_light/deferred_light.json b/Shaders/deferred_light/deferred_light.json index 641aec97..7c74f4b9 100755 --- a/Shaders/deferred_light/deferred_light.json +++ b/Shaders/deferred_light/deferred_light.json @@ -106,16 +106,6 @@ "name": "LWVP", "link": "_biasLampWorldViewProjectionMatrix" }, - { - "name": "snoise", - "link": "_noise64", - "ifdef": ["_PCSS"] - }, - { - "name": "lampSizeUV", - "link": "_lampSizeUV", - "ifdef": ["_PCSS"] - }, { "name": "VP", "link": "_viewProjectionMatrix", diff --git a/Shaders/deferred_light_quad/deferred_light_quad.frag.glsl b/Shaders/deferred_light_quad/deferred_light_quad.frag.glsl index 619d6788..5f889f21 100644 --- a/Shaders/deferred_light_quad/deferred_light_quad.frag.glsl +++ b/Shaders/deferred_light_quad/deferred_light_quad.frag.glsl @@ -11,11 +11,7 @@ precision mediump float; #include "../std/conetrace.glsl" #endif #ifndef _NoShadows - // #ifdef _PCSS - // #include "../std/shadows_pcss.glsl" - // #else - #include "../std/shadows_csm.glsl" - // #endif + #include "../std/shadows.glsl" #endif #ifdef _SSS #include "../std/sss.glsl" @@ -42,10 +38,6 @@ vec2 lightPlane; #ifndef _NoShadows //!uniform sampler2D shadowMap; - // #ifdef _PCSS - //-!uniform sampler2D snoise; - //-!uniform float lampSizeUV; - // #endif #ifdef _CSM //!uniform vec4 casData[shadowmapCascades * 4 + 4]; #else @@ -103,10 +95,10 @@ void main() { #ifndef _NoShadows if (lightShadow == 1) { #ifdef _CSM - visibility = shadowTestCascade(eye, p, shadowsBias); + visibility = shadowTestCascade(eye, p, shadowsBias, shadowmapSize * vec2(shadowmapCascades, 1.0)); #else vec4 lPos = LWVP * vec4(p, 1.0); - if (lPos.w > 0.0) visibility = shadowTest(lPos.xyz / lPos.w, shadowsBias); + if (lPos.w > 0.0) visibility = shadowTest(lPos.xyz / lPos.w, shadowsBias, shadowmapSize); #endif } #endif diff --git a/Shaders/deferred_light_quad/deferred_light_quad.json b/Shaders/deferred_light_quad/deferred_light_quad.json index 07fd83bb..375544c6 100755 --- a/Shaders/deferred_light_quad/deferred_light_quad.json +++ b/Shaders/deferred_light_quad/deferred_light_quad.json @@ -76,16 +76,6 @@ "link": "_cascadeData", "ifdef": ["_CSM"] }, - { - "name": "snoise", - "link": "_noise64", - "ifdef": ["_PCSS"] - }, - { - "name": "lampSizeUV", - "link": "_lampSizeUV", - "ifdef": ["_PCSS"] - }, { "name": "VP", "link": "_viewProjectionMatrix", diff --git a/Shaders/pt_trace_pass/pt_material.json b/Shaders/pt_trace_pass/pt_material.json deleted file mode 100644 index ace5d3b9..00000000 --- a/Shaders/pt_trace_pass/pt_material.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "material_datas": [ - { - "contexts": [ - { - "bind_constants": [], - "bind_textures": [], - "name": "pt_trace_pass" - } - ], - "name": "pt_material", - "shader": "pt_trace_pass/pt_trace_pass" - } - ] -} diff --git a/Shaders/pt_trace_pass/pt_trace_pass.frag.glsl b/Shaders/pt_trace_pass/pt_trace_pass.frag.glsl deleted file mode 100644 index 64464a11..00000000 --- a/Shaders/pt_trace_pass/pt_trace_pass.frag.glsl +++ /dev/null @@ -1,197 +0,0 @@ - -#version 450 -#ifdef GL_ES -precision mediump float; -#endif -in vec3 initialRay; -in vec2 texCoord; -out vec4 fragColor; -uniform vec3 eye; -//uniform float textureWeight; -uniform float timeSinceStart; -//uniform sampler2D stexture; -uniform float glossiness; -//vec3 roomCubeMin = vec3(0.0, 0.0, 0.0); -//vec3 roomCubeMax = vec3(1.0, 1.0, 1.0); - -vec3 origin; -vec3 ray; -vec3 colorMask = vec3(1.0); -vec3 accumulatedColor = vec3(0.0); -uniform vec3 light; -uniform vec3 cubeCenter0; -uniform vec3 cubeSize0; -uniform vec3 cubeColor0; -vec2 intersectCube(vec3 origin, vec3 ray, vec3 cubeCenter, vec3 cubeSize) { - vec3 cubeMin = cubeCenter - cubeSize; - vec3 cubeMax = cubeCenter + cubeSize; - vec3 tMin = (cubeMin - origin) / ray; - vec3 tMax = (cubeMax - origin) / ray; - vec3 t1 = min(tMin, tMax); - vec3 t2 = max(tMin, tMax); - float tNear = max(max(t1.x, t1.y), t1.z); - float tFar = min(min(t2.x, t2.y), t2.z); - return vec2(tNear, tFar); -} - -vec3 normalForCube(vec3 hit, vec3 cubeCenter, vec3 cubeSize) { - vec3 cubeMin = cubeCenter - cubeSize; - vec3 cubeMax = cubeCenter + cubeSize; - if (hit.x < cubeMin.x + 0.0001) return vec3(-1.0, 0.0, 0.0); - else if (hit.x > cubeMax.x - 0.0001) return vec3(1.0, 0.0, 0.0); - else if (hit.y < cubeMin.y + 0.0001) return vec3(0.0, -1.0, 0.0); - else if (hit.y > cubeMax.y - 0.0001) return vec3(0.0, 1.0, 0.0); - else if (hit.z < cubeMin.z + 0.0001) return vec3(0.0, 0.0, -1.0); - //else return vec3(0.0, 0.0, 1.0); - return vec3(0.0, 0.0, 1.0); -} - -float intersectSphere(vec3 origin, vec3 ray, vec3 sphereCenter, float sphereRadius) { - vec3 toSphere = origin - sphereCenter; - float a = dot(ray, ray); - float b = 2.0 * dot(toSphere, ray); - float c = dot(toSphere, toSphere) - sphereRadius*sphereRadius; - float discriminant = b*b - 4.0*a*c; - if (discriminant > 0.0) { - float t = (-b - sqrt(discriminant)) / (2.0 * a); - if (t > 0.0) return t; - } - return 10000.0; -} - -vec3 normalForSphere(vec3 hit, vec3 sphereCenter, float sphereRadius) { - return (hit - sphereCenter) / sphereRadius; -} - -float random(vec3 scale, float seed) { - // return fract(sin(dot(texCoord.xyx + seed, scale)) * 43758.5453 + seed); - float d = 43758.5453; - float dt = dot(texCoord.xyx + seed,scale); - float sn = mod(dt,3.1415926); - return fract(sin(sn) * d); -} - -vec3 cosineWeightedDirection(float seed, vec3 normal) { - float u = random(vec3(12.9898, 78.233, 151.7182), seed); - float v = random(vec3(63.7264, 10.873, 623.6736), seed); - float r = sqrt(u); - float angle = 6.283185307179586 * v; - // compute basis from normal - vec3 sdir, tdir; - if (abs(normal.x) < 0.5) { - sdir = cross(normal, vec3(1.0, 0.0, 0.0)); - } - else { - sdir = cross(normal, vec3(0.0, 1.0, 0.0)); - } - tdir = cross(normal, sdir); - return r*cos(angle)*sdir + r*sin(angle)*tdir + sqrt(1.0-u)*normal; -} - -vec3 uniformlyRandomDirection(float seed) { - float u = random(vec3(12.9898, 78.233, 151.7182), seed); - float v = random(vec3(63.7264, 10.873, 623.6736), seed); - float z = 1.0 - 2.0 * u; - float r = sqrt(1.0 - z * z); - float angle = 6.283185307179586 * v; - return vec3(r * cos(angle), r * sin(angle), z); -} - -vec3 uniformlyRandomVector(float seed) { - return uniformlyRandomDirection(seed) * sqrt(random(vec3(36.7539, 50.3658, 306.2759), seed)); -} - -float shadow(vec3 origin, vec3 ray) { - - - vec2 tCube0 = intersectCube(origin, ray, cubeCenter0, cubeSize0); - if (tCube0.x > 0.0 && tCube0.x < 1.0 && tCube0.x < tCube0.y) return 0.0; - return 1.0; -} -int doBounce(float time, vec3 light, int bounce) { - // compute the intersection with everything - - vec2 tCube0 = intersectCube(origin, ray, cubeCenter0, cubeSize0); - - // find the closest intersection - float t = 10000.0; - - if (tCube0.x > 0.0 && tCube0.x < tCube0.y && tCube0.x < t) t = tCube0.x; - - // info about hit - vec3 hit = origin + ray * t; - vec3 surfaceColor = vec3(0.75); - float specularHighlight = 0.0; - vec3 normal; - - if (t == 10000.0) { - //break; - return 0; - } - else { - int aa = 0; - if (aa == 1) {aa = 0;} // hack to discard the first 'else' in 'else if' - - // have to compare intersectStr.x < intersectStr.y otherwise two coplanar - // cubes will look wrong (one cube will "steal" the hit from the other) - else if (t == tCube0.x) { if (tCube0.x < tCube0.y) normal = normalForCube(hit, cubeCenter0, cubeSize0); surfaceColor = cubeColor0; } - - ray = cosineWeightedDirection(time + float(bounce), normal); - } - - // compute diffuse lighting contribution - vec3 toLight = light - hit; - //float diffuse = max(0.0, dot(normalize(toLight), normal)); - float diffuse = max(0.0, dot(normalize(toLight), normal)) / dot(toLight,toLight); - - // do light bounce - colorMask *= surfaceColor; - //if (bounce > 0) { - // trace a shadow ray to the light - float shadowIntensity = shadow(hit + normal * 0.0001, toLight); - - accumulatedColor += colorMask * (0.5 * diffuse * shadowIntensity); - accumulatedColor += colorMask * specularHighlight * shadowIntensity; - //} - - // calculate next origin - origin = hit; - - return 0; -} - -vec3 calculateColor(float time, vec3 _origin, vec3 _ray, vec3 light) { - //vec3 colorMask = vec3(1.0); - //vec3 accumulatedColor = vec3(0.0); - - origin = _origin; - ray = _ray; - - // main raytracing loop - //for (int bounce = 0; bounce < 2; bounce++) { - int a; - a = doBounce(time, light, 0); - a = doBounce(time, light, 1); - a = doBounce(time, light, 2); - //} - - return accumulatedColor; - } - -void main() { - float time = 0.0;//timeSinceStart; - //timeSinceStart % 46735.275 ) / 1000; - vec3 col = vec3(0.0); - const int samples = 1; - vec3 newLight; - - //for (int i = 0; i < samples; i++) { - newLight = light + uniformlyRandomVector(time - 53.0) * 0.1; -col += calculateColor(time, eye, initialRay, newLight); -time += 0.35; - - //} - - fragColor = vec4(vec3(col / samples), 1.0); - fragColor.rgb = pow(fragColor.rgb * 0.7, vec3(1.0 / 2.2)); -} diff --git a/Shaders/pt_trace_pass/pt_trace_pass.json b/Shaders/pt_trace_pass/pt_trace_pass.json deleted file mode 100755 index 906223f1..00000000 --- a/Shaders/pt_trace_pass/pt_trace_pass.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "contexts": [ - { - "name": "pt_trace_pass", - "depth_write": false, - "compare_mode": "always", - "cull_mode": "none", - "links": [ - { - "name": "timeSinceStart", - "link": "_time" - }, - { - "name": "eye", - "link": "_cameraPosition" - }, - { - "name": "light", - "link": "_lightPosition" - } - ], - "texture_params": [], - "vertex_shader": "pt_trace_pass.vert.glsl", - "fragment_shader": "pt_trace_pass.frag.glsl" - } - ] -} diff --git a/Shaders/pt_trace_pass/pt_trace_pass.vert.glsl b/Shaders/pt_trace_pass/pt_trace_pass.vert.glsl deleted file mode 100755 index 0b1fc1bf..00000000 --- a/Shaders/pt_trace_pass/pt_trace_pass.vert.glsl +++ /dev/null @@ -1,27 +0,0 @@ -#version 450 - -#ifdef GL_ES -precision highp float; -#endif - -in vec2 pos; - -uniform vec3 ray00; -uniform vec3 ray01; -uniform vec3 ray10; -uniform vec3 ray11; - -out vec3 initialRay; -out vec2 texCoord; - -void main() { - // Scale vertex attribute to [0-1] range - const vec2 madd = vec2(0.5, 0.5); - texCoord = pos.xy * madd + madd; - #ifdef _InvY - texCoord.y = 1.0 - texCoord.y; - #endif - - initialRay = mix(mix(ray00, ray01, texCoord.y), mix(ray10, ray11, texCoord.y), texCoord.x); - gl_Position = vec4(pos.xy, 0.0, 1.0); -} diff --git a/Shaders/std/shadows.glsl b/Shaders/std/shadows.glsl index d5094162..394d7dd7 100755 --- a/Shaders/std/shadows.glsl +++ b/Shaders/std/shadows.glsl @@ -7,18 +7,12 @@ uniform samplerCube shadowMapCube; uniform vec4 casData[shadowmapCascades * 4 + 4]; #endif -// #ifdef _CSM -// const vec2 smSize = shadowmapSize * vec2(shadowmapCascades, 1.0); -// #else -const vec2 smSize = shadowmapSize; -// #endif - float shadowCompare(const vec2 uv, const float compare){ float depth = texture(shadowMap, uv).r; return step(compare, depth); } -float shadowLerp(const vec2 uv, const float compare){ +float shadowLerp(const vec2 uv, const float compare, const vec2 smSize){ const vec2 texelSize = vec2(1.0) / smSize; vec2 f = fract(uv * smSize + 0.5); vec2 centroidUV = floor(uv * smSize + 0.5) / smSize; @@ -32,23 +26,16 @@ float shadowLerp(const vec2 uv, const float compare){ return c; } -float PCF(const vec2 uv, const float compare) { - // float result = 0.0; - // for (int x = -1; x <= 1; x++){ - // for(int y = -1; y <= 1; y++){ - // vec2 off = vec2(x, y) / smSize; - // result += shadowLerp(smSize, uv + off, compare); - float result = shadowLerp(uv + (vec2(-1.0, -1.0) / smSize), compare); - result += shadowLerp(uv + (vec2(-1.0, 0.0) / smSize), compare); - result += shadowLerp(uv + (vec2(-1.0, 1.0) / smSize), compare); - result += shadowLerp(uv + (vec2(0.0, -1.0) / smSize), compare); - result += shadowLerp(uv, compare); - result += shadowLerp(uv + (vec2(0.0, 1.0) / smSize), compare); - result += shadowLerp(uv + (vec2(1.0, -1.0) / smSize), compare); - result += shadowLerp(uv + (vec2(1.0, 0.0) / smSize), compare); - result += shadowLerp(uv + (vec2(1.0, 1.0) / smSize), compare); - // } - // } +float PCF(const vec2 uv, const float compare, const vec2 smSize) { + float result = shadowLerp(uv + (vec2(-1.0, -1.0) / smSize), compare, smSize); + result += shadowLerp(uv + (vec2(-1.0, 0.0) / smSize), compare, smSize); + result += shadowLerp(uv + (vec2(-1.0, 1.0) / smSize), compare, smSize); + result += shadowLerp(uv + (vec2(0.0, -1.0) / smSize), compare, smSize); + result += shadowLerp(uv, compare, smSize); + result += shadowLerp(uv + (vec2(0.0, 1.0) / smSize), compare, smSize); + result += shadowLerp(uv + (vec2(1.0, -1.0) / smSize), compare, smSize); + result += shadowLerp(uv + (vec2(1.0, 0.0) / smSize), compare, smSize); + result += shadowLerp(uv + (vec2(1.0, 1.0) / smSize), compare, smSize); return result / 9.0; } @@ -78,7 +65,7 @@ float PCFCube(const vec3 lp, vec3 ml, const float bias, const vec2 lightProj, co return result; } -float shadowTest(const vec3 lPos, const float shadowsBias) { +float shadowTest(const vec3 lPos, const float shadowsBias, const vec2 smSize) { // float cosAngle = max(1.0 - dotNL, 0.0); // vec3 noff = n * shadowsBias * cosAngle; @@ -87,7 +74,7 @@ float shadowTest(const vec3 lPos, const float shadowsBias) { // Out of bounds if (lPos.x < 0.0 || lPos.y < 0.0 || lPos.x > 1.0 || lPos.y > 1.0) return 1.0; - return PCF(lPos.xy, lPos.z - shadowsBias); + return PCF(lPos.xy, lPos.z - shadowsBias, smSize); } #ifdef _CSM @@ -119,7 +106,7 @@ mat4 getCascadeMat(const float d, out int casi, out int casIndex) { casData[casIndex + 3]); } -float shadowTestCascade(const vec3 eye, const vec3 p, const float shadowsBias) { +float shadowTestCascade(const vec3 eye, const vec3 p, const float shadowsBias, const vec2 smSize) { const int c = shadowmapCascades; float d = distance(eye, p); @@ -129,7 +116,7 @@ float shadowTestCascade(const vec3 eye, const vec3 p, const float shadowsBias) { vec4 lPos = LWVP * vec4(p, 1.0); float visibility = 1.0; - if (lPos.w > 0.0) visibility = shadowTest(lPos.xyz / lPos.w, shadowsBias); + if (lPos.w > 0.0) visibility = shadowTest(lPos.xyz / lPos.w, shadowsBias, smSize); // Blend cascade // https://github.com/TheRealMJP/Shadows @@ -147,7 +134,7 @@ float shadowTestCascade(const vec3 eye, const vec3 p, const float shadowsBias) { vec4 lPos2 = LWVP2 * vec4(p, 1.0); float visibility2 = 1.0; - if (lPos2.w > 0.0) visibility2 = shadowTest(lPos2.xyz / lPos2.w, shadowsBias); + if (lPos2.w > 0.0) visibility2 = shadowTest(lPos2.xyz / lPos2.w, shadowsBias, smSize); float lerpAmt = smoothstep(0.0, blendThres, splitDist); return mix(visibility2, visibility, lerpAmt); diff --git a/Shaders/std/shadows_csm.glsl b/Shaders/std/shadows_csm.glsl deleted file mode 100755 index b0cda838..00000000 --- a/Shaders/std/shadows_csm.glsl +++ /dev/null @@ -1,167 +0,0 @@ -#include "../compiled.glsl" - -uniform sampler2D shadowMap; -uniform samplerCube shadowMapCube; - -#ifdef _CSM -uniform vec4 casData[shadowmapCascades * 4 + 4]; -#endif - -#ifdef _CSM -const vec2 smSize = shadowmapSize * vec2(shadowmapCascades, 1.0); -#else -const vec2 smSize = shadowmapSize; -#endif - -float shadowCompare(const vec2 uv, const float compare){ - float depth = texture(shadowMap, uv).r; - return step(compare, depth); -} - -float shadowLerp(const vec2 uv, const float compare){ - const vec2 texelSize = vec2(1.0) / smSize; - vec2 f = fract(uv * smSize + 0.5); - vec2 centroidUV = floor(uv * smSize + 0.5) / smSize; - float lb = shadowCompare(centroidUV, compare); - float lt = shadowCompare(centroidUV + texelSize * vec2(0.0, 1.0), compare); - float rb = shadowCompare(centroidUV + texelSize * vec2(1.0, 0.0), compare); - float rt = shadowCompare(centroidUV + texelSize, compare); - float a = mix(lb, lt, f.y); - float b = mix(rb, rt, f.y); - float c = mix(a, b, f.x); - return c; -} - -float PCF(const vec2 uv, const float compare) { - // float result = 0.0; - // for (int x = -1; x <= 1; x++){ - // for(int y = -1; y <= 1; y++){ - // vec2 off = vec2(x, y) / smSize; - // result += shadowLerp(smSize, uv + off, compare); - float result = shadowLerp(uv + (vec2(-1.0, -1.0) / smSize), compare); - result += shadowLerp(uv + (vec2(-1.0, 0.0) / smSize), compare); - result += shadowLerp(uv + (vec2(-1.0, 1.0) / smSize), compare); - result += shadowLerp(uv + (vec2(0.0, -1.0) / smSize), compare); - result += shadowLerp(uv, compare); - result += shadowLerp(uv + (vec2(0.0, 1.0) / smSize), compare); - result += shadowLerp(uv + (vec2(1.0, -1.0) / smSize), compare); - result += shadowLerp(uv + (vec2(1.0, 0.0) / smSize), compare); - result += shadowLerp(uv + (vec2(1.0, 1.0) / smSize), compare); - // } - // } - return result / 9.0; -} - -float lpToDepth(vec3 lp, const vec2 lightPlane) { - // TODO: pass uniforms - float a = lightPlane.y + lightPlane.x; - float b = lightPlane.y - lightPlane.x; - float c = 2.0 * lightPlane.y * lightPlane.x; - lp = abs(lp); - float zcomp = max(lp.x, max(lp.y, lp.z)); - zcomp = a / b - c / b / zcomp; - return zcomp * 0.5 + 0.5; -} - -float PCFCube(const vec3 lp, const vec3 ml, const float bias, const vec2 lightPlane) { - // return float(texture(shadowMapCube, ml).r + bias > lpToDepth(lp, lightPlane)); - float compare = lpToDepth(lp, lightPlane) - bias; - float result = step(compare, texture(shadowMapCube, ml).r); - const float s = shadowmapCubePcfSize; // 0.001 TODO: incorrect... - result += step(compare, texture(shadowMapCube, ml + vec3(s, s, s)).r); - result += step(compare, texture(shadowMapCube, ml + vec3(-s, s, s)).r); - result += step(compare, texture(shadowMapCube, ml + vec3(s, -s, s)).r); - result += step(compare, texture(shadowMapCube, ml + vec3(s, s, -s)).r); - result += step(compare, texture(shadowMapCube, ml + vec3(-s, -s, s)).r); - result += step(compare, texture(shadowMapCube, ml + vec3(s, -s, -s)).r); - result += step(compare, texture(shadowMapCube, ml + vec3(-s, s, -s)).r); - result += step(compare, texture(shadowMapCube, ml + vec3(-s, -s, -s)).r); - result /= 9.0; - return result; -} - - - -float shadowTest(const vec3 lPos, const float shadowsBias) { - - // float cosAngle = max(1.0 - dotNL, 0.0); - // vec3 noff = n * shadowsBias * cosAngle; - // vec4 lPos = LWVP * vec4(p + noff, 1.0); - - // Out of bounds - if (lPos.x < 0.0 || lPos.y < 0.0 || lPos.x > 1.0 || lPos.y > 1.0) return 1.0; - - return PCF(lPos.xy, lPos.z - shadowsBias); -} - -#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 + 0], - casData[casIndex + 1], - casData[casIndex + 2], - casData[casIndex + 3]); -} - -float shadowTestCascade(const vec3 eye, const vec3 p, const float shadowsBias) { - 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); - float visibility = 1.0; - if (lPos.w > 0.0) visibility = shadowTest(lPos.xyz / lPos.w, shadowsBias); - - // 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 + 0], - casData[casIndex2 + 1], - casData[casIndex2 + 2], - casData[casIndex2 + 3]); - - vec4 lPos2 = LWVP2 * vec4(p, 1.0); - float visibility2 = 1.0; - if (lPos2.w > 0.0) visibility2 = shadowTest(lPos2.xyz / lPos2.w, shadowsBias); - - 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 diff --git a/Shaders/std/shadows_pcss.glsl b/Shaders/std/shadows_pcss.glsl deleted file mode 100755 index 8e7ab2e8..00000000 --- a/Shaders/std/shadows_pcss.glsl +++ /dev/null @@ -1,218 +0,0 @@ -// Based on ThreeJS and nvidia pcss -#include "../compiled.glsl" - -uniform sampler2D shadowMap; -uniform samplerCube shadowMapCube; -uniform sampler2D snoise; -uniform float lampSizeUV; - -const int NUM_SAMPLES = 17; -const float radiusStep = 1.0 / float(NUM_SAMPLES); -const float angleStep = PI2 * float(pcssRings) / float(NUM_SAMPLES); -const float lampNear = 0.5; - -vec2 poissonDisk0; vec2 poissonDisk1; vec2 poissonDisk2; -vec2 poissonDisk3; vec2 poissonDisk4; vec2 poissonDisk5; -vec2 poissonDisk6; vec2 poissonDisk7; vec2 poissonDisk8; -vec2 poissonDisk9; vec2 poissonDisk10; vec2 poissonDisk11; -vec2 poissonDisk12; vec2 poissonDisk13; vec2 poissonDisk14; -vec2 poissonDisk15; vec2 poissonDisk16; - -void initPoissonSamples(const vec2 randomSeed) { - float angle = texture(snoise, randomSeed).r * 1000.0; - float radius = radiusStep; - // for (int i = 0; i < NUM_SAMPLES; i++) { - poissonDisk0 = vec2(cos(angle), sin(angle)) * pow(radius, 0.75); - radius += radiusStep; angle += angleStep; - poissonDisk1 = vec2(cos(angle), sin(angle)) * pow(radius, 0.75); - radius += radiusStep; angle += angleStep; - poissonDisk2 = vec2(cos(angle), sin(angle)) * pow(radius, 0.75); - radius += radiusStep; angle += angleStep; - poissonDisk3 = vec2(cos(angle), sin(angle)) * pow(radius, 0.75); - radius += radiusStep; angle += angleStep; - poissonDisk4 = vec2(cos(angle), sin(angle)) * pow(radius, 0.75); - radius += radiusStep; angle += angleStep; - poissonDisk5 = vec2(cos(angle), sin(angle)) * pow(radius, 0.75); - radius += radiusStep; angle += angleStep; - poissonDisk6 = vec2(cos(angle), sin(angle)) * pow(radius, 0.75); - radius += radiusStep; angle += angleStep; - poissonDisk7 = vec2(cos(angle), sin(angle)) * pow(radius, 0.75); - radius += radiusStep; angle += angleStep; - poissonDisk8 = vec2(cos(angle), sin(angle)) * pow(radius, 0.75); - radius += radiusStep; angle += angleStep; - poissonDisk9 = vec2(cos(angle), sin(angle)) * pow(radius, 0.75); - radius += radiusStep; angle += angleStep; - poissonDisk10 = vec2(cos(angle), sin(angle)) * pow(radius, 0.75); - radius += radiusStep; angle += angleStep; - poissonDisk11 = vec2(cos(angle), sin(angle)) * pow(radius, 0.75); - radius += radiusStep; angle += angleStep; - poissonDisk12 = vec2(cos(angle), sin(angle)) * pow(radius, 0.75); - radius += radiusStep; angle += angleStep; - poissonDisk13 = vec2(cos(angle), sin(angle)) * pow(radius, 0.75); - radius += radiusStep; angle += angleStep; - poissonDisk14 = vec2(cos(angle), sin(angle)) * pow(radius, 0.75); - radius += radiusStep; angle += angleStep; - poissonDisk15 = vec2(cos(angle), sin(angle)) * pow(radius, 0.75); - radius += radiusStep; angle += angleStep; - poissonDisk16 = vec2(cos(angle), sin(angle)) * pow(radius, 0.75); - radius += radiusStep; angle += angleStep; - // } -} - -float findBlocker(const vec2 uv, const float zReceiver) { - // This uses similar triangles to compute what area of the shadow map we should search - float searchRadius = lampSizeUV * (zReceiver - lampNear) / zReceiver; - float blockerDepthSum = 0.0; - int numBlockers = 0; - // for (int i = 0; i < NUM_SAMPLES; i++) { - float shadowMapDepth = texture(shadowMap, uv + poissonDisk0 * searchRadius).r; - if (shadowMapDepth < zReceiver) { blockerDepthSum += shadowMapDepth; numBlockers++; } - shadowMapDepth = texture(shadowMap, uv + poissonDisk1 * searchRadius).r; - if (shadowMapDepth < zReceiver) { blockerDepthSum += shadowMapDepth; numBlockers++; } - shadowMapDepth = texture(shadowMap, uv + poissonDisk2 * searchRadius).r; - if (shadowMapDepth < zReceiver) { blockerDepthSum += shadowMapDepth; numBlockers++; } - shadowMapDepth = texture(shadowMap, uv + poissonDisk3 * searchRadius).r; - if (shadowMapDepth < zReceiver) { blockerDepthSum += shadowMapDepth; numBlockers++; } - shadowMapDepth = texture(shadowMap, uv + poissonDisk4 * searchRadius).r; - if (shadowMapDepth < zReceiver) { blockerDepthSum += shadowMapDepth; numBlockers++; } - shadowMapDepth = texture(shadowMap, uv + poissonDisk5 * searchRadius).r; - if (shadowMapDepth < zReceiver) { blockerDepthSum += shadowMapDepth; numBlockers++; } - shadowMapDepth = texture(shadowMap, uv + poissonDisk6 * searchRadius).r; - if (shadowMapDepth < zReceiver) { blockerDepthSum += shadowMapDepth; numBlockers++; } - shadowMapDepth = texture(shadowMap, uv + poissonDisk7 * searchRadius).r; - if (shadowMapDepth < zReceiver) { blockerDepthSum += shadowMapDepth; numBlockers++; } - shadowMapDepth = texture(shadowMap, uv + poissonDisk8 * searchRadius).r; - if (shadowMapDepth < zReceiver) { blockerDepthSum += shadowMapDepth; numBlockers++; } - shadowMapDepth = texture(shadowMap, uv + poissonDisk9 * searchRadius).r; - if (shadowMapDepth < zReceiver) { blockerDepthSum += shadowMapDepth; numBlockers++; } - shadowMapDepth = texture(shadowMap, uv + poissonDisk10 * searchRadius).r; - if (shadowMapDepth < zReceiver) { blockerDepthSum += shadowMapDepth; numBlockers++; } - shadowMapDepth = texture(shadowMap, uv + poissonDisk11 * searchRadius).r; - if (shadowMapDepth < zReceiver) { blockerDepthSum += shadowMapDepth; numBlockers++; } - shadowMapDepth = texture(shadowMap, uv + poissonDisk12 * searchRadius).r; - if (shadowMapDepth < zReceiver) { blockerDepthSum += shadowMapDepth; numBlockers++; } - shadowMapDepth = texture(shadowMap, uv + poissonDisk13 * searchRadius).r; - if (shadowMapDepth < zReceiver) { blockerDepthSum += shadowMapDepth; numBlockers++; } - shadowMapDepth = texture(shadowMap, uv + poissonDisk14 * searchRadius).r; - if (shadowMapDepth < zReceiver) { blockerDepthSum += shadowMapDepth; numBlockers++; } - shadowMapDepth = texture(shadowMap, uv + poissonDisk15 * searchRadius).r; - if (shadowMapDepth < zReceiver) { blockerDepthSum += shadowMapDepth; numBlockers++; } - shadowMapDepth = texture(shadowMap, uv + poissonDisk16 * searchRadius).r; - if (shadowMapDepth < zReceiver) { blockerDepthSum += shadowMapDepth; numBlockers++; } - // } - if (numBlockers == 0) return -1.0; - return blockerDepthSum / float(numBlockers); -} - -float filterPCF(const vec2 uv, const float zReceiver, const float filterRadius) { - float sum = 0.0; - // for (int i = 0; i < NUM_SAMPLES; i++) { - float depth = texture(shadowMap, uv + poissonDisk0 * filterRadius).r; - if (zReceiver <= depth) sum += 1.0; - depth = texture(shadowMap, uv + poissonDisk1 * filterRadius).r; - if (zReceiver <= depth) sum += 1.0; - depth = texture(shadowMap, uv + poissonDisk2 * filterRadius).r; - if (zReceiver <= depth) sum += 1.0; - depth = texture(shadowMap, uv + poissonDisk3 * filterRadius).r; - if (zReceiver <= depth) sum += 1.0; - depth = texture(shadowMap, uv + poissonDisk4 * filterRadius).r; - if (zReceiver <= depth) sum += 1.0; - depth = texture(shadowMap, uv + poissonDisk5 * filterRadius).r; - if (zReceiver <= depth) sum += 1.0; - depth = texture(shadowMap, uv + poissonDisk6 * filterRadius).r; - if (zReceiver <= depth) sum += 1.0; - depth = texture(shadowMap, uv + poissonDisk7 * filterRadius).r; - if (zReceiver <= depth) sum += 1.0; - depth = texture(shadowMap, uv + poissonDisk8 * filterRadius).r; - if (zReceiver <= depth) sum += 1.0; - depth = texture(shadowMap, uv + poissonDisk9 * filterRadius).r; - if (zReceiver <= depth) sum += 1.0; - depth = texture(shadowMap, uv + poissonDisk10 * filterRadius).r; - if (zReceiver <= depth) sum += 1.0; - depth = texture(shadowMap, uv + poissonDisk11 * filterRadius).r; - if (zReceiver <= depth) sum += 1.0; - depth = texture(shadowMap, uv + poissonDisk12 * filterRadius).r; - if (zReceiver <= depth) sum += 1.0; - depth = texture(shadowMap, uv + poissonDisk13 * filterRadius).r; - if (zReceiver <= depth) sum += 1.0; - depth = texture(shadowMap, uv + poissonDisk14 * filterRadius).r; - if (zReceiver <= depth) sum += 1.0; - depth = texture(shadowMap, uv + poissonDisk15 * filterRadius).r; - if (zReceiver <= depth) sum += 1.0; - depth = texture(shadowMap, uv + poissonDisk16 * filterRadius).r; - if (zReceiver <= depth) sum += 1.0; - // } - // for (int i = 0; i < NUM_SAMPLES; i++) { - depth = texture(shadowMap, uv + -poissonDisk0.yx * filterRadius).r; - if (zReceiver <= depth) sum += 1.0; - depth = texture(shadowMap, uv + -poissonDisk1.yx * filterRadius).r; - if (zReceiver <= depth) sum += 1.0; - depth = texture(shadowMap, uv + -poissonDisk2.yx * filterRadius).r; - if (zReceiver <= depth) sum += 1.0; - depth = texture(shadowMap, uv + -poissonDisk3.yx * filterRadius).r; - if (zReceiver <= depth) sum += 1.0; - depth = texture(shadowMap, uv + -poissonDisk4.yx * filterRadius).r; - if (zReceiver <= depth) sum += 1.0; - depth = texture(shadowMap, uv + -poissonDisk5.yx * filterRadius).r; - if (zReceiver <= depth) sum += 1.0; - depth = texture(shadowMap, uv + -poissonDisk6.yx * filterRadius).r; - if (zReceiver <= depth) sum += 1.0; - depth = texture(shadowMap, uv + -poissonDisk7.yx * filterRadius).r; - if (zReceiver <= depth) sum += 1.0; - depth = texture(shadowMap, uv + -poissonDisk8.yx * filterRadius).r; - if (zReceiver <= depth) sum += 1.0; - depth = texture(shadowMap, uv + -poissonDisk9.yx * filterRadius).r; - if (zReceiver <= depth) sum += 1.0; - depth = texture(shadowMap, uv + -poissonDisk10.yx * filterRadius).r; - if (zReceiver <= depth) sum += 1.0; - depth = texture(shadowMap, uv + -poissonDisk11.yx * filterRadius).r; - if (zReceiver <= depth) sum += 1.0; - depth = texture(shadowMap, uv + -poissonDisk12.yx * filterRadius).r; - if (zReceiver <= depth) sum += 1.0; - depth = texture(shadowMap, uv + -poissonDisk13.yx * filterRadius).r; - if (zReceiver <= depth) sum += 1.0; - depth = texture(shadowMap, uv + -poissonDisk14.yx * filterRadius).r; - if (zReceiver <= depth) sum += 1.0; - depth = texture(shadowMap, uv + -poissonDisk15.yx * filterRadius).r; - if (zReceiver <= depth) sum += 1.0; - depth = texture(shadowMap, uv + -poissonDisk16.yx * filterRadius).r; - if (zReceiver <= depth) sum += 1.0; - // } - return sum / (2.0 * float(NUM_SAMPLES)); -} - -float PCSS(const vec2 uv, const float zReceiver) { - initPoissonSamples(uv); - float avgBlockerDepth = findBlocker(uv, zReceiver); - if (avgBlockerDepth == -1.0) return 1.0; - float penumbraRatio = (zReceiver - avgBlockerDepth) / avgBlockerDepth; - float filterRadius = penumbraRatio * lampSizeUV * lampNear / zReceiver; - return filterPCF(uv, zReceiver, filterRadius); -} - -// No soft shadows for cube yet.. -float lpToDepth(vec3 lp, const vec2 lightPlane) { - float d = lightPlane.y - lightPlane.x; - lp = abs(lp); - float zcomp = max(lp.x, max(lp.y, lp.z)); - zcomp = (lightPlane.y + lightPlane.x) / (d) - (2.0 * lightPlane.y * lightPlane.x) / (d) / zcomp; - return zcomp * 0.5 + 0.5; -} - -float PCFCube(const vec3 lp, const vec3 ml, const float bias, const vec2 lightPlane) { - // return float(texture(shadowMapCube, ml).r + bias > lpToDepth(lp)); - - const float s = 0.001; // TODO: incorrect... - float compare = lpToDepth(lp, lightPlane) - bias; - float result = step(compare, texture(shadowMapCube, ml).r); - result += step(compare, texture(shadowMapCube, ml + vec3(s, s, s)).r); - result += step(compare, texture(shadowMapCube, ml + vec3(-s, s, s)).r); - result += step(compare, texture(shadowMapCube, ml + vec3(s, -s, s)).r); - result += step(compare, texture(shadowMapCube, ml + vec3(s, s, -s)).r); - result += step(compare, texture(shadowMapCube, ml + vec3(-s, -s, s)).r); - result += step(compare, texture(shadowMapCube, ml + vec3(s, -s, -s)).r); - result += step(compare, texture(shadowMapCube, ml + vec3(-s, s, -s)).r); - result += step(compare, texture(shadowMapCube, ml + vec3(-s, -s, -s)).r); - result /= 9.0; - return result; -} \ No newline at end of file diff --git a/Shaders/world/world.frag.glsl b/Shaders/world/world.frag.glsl index 705912ed..b675996d 100644 --- a/Shaders/world/world.frag.glsl +++ b/Shaders/world/world.frag.glsl @@ -143,22 +143,6 @@ vec2 traceCloud(vec3 pos, vec3 dir) { shadeSum = doCloudTrace(add, shadeSum); if (shadeSum.y >= 1.0) return shadeSum; shadeSum = doCloudTrace(add, shadeSum); if (shadeSum.y >= 1.0) return shadeSum; shadeSum = doCloudTrace(add, shadeSum); if (shadeSum.y >= 1.0) return shadeSum; - - // shadeSum = doCloudTrace(add, shadeSum); if (shadeSum.y >= 1.0) return shadeSum; - // shadeSum = doCloudTrace(add, shadeSum); if (shadeSum.y >= 1.0) return shadeSum; - // shadeSum = doCloudTrace(add, shadeSum); if (shadeSum.y >= 1.0) return shadeSum; - // shadeSum = doCloudTrace(add, shadeSum); if (shadeSum.y >= 1.0) return shadeSum; - // shadeSum = doCloudTrace(add, shadeSum); if (shadeSum.y >= 1.0) return shadeSum; - // shadeSum = doCloudTrace(add, shadeSum); if (shadeSum.y >= 1.0) return shadeSum; - // shadeSum = doCloudTrace(add, shadeSum); if (shadeSum.y >= 1.0) return shadeSum; - // shadeSum = doCloudTrace(add, shadeSum); if (shadeSum.y >= 1.0) return shadeSum; - // shadeSum = doCloudTrace(add, shadeSum); if (shadeSum.y >= 1.0) return shadeSum; - // shadeSum = doCloudTrace(add, shadeSum); if (shadeSum.y >= 1.0) return shadeSum; - // shadeSum = doCloudTrace(add, shadeSum); if (shadeSum.y >= 1.0) return shadeSum; - // shadeSum = doCloudTrace(add, shadeSum); if (shadeSum.y >= 1.0) return shadeSum; - // shadeSum = doCloudTrace(add, shadeSum); if (shadeSum.y >= 1.0) return shadeSum; - // shadeSum = doCloudTrace(add, shadeSum); if (shadeSum.y >= 1.0) return shadeSum; - // shadeSum = doCloudTrace(add, shadeSum); if (shadeSum.y >= 1.0) return shadeSum; return shadeSum; } // GPU PRO 7 - Real-time Volumetric Cloudscapes @@ -178,9 +162,6 @@ vec3 cloudsColor(vec3 R, vec3 pos, vec3 dir) { #endif void main() { - // if (texture(gbufferD, texCoord).r/* * 2.0 - 1.0*/ != 1.0) { - // discard; - // } #ifdef _EnvCol fragColor.rgb = backgroundCol; diff --git a/blender/arm/make_renderer.py b/blender/arm/make_renderer.py index 0374284a..80784d40 100644 --- a/blender/arm/make_renderer.py +++ b/blender/arm/make_renderer.py @@ -156,7 +156,6 @@ def set_preset(self, context, preset): rpdat.rp_motionblur = 'None' rpdat.arm_rp_resolution = 'Display' rpdat.arm_material_model = 'Full' - rpdat.arm_pcss_state = 'On' rpdat.arm_texture_filter = 'Anisotropic' rpdat.arm_diffuse_model = 'OrenNayar' elif preset == 'VR': @@ -260,7 +259,6 @@ def set_preset(self, context, preset): rpdat.rp_motionblur = 'None' rpdat.arm_rp_resolution = 'Display' rpdat.arm_material_model = 'Full' - rpdat.arm_pcss_state = 'Off' rpdat.arm_texture_filter = 'Anisotropic' rpdat.arm_diffuse_model = 'Lambert' diff --git a/blender/arm/make_renderpath.py b/blender/arm/make_renderpath.py index 23a5bc4b..58131544 100755 --- a/blender/arm/make_renderpath.py +++ b/blender/arm/make_renderpath.py @@ -262,6 +262,9 @@ def make_draw_compositor(stage, node_group, node, with_fxaa=False): if wrd.arm_vignette: compositor_defs += '_CVignette' + if wrd.arm_lensflare: + compositor_defs += '_CGlare' + wrd.compo_defs = compositor_defs defs = world_defs + compositor_defs diff --git a/blender/arm/make_world.py b/blender/arm/make_world.py index 2ab534bb..8fad295b 100755 --- a/blender/arm/make_world.py +++ b/blender/arm/make_world.py @@ -80,13 +80,6 @@ def build_node_tree(world): if rpdat.arm_clouds: wrd.world_defs += '_EnvClouds' - # Percentage closer soft shadows - # if rpdat.arm_pcss_state == 'On': - # wrd.world_defs += '_PCSS' - # sdk_path = arm.utils.get_sdk_path() - # assets.add(sdk_path + 'armory/Assets/noise64.png') - # assets.add_embedded_data('noise64.png') - # Screen-space ray-traced shadows if rpdat.arm_ssrs: wrd.world_defs += '_SSRS' diff --git a/blender/arm/material/make_mesh.py b/blender/arm/material/make_mesh.py index 27be6199..6c8adff9 100644 --- a/blender/arm/material/make_mesh.py +++ b/blender/arm/material/make_mesh.py @@ -424,19 +424,18 @@ def make_forward_mobile(con_mesh): frag.add_uniform('sampler2D shadowMap', included=True) frag.add_uniform('float shadowsBias', '_lampShadowsBias') frag.write(' if (lampPos.w > 0.0) {') - frag.write(' vec3 lpos = lampPos.xyz / lampPos.w;') - # frag.write(' visibility *= PCF(lpos.xy, lpos.z - shadowsBias);') + frag.write(' vec3 lPos = lampPos.xyz / lampPos.w;') frag.write(' const float texelSize = 1.0 / shadowmapSize.x;') frag.write(' visibility = 0.0;') # TODO: CSM - frag.write(' visibility += float(texture(shadowMap, lpos.xy).r + shadowsBias > lpos.z);') - frag.write(' visibility += float(texture(shadowMap, lpos.xy + vec2(texelSize, 0.0)).r + shadowsBias > lpos.z) * 0.5;') - frag.write(' visibility += float(texture(shadowMap, lpos.xy + vec2(-texelSize, 0.0)).r + shadowsBias > lpos.z) * 0.25;') - frag.write(' visibility += float(texture(shadowMap, lpos.xy + vec2(0.0, texelSize)).r + shadowsBias > lpos.z) * 0.5;') - frag.write(' visibility += float(texture(shadowMap, lpos.xy + vec2(0.0, -texelSize)).r + shadowsBias > lpos.z) * 0.25;') + frag.write(' visibility += float(texture(shadowMap, lPos.xy).r + shadowsBias > lPos.z);') + frag.write(' visibility += float(texture(shadowMap, lPos.xy + vec2(texelSize, 0.0)).r + shadowsBias > lPos.z) * 0.5;') + frag.write(' visibility += float(texture(shadowMap, lPos.xy + vec2(-texelSize, 0.0)).r + shadowsBias > lPos.z) * 0.25;') + frag.write(' visibility += float(texture(shadowMap, lPos.xy + vec2(0.0, texelSize)).r + shadowsBias > lPos.z) * 0.5;') + frag.write(' visibility += float(texture(shadowMap, lPos.xy + vec2(0.0, -texelSize)).r + shadowsBias > lPos.z) * 0.25;') frag.write(' visibility /= 2.5;') frag.write(' visibility = max(visibility, 0.5);') - # frag.write(' visibility = max(float(texture(shadowMap, lpos.xy).r + shadowsBias > lpos.z), 0.5);') + # frag.write(' visibility = max(float(texture(shadowMap, lPos.xy).r + shadowsBias > lPos.z), 0.5);') frag.write(' }') frag.add_out('vec4 fragColor') @@ -567,7 +566,6 @@ def make_forward_base(con_mesh, parse_opacity=False): frag.add_uniform('int envmapNumMipmaps', link='_envmapNumMipmaps') is_shadows = not '_NoShadows' in wrd.world_defs - is_pcss = '_PCSS' in wrd.world_defs frag.write('float visibility = 1.0;') frag.write('vec3 lp = lightPos - wposition;') @@ -586,18 +584,12 @@ def make_forward_base(con_mesh, parse_opacity=False): tese.add_uniform('int lightShadow', '_lampCastShadow') tese.write('if (lightShadow == 1) lampPos = LVP * vec4(wposition, 1.0);') else: - if not '_CSM' in wrd.world_defs: - vert.add_out('vec4 lampPos') - vert.add_uniform('int lightShadow', '_lampCastShadow') - vert.add_uniform('mat4 LWVP', '_biasLampWorldViewProjectionMatrix') - vert.write('if (lightShadow == 1) lampPos = LWVP * spos;') + vert.add_out('vec4 lampPos') + vert.add_uniform('int lightShadow', '_lampCastShadow') + vert.add_uniform('mat4 LWVP', '_biasLampWorldViewProjectionMatrix') + vert.write('if (lightShadow == 1) lampPos = LWVP * spos;') - if is_pcss: - frag.add_include('../../Shaders/std/shadows_pcss.glsl') - frag.add_uniform('sampler2D snoise', link='_noise64', included=True) - frag.add_uniform('float lampSizeUV', link='_lampSizeUV', included=True) - else: - frag.add_include('../../Shaders/std/shadows.glsl') + frag.add_include('../../Shaders/std/shadows.glsl') frag.add_uniform('sampler2D shadowMap', included=True) frag.add_uniform('samplerCube shadowMapCube', included=True) frag.add_uniform('bool receiveShadow') @@ -611,16 +603,25 @@ def make_forward_base(con_mesh, parse_opacity=False): frag.add_include('../../Shaders/compiled.glsl') frag.add_uniform('vec4 casData[shadowmapCascades * 4 + 4]', '_cascadeData', included=True) frag.add_uniform('vec3 eye', '_cameraPosition') + frag.write('vec2 smSize;') + frag.write('vec3 lPos;') + frag.write('if (lightType == 0) {') frag.write(' int casi;') frag.write(' int casindex;') frag.write(' mat4 LWVP = getCascadeMat(distance(eye, wposition), casi, casindex);') frag.write(' vec4 lampPos = LWVP * vec4(wposition, 1.0);') - frag.write(' vec3 lpos = lampPos.xyz / lampPos.w;') - # frag.write('float bias = clamp(shadowsBias * 1.0 * tan(acos(clamp(dotNL, 0.0, 1.0))), 0.0, 0.01);') - if is_pcss: - frag.write(' visibility *= PCSS(lpos.xy, lpos.z - shadowsBias);') + frag.write(' lPos = lampPos.xyz / lampPos.w;') + frag.write(' smSize = shadowmapSize * vec2(shadowmapCascades, 1.0);') + frag.write('}') + frag.write('else {') + frag.write(' lPos = lampPos.xyz / lampPos.w;') + frag.write(' smSize = shadowmapSize;') + frag.write('}') else: - frag.write(' visibility *= PCF(lpos.xy, lpos.z - shadowsBias);') + frag.write(' vec3 lPos = lampPos.xyz / lampPos.w;') + frag.write(' const vec2 smSize = shadowmapSize;') + # frag.write('float bias = clamp(shadowsBias * 1.0 * tan(acos(clamp(dotNL, 0.0, 1.0))), 0.0, 0.01);') + frag.write(' visibility *= PCF(lPos.xy, lPos.z - shadowsBias, smSize);') frag.write(' }') frag.write(' else if (lightShadow == 2) visibility *= PCFCube(lp, -l, shadowsBias, lightProj, n);') frag.write('}') diff --git a/blender/arm/props.py b/blender/arm/props.py index 3f3f7ea7..9df4c89c 100755 --- a/blender/arm/props.py +++ b/blender/arm/props.py @@ -297,7 +297,6 @@ def init_properties(): bpy.types.World.arm_ssr_jitter = bpy.props.FloatProperty(name="Jitter", default=0.6, update=assets.invalidate_shader_cache) bpy.types.World.arm_volumetric_light_air_turbidity = bpy.props.FloatProperty(name="Air Turbidity", default=1.0, update=assets.invalidate_shader_cache) bpy.types.World.arm_volumetric_light_air_color = bpy.props.FloatVectorProperty(name="Air Color", size=3, default=[1.0, 1.0, 1.0], subtype='COLOR', min=0, max=1, update=assets.invalidate_shader_cache) - bpy.types.World.arm_pcss_rings = bpy.props.IntProperty(name="Rings", description="", default=20, update=assets.invalidate_shader_cache) bpy.types.World.arm_shadowmap_split = bpy.props.FloatProperty(name="Cascade Split", description="Split factor for cascaded shadow maps, higher factor favors detail on close surfaces", default=0.8, update=assets.invalidate_shader_cache) bpy.types.World.arm_autoexposure_strength = bpy.props.FloatProperty(name="Auto Exposure Strength", default=0.7, update=assets.invalidate_shader_cache) bpy.types.World.arm_ssrs_ray_step = bpy.props.FloatProperty(name="Ray Step", default=0.01, update=assets.invalidate_shader_cache) @@ -328,6 +327,7 @@ def init_properties(): bpy.types.World.arm_lens_texture = bpy.props.StringProperty(name="Lens Texture", default="") bpy.types.World.arm_fisheye = bpy.props.BoolProperty(name="Fish Eye", default=False, update=assets.invalidate_shader_cache) bpy.types.World.arm_vignette = bpy.props.BoolProperty(name="Vignette", default=False, update=assets.invalidate_shader_cache) + bpy.types.World.arm_lensflare = bpy.props.BoolProperty(name="Lens Flare", default=False, update=assets.invalidate_shader_cache) # Skin bpy.types.World.arm_skin = EnumProperty( items=[('GPU (Dual-Quat)', 'GPU (Dual-Quat)', 'GPU (Dual-Quat)'), diff --git a/blender/arm/props_renderpath.py b/blender/arm/props_renderpath.py index 9dc1cd98..e4bcfc5d 100644 --- a/blender/arm/props_renderpath.py +++ b/blender/arm/props_renderpath.py @@ -176,7 +176,7 @@ class ArmRPListItem(bpy.types.PropertyGroup): ('0.25', '0.25', '0.25')], name="Resolution Z", description="3D texture z resolution multiplier", default='1.0', update=update_renderpath) arm_clouds = bpy.props.BoolProperty(name="Clouds", default=False, update=assets.invalidate_shader_cache) - arm_pcss_state = EnumProperty( + arm_soft_shadows = EnumProperty( items=[('On', 'On', 'On'), ('Off', 'Off', 'Off'), ('Auto', 'Auto', 'Auto')], diff --git a/blender/arm/props_ui.py b/blender/arm/props_ui.py index fa68ff3f..011c9cc4 100644 --- a/blender/arm/props_ui.py +++ b/blender/arm/props_ui.py @@ -1019,7 +1019,7 @@ class ArmRenderPathPanel(bpy.types.Panel): layout.prop(rpdat, 'arm_rp_resolution') layout.separator() - # layout.prop(rpdat, 'arm_pcss_state') + layout.prop(rpdat, 'arm_soft_shadows') layout.prop(rpdat, 'arm_samples_per_pixel') layout.prop(rpdat, 'arm_texture_filter') layout.prop(rpdat, "arm_diffuse_model") @@ -1051,9 +1051,6 @@ class ArmRenderPropsPanel(bpy.types.Panel): layout.label('Shadows') layout.prop(wrd, 'arm_shadowmap_split') - # layout.label('PCSS') - # layout.prop(wrd, 'arm_pcss_rings') - layout.label('Clouds') row = layout.row() row.prop(wrd, 'arm_clouds_density') @@ -1139,6 +1136,7 @@ class ArmRenderPropsPanel(bpy.types.Panel): row.prop(wrd, 'arm_fog_amountb') layout.prop(wrd, 'arm_fisheye') layout.prop(wrd, 'arm_vignette') + layout.prop(wrd, 'arm_lensflare') layout.prop(wrd, 'arm_autoexposure_strength') layout.prop(wrd, 'arm_lens_texture') diff --git a/blender/arm/write_data.py b/blender/arm/write_data.py index 7fbeb8dc..fc8b298b 100755 --- a/blender/arm/write_data.py +++ b/blender/arm/write_data.py @@ -426,11 +426,6 @@ const float ssrJitter = """ + str(round(wrd.arm_ssr_jitter * 100) / 100) + """; f.write( """const float volumAirTurbidity = """ + str(round(wrd.arm_volumetric_light_air_turbidity * 100) / 100) + """; const vec3 volumAirColor = vec3(""" + str(round(wrd.arm_volumetric_light_air_color[0] * 100) / 100) + """, """ + str(round(wrd.arm_volumetric_light_air_color[1] * 100) / 100) + """, """ + str(round(wrd.arm_volumetric_light_air_color[2] * 100) / 100) + """); -""") - - if rpdat.arm_pcss_state == 'On': - f.write( -"""const int pcssRings = """ + str(wrd.arm_pcss_rings) + """; """) if rpdat.rp_autoexposure: