This commit is contained in:
Lubos Lenco 2017-01-08 11:06:14 +01:00
parent b038f99225
commit 3288c4d804
55 changed files with 6 additions and 3661 deletions

View File

@ -4,10 +4,11 @@ os:
- osx
language: node_js
before_script:
- git clone --recursive https://github.com/kode/Kha.git tools/ci/Kha
- git clone https://github.com/armory3d/iron.git tools/ci/Libraries/iron
- git clone https://github.com/kode/nodejs_bin.git tools/ci/nodejs_bin
- tools/ci/nodejs_bin/copysysbin.sh
- git clone https://github.com/armory3d/armory_ci
- git clone --recursive https://github.com/kode/Kha.git armory_ci/test1/Kha
- git clone https://github.com/armory3d/iron.git armory_ci/test1/Libraries/iron
- git clone https://github.com/kode/nodejs_bin.git armory_ci/test1/nodejs_bin
- armory_ci/test1/nodejs_bin/copysysbin.sh
script:
- cd tools/ci
- cd armory_ci/test1
- nodejs_bin/node Kha/make.js krom

View File

@ -1,42 +0,0 @@
// Auto-generated
package ;
class Main {
public static inline var projectName = 'untitled';
public static inline var projectPackage = 'arm';
public static inline var projectAssets = 9;
static inline var projectWidth = 960;
static inline var projectHeight = 540;
static inline var projectSamplesPerPixel = 1;
static inline var projectScene = 'Scene';
static var state:Int;
#if js
static function loadLib(name:String) {
kha.LoaderImpl.loadBlobFromDescription({ files: [name] }, function(b:kha.Blob) {
untyped __js__("(1, eval)({0})", b.toString());
state--;
start();
});
}
#end
public static function main() {
iron.system.CompileTime.importPackage('armory.trait');
iron.system.CompileTime.importPackage('armory.renderpath');
iron.system.CompileTime.importPackage('arm');
state = 1;
#if (js && arm_physics) state++; loadLib("ammo.js"); #end
#if (js && arm_navigation) state++; loadLib("recast.js"); #end
state--; start();
}
static function start() {
if (state > 0) return;
armory.object.Uniforms.register();
kha.System.init({title: projectName, width: projectWidth, height: projectHeight, samplesPerPixel: projectSamplesPerPixel}, function() {
iron.App.init(function() {
iron.Scene.setActive(projectScene, function(object:iron.object.Object) {
object.addTrait(new armory.trait.internal.SpaceArmory());
});
});
});
}
}

View File

@ -1 +0,0 @@
<EFBFBD>¬shader_datasƒ°vertex_structure¤name£pos¤size¤name¿blur_edge_pass_EnvCol_SSAO_SMAA¨contexts”ˆ¬compare_mode¦always©constantsƒ¤link¦_vec2x¤name£dir¤type¤vec2ƒ¤link«_screenSize¤nameªscreenSize¤type¤vec2¤name°blur_edge_pass_x¯fragment_shaderÙ$blur_edge_pass_EnvCol_SSAO_SMAA.frag©cull_mode¤none­vertex_shaderÙ$blur_edge_pass_EnvCol_SSAO_SMAA.vert­texture_units<73>¤name£tex<65>¤name¨gbuffer0«depth_writeˆ¬compare_mode¦always©constantsƒ¤link¦_vec2y¤name£dir¤type¤vec2ƒ¤link«_screenSize¤nameªscreenSize¤type¤vec2¤name°blur_edge_pass_y¯fragment_shaderÙ$blur_edge_pass_EnvCol_SSAO_SMAA.frag©cull_mode¤none­vertex_shaderÙ$blur_edge_pass_EnvCol_SSAO_SMAA.vert­texture_units<73>¤name£tex<65>¤name¨gbuffer0«depth_write±blend_destinationªblend_zero¬compare_mode¦always¬blend_source±destination_color©constantsƒ¤link¦_vec2y¤name£dir¤type¤vec2ƒ¤link«_screenSize¤nameªscreenSize¤type¤vec2¤name¶blur_edge_pass_y_blend¯fragment_shaderÙ$blur_edge_pass_EnvCol_SSAO_SMAA.frag©cull_mode¤none­vertex_shaderÙ$blur_edge_pass_EnvCol_SSAO_SMAA.vert­texture_units<73>¤name£tex<65>¤name¨gbuffer0«depth_write¯blend_operation£add<64>¬compare_mode¦always·alpha_blend_destination©blend_one¤nameºblur_edge_pass_y_blend_add­vertex_shaderÙ$blur_edge_pass_EnvCol_SSAO_SMAA.vert­texture_units<73>¤name£tex<65>¤name¨gbuffer0¯blend_operation£add±blend_destination©blend_one¬blend_source©blend_one©constantsƒ¤link¦_vec2y¤name£dir¤type¤vec2ƒ¤link«_screenSize¤nameªscreenSize¤type¤vec2©cull_mode¤none²alpha_blend_source©blend_one«depth_write¯fragment_shaderÙ$blur_edge_pass_EnvCol_SSAO_SMAA.frag

View File

@ -1 +0,0 @@
<EFBFBD>¬shader_datasƒ°vertex_structure¤name£pos¤size¤nameÙ-compositor_pass_EnvCol_SSAO_SMAA_CompoTonemap¨contextsˆ¬compare_mode¦always©constants<74>¤name¯compositor_pass¯fragment_shaderÙ2compositor_pass_EnvCol_SSAO_SMAA_CompoTonemap.frag©cull_mode¤none­vertex_shaderÙ2compositor_pass_EnvCol_SSAO_SMAA_CompoTonemap.vert­texture_units”<73>¤name£tex<65>¤name¨gbufferD<72>¤name¨gbuffer0<72>¤name¨gbuffer1«depth_writeÂ

View File

@ -1 +0,0 @@
<EFBFBD>¬shader_datasƒ°vertex_structure¤name£pos¤size¤nameÙ"deferred_indirect_EnvCol_SSAO_SMAA¨contextsˆ¬compare_mode¦always©constantsƒ¤link±_envmapIrradiance¤name¥shirr¤type¦floatsƒ¤link¯_envmapStrength¤name®envmapStrength¤type¥float¤name±deferred_indirect¯fragment_shaderÙ'deferred_indirect_EnvCol_SSAO_SMAA.frag©cull_mode¤none­vertex_shaderÙ'deferred_indirect_EnvCol_SSAO_SMAA.vert­texture_units”<73>¤name¨gbufferD<72>¤name¨gbuffer0<72>¤name¨gbuffer1<72>¤name§ssaotex«depth_writeÂ

View File

@ -1 +0,0 @@
<EFBFBD>shader_datas<EFBFBD>釘ertex_structure<EFBFBD>孓ameφos山ize孓ame盥eferred_light_EnvCol_SSAO_SMAA牢ontexts<74>柚ompare_mode君reater戢lpha_blend_destination奔lend_one孓ame宵eferred_light赳ertex_shader<65>$deferred_light_EnvCol_SSAO_SMAA.vert負exture_units<74>孓ame狂bufferD<72>name狂buffer0<72>name狂buffer1<72>name孟hadowMap畜lend_operationζdd帳lend_destination奔lend_one枴lend_source奔lend_one妾onstants<74>子ink<6E>$_lampVolumeWorldViewProjectionMatrix孓ame他VWVP川ype孑at4<74>link嫻inverseViewProjectionMatrix孓ame可nvVP川ype孑at4<74>link<6E>"_biasLampWorldViewProjectionMatrix孓ame几WVP川ype孑at4<74>link茁lampPosition孓ame甸ightPos川ype己ec3<63>link宰lampDirection孓ame甸ightDir川ype己ec3<63>link奇lampType孓ame始ightType川ypeξnt<6E>link泣lampColor孓ame泓ightColor川ype己ec3<63>link起lampShadowsBias孓ame哀hadowsBias川ype卯loat<61>link珞spotlampCutoff孓ame盎potlightCutoff川ype卯loat<61>link巢spotlampExponent孓ame御potlightExponent川ype卯loat<61>link珞cameraPosition孓ameκye川ype己ec3妾ull_mode帷ounter_clockwise淮lpha_blend_source奔lend_one削epth_write簪fragment_shader<65>$deferred_light_EnvCol_SSAO_SMAA.frag

View File

@ -1 +0,0 @@
〓shader_datas巣ーvertex_structure曹、name」pos、size、nameル"smaa_blend_weight_EnvCol_SSAO_SMAAィcontexts争ャcompare_modeヲalwaysゥconstants茶、linkォ_screenSize、nameェscreenSize、type、vec2Ζlinkョ_screenSizeInv、nameュscreenSizeInv、type、vec2、nameアsmaa_blend_weightッfragment_shaderル'smaa_blend_weight_EnvCol_SSAO_SMAA.fragゥcull_mode、noneュvertex_shaderル'smaa_blend_weight_EnvCol_SSAO_SMAA.vertュtexture_units煤、nameィcolorTex▽nameィedgesTexうlinkゥ_smaaArea、nameァareaTexうlinkォ_smaaSearch、nameゥsearchTexォdepth_writeツ

View File

@ -1 +0,0 @@
<EFBFBD>¬shader_datasƒ°vertex_structure¤name£pos¤size¤nameÙ!smaa_edge_detect_EnvCol_SSAO_SMAA¨contextsˆ¬compare_mode¦always©constantsƒ¤link®_screenSizeInv¤name­screenSizeInv¤type¤vec2¤name°smaa_edge_detect¯fragment_shaderÙ&smaa_edge_detect_EnvCol_SSAO_SMAA.frag©cull_mode¤none­vertex_shaderÙ&smaa_edge_detect_EnvCol_SSAO_SMAA.vert­texture_units<73>¤name¨colorTex«depth_writeÂ

View File

@ -1 +0,0 @@
<EFBFBD>¬shader_datasƒ°vertex_structure¤name£pos¤size¤nameÙ(smaa_neighborhood_blend_EnvCol_SSAO_SMAA¨contextsˆ¬compare_mode¦always©constantsƒ¤link®_screenSizeInv¤name­screenSizeInv¤type¤vec2¤name·smaa_neighborhood_blend¯fragment_shaderÙ-smaa_neighborhood_blend_EnvCol_SSAO_SMAA.frag©cull_mode¤none­vertex_shaderÙ-smaa_neighborhood_blend_EnvCol_SSAO_SMAA.vert­texture_units<73>¤name¨colorTex<65>¤name¨blendTex«depth_writeÂ

View File

@ -1 +0,0 @@
〓shader_datas巣ーvertex_structure曹、name」pos、size、nameコssao_pass_EnvCol_SSAO_SMAAィcontexts争ャcompare_modeヲalwaysゥconstants買、linkシ_inverseViewProjectionMatrix、name・invVP、type、mat4Ζlinkッ_cameraPosition、name」eye、type、vec3Ζlinkォ_screenSize、nameェscreenSize、type、vec2Ζlinkャ_aspectRatio、nameォaspectRatio、type、vec2、nameゥssao_passッfragment_shaderソssao_pass_EnvCol_SSAO_SMAA.fragゥcull_mode、noneュvertex_shaderソssao_pass_EnvCol_SSAO_SMAA.vertュtexture_units刀、nameィgbufferD▽nameィgbuffer0うlinkァ_noise8、nameヲsnoiseォdepth_writeツ

View File

@ -1 +0,0 @@
〓shader_datas巣ーvertex_structure窒、name」pos、sizeうname」nor、size、nameカworld_EnvCol_SSAO_SMAAィcontexts争ャcompare_mode、lessゥconstants塔、linkョ_skydomeMatrix、name、SMVP、type、mat4Ζlinkョ_backgroundCol、nameュbackgroundCol、type、vec3うnameョenvmapStrength、type・float、name・worldッfragment_shaderサworld_EnvCol_SSAO_SMAA.fragゥcull_modeゥclockwiseュvertex_shaderサworld_EnvCol_SSAO_SMAA.vertュtexture_units性depth_writeツ

View File

@ -1 +0,0 @@
〓shader_datas巣ーvertex_structure窒、name」pos、sizeうname」nor、size、nameュMaterial_dataィcontexts宙ャcompare_mode、less、name、meshゥconstants買、linkャ_worldMatrix、name。W、type、mat4Ζlinkュ_normalMatrix、name。N、type、mat4Ζlinkコ_worldViewProjectionMatrix、name」WVP、type、mat4Ζlinkッ_cameraPosition、name」eye、type、vec3ゥcull_modeゥclockwiseュvertex_shaderイMaterial_mesh.vertュtexture_units性depth_writeテッfragment_shaderイMaterial_mesh.frag握compare_mode、less、nameゥshadowmapゥconstants巣、linkセ_lampWorldViewProjectionMatrix、name、LWVP、type、mat4ゥcull_modeゥclockwiseュvertex_shaderキMaterial_shadowmap.vertュtexture_units性depth_writeテッfragment_shaderキMaterial_shadowmap.frag

View File

@ -1,27 +0,0 @@
#version 450
#define _EnvCol
#define _SSAO
#define _SMAA
#include "../../Shaders/compiled.glsl"
#include "../../Shaders/std/gbuffer.glsl"
in vec3 wposition;
in vec3 eyeDir;
in vec3 wnormal;
out vec4[2] fragColor;
void main() {
vec3 n = normalize(wnormal);
vec3 v = normalize(eyeDir);
float dotNV = max(dot(n, v), 0.0);
vec3 basecol;
float roughness;
float metallic;
float occlusion;
basecol = vec3(0.800000011920929, 0.800000011920929, 0.800000011920929);
roughness = 0.0;
metallic = 0.0;
occlusion = 1.0;
n /= (abs(n.x) + abs(n.y) + abs(n.z));
n.xy = n.z >= 0.0 ? n.xy : octahedronWrap(n.xy);
fragColor[0] = vec4(n.xy, packFloat(metallic, roughness), 1.0 - gl_FragCoord.z);
fragColor[1] = vec4(basecol.rgb, occlusion);
}

View File

@ -1,20 +0,0 @@
#version 450
#define _EnvCol
#define _SSAO
#define _SMAA
in vec3 pos;
in vec3 nor;
out vec3 wposition;
out vec3 eyeDir;
out vec3 wnormal;
uniform mat4 W;
uniform mat4 N;
uniform mat4 WVP;
uniform vec3 eye;
void main() {
vec4 spos = vec4(pos, 1.0);
wnormal = normalize(mat3(N) * nor);
wposition = vec4(W * spos).xyz;
eyeDir = eye - wposition;
gl_Position = WVP * spos;
}

View File

@ -1,8 +0,0 @@
#version 450
#define _EnvCol
#define _SSAO
#define _SMAA
out vec4 fragColor;
void main() {
fragColor = vec4(0.0);
}

View File

@ -1,11 +0,0 @@
#version 450
#define _EnvCol
#define _SSAO
#define _SMAA
in vec3 pos;
in vec3 nor;
uniform mat4 LWVP;
void main() {
vec4 spos = vec4(pos, 1.0);
gl_Position = LWVP * spos;
}

View File

@ -1,69 +0,0 @@
// Exclusive to SSAO for now
#version 450
#define _EnvCol
#define _SSAO
#define _SMAA
#ifdef GL_ES
precision mediump float;
#endif
#include "../compiled.glsl"
#include "../std/gbuffer.glsl"
// getNor()
uniform sampler2D tex;
uniform sampler2D gbuffer0;
uniform vec2 dir;
uniform vec2 screenSize;
in vec2 texCoord;
out vec4 fragColor;
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;
vec3 result = vec3(0.0);
float doBlur(float blurWeight, int pos, vec3 nor, vec2 texCoord) {
vec2 texstep = dir / screenSize;
vec3 nor2 = getNor(texture(gbuffer0, texCoord + pos * texstep).rg);
float influenceFactor = step(discardThreshold, dot(nor2, nor));
vec3 col = texture(tex, texCoord + (pos + 0.5) * texstep).rgb;
result += col * blurWeight * influenceFactor;
float weight = blurWeight * influenceFactor;
nor2 = getNor(texture(gbuffer0, texCoord - pos * texstep).rg);
influenceFactor = step(discardThreshold, dot(nor2, nor));
col = texture(tex, texCoord - (pos + 0.5) * texstep).rgb;
result += col * blurWeight * influenceFactor;
weight += blurWeight * influenceFactor;
return weight;
}
void main() {
vec2 tc = texCoord * ssaoTextureScale;
vec3 nor = getNor(texture(gbuffer0, texCoord).rg);
// for (int i = 0; i < 9; i++) {
vec3 col = texture(tex, tc).rgb;
result += col * blurWeights[0];
float weight = blurWeights[0];
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);
// }
result /= weight;
fragColor = vec4(result.rrr, 1.0); // SSAO only
}

View File

@ -1,20 +0,0 @@
#version 450
#define _EnvCol
#define _SSAO
#define _SMAA
#ifdef GL_ES
precision highp float;
#endif
in vec2 pos;
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;
gl_Position = vec4(pos.xy, 0.0, 1.0);
}

View File

@ -1,23 +0,0 @@
#ifndef _COMPILED_GLSL_
#define _COMPILED_GLSL_
const float PI = 3.1415926535;
const float PI2 = PI * 2.0;
const vec2 cameraPlane = vec2(0.1, 200.0);
const vec2 shadowmapSize = vec2(2048, 2048);
const float ssaoSize = 0.12;
const float ssaoStrength = 0.25;
const float ssaoTextureScale = 1.0;
const float bloomThreshold = 20.0;
const float bloomStrength = 0.5;
const float bloomRadius = 0.5;
const float motionBlurIntensity = 1.0;
const float ssrRayStep = 0.04;
const float ssrMinRayStep = 0.05;
const float ssrSearchDist = 5.0;
const float ssrFalloffExp = 5.0;
const float ssrJitter = 0.6;
const float ssrTextureScale = 1.0;
const float volumAirTurbidity = 1.0;
const vec3 volumAirColor = vec3(1.0, 1.0, 1.0);
const int skinMaxBones = 50;
#endif // _COMPILED_GLSL_

View File

@ -1,271 +0,0 @@
#version 450
#define _EnvCol
#define _SSAO
#define _SMAA
#define _CompoTonemap
#ifdef GL_ES
precision highp float;
#endif
#include "../compiled.glsl"
#include "../std/tonemap.glsl"
// tonemapUncharted2()
// tonemapFilmic()
#include "../std/math.glsl"
// linearize()
#ifdef _CDOF
#include "../std/dof.glsl"
#endif
uniform sampler2D tex;
uniform sampler2D gbufferD;
uniform sampler2D gbuffer0;
uniform sampler2D gbuffer1;
// #ifdef _CPos
// uniform vec3 eye;
// uniform vec3 eyeLook;
// #endif
#ifdef _CGlare
uniform vec3 light;
uniform mat4 VP;
uniform vec3 eye;
uniform vec3 eyeLook;
uniform float aspectRatio;
#endif
#ifdef _CFXAA
uniform vec2 texStep;
#elif _CDOF
uniform vec2 texStep;
#endif
#ifdef _CGrain
uniform float time;
#endif
#ifdef _DynRes
uniform float dynamicScale;
#endif
in vec2 texCoord;
// #ifdef _CPos
// in vec3 viewRay;
// #endif
out vec4 fragColor;
#ifdef _CFog
// const vec3 compoFogColor = vec3(0.5, 0.6, 0.7);
// const float compoFogAmountA = 1.0; // b = 0.01
// const float compoFogAmountB = 1.0; // c = 0.1
// vec3 applyFog(vec3 rgb, // original color of the pixel
// float distance, // camera to point distance
// vec3 rayOri, // camera position
// vec3 rayDir) { // camera to point vector
// float fogAmount = compoFogAmountB * exp(-rayOri.y * compoFogAmountA) * (1.0 - exp(-distance * rayDir.y * compoFogAmountA)) / rayDir.y;
// return mix(rgb, compoFogColor, fogAmount);
// }
vec3 applyFog(vec3 rgb, float distance) {
// float fogAmount = 1.0 - exp(-distance * compoFogAmountA);
float fogAmount = 1.0 - exp(-distance * 0.0055);
return mix(rgb, compoFogColor, fogAmount);
}
#endif
float vignette() {
// vignetting from iq
// return 0.4 + 0.6 * pow(16.0 * texCoord.x * texCoord.y * (1.0 - texCoord.x) * (1.0 - texCoord.y), 0.2);
return 0.3 + 0.7 * pow(16.0 * texCoord.x * texCoord.y * (1.0 - texCoord.x) * (1.0 - texCoord.y), 0.2);
}
#ifdef _CGlare
// Based on lense flare implementation by musk
// https://www.shadertoy.com/view/4sX3Rs
vec3 lensflare(vec2 uv, vec2 pos) {
vec2 uvd = uv * (length(uv));
float f2 = max(1.0/(1.0+32.0*pow(length(uvd+0.8*pos),2.0)),0.0)*0.25;
float f22 = max(1.0/(1.0+32.0*pow(length(uvd+0.85*pos),2.0)),0.0)*0.23;
float f23 = max(1.0/(1.0+32.0*pow(length(uvd+0.9*pos),2.0)),0.0)*0.21;
vec2 uvx = mix(uv, uvd, -0.5);
float f4 = max(0.01-pow(length(uvx+0.4*pos),2.4),0.0)*6.0;
float f42 = max(0.01-pow(length(uvx+0.45*pos),2.4),0.0)*5.0;
float f43 = max(0.01-pow(length(uvx+0.5*pos),2.4),0.0)*3.0;
uvx = mix(uv, uvd, -0.4);
float f5 = max(0.01-pow(length(uvx+0.2*pos),5.5),0.0)*2.0;
float f52 = max(0.01-pow(length(uvx+0.4*pos),5.5),0.0)*2.0;
float f53 = max(0.01-pow(length(uvx+0.6*pos),5.5),0.0)*2.0;
uvx = mix(uv, uvd, -0.5);
float f6 = max(0.01-pow(length(uvx-0.3*pos),1.6),0.0)*6.0;
float f62 = max(0.01-pow(length(uvx-0.325*pos),1.6),0.0)*3.0;
float f63 = max(0.01-pow(length(uvx-0.35*pos),1.6),0.0)*5.0;
vec3 c = vec3(0.0);
c.r += f2 + f4 + f5 + f6;
c.g += f22 + f42 + f52 + f62;
c.b += f23 + f43 + f53 + f63;
return c;
}
#endif
void main() {
vec2 texCo = texCoord;
#ifdef _DynRes
texCo *= dynamicScale;
#endif
#ifdef _CFishEye
const float fishEyeStrength = -0.01;
const vec2 m = vec2(0.5, 0.5);
vec2 d = texCo - m;
float r = sqrt(dot(d, d));
float power = (2.0 * PI / (2.0 * sqrt(dot(m, m)))) * fishEyeStrength;
float bind;
if (power > 0.0) { bind = sqrt(dot(m, m)); }
else { bind = m.x; }
if (power > 0.0) {
texCo = m + normalize(d) * tan(r * power) * bind / tan(bind * power);
}
else {
texCo = m + normalize(d) * atan(r * -power * 10.0) * bind / atan(-power * bind * 10.0);
}
#endif
#ifdef _CDepth
float depth = texture(gbufferD, texCo).r * 2.0 - 1.0;
#endif
#ifdef _CFXAA
const float FXAA_REDUCE_MIN = 1.0 / 128.0;
const float FXAA_REDUCE_MUL = 1.0 / 8.0;
const float FXAA_SPAN_MAX = 8.0;
vec2 tcrgbNW = (texCo + vec2(-1.0, -1.0) * texStep);
vec2 tcrgbNE = (texCo + vec2(1.0, -1.0) * texStep);
vec2 tcrgbSW = (texCo + vec2(-1.0, 1.0) * texStep);
vec2 tcrgbSE = (texCo + vec2(1.0, 1.0) * texStep);
vec2 tcrgbM = vec2(texCo);
vec3 rgbNW = texture(tex, tcrgbNW).rgb;
vec3 rgbNE = texture(tex, tcrgbNE).rgb;
vec3 rgbSW = texture(tex, tcrgbSW).rgb;
vec3 rgbSE = texture(tex, tcrgbSE).rgb;
vec3 rgbM = texture(tex, tcrgbM).rgb;
vec3 luma = vec3(0.299, 0.587, 0.114);
float lumaNW = dot(rgbNW, luma);
float lumaNE = dot(rgbNE, luma);
float lumaSW = dot(rgbSW, luma);
float lumaSE = dot(rgbSE, luma);
float lumaM = dot(rgbM, luma);
float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));
float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));
vec2 dir;
dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));
dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));
float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) *
(0.25 * FXAA_REDUCE_MUL), FXAA_REDUCE_MIN);
float rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);
dir = min(vec2(FXAA_SPAN_MAX, FXAA_SPAN_MAX),
max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),
dir * rcpDirMin)) * texStep;
vec3 rgbA = 0.5 * (
texture(tex, texCo + dir * (1.0 / 3.0 - 0.5)).rgb +
texture(tex, texCo + dir * (2.0 / 3.0 - 0.5)).rgb);
vec3 rgbB = rgbA * 0.5 + 0.25 * (
texture(tex, texCo + dir * -0.5).rgb +
texture(tex, texCo + dir * 0.5).rgb);
vec3 col;
float lumaB = dot(rgbB, luma);
if ((lumaB < lumaMin) || (lumaB > lumaMax)) col = rgbA;
else col = rgbB;
#else
#ifdef _CDOF
vec3 col = dof(texCo, depth, tex, gbufferD, texStep);
#else
vec3 col = texture(tex, texCo).rgb;
#endif
#endif
#ifdef _CFog
// if (depth < 1.0) {
// vec3 pos = getPos(depth);
// float dist = distance(pos, eye);
float dist = linearize(depth);
// vec3 eyedir = eyeLook;// normalize(eye + pos);
// col.rgb = applyFog(col.rgb, dist, eye, eyedir);
col.rgb = applyFog(col.rgb, dist);
// }
#endif
#ifdef _CGlare
if (dot(light, eyeLook) > 0.0) { // Facing light
vec4 lndc = VP * vec4(light, 1.0);
lndc.xy /= lndc.w;
vec2 lss = lndc.xy * 0.5 + 0.5;
float lssdepth = linearize(texture(gbufferD, lss).r * 2.0 - 1.0);
float lightDistance = distance(eye, light);
if (lightDistance <= lssdepth) {
vec2 lensuv = texCo * 2.0 - 1.0;
lensuv.x *= aspectRatio;
vec3 lensflarecol = vec3(1.4, 1.2, 1.0) * lensflare(lensuv, lndc.xy);
col.rgb += lensflarecol;
}
}
#endif
#ifdef _CGrain
// const float compoGrainStrength = 4.0;
float x = (texCo.x + 4.0) * (texCo.y + 4.0) * (time * 10.0);
col.rgb += vec3(mod((mod(x, 13.0) + 1.0) * (mod(x, 123.0) + 1.0), 0.01) - 0.005) * compoGrainStrength;
#endif
#ifdef _CVignette
col.rgb *= vignette();
#endif
#ifdef _CExposure
col.rgb *= compoExposureStrength;
#endif
#ifdef _CTonemap
col.rgb = tonemapUncharted2(col.rgb);
// col.rgb = tonemapFilmic(col.rgb); // With gamma
#endif
// To gamma
col.rgb = pow(col.rgb, vec3(1.0 / 2.2));
#ifdef _CBW
// col.rgb = vec3(clamp(dot(col.rgb, col.rgb), 0.0, 1.0));
col.rgb = vec3((col.r * 0.3 + col.g * 0.59 + col.b * 0.11) / 3.0) * 2.5;
#endif
// #ifdef _CContrast
// -0.5 - 0.5
// const float compoContrast = 0.2;
// col.rgb = ((col.rgb - 0.5) * max(compoContrast + 1.0, 0.0)) + 0.5;
// #endif
// #ifdef _CBrighness
// col.rgb += compoBrightness;
// #endif
#ifdef _CLetterbox
// const float compoLetterboxSize = 0.1;
col.rgb *= 1.0 - step(0.5 - compoLetterboxSize, abs(0.5 - texCo.y));
#endif
fragColor = vec4(col, 1.0);
}

View File

@ -1,37 +0,0 @@
#version 450
#define _EnvCol
#define _SSAO
#define _SMAA
#define _CompoTonemap
#ifdef GL_ES
precision highp float;
#endif
// #ifdef _CPos
// uniform mat4 invVP;
// uniform vec3 eye;
// #endif
in vec2 pos;
out vec2 texCoord;
// #ifdef _CPos
// out vec3 viewRay;
// #endif
void main() {
// Scale vertex attribute to [0-1] range
const vec2 madd = vec2(0.5, 0.5);
texCoord = pos.xy * madd + madd;
gl_Position = vec4(pos.xy, 0.0, 1.0);
// #ifdef _CPos
// NDC (at the back of cube)
// vec4 v = vec4(pos.xy, 1.0, 1.0);
// v = vec4(invVP * v);
// v.xyz /= v.w;
// viewRay = v.xyz - eye;
// #endif
}

View File

@ -1,99 +0,0 @@
#version 450
#define _EnvCol
#define _SSAO
#define _SMAA
#ifdef GL_ES
precision mediump float;
#endif
#include "../compiled.glsl"
#include "../std/gbuffer.glsl"
// octahedronWrap()
// unpackFloat()
#include "../std/math.glsl"
// envMapEquirect()
#include "../std/brdf.glsl"
#include "../std/shirr.glsl"
uniform sampler2D gbufferD;
uniform sampler2D gbuffer0;
uniform sampler2D gbuffer1;
//!uniform float shirr[27];
uniform float envmapStrength;
#ifdef _Rad
uniform sampler2D senvmapRadiance;
uniform sampler2D senvmapBrdf;
uniform int envmapNumMipmaps;
#endif
#ifdef _SSAO
uniform sampler2D ssaotex;
#endif
#ifdef _Rad
uniform vec3 eye;
uniform vec3 eyeLook;
#endif
in vec2 texCoord;
#ifdef _Rad
in vec3 viewRay;
#endif
out vec4 fragColor;
void main() {
vec4 g0 = texture(gbuffer0, texCoord); // Normal.xy, metallic/roughness, mask
vec3 n;
n.z = 1.0 - abs(g0.x) - abs(g0.y);
n.xy = n.z >= 0.0 ? g0.xy : octahedronWrap(g0.xy);
n = normalize(n);
vec2 metrough = unpackFloat(g0.b);
#ifdef _Rad
float depth = texture(gbufferD, texCoord).r * 2.0 - 1.0;
vec3 p = getPos(eye, eyeLook, viewRay, depth);
vec3 v = normalize(eye - p.xyz);
#endif
// Indirect
vec3 indirect = shIrradiance(n, 2.2) / PI;
#ifdef _Rad
vec3 reflectionWorld = reflect(-v, n);
float lod = getMipFromRoughness(metrough.y, envmapNumMipmaps);
vec3 prefilteredColor = textureLod(senvmapRadiance, envMapEquirect(reflectionWorld), lod).rgb;
#endif
#ifdef _EnvLDR
indirect = pow(indirect, vec3(2.2));
#ifdef _Rad
prefilteredColor = pow(prefilteredColor, vec3(2.2));
#endif
#endif
vec4 g1 = texture(gbuffer1, texCoord); // Basecolor.rgb, occlusion
vec3 albedo = surfaceAlbedo(g1.rgb, metrough.x); // g1.rgb - basecolor
indirect *= albedo;
#ifdef _Rad
// Indirect specular
float dotNV = max(dot(n, v), 0.0);
vec3 f0 = surfaceF0(g1.rgb, metrough.x);
vec2 envBRDF = texture(senvmapBrdf, vec2(metrough.y, 1.0 - dotNV)).xy;
indirect += prefilteredColor * (f0 * envBRDF.x + envBRDF.y);
#endif
indirect = indirect * envmapStrength;// * lightColor;
indirect = indirect * g1.a; // Occlusion
#ifdef _SSAO
indirect *= texture(ssaotex, texCoord).r; // SSAO
#endif
fragColor.rgb = indirect;
}

View File

@ -1,36 +0,0 @@
#version 450
#define _EnvCol
#define _SSAO
#define _SMAA
#ifdef GL_ES
precision highp float;
#endif
#ifdef _Rad
uniform mat4 invVP;
uniform vec3 eye;
#endif
in vec2 pos;
out vec2 texCoord;
#ifdef _Rad
out vec3 viewRay;
#endif
void main() {
// Scale vertex attribute to [0-1] range
const vec2 madd = vec2(0.5, 0.5);
texCoord = pos.xy * madd + madd;
gl_Position = vec4(pos.xy, 0.0, 1.0);
#ifdef _Rad
// NDC (at the back of cube)
vec4 v = vec4(pos.x, pos.y, 1.0, 1.0);
v = vec4(invVP * v);
v.xyz /= v.w;
viewRay = v.xyz - eye;
#endif
}

View File

@ -1,279 +0,0 @@
#version 450
#define _EnvCol
#define _SSAO
#define _SMAA
#ifdef GL_ES
precision mediump float;
#endif
#include "../compiled.glsl"
#include "../std/brdf.glsl"
#include "../std/math.glsl"
// #ifdef _PolyLight
#include "../std/ltc.glsl"
// #endif
// ...
#ifndef _NoShadows
#ifdef _PCSS
#include "../std/shadows_pcss.glsl"
// PCSS()
#else
#include "../std/shadows.glsl"
// PCF()
#endif
#endif
#include "../std/gbuffer.glsl"
// octahedronWrap()
// unpackFloat()
uniform sampler2D gbufferD;
uniform sampler2D gbuffer0;
uniform sampler2D gbuffer1;
#ifndef _NoShadows
//!uniform sampler2D shadowMap;
#ifdef _PCSS
//!uniform sampler2D snoise;
//!uniform float lampSizeUV;
#endif
#endif
#ifdef _VoxelGI
uniform sampler2D ssaotex;
uniform sampler2D senvmapBrdf;
//!uniform sampler3D voxels;
#endif
#ifdef _PolyLight
//!uniform sampler2D sltcMat;
//!uniform sampler2D sltcMag;
#endif
uniform mat4 invVP;
uniform mat4 LWVP;
uniform vec3 lightPos;
uniform vec3 lightDir;
uniform int lightType;
// uniform int lightIndex;
uniform vec3 lightColor;
uniform float shadowsBias;
uniform float spotlightCutoff;
uniform float spotlightExponent;
#ifdef _PolyLight
uniform vec3 lampArea0;
uniform vec3 lampArea1;
uniform vec3 lampArea2;
uniform vec3 lampArea3;
#endif
uniform vec3 eye;
// uniform vec3 eyeLook;
// uniform vec2 screenSize;
#ifdef _LampColTex
uniform sampler2D texlampcolor;
#endif
// in vec2 texCoord;
in vec4 wvpposition;
// in vec3 viewRay;
out vec4 fragColor;
// Separable SSS Transmittance Function, ref to sss_pass
#ifdef _SSS
vec3 SSSSTransmittance(float translucency, float sssWidth, vec3 worldPosition, vec3 worldNormal, vec3 lightDir) {
float scale = 8.25 * (1.0 - translucency) / sssWidth;
vec4 shrinkedPos = vec4(worldPosition - 0.005 * worldNormal, 1.0);
vec4 shadowPosition = LWVP * shrinkedPos;
float d1 = texture(shadowMap, shadowPosition.xy / shadowPosition.w).r; // 'd1' has a range of 0..1
float d2 = shadowPosition.z; // 'd2' has a range of 0..'lightFarPlane'
const float lightFarPlane = 120 / 3.5;
d1 *= lightFarPlane; // So we scale 'd1' accordingly:
float d = scale * abs(d1 - d2);
float dd = -d * d;
vec3 profile = vec3(0.233, 0.455, 0.649) * exp(dd / 0.0064) +
vec3(0.1, 0.336, 0.344) * exp(dd / 0.0484) +
vec3(0.118, 0.198, 0.0) * exp(dd / 0.187) +
vec3(0.113, 0.007, 0.007) * exp(dd / 0.567) +
vec3(0.358, 0.004, 0.0) * exp(dd / 1.99) +
vec3(0.078, 0.0, 0.0) * exp(dd / 7.41);
return profile * clamp(0.3 + dot(lightDir, -worldNormal), 0.0, 1.0);
}
#endif
#ifndef _NoShadows
float shadowTest(vec4 lPos) {
lPos.xyz /= lPos.w;
lPos.xy = lPos.xy * 0.5 + 0.5;
#ifdef _Clampstc
// Filtering out of bounds, remove
// const vec2 border = vec2(1.0 / shadowmapSize[0], 1.0 / shadowmapSize[1]) * 2.0;
// lPos.xy = clamp(lPos.xy, border[0], 1.0 - border[1]);
if (lPos.x < 0.0) return 1.0;
if (lPos.y < 0.0) return 1.0;
if (lPos.x > 1.0) return 1.0;
if (lPos.y > 1.0) return 1.0;
#endif
#ifdef _PCSS
return PCSS(lPos.xy, lPos.z - shadowsBias);
#else
return PCF(lPos.xy, lPos.z - shadowsBias);
#endif
}
#endif
void main() {
vec2 screenPosition = wvpposition.xy / wvpposition.w;
vec2 texCoord = screenPosition * 0.5 + 0.5;
// texCoord += vec2(0.5 / screenSize); // Half pixel offset
vec4 g0 = texture(gbuffer0, texCoord); // Normal.xy, metallic/roughness, mask
vec4 g1 = texture(gbuffer1, texCoord); // Basecolor.rgb, occlusion
// 0 - 1 => -1 - 1
// float depth = texture(gbufferD, texCoord).r * 2.0 - 1.0;
// TODO: Can not read and test depth buffer at once, fetch depth from g0
float depth = (1.0 - g0.a) * 2.0 - 1.0;
vec3 n;
n.z = 1.0 - abs(g0.x) - abs(g0.y);
n.xy = n.z >= 0.0 ? g0.xy : octahedronWrap(g0.xy);
n = normalize(n);
vec3 p = getPos2(invVP, depth, texCoord);
vec2 metrough = unpackFloat(g0.b);
vec3 v = normalize(eye - p);
float dotNV = dot(n, v);
vec3 albedo = surfaceAlbedo(g1.rgb, metrough.x); // g1.rgb - basecolor
vec3 f0 = surfaceF0(g1.rgb, metrough.x);
// Per-light
vec3 l;
if (lightType == 0) { // Sun
l = lightDir;
}
else { // Point, spot
l = normalize(lightPos - p);
}
vec3 h = normalize(v + l);
float dotNH = dot(n, h);
float dotVH = dot(v, h);
float dotNL = dot(n, l);
// float dotLV = dot(l, v);
// float dotLH = dot(l, h);
float visibility = 1.0;
#ifndef _NoShadows
vec4 lampPos = LWVP * vec4(p, 1.0);
if (lampPos.w > 0.0) {
visibility = shadowTest(lampPos);
}
#endif
// Direct
vec3 direct;
#ifdef _PolyLight
if (lightType == 3) { // Area
float theta = acos(dotNV);
vec2 tuv = vec2(metrough.y, theta / (0.5 * PI));
tuv = tuv * LUT_SCALE + LUT_BIAS;
// vec4 t = texture(sltcMat, tuv);
vec4 t = clamp(texture(sltcMat, tuv), 0.0, 1.0);
mat3 invM = mat3(
vec3(1.0, 0.0, t.y),
vec3(0.0, t.z, 0.0),
vec3(t.w, 0.0, t.x));
vec3 ltcspec = ltcEvaluate(n, v, dotNV, p, invM, lampArea0, lampArea1, lampArea2, lampArea3, true);
ltcspec *= texture(sltcMag, tuv).a;
vec3 ltcdiff = ltcEvaluate(n, v, dotNV, p, mat3(1.0), lampArea0, lampArea1, lampArea2, lampArea3, true);
direct = ltcdiff * albedo + ltcspec;
direct = clamp(direct, 0.0, 10.0);
}
else {
#endif
#ifdef _OrenNayar
direct = orenNayarDiffuseBRDF(albedo, metrough.y, dotNV, dotNL, dotVH) + specularBRDF(f0, metrough.y, dotNL, dotNH, dotNV, dotVH);
#else
direct = lambertDiffuseBRDF(albedo, dotNL) + specularBRDF(f0, metrough.y, dotNL, dotNH, dotNV, dotVH);
#endif
if (lightType == 2) { // Spot
float spotEffect = dot(lightDir, l);
if (spotEffect < spotlightCutoff) {
float spotEffect = smoothstep(spotlightCutoff - spotlightExponent, spotlightCutoff, spotEffect);
direct *= spotEffect;
}
}
#ifdef _PolyLight
}
#endif
// Aniso spec
// #ifdef _Aniso
// float shinyParallel = metrough.y;
// float shinyPerpendicular = 0.08;
// vec3 fiberDirection = vec3(0.0, 1.0, 8.0);
// vec3 direct = diffuseBRDF(albedo, metrough.y, dotNV, dotNL, dotVH, dotLV) + wardSpecular(n, h, dotNL, dotNV, dotNH, fiberDirection, shinyParallel, shinyPerpendicular);
// #endif
direct *= lightColor;
#ifdef _LampColTex
// direct *= texture(texlampcolor, envMapEquirect(l)).rgb;
direct *= pow(texture(texlampcolor, l.xy).rgb, vec3(2.2));
#endif
#ifdef _SSS
float mask = g0.a;
if (mask == 2.0) {
direct *= SSSSTransmittance(1.0, 0.005, p, n, l);
}
#endif
// Direct
fragColor = vec4(vec3(direct * visibility), 1.0);
// Voxels test..
#ifdef _VoxelGI
vec4 g1a = texture(gbuffer1, texCoord); // Basecolor.rgb, occlusion
vec3 albedoa = surfaceAlbedo(g1a.rgb, metrough.x); // g1a.rgb - basecolor
vec3 tangent = normalize(cross(n, vec3(0.0, 1.0, 0.0)));
if (length(tangent) == 0.0) {
tangent = normalize(cross(n, vec3(0.0, 0.0, 1.0)));
}
vec3 bitangent = normalize(cross(n, tangent));
mat3 tanToWorld = inverse(transpose(mat3(tangent, bitangent, n)));
float diffOcclusion = 0.0;
vec3 indirectDiffusea = coneTraceIndirect(p, tanToWorld, n, diffOcclusion).rgb * 4.0;
indirectDiffusea *= albedoa;
diffOcclusion = min(1.0, 1.5 * diffOcclusion);
vec3 reflectWorld = reflect(-v, n);
float specularOcclusion;
float lodOffset = 0.0;//getMipFromRoughness(roughness, numMips);
vec3 indirectSpecular = coneTrace(p, reflectWorld, n, 0.07 + lodOffset, specularOcclusion).rgb;
if (metrough.y > 0.0) { // Temp..
float dotNVa = max(dot(n, v), 0.0);
vec3 f0a = surfaceF0(g1a.rgb, metrough.x);
vec2 envBRDFa = texture(senvmapBrdf, vec2(metrough.y, 1.0 - dotNVa)).xy;
indirectSpecular *= (f0a * envBRDFa.x + envBRDFa.y);
}
vec3 indirect1 = indirectDiffusea * diffOcclusion + indirectSpecular;
indirect1 *= texture(ssaotex, texCoord).r;
fragColor.rgb += indirect1;
#endif
}

View File

@ -1,19 +0,0 @@
#version 450
#define _EnvCol
#define _SSAO
#define _SMAA
#ifdef GL_ES
precision highp float;
#endif
uniform mat4 LVWVP;
in vec3 pos;
out vec4 wvpposition;
void main() {
wvpposition = LVWVP * vec4(pos, 1.0);
gl_Position = wvpposition;
}

View File

@ -1,735 +0,0 @@
#version 450
#define _EnvCol
#define _SSAO
#define _SMAA
#ifdef GL_ES
precision mediump float;
#endif
#define SMAA_MAX_SEARCH_STEPS_DIAG 8
#define SMAA_AREATEX_MAX_DISTANCE 16
#define SMAA_AREATEX_MAX_DISTANCE_DIAG 20
#define SMAA_AREATEX_PIXEL_SIZE (1.0 / vec2(160.0, 560.0))
#define SMAA_AREATEX_SUBTEX_SIZE (1.0 / 7.0)
#define SMAA_SEARCHTEX_SIZE vec2(66.0, 33.0)
#define SMAA_SEARCHTEX_PACKED_SIZE vec2(64.0, 16.0)
#define SMAA_CORNER_ROUNDING 25
#define SMAA_CORNER_ROUNDING_NORM (float(SMAA_CORNER_ROUNDING) / 100.0)
#define SMAA_AREATEX_SELECT(sample) sample.rg
#define SMAA_SEARCHTEX_SELECT(sample) sample.r
// #define SMAA_RT_METRICS vec4(1.0 / 800.0, 1.0 / 600.0, 800.0, 600.0)
#define SMAASampleLevelZeroOffset(tex, coord, offset) textureLod(tex, coord + offset * screenSizeInv.xy, 0.0)
#define mad(a, b, c) (a * b + c)
#define saturate(a) clamp(a, 0.0, 1.0)
#define round(a) floor(a + 0.5)
uniform sampler2D colorTex;
uniform sampler2D edgesTex;
uniform sampler2D areaTex;
uniform sampler2D searchTex;
uniform vec2 screenSize;
uniform vec2 screenSizeInv;
in vec2 texCoord;
in vec2 pixcoord;
// in vec4 offset[3];
in vec4 offset0;
in vec4 offset1;
in vec4 offset2;
out vec4 fragColor;
// Blending Weight Calculation Pixel Shader (Second Pass)
vec2 cdw_end;
//-----------------------------------------------------------------------------
// Diagonal Search Functions
// Conditional move:
// void SMAAMovc(bvec2 cond, inout vec2 variable, vec2 value) {
// /*SMAA_FLATTEN*/ if (cond.x) variable.x = value.x;
// /*SMAA_FLATTEN*/ if (cond.y) variable.y = value.y;
// }
// void SMAAMovc(bvec4 cond, inout vec4 variable, vec4 value) {
// SMAAMovc(cond.xy, variable.xy, value.xy);
// SMAAMovc(cond.zw, variable.zw, value.zw);
// }
// #if !defined(SMAA_DISABLE_DIAG_DETECTION)
/**
* Allows to decode two binary values from a bilinear-filtered access.
*/
vec2 SMAADecodeDiagBilinearAccess(vec2 e) {
// Bilinear access for fetching 'e' have a 0.25 offset, and we are
// interested in the R and G edges:
//
// +---G---+-------+
// | x o R x |
// +-------+-------+
//
// Then, if one of these edge is enabled:
// Red: (0.75 * X + 0.25 * 1) => 0.25 or 1.0
// Green: (0.75 * 1 + 0.25 * X) => 0.75 or 1.0
//
// This function will unpack the values (mad + mul + round):
// wolframalpha.com: round(x * abs(5 * x - 5 * 0.75)) plot 0 to 1
e.r = e.r * abs(5.0 * e.r - 5.0 * 0.75);
return round(e);
}
vec4 SMAADecodeDiagBilinearAccess(vec4 e) {
e.rb = e.rb * abs(5.0 * e.rb - 5.0 * 0.75);
return round(e);
}
/**
* These functions allows to perform diagonal pattern searches.
*/
vec2 SMAASearchDiag1(/*sampler2D edgesTex,*/ vec2 texcoord, vec2 dir/*, out vec2 e*/) {
vec4 coord = vec4(texcoord, -1.0, 1.0);
vec3 t = vec3(screenSizeInv.xy, 1.0);
if (coord.w <= 0.9) return coord.zw; //
if (coord.z >= float(SMAA_MAX_SEARCH_STEPS_DIAG - 1)) return coord.zw; //
// while (coord.z < float(SMAA_MAX_SEARCH_STEPS_DIAG - 1) && coord.w > 0.9) {
coord.xyz = mad(t, vec3(dir, 1.0), coord.xyz);
cdw_end /*e*/ = textureLod(edgesTex, coord.xy, 0.0).rg;
coord.w = dot(cdw_end /*e*/, vec2(0.5, 0.5));
// Waiting for loops
if (coord.w <= 0.9) return coord.zw; //
coord.xyz = mad(t, vec3(dir, 1.0), coord.xyz);
cdw_end /*e*/ = textureLod(edgesTex, coord.xy, 0.0).rg;
coord.w = dot(cdw_end /*e*/, vec2(0.5, 0.5));
if (coord.w <= 0.9) return coord.zw; //
coord.xyz = mad(t, vec3(dir, 1.0), coord.xyz);
cdw_end /*e*/ = textureLod(edgesTex, coord.xy, 0.0).rg;
coord.w = dot(cdw_end /*e*/, vec2(0.5, 0.5));
if (coord.w <= 0.9) return coord.zw; //
coord.xyz = mad(t, vec3(dir, 1.0), coord.xyz);
cdw_end /*e*/ = textureLod(edgesTex, coord.xy, 0.0).rg;
coord.w = dot(cdw_end /*e*/, vec2(0.5, 0.5));
if (coord.w <= 0.9) return coord.zw; //
coord.xyz = mad(t, vec3(dir, 1.0), coord.xyz);
cdw_end /*e*/ = textureLod(edgesTex, coord.xy, 0.0).rg;
coord.w = dot(cdw_end /*e*/, vec2(0.5, 0.5));
if (coord.w <= 0.9) return coord.zw; //
coord.xyz = mad(t, vec3(dir, 1.0), coord.xyz);
cdw_end /*e*/ = textureLod(edgesTex, coord.xy, 0.0).rg;
coord.w = dot(cdw_end /*e*/, vec2(0.5, 0.5));
if (coord.w <= 0.9) return coord.zw; //
coord.xyz = mad(t, vec3(dir, 1.0), coord.xyz);
cdw_end /*e*/ = textureLod(edgesTex, coord.xy, 0.0).rg;
coord.w = dot(cdw_end /*e*/, vec2(0.5, 0.5));
// }
return coord.zw;
}
vec2 SMAASearchDiag2(/*sampler2D edgesTex,*/ vec2 texcoord, vec2 dir/*, out vec2 e*/) {
vec4 coord = vec4(texcoord, -1.0, 1.0);
coord.x += 0.25 * screenSizeInv.x; // See @SearchDiag2Optimization
vec3 t = vec3(screenSizeInv.xy, 1.0);
if (coord.w <= 0.9) return coord.zw; //
if (coord.z >= float(SMAA_MAX_SEARCH_STEPS_DIAG - 1)) return coord.zw; //
// while (coord.z < float(SMAA_MAX_SEARCH_STEPS_DIAG - 1) && coord.w > 0.9) {
coord.xyz = mad(t, vec3(dir, 1.0), coord.xyz);
// @SearchDiag2Optimization
// Fetch both edges at once using bilinear filtering:
cdw_end /*e*/ = textureLod(edgesTex, coord.xy, 0.0).rg;
cdw_end /*e*/ = SMAADecodeDiagBilinearAccess(cdw_end /*e*/);
// Non-optimized version:
// e.g = SMAASampleLevelZero(edgesTex, coord.xy).g;
// e.r = SMAASampleLevelZeroOffset(edgesTex, coord.xy, ivec2(1, 0)).r;
coord.w = dot(cdw_end /*e*/, vec2(0.5, 0.5));
// Waiting for loops
if (coord.w <= 0.9) return coord.zw; //
coord.xyz = mad(t, vec3(dir, 1.0), coord.xyz);
cdw_end /*e*/ = textureLod(edgesTex, coord.xy, 0.0).rg;
cdw_end /*e*/ = SMAADecodeDiagBilinearAccess(cdw_end /*e*/);
coord.w = dot(cdw_end /*e*/, vec2(0.5, 0.5));
if (coord.w <= 0.9) return coord.zw; //
coord.xyz = mad(t, vec3(dir, 1.0), coord.xyz);
cdw_end /*e*/ = textureLod(edgesTex, coord.xy, 0.0).rg;
cdw_end /*e*/ = SMAADecodeDiagBilinearAccess(cdw_end /*e*/);
coord.w = dot(cdw_end /*e*/, vec2(0.5, 0.5));
if (coord.w <= 0.9) return coord.zw; //
coord.xyz = mad(t, vec3(dir, 1.0), coord.xyz);
cdw_end /*e*/ = textureLod(edgesTex, coord.xy, 0.0).rg;
cdw_end /*e*/ = SMAADecodeDiagBilinearAccess(cdw_end /*e*/);
coord.w = dot(cdw_end /*e*/, vec2(0.5, 0.5));
if (coord.w <= 0.9) return coord.zw; //
coord.xyz = mad(t, vec3(dir, 1.0), coord.xyz);
cdw_end /*e*/ = textureLod(edgesTex, coord.xy, 0.0).rg;
cdw_end /*e*/ = SMAADecodeDiagBilinearAccess(cdw_end /*e*/);
coord.w = dot(cdw_end /*e*/, vec2(0.5, 0.5));
if (coord.w <= 0.9) return coord.zw; //
coord.xyz = mad(t, vec3(dir, 1.0), coord.xyz);
cdw_end /*e*/ = textureLod(edgesTex, coord.xy, 0.0).rg;
cdw_end /*e*/ = SMAADecodeDiagBilinearAccess(cdw_end /*e*/);
coord.w = dot(cdw_end /*e*/, vec2(0.5, 0.5));
if (coord.w <= 0.9) return coord.zw; //
coord.xyz = mad(t, vec3(dir, 1.0), coord.xyz);
cdw_end /*e*/ = textureLod(edgesTex, coord.xy, 0.0).rg;
cdw_end /*e*/ = SMAADecodeDiagBilinearAccess(cdw_end /*e*/);
coord.w = dot(cdw_end /*e*/, vec2(0.5, 0.5));
//}
return coord.zw;
}
/**
* Similar to SMAAArea, this calculates the area corresponding to a certain
* diagonal distance and crossing edges 'e'.
*/
vec2 SMAAAreaDiag(/*sampler2D areaTex,*/ vec2 dist, vec2 e, float offset) {
vec2 texcoord = mad(vec2(SMAA_AREATEX_MAX_DISTANCE_DIAG, SMAA_AREATEX_MAX_DISTANCE_DIAG), e, dist);
// We do a scale and bias for mapping to texel space:
texcoord = mad(SMAA_AREATEX_PIXEL_SIZE, texcoord, 0.5 * SMAA_AREATEX_PIXEL_SIZE);
// Diagonal areas are on the second half of the texture:
texcoord.x += 0.5;
// Move to proper place, according to the subpixel offset:
texcoord.y += SMAA_AREATEX_SUBTEX_SIZE * offset;
// Do it!
return SMAA_AREATEX_SELECT(textureLod(areaTex, texcoord, 0.0));
}
/**
* This searches for diagonal patterns and returns the corresponding weights.
*/
vec2 SMAACalculateDiagWeights(/*sampler2D edgesTex, sampler2D areaTex,*/ vec2 texcoord, vec2 e, vec4 subsampleIndices) {
vec2 weights = vec2(0.0, 0.0);
// Search for the line ends:
vec4 d;
if (e.r > 0.0) {
d.xz = SMAASearchDiag1(/*edgesTex,*/ texcoord, vec2(-1.0, 1.0)/*, cdw_end*/);
float dadd = cdw_end.y > 0.9 ? 1.0 : 0.0;
d.x += dadd;
}
else {
d.xz = vec2(0.0, 0.0);
}
d.yw = SMAASearchDiag1(/*edgesTex,*/ texcoord, vec2(1.0, -1.0)/*, cdw_end*/);
//SMAA_BRANCH
if (d.x + d.y > 2.0) { // d.x + d.y + 1 > 3
// Fetch the crossing edges:
vec4 coords = mad(vec4(-d.x + 0.25, d.x, d.y, -d.y - 0.25), screenSizeInv.xyxy, texcoord.xyxy);
vec4 c;
c.xy = SMAASampleLevelZeroOffset(edgesTex, coords.xy, ivec2(-1, 0)).rg;
c.zw = SMAASampleLevelZeroOffset(edgesTex, coords.zw, ivec2( 1, 0)).rg;
c.yxwz = SMAADecodeDiagBilinearAccess(c.xyzw);
// Non-optimized version:
// vec4 coords = mad(vec4(-d.x, d.x, d.y, -d.y), screenSizeInv.xyxy, texcoord.xyxy);
// vec4 c;
// c.x = SMAASampleLevelZeroOffset(edgesTex, coords.xy, ivec2(-1, 0)).g;
// c.y = SMAASampleLevelZeroOffset(edgesTex, coords.xy, ivec2( 0, 0)).r;
// c.z = SMAASampleLevelZeroOffset(edgesTex, coords.zw, ivec2( 1, 0)).g;
// c.w = SMAASampleLevelZeroOffset(edgesTex, coords.zw, ivec2( 1, -1)).r;
// Merge crossing edges at each side into a single value:
vec2 cc = mad(vec2(2.0, 2.0), c.xz, c.yw);
// Remove the crossing edge if we didn't found the end of the line:
// SMAAMovc(bvec2(step(0.9, d.zw)), cc, vec2(0.0, 0.0));
float a1condx = step(0.9, d.z);
float a1condy = step(0.9, d.w);
if (a1condx == 1.0) cc.x = 0.0;
if (a1condy == 1.0) cc.y = 0.0;
// Fetch the areas for this line:
weights += SMAAAreaDiag(/*areaTex,*/ d.xy, cc, subsampleIndices.z);
}
// Search for the line ends:
d.xz = SMAASearchDiag2(/*edgesTex,*/ texcoord, vec2(-1.0, -1.0)/*, cdw_end*/);
if (SMAASampleLevelZeroOffset(edgesTex, texcoord, ivec2(1, 0)).r > 0.0) {
d.yw = SMAASearchDiag2(/*edgesTex,*/ texcoord, vec2(1.0, 1.0)/*, cdw_end*/);
float dadd = cdw_end.y > 0.9 ? 1.0 : 0.0;
d.y += dadd;
}
else {
d.yw = vec2(0.0, 0.0);
}
// SMAA_BRANCH
if (d.x + d.y > 2.0) { // d.x + d.y + 1 > 3
// Fetch the crossing edges:
vec4 coords = mad(vec4(-d.x, -d.x, d.y, d.y), screenSizeInv.xyxy, texcoord.xyxy);
vec4 c;
c.x = SMAASampleLevelZeroOffset(edgesTex, coords.xy, ivec2(-1, 0)).g;
c.y = SMAASampleLevelZeroOffset(edgesTex, coords.xy, ivec2( 0, -1)).r;
c.zw = SMAASampleLevelZeroOffset(edgesTex, coords.zw, ivec2( 1, 0)).gr;
vec2 cc = mad(vec2(2.0, 2.0), c.xz, c.yw);
// Remove the crossing edge if we didn't found the end of the line:
// SMAAMovc(bvec2(step(0.9, d.zw)), cc, vec2(0.0, 0.0));
float a1condx = step(0.9, d.z);
float a1condy = step(0.9, d.w);
if (a1condx == 1.0) cc.x = 0.0;
if (a1condy == 1.0) cc.y = 0.0;
// Fetch the areas for this line:
weights += SMAAAreaDiag(/*areaTex,*/ d.xy, cc, subsampleIndices.w).gr;
}
return weights;
}
// #endif
//-----------------------------------------------------------------------------
// Horizontal/Vertical Search Functions
/**
* This allows to determine how much length should we add in the last step
* of the searches. It takes the bilinearly interpolated edge (see
* @PSEUDO_GATHER4), and adds 0, 1 or 2, depending on which edges and
* crossing edges are active.
*/
float SMAASearchLength(/*sampler2D searchTex,*/ vec2 e, float offset) {
// The texture is flipped vertically, with left and right cases taking half
// of the space horizontally:
vec2 scale = SMAA_SEARCHTEX_SIZE * vec2(0.5, -1.0);
vec2 bias = SMAA_SEARCHTEX_SIZE * vec2(offset, 1.0);
// Scale and bias to access texel centers:
scale += vec2(-1.0, 1.0);
bias += vec2( 0.5, -0.5);
// Convert from pixel coordinates to texcoords:
// (We use SMAA_SEARCHTEX_PACKED_SIZE because the texture is cropped)
scale *= 1.0 / SMAA_SEARCHTEX_PACKED_SIZE;
bias *= 1.0 / SMAA_SEARCHTEX_PACKED_SIZE;
// Lookup the search texture:
return SMAA_SEARCHTEX_SELECT(textureLod(searchTex, mad(scale, e, bias), 0.0));
}
/**
* Horizontal/vertical search functions for the 2nd pass.
*/
float endLoopXLeft(vec2 texcoord, vec2 e) {
float offset = mad(-(255.0 / 127.0), SMAASearchLength(/*searchTex,*/ e, 0.0), 3.25);
return mad(screenSizeInv.x, offset, texcoord.x);
}
float SMAASearchXLeft(/*sampler2D edgesTex, sampler2D searchTex,*/ vec2 texcoord, float end) {
/**
* @PSEUDO_GATHER4
* This texcoord has been offset by (-0.25, -0.125) in the vertex shader to
* sample between edge, thus fetching four edges in a row.
* Sampling with different offsets in each direction allows to disambiguate
* which edges are active from the four fetched ones.
*/
vec2 e = vec2(0.0, 1.0);
if (texcoord.x <= end) return endLoopXLeft(texcoord, e); //
if (e.g <= 0.8281) return endLoopXLeft(texcoord, e);
if (e.r != 0.0) return endLoopXLeft(texcoord, e);
// while (texcoord.x > end &&
// e.g > 0.8281 && // Is there some edge not activated?
// e.r == 0.0) { // Or is there a crossing edge that breaks the line?
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(-vec2(2.0, 0.0), screenSizeInv.xy, texcoord);
// Waiting for loops
if (texcoord.x <= end) return endLoopXLeft(texcoord, e); //
if (e.g <= 0.8281) return endLoopXLeft(texcoord, e);
if (e.r != 0.0) return endLoopXLeft(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(-vec2(2.0, 0.0), screenSizeInv.xy, texcoord);
if (texcoord.x <= end) return endLoopXLeft(texcoord, e); //
if (e.g <= 0.8281) return endLoopXLeft(texcoord, e);
if (e.r != 0.0) return endLoopXLeft(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(-vec2(2.0, 0.0), screenSizeInv.xy, texcoord);
if (texcoord.x <= end) return endLoopXLeft(texcoord, e); //
if (e.g <= 0.8281) return endLoopXLeft(texcoord, e);
if (e.r != 0.0) return endLoopXLeft(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(-vec2(2.0, 0.0), screenSizeInv.xy, texcoord);
if (texcoord.x <= end) return endLoopXLeft(texcoord, e); //
if (e.g <= 0.8281) return endLoopXLeft(texcoord, e);
if (e.r != 0.0) return endLoopXLeft(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(-vec2(2.0, 0.0), screenSizeInv.xy, texcoord);
if (texcoord.x <= end) return endLoopXLeft(texcoord, e); //
if (e.g <= 0.8281) return endLoopXLeft(texcoord, e);
if (e.r != 0.0) return endLoopXLeft(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(-vec2(2.0, 0.0), screenSizeInv.xy, texcoord);
if (texcoord.x <= end) return endLoopXLeft(texcoord, e); //
if (e.g <= 0.8281) return endLoopXLeft(texcoord, e);
if (e.r != 0.0) return endLoopXLeft(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(-vec2(2.0, 0.0), screenSizeInv.xy, texcoord);
if (texcoord.x <= end) return endLoopXLeft(texcoord, e); //
if (e.g <= 0.8281) return endLoopXLeft(texcoord, e);
if (e.r != 0.0) return endLoopXLeft(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(-vec2(2.0, 0.0), screenSizeInv.xy, texcoord);
// }
float offset = mad(-(255.0 / 127.0), SMAASearchLength(/*searchTex,*/ e, 0.0), 3.25);
return mad(screenSizeInv.x, offset, texcoord.x);
// Non-optimized version:
// We correct the previous (-0.25, -0.125) offset we applied:
// texcoord.x += 0.25 * screenSizeInv.x;
// The searches are bias by 1, so adjust the coords accordingly:
// texcoord.x += screenSizeInv.x;
// Disambiguate the length added by the last step:
// texcoord.x += 2.0 * screenSizeInv.x; // Undo last step
// texcoord.x -= screenSizeInv.x * (255.0 / 127.0) * SMAASearchLength(/*searchTex,*/ e, 0.0);
// return mad(screenSizeInv.x, offset, texcoord.x);
}
float endLoopXRight(vec2 texcoord, vec2 e) {
float offset = mad(-(255.0 / 127.0), SMAASearchLength(/*searchTex,*/ e, 0.5), 3.25);
return mad(-screenSizeInv.x, offset, texcoord.x);
}
float SMAASearchXRight(/*sampler2D edgesTex, sampler2D searchTex,*/ vec2 texcoord, float end) {
vec2 e = vec2(0.0, 1.0);
if (texcoord.x >= end) return endLoopXRight(texcoord, e); //
if (e.g <= 0.8281) return endLoopXRight(texcoord, e);
if (e.r != 0.0) return endLoopXRight(texcoord, e);
// while (texcoord.x < end &&
// e.g > 0.8281 && // Is there some edge not activated?
// e.r == 0.0) { // Or is there a crossing edge that breaks the line?
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(vec2(2.0, 0.0), screenSizeInv.xy, texcoord);
// Waiting for loops
if (texcoord.x >= end) return endLoopXRight(texcoord, e); //
if (e.g <= 0.8281) return endLoopXRight(texcoord, e);
if (e.r != 0.0) return endLoopXRight(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(vec2(2.0, 0.0), screenSizeInv.xy, texcoord);
if (texcoord.x >= end) return endLoopXRight(texcoord, e); //
if (e.g <= 0.8281) return endLoopXRight(texcoord, e);
if (e.r != 0.0) return endLoopXRight(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(vec2(2.0, 0.0), screenSizeInv.xy, texcoord);
if (texcoord.x >= end) return endLoopXRight(texcoord, e); //
if (e.g <= 0.8281) return endLoopXRight(texcoord, e);
if (e.r != 0.0) return endLoopXRight(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(vec2(2.0, 0.0), screenSizeInv.xy, texcoord);
if (texcoord.x >= end) return endLoopXRight(texcoord, e); //
if (e.g <= 0.8281) return endLoopXRight(texcoord, e);
if (e.r != 0.0) return endLoopXRight(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(vec2(2.0, 0.0), screenSizeInv.xy, texcoord);
if (texcoord.x >= end) return endLoopXRight(texcoord, e); //
if (e.g <= 0.8281) return endLoopXRight(texcoord, e);
if (e.r != 0.0) return endLoopXRight(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(vec2(2.0, 0.0), screenSizeInv.xy, texcoord);
if (texcoord.x >= end) return endLoopXRight(texcoord, e); //
if (e.g <= 0.8281) return endLoopXRight(texcoord, e);
if (e.r != 0.0) return endLoopXRight(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(vec2(2.0, 0.0), screenSizeInv.xy, texcoord);
if (texcoord.x >= end) return endLoopXRight(texcoord, e); //
if (e.g <= 0.8281) return endLoopXRight(texcoord, e);
if (e.r != 0.0) return endLoopXRight(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(vec2(2.0, 0.0), screenSizeInv.xy, texcoord);
// }
float offset = mad(-(255.0 / 127.0), SMAASearchLength(/*searchTex,*/ e, 0.5), 3.25);
return mad(-screenSizeInv.x, offset, texcoord.x);
}
float endLoopYUp(vec2 texcoord, vec2 e) {
float offset = mad(-(255.0 / 127.0), SMAASearchLength(/*searchTex,*/ e.gr, 0.0), 3.25);
return mad(screenSizeInv.y, offset, texcoord.y);
}
float SMAASearchYUp(/*sampler2D edgesTex, sampler2D searchTex,*/ vec2 texcoord, float end) {
vec2 e = vec2(1.0, 0.0);
if (texcoord.y <= end) return endLoopYUp(texcoord, e); //
if (e.r <= 0.8281) return endLoopYUp(texcoord, e);
if (e.g != 0.0) return endLoopYUp(texcoord, e);
// while (texcoord.y > end &&
// e.r > 0.8281 && // Is there some edge not activated?
// e.g == 0.0) { // Or is there a crossing edge that breaks the line?
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(-vec2(0.0, 2.0), screenSizeInv.xy, texcoord);
// Waiting for loops
if (texcoord.y <= end) return endLoopYUp(texcoord, e); //
if (e.r <= 0.8281) return endLoopYUp(texcoord, e);
if (e.g != 0.0) return endLoopYUp(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(-vec2(0.0, 2.0), screenSizeInv.xy, texcoord);
if (texcoord.y <= end) return endLoopYUp(texcoord, e); //
if (e.r <= 0.8281) return endLoopYUp(texcoord, e);
if (e.g != 0.0) return endLoopYUp(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(-vec2(0.0, 2.0), screenSizeInv.xy, texcoord);
if (texcoord.y <= end) return endLoopYUp(texcoord, e); //
if (e.r <= 0.8281) return endLoopYUp(texcoord, e);
if (e.g != 0.0) return endLoopYUp(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(-vec2(0.0, 2.0), screenSizeInv.xy, texcoord);
if (texcoord.y <= end) return endLoopYUp(texcoord, e); //
if (e.r <= 0.8281) return endLoopYUp(texcoord, e);
if (e.g != 0.0) return endLoopYUp(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(-vec2(0.0, 2.0), screenSizeInv.xy, texcoord);
if (texcoord.y <= end) return endLoopYUp(texcoord, e); //
if (e.r <= 0.8281) return endLoopYUp(texcoord, e);
if (e.g != 0.0) return endLoopYUp(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(-vec2(0.0, 2.0), screenSizeInv.xy, texcoord);
if (texcoord.y <= end) return endLoopYUp(texcoord, e); //
if (e.r <= 0.8281) return endLoopYUp(texcoord, e);
if (e.g != 0.0) return endLoopYUp(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(-vec2(0.0, 2.0), screenSizeInv.xy, texcoord);
if (texcoord.y <= end) return endLoopYUp(texcoord, e); //
if (e.r <= 0.8281) return endLoopYUp(texcoord, e);
if (e.g != 0.0) return endLoopYUp(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(-vec2(0.0, 2.0), screenSizeInv.xy, texcoord);
// }
float offset = mad(-(255.0 / 127.0), SMAASearchLength(/*searchTex,*/ e.gr, 0.0), 3.25);
return mad(screenSizeInv.y, offset, texcoord.y);
}
float endLoopYDown(vec2 texcoord, vec2 e) {
float offset = mad(-(255.0 / 127.0), SMAASearchLength(/*searchTex,*/ e.gr, 0.5), 3.25);
return mad(-screenSizeInv.y, offset, texcoord.y);
}
float SMAASearchYDown(/*sampler2D edgesTex, sampler2D searchTex,*/ vec2 texcoord, float end) {
vec2 e = vec2(1.0, 0.0);
if (texcoord.y >= end) return endLoopYDown(texcoord, e); //
if (e.r <= 0.8281) return endLoopYDown(texcoord, e);
if (e.g != 0.0) return endLoopYDown(texcoord, e);
// while (texcoord.y < end &&
// e.r > 0.8281 && // Is there some edge not activated?
// e.g == 0.0) { // Or is there a crossing edge that breaks the line?
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(vec2(0.0, 2.0), screenSizeInv.xy, texcoord);
// Waiting for loops
if (texcoord.y >= end) return endLoopYDown(texcoord, e); //
if (e.r <= 0.8281) return endLoopYDown(texcoord, e);
if (e.g != 0.0) return endLoopYDown(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(vec2(0.0, 2.0), screenSizeInv.xy, texcoord);
if (texcoord.y >= end) return endLoopYDown(texcoord, e); //
if (e.r <= 0.8281) return endLoopYDown(texcoord, e);
if (e.g != 0.0) return endLoopYDown(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(vec2(0.0, 2.0), screenSizeInv.xy, texcoord);
if (texcoord.y >= end) return endLoopYDown(texcoord, e); //
if (e.r <= 0.8281) return endLoopYDown(texcoord, e);
if (e.g != 0.0) return endLoopYDown(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(vec2(0.0, 2.0), screenSizeInv.xy, texcoord);
if (texcoord.y >= end) return endLoopYDown(texcoord, e); //
if (e.r <= 0.8281) return endLoopYDown(texcoord, e);
if (e.g != 0.0) return endLoopYDown(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(vec2(0.0, 2.0), screenSizeInv.xy, texcoord);
if (texcoord.y >= end) return endLoopYDown(texcoord, e); //
if (e.r <= 0.8281) return endLoopYDown(texcoord, e);
if (e.g != 0.0) return endLoopYDown(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(vec2(0.0, 2.0), screenSizeInv.xy, texcoord);
if (texcoord.y >= end) return endLoopYDown(texcoord, e); //
if (e.r <= 0.8281) return endLoopYDown(texcoord, e);
if (e.g != 0.0) return endLoopYDown(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(vec2(0.0, 2.0), screenSizeInv.xy, texcoord);
if (texcoord.y >= end) return endLoopYDown(texcoord, e); //
if (e.r <= 0.8281) return endLoopYDown(texcoord, e);
if (e.g != 0.0) return endLoopYDown(texcoord, e);
e = textureLod(edgesTex, texcoord, 0.0).rg;
texcoord = mad(vec2(0.0, 2.0), screenSizeInv.xy, texcoord);
// }
float offset = mad(-(255.0 / 127.0), SMAASearchLength(/*searchTex,*/ e.gr, 0.5), 3.25);
return mad(-screenSizeInv.y, offset, texcoord.y);
}
/**
* Ok, we have the distance and both crossing edges. So, what are the areas
* at each side of current edge?
*/
vec2 SMAAArea(/*sampler2D areaTex,*/ vec2 dist, float e1, float e2, float offset) {
// Rounding prevents precision errors of bilinear filtering:
vec2 texcoord = mad(vec2(SMAA_AREATEX_MAX_DISTANCE, SMAA_AREATEX_MAX_DISTANCE), round(4.0 * vec2(e1, e2)), dist);
// We do a scale and bias for mapping to texel space:
texcoord = mad(SMAA_AREATEX_PIXEL_SIZE, texcoord, 0.5 * SMAA_AREATEX_PIXEL_SIZE);
// Move to proper place, according to the subpixel offset:
texcoord.y = mad(SMAA_AREATEX_SUBTEX_SIZE, offset, texcoord.y);
// Do it!
return SMAA_AREATEX_SELECT(textureLod(areaTex, texcoord, 0.0));
}
//-----------------------------------------------------------------------------
// Corner Detection Functions
vec2 /*void*/ SMAADetectHorizontalCornerPattern(/*sampler2D edgesTex,*/ /*inout*/ vec2 weights, vec4 texcoord, vec2 d) {
// #if !defined(SMAA_DISABLE_CORNER_DETECTION)
vec2 leftRight = step(d.xy, d.yx);
vec2 rounding = (1.0 - SMAA_CORNER_ROUNDING_NORM) * leftRight;
rounding /= leftRight.x + leftRight.y; // Reduce blending for pixels in the center of a line.
vec2 factor = vec2(1.0, 1.0);
factor.x -= rounding.x * SMAASampleLevelZeroOffset(edgesTex, texcoord.xy, ivec2(0, 1)).r;
factor.x -= rounding.y * SMAASampleLevelZeroOffset(edgesTex, texcoord.zw, ivec2(1, 1)).r;
factor.y -= rounding.x * SMAASampleLevelZeroOffset(edgesTex, texcoord.xy, ivec2(0, -2)).r;
factor.y -= rounding.y * SMAASampleLevelZeroOffset(edgesTex, texcoord.zw, ivec2(1, -2)).r;
weights *= saturate(factor);
return weights; //
// #endif
}
vec2 /*void*/ SMAADetectVerticalCornerPattern(/*sampler2D edgesTex,*/ /*inout*/ vec2 weights, vec4 texcoord, vec2 d) {
//#if !defined(SMAA_DISABLE_CORNER_DETECTION)
vec2 leftRight = step(d.xy, d.yx);
vec2 rounding = (1.0 - SMAA_CORNER_ROUNDING_NORM) * leftRight;
rounding /= leftRight.x + leftRight.y;
vec2 factor = vec2(1.0, 1.0);
factor.x -= rounding.x * SMAASampleLevelZeroOffset(edgesTex, texcoord.xy, ivec2( 1, 0)).g;
factor.x -= rounding.y * SMAASampleLevelZeroOffset(edgesTex, texcoord.zw, ivec2( 1, 1)).g;
factor.y -= rounding.x * SMAASampleLevelZeroOffset(edgesTex, texcoord.xy, ivec2(-2, 0)).g;
factor.y -= rounding.y * SMAASampleLevelZeroOffset(edgesTex, texcoord.zw, ivec2(-2, 1)).g;
weights *= saturate(factor);
return weights; //
// #endif
}
vec4 SMAABlendingWeightCalculationPS(vec2 texcoord, vec2 pixcoord, /*vec4 offset[3],*/
/*sampler2D edgesTex, sampler2D areaTex, sampler2D searchTex,*/
vec4 subsampleIndices) { // Just pass zero for SMAA 1x, see @SUBSAMPLE_INDICES.
vec4 weights = vec4(0.0, 0.0, 0.0, 0.0);
vec2 e = texture(edgesTex, texcoord).rg;
//SMAA_BRANCH
if (e.g > 0.0) { // Edge at north
//#if !defined(SMAA_DISABLE_DIAG_DETECTION)
// Diagonals have both north and west edges, so searching for them in
// one of the boundaries is enough.
weights.rg = SMAACalculateDiagWeights(/*edgesTex, areaTex,*/ texcoord, e, subsampleIndices);
// We give priority 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
//#endif
vec2 d;
// Find the distance to the left:
vec3 coords;
coords.x = SMAASearchXLeft(/*edgesTex, searchTex,*/ offset0.xy, offset2.x);
coords.y = offset1.y; // offset[1].y = texcoord.y - 0.25 * screenSizeInv.y (@CROSSING_OFFSET)
d.x = coords.x;
// Now fetch the left crossing edges, two at a time using bilinear
// filtering. Sampling at -0.25 (see @CROSSING_OFFSET) enables to
// discern what value each edge has:
float e1 = textureLod(edgesTex, coords.xy, 0.0).r;
// Find the distance to the right:
coords.z = SMAASearchXRight(/*edgesTex, searchTex,*/ offset0.zw, offset2.y);
d.y = coords.z;
// We want the distances to be in pixel units (doing this here allow to
// better interleave arithmetic and memory accesses):
d = abs(round(mad(screenSize.xx, d, -pixcoord.xx)));
// SMAAArea below needs a sqrt, as the areas texture is compressed
// quadratically:
vec2 sqrt_d = sqrt(d);
// Fetch the right crossing edges:
float e2 = SMAASampleLevelZeroOffset(edgesTex, coords.zy, ivec2(1, 0)).r;
// Ok, we know how this pattern looks like, now it is time for getting
// the actual area:
weights.rg = SMAAArea(/*areaTex,*/ sqrt_d, e1, e2, subsampleIndices.y);
// Fix corners:
coords.y = texcoord.y;
weights.rg = SMAADetectHorizontalCornerPattern(/*edgesTex,*/ weights.rg, coords.xyzy, d);
//#if !defined(SMAA_DISABLE_DIAG_DETECTION)
}
else {
e.r = 0.0; // Skip vertical processing.
}
//#endif
}
//SMAA_BRANCH
if (e.r > 0.0) { // Edge at west
vec2 d;
// Find the distance to the top:
vec3 coords;
coords.y = SMAASearchYUp(/*edgesTex, searchTex,*/ offset1.xy, offset2.z);
coords.x = offset0.x; // offset[1].x = texcoord.x - 0.25 * screenSizeInv.x;
d.x = coords.y;
// Fetch the top crossing edges:
float e1 = textureLod(edgesTex, coords.xy, 0.0).g;
// Find the distance to the bottom:
coords.z = SMAASearchYDown(/*edgesTex, searchTex,*/ offset1.zw, offset2.w);
d.y = coords.z;
// We want the distances to be in pixel units:
d = abs(round(mad(screenSize.yy, d, -pixcoord.yy)));
// SMAAArea below needs a sqrt, as the areas texture is compressed
// quadratically:
vec2 sqrt_d = sqrt(d);
// Fetch the bottom crossing edges:
float e2 = SMAASampleLevelZeroOffset(edgesTex, coords.xz, ivec2(0, 1)).g;
// Get the area for this direction:
weights.ba = SMAAArea(/*areaTex,*/ sqrt_d, e1, e2, subsampleIndices.x);
// Fix corners:
coords.x = texcoord.x;
weights.ba = SMAADetectVerticalCornerPattern(/*edgesTex,*/ weights.ba, coords.xyxz, d);
}
return weights;
}
void main() {
fragColor = SMAABlendingWeightCalculationPS(texCoord, pixcoord, /*offset,*/
/*edgesTex, areaTex, searchTex,*/ vec4(0.0));
}

View File

@ -1,43 +0,0 @@
#version 450
#define _EnvCol
#define _SSAO
#define _SMAA
#ifdef GL_ES
precision highp float;
#endif
in vec2 pos;
uniform vec2 screenSize;
uniform vec2 screenSizeInv;
out vec2 texCoord;
out vec2 pixcoord;
out vec4 offset0;
out vec4 offset1;
out vec4 offset2;
const int SMAA_MAX_SEARCH_STEPS = 16;
void main() {
// Scale vertex attribute to [0-1] range
const vec2 madd = vec2(0.5, 0.5);
texCoord = pos.xy * madd + madd;
// Blend Weight Calculation Vertex Shader
// void SMAABlendingWeightCalculationVS(vec2 texcoord, out vec2 pixcoord, out vec4 offset[3]) {
pixcoord = texCoord * screenSize;
// We will use these offsets for the searches later on (see @PSEUDO_GATHER4):
offset0 = screenSizeInv.xyxy * vec4(-0.25, -0.125, 1.25, -0.125) + texCoord.xyxy;
offset1 = screenSizeInv.xyxy * vec4(-0.125, -0.25, -0.125, 1.25) + texCoord.xyxy;
// And these for the searches, they indicate the ends of the loops:
offset2 = screenSizeInv.xxyy *
(vec4(-2.0, 2.0, -2.0, 2.0) * float(SMAA_MAX_SEARCH_STEPS)) +
vec4(offset0.xz, offset1.yw);
// }
gl_Position = vec4(pos.xy, 0.0, 1.0);
}

View File

@ -1,215 +0,0 @@
/**
* Copyright (C) 2013 Jorge Jimenez (jorge@iryoku.com)
* Copyright (C) 2013 Jose I. Echevarria (joseignacioechevarria@gmail.com)
* Copyright (C) 2013 Belen Masia (bmasia@unizar.es)
* Copyright (C) 2013 Fernando Navarro (fernandn@microsoft.com)
* Copyright (C) 2013 Diego Gutierrez (diegog@unizar.es)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to
* do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software. As clarification, there
* is no requirement that the copyright notice and permission be included in
* binary distributions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/**
* _______ ___ ___ ___ ___
* / || \/ | / \ / \
* | (---- | \ / | / ^ \ / ^ \
* \ \ | |\/| | / /_\ \ / /_\ \
* ----) | | | | | / _____ \ / _____ \
* |_______/ |__| |__| /__/ \__\ /__/ \__\
*
* E N H A N C E D
* S U B P I X E L M O R P H O L O G I C A L A N T I A L I A S I N G
*
* http://www.iryoku.com/smaa/
*/
#version 450
#define _EnvCol
#define _SSAO
#define _SMAA
#ifdef GL_ES
precision mediump float;
#endif
#define SMAA_THRESHOLD 0.1
#define SMAA_DEPTH_THRESHOLD (0.1 * SMAA_THRESHOLD) // For depth edge detection, depends on the depth range of the scene
#define SMAA_LOCAL_CONTRAST_ADAPTATION_FACTOR 2.0
uniform sampler2D colorTex;
in vec2 texCoord;
in vec4 offset0;
in vec4 offset1;
in vec4 offset2;
out vec4 fragColor;
// Misc functions
// Gathers current pixel, and the top-left neighbors.
// vec3 SMAAGatherNeighbours(vec2 texcoord/*, vec4 offset[3], sampler2D tex*/) {
// float P = texture(tex, texcoord).r;
// float Pleft = texture(tex, offset0.xy).r;
// float Ptop = texture(tex, offset0.zw).r;
// return vec3(P, Pleft, Ptop);
// }
// Edge Detection Pixel Shaders (First Pass)
// Adjusts the threshold by means of predication.
// vec2 SMAACalculatePredicatedThreshold(vec2 texcoord, vec4 offset[3], sampler2D predicationTex) {
// vec3 neighbours = SMAAGatherNeighbours(texcoord, offset, predicationTex);
// vec2 delta = abs(neighbours.xx - neighbours.yz);
// vec2 edges = step(SMAA_PREDICATION_THRESHOLD, delta);
// return SMAA_PREDICATION_SCALE * SMAA_THRESHOLD * (1.0 - SMAA_PREDICATION_STRENGTH * edges);
// }
// Luma Edge Detection
// IMPORTANT NOTICE: luma edge detection requires gamma-corrected colors, and
// thus 'colorTex' should be a non-sRGB texture.
vec2 SMAALumaEdgeDetectionPS(vec2 texcoord/*, vec4 offset[3], sampler2D colorTex*/
//#if SMAA_PREDICATION
//, sampler2D predicationTex
//#endif
) {
// Calculate the threshold:
//#if SMAA_PREDICATION
//vec2 threshold = SMAACalculatePredicatedThreshold(texcoord, offset, SMAATexturePass2D(predicationTex));
//#else
vec2 threshold = vec2(SMAA_THRESHOLD, SMAA_THRESHOLD);
//#endif
// Calculate lumas:
vec3 weights = vec3(0.2126, 0.7152, 0.0722);
float L = dot(texture(colorTex, texcoord).rgb, weights);
float Lleft = dot(texture(colorTex, offset0.xy).rgb, weights);
float Ltop = dot(texture(colorTex, offset0.zw).rgb, weights);
// We do the usual threshold:
vec4 delta;
delta.xy = abs(L - vec2(Lleft, Ltop));
vec2 edges = step(threshold, delta.xy);
// Then discard if there is no edge:
if (dot(edges, vec2(1.0, 1.0)) == 0.0)
discard;
// Calculate right and bottom deltas:
float Lright = dot(texture(colorTex, offset1.xy).rgb, weights);
float Lbottom = dot(texture(colorTex, offset1.zw).rgb, weights);
delta.zw = abs(L - vec2(Lright, Lbottom));
// Calculate the maximum delta in the direct neighborhood:
vec2 maxDelta = max(delta.xy, delta.zw);
// Calculate left-left and top-top deltas:
float Lleftleft = dot(texture(colorTex, offset2.xy).rgb, weights);
float Ltoptop = dot(texture(colorTex, offset2.zw).rgb, weights);
delta.zw = abs(vec2(Lleft, Ltop) - vec2(Lleftleft, Ltoptop));
// Calculate the final maximum delta:
maxDelta = max(maxDelta.xy, delta.zw);
float finalDelta = max(maxDelta.x, maxDelta.y);
// Local contrast adaptation:
edges.xy *= step(finalDelta, SMAA_LOCAL_CONTRAST_ADAPTATION_FACTOR * delta.xy);
return edges;
}
// Color Edge Detection
// IMPORTANT NOTICE: color edge detection requires gamma-corrected colors, and
// thus 'colorTex' should be a non-sRGB texture.
vec2 SMAAColorEdgeDetectionPS(vec2 texcoord/*, vec4 offset[3], sampler2D colorTex*/
//#if SMAA_PREDICATION
//, sampler2D predicationTex
//#endif
) {
// Calculate the threshold:
//#if SMAA_PREDICATION
//vec2 threshold = SMAACalculatePredicatedThreshold(texcoord, offset, predicationTex);
//#else
vec2 threshold = vec2(SMAA_THRESHOLD, SMAA_THRESHOLD);
//#endif
// Calculate color deltas:
vec4 delta;
vec3 C = texture(colorTex, texcoord).rgb;
vec3 Cleft = texture(colorTex, offset0.xy).rgb;
vec3 t = abs(C - Cleft);
delta.x = max(max(t.r, t.g), t.b);
vec3 Ctop = texture(colorTex, offset0.zw).rgb;
t = abs(C - Ctop);
delta.y = max(max(t.r, t.g), t.b);
// We do the usual threshold:
vec2 edges = step(threshold, delta.xy);
// Then discard if there is no edge:
if (dot(edges, vec2(1.0, 1.0)) == 0.0)
discard;
// Calculate right and bottom deltas:
vec3 Cright = texture(colorTex, offset1.xy).rgb;
t = abs(C - Cright);
delta.z = max(max(t.r, t.g), t.b);
vec3 Cbottom = texture(colorTex, offset1.zw).rgb;
t = abs(C - Cbottom);
delta.w = max(max(t.r, t.g), t.b);
// Calculate the maximum delta in the direct neighborhood:
vec2 maxDelta = max(delta.xy, delta.zw);
// Calculate left-left and top-top deltas:
vec3 Cleftleft = texture(colorTex, offset2.xy).rgb;
t = abs(C - Cleftleft);
delta.z = max(max(t.r, t.g), t.b);
vec3 Ctoptop = texture(colorTex, offset2.zw).rgb;
t = abs(C - Ctoptop);
delta.w = max(max(t.r, t.g), t.b);
// Calculate the final maximum delta:
maxDelta = max(maxDelta.xy, delta.zw);
float finalDelta = max(maxDelta.x, maxDelta.y);
// Local contrast adaptation:
edges.xy *= step(finalDelta, SMAA_LOCAL_CONTRAST_ADAPTATION_FACTOR * delta.xy);
return edges;
}
// Depth Edge Detection
// vec2 SMAADepthEdgeDetectionPS(vec2 texcoord, /*vec4 offset[3],*/ sampler2D depthTex) {
// vec3 neighbours = SMAAGatherNeighbours(texcoord, /*offset,*/ depthTex);
// vec2 delta = abs(neighbours.xx - vec2(neighbours.y, neighbours.z));
// vec2 edges = step(SMAA_DEPTH_THRESHOLD, delta);
// if (dot(edges, vec2(1.0, 1.0)) == 0.0)
// discard;
// return edges;
// }
void main() {
// fragColor.rg = SMAALumaEdgeDetectionPS(texCoord/*, offset, colorTex*/);
fragColor.rg = SMAAColorEdgeDetectionPS(texCoord/*, offset, colorTex*/);
}

View File

@ -1,32 +0,0 @@
#version 450
#define _EnvCol
#define _SSAO
#define _SMAA
#ifdef GL_ES
precision highp float;
#endif
in vec2 pos;
uniform vec2 screenSizeInv;
out vec2 texCoord;
out vec4 offset0;
out vec4 offset1;
out vec4 offset2;
void main() {
// Scale vertex attribute to [0-1] range
const vec2 madd = vec2(0.5, 0.5);
texCoord = pos.xy * madd + madd;
// Edge Detection Vertex Shader
//void SMAAEdgeDetectionVS(vec2 texcoord, out vec4 offset[3]) {
offset0 = screenSizeInv.xyxy * vec4(-1.0, 0.0, 0.0, -1.0) + texCoord.xyxy;
offset1 = screenSizeInv.xyxy * vec4( 1.0, 0.0, 0.0, 1.0) + texCoord.xyxy;
offset2 = screenSizeInv.xyxy * vec4(-2.0, 0.0, 0.0, -2.0) + texCoord.xyxy;
//}
gl_Position = vec4(pos.xy, 0.0, 1.0);
}

View File

@ -1,104 +0,0 @@
#version 450
#define _EnvCol
#define _SSAO
#define _SMAA
#ifdef GL_ES
precision mediump float;
#endif
uniform sampler2D colorTex;
uniform sampler2D blendTex;
#ifdef _Veloc
uniform sampler2D sveloc;
#endif
uniform vec2 screenSizeInv;
in vec2 texCoord;
in vec4 offset;
out vec4 fragColor;
//-----------------------------------------------------------------------------
// Neighborhood Blending Pixel Shader (Third Pass)
// Conditional move:
// void SMAAMovc(bvec2 cond, inout vec2 variable, vec2 value) {
// /*SMAA_FLATTEN*/ if (cond.x) variable.x = value.x;
// /*SMAA_FLATTEN*/ if (cond.y) variable.y = value.y;
//}
//void SMAAMovc(bvec4 cond, inout vec4 variable, vec4 value) {
// SMAAMovc(cond.xy, variable.xy, value.xy);
// SMAAMovc(cond.zw, variable.zw, value.zw);
//}
vec4 SMAANeighborhoodBlendingPS(vec2 texcoord, vec4 offset/*, sampler2D colorTex, sampler2D blendTex*/
//#if SMAA_REPROJECTION
//, sampler2D velocityTex
//#endif
) {
// Fetch the blending weights for current pixel:
vec4 a;
a.x = texture(blendTex, offset.xy).a; // Right
a.y = texture(blendTex, offset.zw).g; // Top
a.wz = texture(blendTex, texcoord).xz; // Bottom / Left
// Is there any blending weight with a value greater than 0.0?
//SMAA_BRANCH
if (dot(a, vec4(1.0, 1.0, 1.0, 1.0)) < 1e-5) {
vec4 color = textureLod(colorTex, texcoord, 0.0);
//#if SMAA_REPROJECTION
#ifdef _Veloc
vec2 velocity = textureLod(sveloc, texCoord, 0.0).rg;
// Pack velocity into the alpha channel:
color.a = sqrt(5.0 * length(velocity));
#endif
return color;
}
else {
bool h = max(a.x, a.z) > max(a.y, a.w); // max(horizontal) > max(vertical)
// Calculate the blending offsets:
vec4 blendingOffset = vec4(0.0, a.y, 0.0, a.w);
vec2 blendingWeight = a.yw;
//SMAAMovc(bvec4(h, h, h, h), blendingOffset, vec4(a.x, 0.0, a.z, 0.0));
if (h) blendingOffset.x = a.x;
if (h) blendingOffset.y = 0.0;
if (h) blendingOffset.z = a.z;
if (h) blendingOffset.w = 0.0;
// SMAAMovc(bvec2(h, h), blendingWeight, a.xz);
if (h) blendingWeight.x = a.x;
if (h) blendingWeight.y = a.z;
blendingWeight /= dot(blendingWeight, vec2(1.0, 1.0));
// Calculate the texture coordinates:
vec4 blendingCoord = blendingOffset * vec4(screenSizeInv.xy, -screenSizeInv.xy) + texcoord.xyxy;
// We exploit bilinear filtering to mix current pixel with the chosen
// neighbor:
vec4 color = blendingWeight.x * textureLod(colorTex, blendingCoord.xy, 0.0);
color += blendingWeight.y * textureLod(colorTex, blendingCoord.zw, 0.0);
//#if SMAA_REPROJECTION
#ifdef _Veloc
// Antialias velocity for proper reprojection in a later stage:
vec2 velocity = blendingWeight.x * textureLod(sveloc, blendingCoord.xy, 0.0).rg;
velocity += blendingWeight.y * textureLod(sveloc, blendingCoord.zw, 0.0).rg;
// Pack velocity into the alpha channel:
color.a = sqrt(5.0 * length(velocity));
#endif
return color;
}
return vec4(0.0);
}
void main() {
fragColor = SMAANeighborhoodBlendingPS(texCoord, offset/*, colorTex, blendTex*/);
}

View File

@ -1,28 +0,0 @@
#version 450
#define _EnvCol
#define _SSAO
#define _SMAA
#ifdef GL_ES
precision highp float;
#endif
in vec2 pos;
uniform vec2 screenSizeInv;
out vec2 texCoord;
out vec4 offset;
void main() {
// Scale vertex attribute to [0-1] range
const vec2 madd = vec2(0.5, 0.5);
texCoord = pos.xy * madd + madd;
// Neighborhood Blending Vertex Shader
//void SMAANeighborhoodBlendingVS(vec2 texcoord, out vec4 offset) {
offset = screenSizeInv.xyxy * vec4(1.0, 0.0, 0.0, 1.0) + texCoord.xyxy;
//}
gl_Position = vec4(pos.xy, 0.0, 1.0);
}

View File

@ -1,141 +0,0 @@
// Alchemy AO
// Compute kernel
// var kernel:Array<Float> = [];
// var kernelSize = 8;
// for (i in 0...kernelSize) {
// var angle = i / kernelSize;
// angle *= 3.1415926535 * 2.0;
// var x1 = Math.cos(angle);
// var y1 = Math.sin(angle);
// x1 = Std.int(x1 * 10000000) / 10000000;
// y1 = Std.int(y1 * 10000000) / 10000000;
// trace(x1, y1);
// }
#version 450
#define _EnvCol
#define _SSAO
#define _SMAA
#ifdef GL_ES
precision mediump float;
#endif
#include "../compiled.glsl"
#include "../std/gbuffer.glsl"
// octahedronWrap
uniform sampler2D gbufferD;
uniform sampler2D gbuffer0;
uniform sampler2D snoise;
uniform mat4 invVP;
uniform vec3 eye;
// uniform vec3 eyeLook;
uniform vec2 screenSize;
uniform vec2 aspectRatio;
in vec2 texCoord;
// in vec3 viewRay;
out vec4 fragColor;
float doAO(vec2 kernelVec, vec2 randomVec, mat2 rotMat, vec3 currentPos, vec3 currentNormal, float currentDistance) {
kernelVec.xy *= aspectRatio;
float radius = ssaoSize * randomVec.y;
kernelVec.xy = ((rotMat * kernelVec.xy) / currentDistance) * radius;
vec2 coord = texCoord + kernelVec.xy;
float depth = texture(gbufferD, coord).r * 2.0 - 1.0;
vec3 pos = getPos2NoEye(eye, invVP, depth, coord) - currentPos;
float angle = dot(pos, currentNormal);
// angle *= step(0.3, angle / length(pos)); // Fix intersect
angle *= step(0.1, angle / length(pos));
angle -= currentDistance * 0.001;
angle = max(0.0, angle);
// angle /= dot(pos, pos) / min(currentDistance * 0.25, 1.0) + 0.00001; // Fix darkening
angle /= dot(pos, pos) / min(currentDistance * 0.25, 1.0) + 0.001;
return angle;
}
void main() {
float depth = texture(gbufferD, texCoord).r * 2.0 - 1.0;
if (depth == 1.0) {
fragColor = vec4(1.0);
return;
}
const int kernelSize = 12;
const vec2 kernel0 = vec2(1.0, 0.0);
const vec2 kernel1 = vec2(0.8660254, 0.4999999);
const vec2 kernel2 = vec2(0.5, 0.8660254);
const vec2 kernel3 = vec2(0.0, 1.0);
const vec2 kernel4 = vec2(-0.4999999, 0.8660254);
const vec2 kernel5 = vec2(-0.8660254, 0.5);
const vec2 kernel6 = vec2(-1.0, 0.0);
const vec2 kernel7 = vec2(-0.8660254, -0.4999999);
const vec2 kernel8 = vec2(-0.5, -0.8660254);
const vec2 kernel9 = vec2(0.0, -1.0);
const vec2 kernel10 = vec2(0.4999999, -0.8660254);
const vec2 kernel11 = vec2(0.8660254, -0.5);
// const vec2 kernel0 = vec2(1.0,0.0);
// const vec2 kernel1 = vec2(0.9510565,0.3090169);
// const vec2 kernel2 = vec2(0.8090169,0.5877852);
// const vec2 kernel3 = vec2(0.5877852,0.8090169);
// const vec2 kernel4 = vec2(0.3090169,0.9510565);
// const vec2 kernel5 = vec2(0.0,1.0);
// const vec2 kernel6 = vec2(-0.3090169,0.9510565);
// const vec2 kernel7 = vec2(-0.5877852,0.8090169);
// const vec2 kernel8 = vec2(-0.8090169,0.5877852);
// const vec2 kernel9 = vec2(-0.9510565,0.3090169);
// const vec2 kernel10 = vec2(-1,0);
// const vec2 kernel11 = vec2(-0.9510565,-0.3090169);
// const vec2 kernel12 = vec2(-0.8090169,-0.5877852);
// const vec2 kernel13 = vec2(-0.5877852,-0.8090169);
// const vec2 kernel14 = vec2(-0.3090169,-0.9510565);
// const vec2 kernel15 = vec2(0.0,-1.0);
// const vec2 kernel16 = vec2(0.3090169,-0.9510565);
// const vec2 kernel17 = vec2(0.5877852,-0.8090169);
// const vec2 kernel18 = vec2(0.8090169,-0.5877852);
// const vec2 kernel19 = vec2(0.9510565,-0.3090169);
vec2 enc = texture(gbuffer0, texCoord).rg;
vec3 currentNormal;
currentNormal.z = 1.0 - abs(enc.x) - abs(enc.y);
currentNormal.xy = currentNormal.z >= 0.0 ? enc.xy : octahedronWrap(enc.xy);
currentNormal = normalize(currentNormal);
vec3 currentPos = getPos2NoEye(eye, invVP, depth, texCoord);
float currentDistance = length(currentPos);
vec2 randomVec = texture(snoise, (texCoord * screenSize) / 8.0).xy;
randomVec = randomVec * 2.0 - 1.0;
mat2 rotMat = mat2(vec2(cos(randomVec.x * PI), -sin(randomVec.x * PI)),
vec2(sin(randomVec.x * PI), cos(randomVec.x * PI)));
// for (int i = 0; i < kernelSize; i++) {
float amount = doAO(kernel0, randomVec, rotMat, currentPos, currentNormal, currentDistance);
amount += doAO(kernel1, randomVec, rotMat, currentPos, currentNormal, currentDistance);
amount += doAO(kernel2, randomVec, rotMat, currentPos, currentNormal, currentDistance);
amount += doAO(kernel3, randomVec, rotMat, currentPos, currentNormal, currentDistance);
amount += doAO(kernel4, randomVec, rotMat, currentPos, currentNormal, currentDistance);
amount += doAO(kernel5, randomVec, rotMat, currentPos, currentNormal, currentDistance);
amount += doAO(kernel6, randomVec, rotMat, currentPos, currentNormal, currentDistance);
amount += doAO(kernel7, randomVec, rotMat, currentPos, currentNormal, currentDistance);
amount += doAO(kernel8, randomVec, rotMat, currentPos, currentNormal, currentDistance);
amount += doAO(kernel9, randomVec, rotMat, currentPos, currentNormal, currentDistance);
amount += doAO(kernel10, randomVec, rotMat, currentPos, currentNormal, currentDistance);
amount += doAO(kernel11, randomVec, rotMat, currentPos, currentNormal, currentDistance);
// amount += doAO(kernel12, randomVec, rotMat, currentPos, currentNormal, currentDistance);
// amount += doAO(kernel13, randomVec, rotMat, currentPos, currentNormal, currentDistance);
// amount += doAO(kernel14, randomVec, rotMat, currentPos, currentNormal, currentDistance);
// amount += doAO(kernel15, randomVec, rotMat, currentPos, currentNormal, currentDistance);
// amount += doAO(kernel16, randomVec, rotMat, currentPos, currentNormal, currentDistance);
// amount += doAO(kernel17, randomVec, rotMat, currentPos, currentNormal, currentDistance);
// amount += doAO(kernel18, randomVec, rotMat, currentPos, currentNormal, currentDistance);
// amount += doAO(kernel19, randomVec, rotMat, currentPos, currentNormal, currentDistance);
// }
amount *= ssaoStrength / kernelSize;
amount = 1.0 - amount;
amount = max(0.0, amount);
fragColor = vec4(amount, 0.0, 0.0, 1.0);
}

View File

@ -1,20 +0,0 @@
#version 450
#define _EnvCol
#define _SSAO
#define _SMAA
#ifdef GL_ES
precision highp float;
#endif
in vec2 pos;
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;
gl_Position = vec4(pos.xy, 0.0, 1.0);
}

View File

@ -1,114 +0,0 @@
vec2 LightingFuncGGX_FV(const float dotLH, const float roughness) {
float alpha = roughness * roughness;
// F
float F_a, F_b;
float dotLH5 = pow(1.0 - dotLH, 5.0);
F_a = 1.0;
F_b = dotLH5;
// V
float vis;
float k = alpha / 2.0;
float k2 = k * k;
float invK2 = 1.0 - k2;
//vis = rcp(dotLH * dotLH * invK2 + k2);
vis = inversesqrt(dotLH * dotLH * invK2 + k2);
return vec2(F_a * vis, F_b * vis);
}
float LightingFuncGGX_D(const float dotNH, const float roughness) {
float alpha = roughness * roughness;
float alphaSqr = alpha * alpha;
float pi = 3.14159;
float denom = dotNH * dotNH * (alphaSqr - 1.0) + 1.0;
float D = alphaSqr / (pi * denom * denom);
return D;
}
// John Hable - Optimizing GGX Shaders
// http://www.filmicworlds.com/2014/04/21/optimizing-ggx-shaders-with-dotlh/
float LightingFuncGGX_OPT3(const float dotNL, const float dotLH, const float dotNH, const float roughness, const float F0) {
// vec3 H = normalize(V + L);
// float dotNL = clamp(dot(N, L), 0.0, 1.0);
// float dotLH = clamp(dot(L, H), 0.0, 1.0);
// float dotNH = clamp(dot(N, H), 0.0, 1.0);
float D = LightingFuncGGX_D(dotNH, roughness);
vec2 FV_helper = LightingFuncGGX_FV(dotLH, roughness);
float FV = F0 * FV_helper.x + (1.0 - F0) * FV_helper.y;
float specular = dotNL * D * FV;
return specular;
}
vec3 f_schlick(const vec3 f0, const float vh) {
return f0 + (1.0-f0)*exp2((-5.55473 * vh - 6.98316)*vh);
}
float v_smithschlick(const float nl, const float nv, const float a) {
return 1.0 / ( (nl*(1.0-a)+a) * (nv*(1.0-a)+a) );
}
float d_ggx(const float nh, const float a) {
float a2 = a*a;
float denom = pow(nh*nh * (a2-1.0) + 1.0, 2.0);
return a2 * (1.0 / 3.1415926535) / denom;
}
vec3 specularBRDF(const vec3 f0, const float roughness, const float nl, const float nh, const float nv, const float vh) {
float a = roughness * roughness;
return d_ggx(nh, a) * clamp(v_smithschlick(nl, nv, a), 0.0, 1.0) * f_schlick(f0, vh) / 4.0;
//return vec3(LightingFuncGGX_OPT3(nl, lh, nh, roughness, f0[0]));
}
vec3 orenNayarDiffuseBRDF(const vec3 albedo, const float roughness, const float nv, const float nl, const float vh) {
float a = roughness * roughness;
float s = a;
float s2 = s * s;
float vl = 2.0 * vh * vh - 1.0; // Double angle identity
float Cosri = vl - nv * nl;
float C1 = 1.0 - 0.5 * s2 / (s2 + 0.33);
float test = 1.0;
if (Cosri >= 0.0) test = (1.0 / (max(nl, nv)));
float C2 = 0.45 * s2 / (s2 + 0.09) * Cosri * test;
return albedo * max(0.0, nl) * (C1 + C2) * (1.0 + roughness * 0.5);
}
vec3 lambertDiffuseBRDF(const vec3 albedo, const float nl) {
return albedo * max(0.0, nl);
}
vec3 surfaceAlbedo(const vec3 baseColor, const float metalness) {
return mix(baseColor, vec3(0.0), metalness);
}
vec3 surfaceF0(const vec3 baseColor, const float metalness) {
return mix(vec3(0.04), baseColor, metalness);
}
float getMipFromRoughness(const float roughness, const float numMipmaps) {
// First mipmap level = roughness 0, last = roughness = 1
return roughness * numMipmaps;
}
float wardSpecular(vec3 N, vec3 H, float dotNL, float dotNV, float dotNH, vec3 fiberDirection, float shinyParallel, float shinyPerpendicular) {
if(dotNL < 0.0 || dotNV < 0.0) {
return 0.0;
}
// fiberDirection - parse from rotation
// shinyParallel - roughness
// shinyPerpendicular - anisotropy
vec3 fiberParallel = normalize(fiberDirection);
vec3 fiberPerpendicular = normalize(cross(N, fiberDirection));
float dotXH = dot(fiberParallel, H);
float dotYH = dot(fiberPerpendicular, H);
const float PI = 3.1415926535;
float coeff = sqrt(dotNL/dotNV) / (4.0 * PI * shinyParallel * shinyPerpendicular);
float theta = (pow(dotXH/shinyParallel, 2.0) + pow(dotYH/shinyPerpendicular, 2.0)) / (1.0 + dotNH);
return clamp(coeff * exp(-2.0 * theta), 0.0, 1.0);
}

View File

@ -1,59 +0,0 @@
uniform sampler3D voxels;
const float voxelGridWorldSize = 150.0;
const int voxelDimensions = 512;
const float maxDist = 30.0;
const float alphaThreshold = 0.95;
const int numCones = 6;
vec3 coneDirections[6] = vec3[](
vec3(0, 1, 0),
vec3(0, 0.5, 0.866025),
vec3(0.823639, 0.5, 0.267617),
vec3(0.509037, 0.5, -0.700629),
vec3(-0.509037, 0.5, -0.700629),
vec3(-0.823639, 0.5, 0.267617));
float coneWeights[6] = float[](0.25, 0.15, 0.15, 0.15, 0.15, 0.15);
vec4 sampleVoxels(vec3 worldPosition, float lod) {
vec3 offset = vec3(1.0 / voxelDimensions, 1.0 / voxelDimensions, 0);
vec3 texco = worldPosition / (voxelGridWorldSize * 0.5);
texco = texco * 0.5 + 0.5 + offset;
return textureLod(voxels, texco, lod);
}
// See https://github.com/Cigg/Voxel-Cone-Tracing
vec4 coneTrace(vec3 posWorld, vec3 direction, vec3 norWorld, float tanHalfAngle, out float occlusion) {
const float voxelWorldSize = voxelGridWorldSize / voxelDimensions;
float dist = voxelWorldSize; // Start one voxel away to avoid self occlusion
vec3 startPos = posWorld + norWorld * voxelWorldSize;
vec3 color = vec3(0.0);
float alpha = 0.0;
occlusion = 0.0;
while (dist < maxDist && alpha < alphaThreshold) {
// Smallest sample diameter possible is the voxel size
float diameter = max(voxelWorldSize, 2.0 * tanHalfAngle * dist);
float lodLevel = log2(diameter / voxelWorldSize);
vec4 voxelColor = sampleVoxels(startPos + dist * direction, lodLevel);
// Front-to-back compositing
float a = (1.0 - alpha);
color += a * voxelColor.rgb;
alpha += a * voxelColor.a;
occlusion += (a * voxelColor.a) / (1.0 + 0.03 * diameter);
dist += diameter * 0.5; // * 2.0
}
return vec4(color, alpha);
}
vec4 coneTraceIndirect(vec3 posWorld, mat3 tanToWorld, vec3 norWorld, out float occlusion) {
vec4 color = vec4(0);
occlusion = 0.0;
for (int i = 0; i < numCones; i++) {
float coneOcclusion;
const float tanangle = tan(30):
color += coneWeights[i] * coneTrace(posWorld, tanToWorld * coneDirections[i], norWorld, tanangle, coneOcclusion);
occlusion += coneWeights[i] * coneOcclusion;
}
occlusion = 1.0 - occlusion;
return color;
}

View File

@ -1,224 +0,0 @@
// DoF with bokeh GLSL shader by Martins Upitis (martinsh) (devlog-martinsh.blogspot.com)
// Creative Commons Attribution 3.0 Unported License
#include "../compiled.glsl"
#include "math.glsl"
// linearize()
// rand2()
// 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 = 3; // Samples on the first ring
const int rings = 3; // Ring count
// const vec2 focus = vec2(0.5, 0.5);
const float coc = 0.03; // 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 = texture(tex, coords + vec2(0.0, 1.0) * texStep * fringe * blur).r;
col.g = texture(tex, coords + vec2(-0.866, -0.5) * texStep * fringe * blur).g;
col.b = texture(tex, coords + vec2(0.866, -0.5) * texStep * fringe * blur).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) {
float depth = linearize(gdepth);
const float fDepth = compoDOFDistance;
// float fDepth = linearize(texture(gbufferD, focus).r * 2.0 - 1.0); // 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 = texture(tex, texCoord).rgb;
}
else {
col = texture(tex, texCoord).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) * mix(1.0, (float(i)) / (float(rings)), bias) * p;
// s += 1.0 * mix(1.0, (float(i)) / (float(rings)), bias) * p;
// }
// }
// Unroll..
int i = 1; // i <= rings
ringsamples = i * samples;
int j = 0; // j < ringsamples
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;
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;
j = 1; //////
step = PI2 / float(ringsamples);
pw = cos(float(j) * step) * float(i);
ph = sin(float(j) * step) * float(i);
p = 1.0;
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;
j = 2; //////
step = PI2 / float(ringsamples);
pw = cos(float(j) * step) * float(i);
ph = sin(float(j) * step) * float(i);
p = 1.0;
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;
//------
i = 2; // i <= rings
ringsamples = i * samples;
j = 0; // j < ringsamples
step = PI2 / float(ringsamples);
pw = cos(float(j) * step) * float(i);
ph = sin(float(j) * step) * float(i);
p = 1.0;
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;
j = 1; //////
step = PI2 / float(ringsamples);
pw = cos(float(j) * step) * float(i);
ph = sin(float(j) * step) * float(i);
p = 1.0;
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;
j = 2; //////
step = PI2 / float(ringsamples);
pw = cos(float(j) * step) * float(i);
ph = sin(float(j) * step) * float(i);
p = 1.0;
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;
j = 3; //////
step = PI2 / float(ringsamples);
pw = cos(float(j) * step) * float(i);
ph = sin(float(j) * step) * float(i);
p = 1.0;
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;
j = 4; //////
step = PI2 / float(ringsamples);
pw = cos(float(j) * step) * float(i);
ph = sin(float(j) * step) * float(i);
p = 1.0;
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;
j = 5; //////
step = PI2 / float(ringsamples);
pw = cos(float(j) * step) * float(i);
ph = sin(float(j) * step) * float(i);
p = 1.0;
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;
//------
i = 3; // i <= rings
ringsamples = i * samples;
j = 0; // j < ringsamples
step = PI2 / float(ringsamples);
pw = cos(float(j) * step) * float(i);
ph = sin(float(j) * step) * float(i);
p = 1.0;
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;
j = 1; //////
step = PI2 / float(ringsamples);
pw = cos(float(j) * step) * float(i);
ph = sin(float(j) * step) * float(i);
p = 1.0;
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;
j = 2; //////
step = PI2 / float(ringsamples);
pw = cos(float(j) * step) * float(i);
ph = sin(float(j) * step) * float(i);
p = 1.0;
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;
j = 3; //////
step = PI2 / float(ringsamples);
pw = cos(float(j) * step) * float(i);
ph = sin(float(j) * step) * float(i);
p = 1.0;
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;
j = 4; //////
step = PI2 / float(ringsamples);
pw = cos(float(j) * step) * float(i);
ph = sin(float(j) * step) * float(i);
p = 1.0;
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;
j = 5; //////
step = PI2 / float(ringsamples);
pw = cos(float(j) * step) * float(i);
ph = sin(float(j) * step) * float(i);
p = 1.0;
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;
j = 6; //////
step = PI2 / float(ringsamples);
pw = cos(float(j) * step) * float(i);
ph = sin(float(j) * step) * float(i);
p = 1.0;
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;
j = 7; //////
step = PI2 / float(ringsamples);
pw = cos(float(j) * step) * float(i);
ph = sin(float(j) * step) * float(i);
p = 1.0;
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;
j = 8; //////
step = PI2 / float(ringsamples);
pw = cos(float(j) * step) * float(i);
ph = sin(float(j) * step) * float(i);
p = 1.0;
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;
}

View File

@ -1,65 +0,0 @@
#include "../compiled.glsl"
vec2 octahedronWrap(const vec2 v) {
return (1.0 - abs(v.yx)) * (vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0));
}
vec3 getNor(const vec2 enc) {
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);
return n;
}
vec3 getPosView(const vec3 viewRay, const float depth) {
const float projectionA = cameraPlane.y / (cameraPlane.y - cameraPlane.x);
const float projectionB = (-cameraPlane.y * cameraPlane.x) / (cameraPlane.y - cameraPlane.x);
float linearDepth = projectionB / (projectionA - depth);
return viewRay * linearDepth;
}
vec3 getPos(const vec3 eye, const vec3 eyeLook, const vec3 viewRay, const float depth) {
vec3 vray = normalize(viewRay);
const float projectionA = cameraPlane.y / (cameraPlane.y - cameraPlane.x);
const float projectionB = (-cameraPlane.y * cameraPlane.x) / (cameraPlane.y - cameraPlane.x);
float linearDepth = projectionB / (depth * 0.5 + 0.5 - projectionA);
float viewZDist = dot(eyeLook, vray);
vec3 wposition = eye + vray * (linearDepth / viewZDist);
return wposition;
}
vec3 getPosNoEye(const vec3 eyeLook, const vec3 viewRay, const float depth) {
vec3 vray = normalize(viewRay);
const float projectionA = cameraPlane.y / (cameraPlane.y - cameraPlane.x);
const float projectionB = -(cameraPlane.y * cameraPlane.x) / (cameraPlane.y - cameraPlane.x);
float linearDepth = projectionB / (depth * 0.5 + 0.5 - projectionA);
float viewZDist = dot(eyeLook, vray);
vec3 wposition = vray * (linearDepth / viewZDist);
return wposition;
}
vec3 getPos2(const mat4 invVP, const float depth, const vec2 coord) {
// vec4 pos = vec4(coord * 2.0 - 1.0, depth * 2.0 - 1.0, 1.0);
vec4 pos = vec4(coord * 2.0 - 1.0, depth, 1.0);
pos = invVP * pos;
pos.xyz /= pos.w;
return pos.xyz;
}
vec3 getPos2NoEye(const vec3 eye, const mat4 invVP, const float depth, const vec2 coord) {
vec4 pos = vec4(coord * 2.0 - 1.0, depth, 1.0);
pos = invVP * pos;
pos.xyz /= pos.w;
return pos.xyz - eye;
}
float packFloat(const float f1, const float f2) {
float index = floor(f1 * 100.0); // Temporary
float alpha = clamp(f2, 0.0, 1.0 - 0.001);
return index + alpha;
}
vec2 unpackFloat(float f) {
return vec2(floor(f) / 100.0, fract(f));
}

View File

@ -1,164 +0,0 @@
// Linearly Transformed Cosines
// https://eheitzresearch.wordpress.com/415-2/
uniform sampler2D sltcMat;
uniform sampler2D sltcMag;
const float LUT_SIZE = 64.0;
const float LUT_SCALE = (LUT_SIZE - 1.0) / LUT_SIZE;
const float LUT_BIAS = 0.5 / LUT_SIZE;
vec3 L0;
vec3 L1;
vec3 L2;
vec3 L3;
vec3 L4;
mat3 transpose2(mat3 v) {
mat3 tmp;
tmp[0] = vec3(v[0].x, v[1].x, v[2].x);
tmp[1] = vec3(v[0].y, v[1].y, v[2].y);
tmp[2] = vec3(v[0].z, v[1].z, v[2].z);
return tmp;
}
float integrateEdge(vec3 v1, vec3 v2) {
float cosTheta = dot(v1, v2);
cosTheta = clamp(cosTheta, -0.9999, 0.9999);
float theta = acos(cosTheta);
float res = cross(v1, v2).z * theta / sin(theta);
return res;
}
int clipQuadToHorizon(/*inout vec3 L[5], out int n*/) {
int n;
// Detect clipping config
int config = 0;
if (L0.z > 0.0) config += 1;
if (L1.z > 0.0) config += 2;
if (L2.z > 0.0) config += 4;
if (L3.z > 0.0) config += 8;
// Clip
if (config == 0) {
// Clip all
}
else if (config == 1) { // V1 clip V2 V3 V4
n = 3;
L1 = -L1.z * L0 + L0.z * L1;
L2 = -L3.z * L0 + L0.z * L3;
}
else if (config == 2) { // V2 clip V1 V3 V4
n = 3;
L0 = -L0.z * L1 + L1.z * L0;
L2 = -L2.z * L1 + L1.z * L2;
}
else if (config == 3) { // V1 V2 clip V3 V4
n = 4;
L2 = -L2.z * L1 + L1.z * L2;
L3 = -L3.z * L0 + L0.z * L3;
}
else if (config == 4) { // V3 clip V1 V2 V4
n = 3;
L0 = -L3.z * L2 + L2.z * L3;
L1 = -L1.z * L2 + L2.z * L1;
}
else if (config == 5) { // V1 V3 clip V2 V4) impossible
n = 0;
}
else if (config == 6) { // V2 V3 clip V1 V4
n = 4;
L0 = -L0.z * L1 + L1.z * L0;
L3 = -L3.z * L2 + L2.z * L3;
}
else if (config == 7) { // V1 V2 V3 clip V4
n = 5;
L4 = -L3.z * L0 + L0.z * L3;
L3 = -L3.z * L2 + L2.z * L3;
}
else if (config == 8) { // V4 clip V1 V2 V3
n = 3;
L0 = -L0.z * L3 + L3.z * L0;
L1 = -L2.z * L3 + L3.z * L2;
L2 = L3;
}
else if (config == 9) { // V1 V4 clip V2 V3
n = 4;
L1 = -L1.z * L0 + L0.z * L1;
L2 = -L2.z * L3 + L3.z * L2;
}
else if (config == 10) { // V2 V4 clip V1 V3) impossible
n = 0;
}
else if (config == 11) { // V1 V2 V4 clip V3
n = 5;
L4 = L3;
L3 = -L2.z * L3 + L3.z * L2;
L2 = -L2.z * L1 + L1.z * L2;
}
else if (config == 12) { // V3 V4 clip V1 V2
n = 4;
L1 = -L1.z * L2 + L2.z * L1;
L0 = -L0.z * L3 + L3.z * L0;
}
else if (config == 13) { // V1 V3 V4 clip V2
n = 5;
L4 = L3;
L3 = L2;
L2 = -L1.z * L2 + L2.z * L1;
L1 = -L1.z * L0 + L0.z * L1;
}
else if (config == 14) { // V2 V3 V4 clip V1
n = 5;
L4 = -L0.z * L3 + L3.z * L0;
L0 = -L0.z * L1 + L1.z * L0;
}
else if (config == 15) { // V1 V2 V3 V4
n = 4;
}
if (n == 3) L3 = L0;
if (n == 4) L4 = L0;
return n;
}
vec3 ltcEvaluate(vec3 N, vec3 V, float dotNV, vec3 P, mat3 Minv, vec3 points0, vec3 points1, vec3 points2, vec3 points3, bool twoSided) {
// Construct orthonormal basis around N
vec3 T1, T2;
T1 = normalize(V - N * dotNV);
T2 = cross(N, T1);
// Rotate area light in (T1, T2, R) basis
Minv = Minv * transpose2(mat3(T1, T2, N));
// Polygon (allocate 5 vertices for clipping)
// vec3 L[5];
L0 = Minv * (points0 - P);
L1 = Minv * (points1 - P);
L2 = Minv * (points2 - P);
L3 = Minv * (points3 - P);
// int n;
int n = clipQuadToHorizon(/*L, n*/);
if (n == 0) return vec3(0.0);
// Project onto sphere
L0 = normalize(L0);
L1 = normalize(L1);
L2 = normalize(L2);
L3 = normalize(L3);
L4 = normalize(L4);
// Integrate
float sum = 0.0;
sum += integrateEdge(L0, L1);
sum += integrateEdge(L1, L2);
sum += integrateEdge(L2, L3);
if (n >= 4) sum += integrateEdge(L3, L4);
if (n == 5) sum += integrateEdge(L4, L0);
sum = twoSided ? abs(sum) : max(0.0, -sum);
return vec3(sum);
}

View File

@ -1,34 +0,0 @@
#ifndef _MATH_GLSL_
#define _MATH_GLSL_
float hash(const vec2 p) {
float h = dot(p, vec2(127.1, 311.7));
return fract(sin(h) * 43758.5453123);
}
vec2 envMapEquirect(const vec3 normal) {
const float PI = 3.1415926535;
const float PI2 = PI * 2.0;
float phi = acos(normal.z);
float theta = atan(-normal.y, normal.x) + PI;
return vec2(theta / PI2, phi / PI);
}
float rand(const vec2 co) { // Unreliable
return fract(sin(dot(co.xy, vec2(12.9898,78.233))) * 43758.5453);
}
vec2 rand2(const vec2 coord) {
const float width = 1100;
const float height = 500;
float noiseX = ((fract(1.0 - coord.s * (width / 2.0)) * 0.25) + (fract(coord.t * (height / 2.0)) * 0.75)) * 2.0 - 1.0;
float noiseY = ((fract(1.0 - coord.s * (width / 2.0)) * 0.75) + (fract(coord.t * (height / 2.0)) * 0.25)) * 2.0 - 1.0;
return vec2(noiseX, noiseY);
}
float linearize(const float depth) {
return -cameraPlane.y * cameraPlane.x / (depth * (cameraPlane.y - cameraPlane.x) - cameraPlane.y);
}
#endif

View File

@ -1,43 +0,0 @@
#include "../compiled.glsl"
uniform sampler2D shadowMap;
float texture2DCompare(const vec2 uv, const float compare){
float depth = texture(shadowMap, uv).r; // * 2.0 - 1.0; // - mult compare instead
return step(compare, depth);
}
float texture2DShadowLerp(const vec2 uv, const float compare){
const vec2 texelSize = vec2(1.0) / shadowmapSize;
vec2 f = fract(uv * shadowmapSize + 0.5);
vec2 centroidUV = floor(uv * shadowmapSize + 0.5) / shadowmapSize;
float lb = texture2DCompare(centroidUV, compare);
float lt = texture2DCompare(centroidUV + texelSize * vec2(0.0, 1.0), compare);
float rb = texture2DCompare(centroidUV + texelSize * vec2(1.0, 0.0), compare);
float rt = texture2DCompare(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, 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) / shadowmapSize;
// result += texture2DShadowLerp(shadowmapSize, uv + off, compare);
compare = compare * 0.5 + 0.5;
float result = texture2DShadowLerp(uv + (vec2(-1.0, -1.0) / shadowmapSize), compare);
result += texture2DShadowLerp(uv + (vec2(-1.0, 0.0) / shadowmapSize), compare);
result += texture2DShadowLerp(uv + (vec2(-1.0, 1.0) / shadowmapSize), compare);
result += texture2DShadowLerp(uv + (vec2(0.0, -1.0) / shadowmapSize), compare);
result += texture2DShadowLerp(uv, compare);
result += texture2DShadowLerp(uv + (vec2(0.0, 1.0) / shadowmapSize), compare);
result += texture2DShadowLerp(uv + (vec2(1.0, -1.0) / shadowmapSize), compare);
result += texture2DShadowLerp(uv + (vec2(1.0, 0.0) / shadowmapSize), compare);
result += texture2DShadowLerp(uv + (vec2(1.0, 1.0) / shadowmapSize), compare);
// }
// }
return result / 9.0;
}

View File

@ -1,190 +0,0 @@
// Based on ThreeJS and nvidia pcss
#include "../compiled.glsl"
uniform sampler2D shadowMap;
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 * 2.0 - 1.0;
if (shadowMapDepth < zReceiver) { blockerDepthSum += shadowMapDepth; numBlockers++; }
shadowMapDepth = texture(shadowMap, uv + poissonDisk1 * searchRadius).r * 2.0 - 1.0;
if (shadowMapDepth < zReceiver) { blockerDepthSum += shadowMapDepth; numBlockers++; }
shadowMapDepth = texture(shadowMap, uv + poissonDisk2 * searchRadius).r * 2.0 - 1.0;
if (shadowMapDepth < zReceiver) { blockerDepthSum += shadowMapDepth; numBlockers++; }
shadowMapDepth = texture(shadowMap, uv + poissonDisk3 * searchRadius).r * 2.0 - 1.0;
if (shadowMapDepth < zReceiver) { blockerDepthSum += shadowMapDepth; numBlockers++; }
shadowMapDepth = texture(shadowMap, uv + poissonDisk4 * searchRadius).r * 2.0 - 1.0;
if (shadowMapDepth < zReceiver) { blockerDepthSum += shadowMapDepth; numBlockers++; }
shadowMapDepth = texture(shadowMap, uv + poissonDisk5 * searchRadius).r * 2.0 - 1.0;
if (shadowMapDepth < zReceiver) { blockerDepthSum += shadowMapDepth; numBlockers++; }
shadowMapDepth = texture(shadowMap, uv + poissonDisk6 * searchRadius).r * 2.0 - 1.0;
if (shadowMapDepth < zReceiver) { blockerDepthSum += shadowMapDepth; numBlockers++; }
shadowMapDepth = texture(shadowMap, uv + poissonDisk7 * searchRadius).r * 2.0 - 1.0;
if (shadowMapDepth < zReceiver) { blockerDepthSum += shadowMapDepth; numBlockers++; }
shadowMapDepth = texture(shadowMap, uv + poissonDisk8 * searchRadius).r * 2.0 - 1.0;
if (shadowMapDepth < zReceiver) { blockerDepthSum += shadowMapDepth; numBlockers++; }
shadowMapDepth = texture(shadowMap, uv + poissonDisk9 * searchRadius).r * 2.0 - 1.0;
if (shadowMapDepth < zReceiver) { blockerDepthSum += shadowMapDepth; numBlockers++; }
shadowMapDepth = texture(shadowMap, uv + poissonDisk10 * searchRadius).r * 2.0 - 1.0;
if (shadowMapDepth < zReceiver) { blockerDepthSum += shadowMapDepth; numBlockers++; }
shadowMapDepth = texture(shadowMap, uv + poissonDisk11 * searchRadius).r * 2.0 - 1.0;
if (shadowMapDepth < zReceiver) { blockerDepthSum += shadowMapDepth; numBlockers++; }
shadowMapDepth = texture(shadowMap, uv + poissonDisk12 * searchRadius).r * 2.0 - 1.0;
if (shadowMapDepth < zReceiver) { blockerDepthSum += shadowMapDepth; numBlockers++; }
shadowMapDepth = texture(shadowMap, uv + poissonDisk13 * searchRadius).r * 2.0 - 1.0;
if (shadowMapDepth < zReceiver) { blockerDepthSum += shadowMapDepth; numBlockers++; }
shadowMapDepth = texture(shadowMap, uv + poissonDisk14 * searchRadius).r * 2.0 - 1.0;
if (shadowMapDepth < zReceiver) { blockerDepthSum += shadowMapDepth; numBlockers++; }
shadowMapDepth = texture(shadowMap, uv + poissonDisk15 * searchRadius).r * 2.0 - 1.0;
if (shadowMapDepth < zReceiver) { blockerDepthSum += shadowMapDepth; numBlockers++; }
shadowMapDepth = texture(shadowMap, uv + poissonDisk16 * searchRadius).r * 2.0 - 1.0;
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 * 2.0 - 1.0;
if (zReceiver <= depth) sum += 1.0;
depth = texture(shadowMap, uv + poissonDisk1 * filterRadius).r * 2.0 - 1.0;
if (zReceiver <= depth) sum += 1.0;
depth = texture(shadowMap, uv + poissonDisk2 * filterRadius).r * 2.0 - 1.0;
if (zReceiver <= depth) sum += 1.0;
depth = texture(shadowMap, uv + poissonDisk3 * filterRadius).r * 2.0 - 1.0;
if (zReceiver <= depth) sum += 1.0;
depth = texture(shadowMap, uv + poissonDisk4 * filterRadius).r * 2.0 - 1.0;
if (zReceiver <= depth) sum += 1.0;
depth = texture(shadowMap, uv + poissonDisk5 * filterRadius).r * 2.0 - 1.0;
if (zReceiver <= depth) sum += 1.0;
depth = texture(shadowMap, uv + poissonDisk6 * filterRadius).r * 2.0 - 1.0;
if (zReceiver <= depth) sum += 1.0;
depth = texture(shadowMap, uv + poissonDisk7 * filterRadius).r * 2.0 - 1.0;
if (zReceiver <= depth) sum += 1.0;
depth = texture(shadowMap, uv + poissonDisk8 * filterRadius).r * 2.0 - 1.0;
if (zReceiver <= depth) sum += 1.0;
depth = texture(shadowMap, uv + poissonDisk9 * filterRadius).r * 2.0 - 1.0;
if (zReceiver <= depth) sum += 1.0;
depth = texture(shadowMap, uv + poissonDisk10 * filterRadius).r * 2.0 - 1.0;
if (zReceiver <= depth) sum += 1.0;
depth = texture(shadowMap, uv + poissonDisk11 * filterRadius).r * 2.0 - 1.0;
if (zReceiver <= depth) sum += 1.0;
depth = texture(shadowMap, uv + poissonDisk12 * filterRadius).r * 2.0 - 1.0;
if (zReceiver <= depth) sum += 1.0;
depth = texture(shadowMap, uv + poissonDisk13 * filterRadius).r * 2.0 - 1.0;
if (zReceiver <= depth) sum += 1.0;
depth = texture(shadowMap, uv + poissonDisk14 * filterRadius).r * 2.0 - 1.0;
if (zReceiver <= depth) sum += 1.0;
depth = texture(shadowMap, uv + poissonDisk15 * filterRadius).r * 2.0 - 1.0;
if (zReceiver <= depth) sum += 1.0;
depth = texture(shadowMap, uv + poissonDisk16 * filterRadius).r * 2.0 - 1.0;
if (zReceiver <= depth) sum += 1.0;
// }
// for (int i = 0; i < NUM_SAMPLES; i++) {
depth = texture(shadowMap, uv + -poissonDisk0.yx * filterRadius).r * 2.0 - 1.0;
if (zReceiver <= depth) sum += 1.0;
depth = texture(shadowMap, uv + -poissonDisk1.yx * filterRadius).r * 2.0 - 1.0;
if (zReceiver <= depth) sum += 1.0;
depth = texture(shadowMap, uv + -poissonDisk2.yx * filterRadius).r * 2.0 - 1.0;
if (zReceiver <= depth) sum += 1.0;
depth = texture(shadowMap, uv + -poissonDisk3.yx * filterRadius).r * 2.0 - 1.0;
if (zReceiver <= depth) sum += 1.0;
depth = texture(shadowMap, uv + -poissonDisk4.yx * filterRadius).r * 2.0 - 1.0;
if (zReceiver <= depth) sum += 1.0;
depth = texture(shadowMap, uv + -poissonDisk5.yx * filterRadius).r * 2.0 - 1.0;
if (zReceiver <= depth) sum += 1.0;
depth = texture(shadowMap, uv + -poissonDisk6.yx * filterRadius).r * 2.0 - 1.0;
if (zReceiver <= depth) sum += 1.0;
depth = texture(shadowMap, uv + -poissonDisk7.yx * filterRadius).r * 2.0 - 1.0;
if (zReceiver <= depth) sum += 1.0;
depth = texture(shadowMap, uv + -poissonDisk8.yx * filterRadius).r * 2.0 - 1.0;
if (zReceiver <= depth) sum += 1.0;
depth = texture(shadowMap, uv + -poissonDisk9.yx * filterRadius).r * 2.0 - 1.0;
if (zReceiver <= depth) sum += 1.0;
depth = texture(shadowMap, uv + -poissonDisk10.yx * filterRadius).r * 2.0 - 1.0;
if (zReceiver <= depth) sum += 1.0;
depth = texture(shadowMap, uv + -poissonDisk11.yx * filterRadius).r * 2.0 - 1.0;
if (zReceiver <= depth) sum += 1.0;
depth = texture(shadowMap, uv + -poissonDisk12.yx * filterRadius).r * 2.0 - 1.0;
if (zReceiver <= depth) sum += 1.0;
depth = texture(shadowMap, uv + -poissonDisk13.yx * filterRadius).r * 2.0 - 1.0;
if (zReceiver <= depth) sum += 1.0;
depth = texture(shadowMap, uv + -poissonDisk14.yx * filterRadius).r * 2.0 - 1.0;
if (zReceiver <= depth) sum += 1.0;
depth = texture(shadowMap, uv + -poissonDisk15.yx * filterRadius).r * 2.0 - 1.0;
if (zReceiver <= depth) sum += 1.0;
depth = texture(shadowMap, uv + -poissonDisk16.yx * filterRadius).r * 2.0 - 1.0;
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);
}

View File

@ -1,31 +0,0 @@
uniform float shirr[27];
vec3 shIrradiance(const vec3 nor, const float scale) {
const float c1 = 0.429043;
const float c2 = 0.511664;
const float c3 = 0.743125;
const float c4 = 0.886227;
const float c5 = 0.247708;
vec3 cl00, cl1m1, cl10, cl11, cl2m2, cl2m1, cl20, cl21, cl22;
cl00 = vec3(shirr[0], shirr[1], shirr[2]);
cl1m1 = vec3(shirr[3], shirr[4], shirr[5]);
cl10 = vec3(shirr[6], shirr[7], shirr[8]);
cl11 = vec3(shirr[9], shirr[10], shirr[11]);
cl2m2 = vec3(shirr[12], shirr[13], shirr[14]);
cl2m1 = vec3(shirr[15], shirr[16], shirr[17]);
cl20 = vec3(shirr[18], shirr[19], shirr[20]);
cl21 = vec3(shirr[21], shirr[22], shirr[23]);
cl22 = vec3(shirr[24], shirr[25], shirr[26]);
return (
c1 * cl22 * (nor.y * nor.y - (-nor.z) * (-nor.z)) +
c3 * cl20 * nor.x * nor.x +
c4 * cl00 -
c5 * cl20 +
2.0 * c1 * cl2m2 * nor.y * (-nor.z) +
2.0 * c1 * cl21 * nor.y * nor.x +
2.0 * c1 * cl2m1 * (-nor.z) * nor.x +
2.0 * c2 * cl11 * nor.y +
2.0 * c2 * cl1m1 * (-nor.z) +
2.0 * c2 * cl10 * nor.x
) * scale;
}

View File

@ -1,50 +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
uniform float skinBones[skinMaxBones * 8];
void getSkinningDualQuat(const ivec4 bone, vec4 weight, out vec4 A, inout vec4 B) {
// Retrieve the real and dual part of the dual-quaternions
mat4 matA, matB;
matA[0][0] = skinBones[bone.x * 8 + 0];
matA[0][1] = skinBones[bone.x * 8 + 1];
matA[0][2] = skinBones[bone.x * 8 + 2];
matA[0][3] = skinBones[bone.x * 8 + 3];
matB[0][0] = skinBones[bone.x * 8 + 4];
matB[0][1] = skinBones[bone.x * 8 + 5];
matB[0][2] = skinBones[bone.x * 8 + 6];
matB[0][3] = skinBones[bone.x * 8 + 7];
matA[1][0] = skinBones[bone.y * 8 + 0];
matA[1][1] = skinBones[bone.y * 8 + 1];
matA[1][2] = skinBones[bone.y * 8 + 2];
matA[1][3] = skinBones[bone.y * 8 + 3];
matB[1][0] = skinBones[bone.y * 8 + 4];
matB[1][1] = skinBones[bone.y * 8 + 5];
matB[1][2] = skinBones[bone.y * 8 + 6];
matB[1][3] = skinBones[bone.y * 8 + 7];
matA[2][0] = skinBones[bone.z * 8 + 0];
matA[2][1] = skinBones[bone.z * 8 + 1];
matA[2][2] = skinBones[bone.z * 8 + 2];
matA[2][3] = skinBones[bone.z * 8 + 3];
matB[2][0] = skinBones[bone.z * 8 + 4];
matB[2][1] = skinBones[bone.z * 8 + 5];
matB[2][2] = skinBones[bone.z * 8 + 6];
matB[2][3] = skinBones[bone.z * 8 + 7];
matA[3][0] = skinBones[bone.w * 8 + 0];
matA[3][1] = skinBones[bone.w * 8 + 1];
matA[3][2] = skinBones[bone.w * 8 + 2];
matA[3][3] = skinBones[bone.w * 8 + 3];
matB[3][0] = skinBones[bone.w * 8 + 4];
matB[3][1] = skinBones[bone.w * 8 + 5];
matB[3][2] = skinBones[bone.w * 8 + 6];
matB[3][3] = skinBones[bone.w * 8 + 7];
// 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;
}

View File

@ -1,36 +0,0 @@
uniform float skinBones[skinMaxBones * 12];
mat4 getBoneMat(const int boneIndex) {
vec4 v0 = vec4(skinBones[boneIndex * 12 + 0],
skinBones[boneIndex * 12 + 1],
skinBones[boneIndex * 12 + 2],
skinBones[boneIndex * 12 + 3]);
vec4 v1 = vec4(skinBones[boneIndex * 12 + 4],
skinBones[boneIndex * 12 + 5],
skinBones[boneIndex * 12 + 6],
skinBones[boneIndex * 12 + 7]);
vec4 v2 = vec4(skinBones[boneIndex * 12 + 8],
skinBones[boneIndex * 12 + 9],
skinBones[boneIndex * 12 + 10],
skinBones[boneIndex * 12 + 11]);
return mat4(v0.x, v0.y, v0.z, v0.w,
v1.x, v1.y, v1.z, v1.w,
v2.x, v2.y, v2.z, v2.w,
0.0, 0.0, 0.0, 1.0);
}
mat4 getSkinningMat(ivec4 bone, vec4 weight) {
return weight.x * getBoneMat(bone.x) +
weight.y * getBoneMat(bone.y) +
weight.z * getBoneMat(bone.z) +
weight.w * getBoneMat(bone.w);
}
mat3 getSkinningMatVec(const mat4 skinningMat) {
return mat3(skinningMat[0].xyz, skinningMat[1].xyz, skinningMat[2].xyz);
}
// mat4 skinningMat = getSkinningMat();
// mat3 skinningMatVec = getSkinningMatVec(skinningMat);
// sPos = sPos * skinningMat;
// vec3 _normal = normalize(mat3(N) * (nor * skinningMatVec));

View File

@ -1,28 +0,0 @@
vec3 uncharted2Tonemap(const vec3 x) {
const float A = 0.15;
const float B = 0.50;
const float C = 0.10;
const float D = 0.20;
const float E = 0.02;
const float F = 0.30;
return ((x * (A * x + C * B) + D * E) / (x * (A * x + B) + D * F)) - E / F;
}
vec3 tonemapUncharted2(const vec3 color) {
const float W = 11.2;
const float exposureBias = 2.0;
vec3 curr = uncharted2Tonemap(exposureBias * color);
vec3 whiteScale = 1.0 / uncharted2Tonemap(vec3(W));
return curr * whiteScale;
}
// Based on Filmic Tonemapping Operators http://filmicgames.com/archives/75
vec3 tonemapFilmic(const vec3 color) {
vec3 x = max(vec3(0.0), color - 0.004);
return (x * (6.2 * x + 0.5)) / (x * (6.2 * x + 1.7) + 0.06);
}
vec3 tonemapReinhard(const vec3 color) {
return color / (color + vec3(1.0));
}

View File

@ -1,26 +0,0 @@
uniform mat4 U; // Undistortion
uniform float maxRadSq;
// GoogleVR Distortion using Vertex Displacement
float distortionFactor(float rSquared) {
float ret = 0.0;
ret = rSquared * (ret + U[1][1]);
ret = rSquared * (ret + U[0][1]);
ret = rSquared * (ret + U[3][0]);
ret = rSquared * (ret + U[2][0]);
ret = rSquared * (ret + U[1][0]);
ret = rSquared * (ret + U[0][0]);
return ret + 1.0;
}
// Convert point from world space to undistorted camera space
vec4 undistort(const mat4 WV, vec4 pos) {
// Go to camera space
pos = WV * pos;
const float nearClip = 0.1;
if (pos.z <= -nearClip) { // Reminder: Forward is -Z
// Undistort the point's coordinates in XY
float r2 = clamp(dot(pos.xy, pos.xy) / (pos.z * pos.z), 0.0, maxRadSq);
pos.xy *= distortionFactor(r2);
}
return pos;
}

View File

@ -1,236 +0,0 @@
#version 450
#define _EnvCol
#define _SSAO
#define _SMAA
#ifdef GL_ES
precision mediump float;
#endif
#include "../compiled.glsl"
#ifdef _EnvTex
#include "../std/math.glsl"
// envMapEquirect()
#endif
#ifdef _EnvCol
uniform vec3 backgroundCol;
#endif
#ifdef _EnvSky
uniform vec3 A;
uniform vec3 B;
uniform vec3 C;
uniform vec3 D;
uniform vec3 E;
uniform vec3 F;
uniform vec3 G;
uniform vec3 H;
uniform vec3 I;
uniform vec3 Z;
uniform vec3 sunDirection;
#endif
#ifdef _EnvClouds
uniform sampler2D snoise;
uniform float time;
// uniform vec3 eye;
const float difference = cloudsUpper - cloudsLower;
const float steps = 45.0;
#endif
#ifdef _EnvTex
uniform sampler2D envmap;
#endif
#ifdef _EnvImg // Static background
uniform vec2 screenSize;
uniform sampler2D envmap;
#endif
// uniform sampler2D gbufferD;
uniform float envmapStrength; // From world material
// in vec2 texCoord;
in vec3 normal;
out vec4 fragColor;
#ifdef _EnvSky
vec3 hosekWilkie(float cos_theta, float gamma, float cos_gamma) {
vec3 chi = (1 + cos_gamma * cos_gamma) / pow(1 + H * H - 2 * cos_gamma * H, vec3(1.5));
return (1 + A * exp(B / (cos_theta + 0.01))) * (C + D * exp(E * gamma) + F * (cos_gamma * cos_gamma) + G * chi + I * sqrt(cos_theta));
}
#endif
#ifdef _EnvClouds
// float hash(vec3 p) {
// p = fract(p * vec3(0.16532, 0.17369, 0.15787));
// p += dot(p.xyz, p.zyx + 19.19);
// return fract(p.x * p.y * p.z);
// }
float noise(vec3 x) {
vec3 p = floor(x);
vec3 f = fract(x);
f = f * f * (3.0 - 2.0 * f);
vec2 uv = (p.xy + vec2(37.0, 17.0) * p.z) + f.xy;
vec2 rg = texture(snoise, (uv + 0.5) / 256.0).yx;
return mix(rg.x, rg.y, f.z);
}
float fbm(vec3 p) {
p *= 0.0005 * cloudsSize;
float f = 0.5 * noise(p); p = p * 3.0; p.y += time * cloudsWind.x;
f += 0.25 * noise(p); p = p * 2.0; p.y += time * cloudsWind.y;
f += 0.125 * noise(p); p = p * 3.0;
f += 0.0625 * noise(p); p = p * 3.0;
f += 0.03125 * noise(p); p = p * 3.0;
f += 0.015625 * noise(p);
return f;
}
float map(vec3 p) {
return fbm(p) - cloudsDensity * 0.6;
}
// Weather by David Hoskins, https://www.shadertoy.com/view/4dsXWn
// Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
vec3 traceP;
vec2 doCloudTrace(vec3 add, vec2 shadeSum) {
float h = map(traceP);
vec2 shade = vec2(traceP.z / difference, max(-h, 0.0));
traceP += add;
return shadeSum + shade * (1.0 - shadeSum.y);
}
vec2 traceCloud(vec3 pos, vec3 dir) {
float beg = ((cloudsLower - pos.z) / dir.z);
float end = ((cloudsUpper - pos.z) / dir.z);
traceP = vec3(pos.x + dir.x * beg, pos.y + dir.y * beg, 0.0);
// beg += hash(traceP) * 150.0; // Noisy
vec3 add = dir * ((end - beg) / steps);
vec2 shadeSum = vec2(0.0);
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;
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;
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;
// 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
// https://www.guerrilla-games.com/read/the-real-time-volumetric-cloudscapes-of-horizon-zero-dawn
vec3 cloudsColor(vec3 R, vec3 pos, vec3 dir) {
vec2 traced = traceCloud(pos, dir);
float d = traced.x / 200.0 * traced.y + traced.x / 1500.0 * cloudsSecondary;
const float g = cloudsEccentricity;
#ifdef _EnvSky
float cosAngle = dot(sunDirection, dir);
#else // Predefined sun direction
float cosAngle = dot(vec3(0.0, -1.0, 0.0), dir);
#endif
float E = 2.0 * exp(-d * cloudsPrecipitation) * (1.0 - exp(-2.0 * d)) * (0.25 * PI) * ((1.0 - g * g) / pow(1.0 + g * g - 2.0 * g * cosAngle, 3.0 / 2.0));
return mix(vec3(R), vec3(E * 24.0), d * 12.0);
}
#endif
void main() {
// if (texture(gbufferD, texCoord).r/* * 2.0 - 1.0*/ != 1.0) {
// discard;
// }
#ifdef _EnvCol
vec3 R = backgroundCol;
#ifdef _EnvClouds
vec3 n = normalize(normal);
#endif
#endif
#ifndef _EnvSky // Prevent case when sky radiance is enabled
#ifdef _EnvTex
vec3 n = normalize(normal);
vec3 R = texture(envmap, envMapEquirect(n)).rgb * envmapStrength;
#endif
#endif
#ifdef _EnvImg // Static background
// Will have to get rid of gl_FragCoord, pass tc from VS
vec2 texco = gl_FragCoord.xy / screenSize;
vec3 R = texture(envmap, vec2(texco.x, 1.0 - texco.y)).rgb * envmapStrength;
#endif
#ifdef _EnvSky
vec3 n = normalize(normal);
vec3 sunDir = vec3(sunDirection.x, -sunDirection.y, sunDirection.z);
float phi = acos(n.z);
float theta = atan(-n.y, n.x) + PI;
float cos_theta = clamp(n.z, 0.0, 1.0);
float cos_gamma = dot(n, sunDir);
float gamma_val = acos(cos_gamma);
vec3 R = Z * hosekWilkie(cos_theta, gamma_val, cos_gamma) * envmapStrength;
// #ifndef _LDR
// R = pow(R, vec3(2.2));
// #endif
#endif
#ifdef _EnvClouds
// cloudsColor(R, eye, n)
vec3 clouds = cloudsColor(R, vec3(0.0), n);
if (n.z > 0.0) R = mix(R, clouds, n.z * 5.0 * envmapStrength);
#endif
#ifdef _LDR
R = pow(R, vec3(1.0 / 2.2));
#endif
fragColor = vec4(R, 1.0);
}

View File

@ -1,21 +0,0 @@
#version 450
#define _EnvCol
#define _SSAO
#define _SMAA
#ifdef GL_ES
precision highp float;
#endif
in vec3 pos;
in vec3 nor;
out vec3 normal;
uniform mat4 SMVP;
void main() {
normal = nor;
vec4 position = SMVP * vec4(pos, 1.0);
gl_Position = vec4(position);
}

View File

@ -1,46 +0,0 @@
// Auto-generated
let project = new Project('untitled');
project.addSources('Sources');
project.addLibrary("../../..");
project.addLibrary("iron");
project.addShaders('build/compiled/ShaderRaws/Material/Material_mesh.frag.glsl');
project.addShaders('build/compiled/ShaderRaws/Material/Material_mesh.vert.glsl');
project.addShaders('build/compiled/ShaderRaws/Material/Material_shadowmap.frag.glsl');
project.addShaders('build/compiled/ShaderRaws/Material/Material_shadowmap.vert.glsl');
project.addShaders('build/compiled/Shaders/blur_edge_pass/blur_edge_pass_EnvCol_SSAO_SMAA.frag.glsl');
project.addShaders('build/compiled/Shaders/blur_edge_pass/blur_edge_pass_EnvCol_SSAO_SMAA.vert.glsl');
project.addShaders('build/compiled/Shaders/compositor_pass/compositor_pass_EnvCol_SSAO_SMAA_CompoTonemap.frag.glsl');
project.addShaders('build/compiled/Shaders/compositor_pass/compositor_pass_EnvCol_SSAO_SMAA_CompoTonemap.vert.glsl');
project.addShaders('build/compiled/Shaders/deferred_indirect/deferred_indirect_EnvCol_SSAO_SMAA.frag.glsl');
project.addShaders('build/compiled/Shaders/deferred_indirect/deferred_indirect_EnvCol_SSAO_SMAA.vert.glsl');
project.addShaders('build/compiled/Shaders/deferred_light/deferred_light_EnvCol_SSAO_SMAA.frag.glsl');
project.addShaders('build/compiled/Shaders/deferred_light/deferred_light_EnvCol_SSAO_SMAA.vert.glsl');
project.addShaders('build/compiled/Shaders/smaa_blend_weight/smaa_blend_weight_EnvCol_SSAO_SMAA.frag.glsl');
project.addShaders('build/compiled/Shaders/smaa_blend_weight/smaa_blend_weight_EnvCol_SSAO_SMAA.vert.glsl');
project.addShaders('build/compiled/Shaders/smaa_edge_detect/smaa_edge_detect_EnvCol_SSAO_SMAA.frag.glsl');
project.addShaders('build/compiled/Shaders/smaa_edge_detect/smaa_edge_detect_EnvCol_SSAO_SMAA.vert.glsl');
project.addShaders('build/compiled/Shaders/smaa_neighborhood_blend/smaa_neighborhood_blend_EnvCol_SSAO_SMAA.frag.glsl');
project.addShaders('build/compiled/Shaders/smaa_neighborhood_blend/smaa_neighborhood_blend_EnvCol_SSAO_SMAA.vert.glsl');
project.addShaders('build/compiled/Shaders/ssao_pass/ssao_pass_EnvCol_SSAO_SMAA.frag.glsl');
project.addShaders('build/compiled/Shaders/ssao_pass/ssao_pass_EnvCol_SSAO_SMAA.vert.glsl');
project.addShaders('build/compiled/Shaders/world/world_EnvCol_SSAO_SMAA.frag.glsl');
project.addShaders('build/compiled/Shaders/world/world_EnvCol_SSAO_SMAA.vert.glsl');
project.addAssets('build/compiled/ShaderDatas/blur_edge_pass/blur_edge_pass_EnvCol_SSAO_SMAA.arm');
project.addAssets('build/compiled/ShaderDatas/compositor_pass/compositor_pass_EnvCol_SSAO_SMAA_CompoTonemap.arm');
project.addAssets('build/compiled/ShaderDatas/deferred_indirect/deferred_indirect_EnvCol_SSAO_SMAA.arm');
project.addAssets('build/compiled/ShaderDatas/deferred_light/deferred_light_EnvCol_SSAO_SMAA.arm');
project.addAssets('build/compiled/ShaderDatas/smaa_blend_weight/smaa_blend_weight_EnvCol_SSAO_SMAA.arm');
project.addAssets('build/compiled/ShaderDatas/smaa_edge_detect/smaa_edge_detect_EnvCol_SSAO_SMAA.arm');
project.addAssets('build/compiled/ShaderDatas/smaa_neighborhood_blend/smaa_neighborhood_blend_EnvCol_SSAO_SMAA.arm');
project.addAssets('build/compiled/ShaderDatas/ssao_pass/ssao_pass_EnvCol_SSAO_SMAA.arm');
project.addAssets('build/compiled/ShaderDatas/world/world_EnvCol_SSAO_SMAA.arm');
project.addAssets('build/compiled/ShaderRaws/Material/Material_data.arm');
project.addAssets('build/compiled/Assets/Scene.arm');
project.addAssets('build/compiled/Assets/envmaps/World_irradiance.arm');
project.addAssets('build/compiled/Assets/materials/World_material.arm');
project.addAssets('build/compiled/Assets/meshes/mesh_Cube.arm');
project.addAssets('build/compiled/Assets/renderpaths/armory_default.arm');
resolve(project);

Binary file not shown.