Fix bloom and dof.

This commit is contained in:
Lubos Lenco 2016-10-21 19:36:08 +02:00
parent 202ad3d7cf
commit 016dc01e5f
13 changed files with 355 additions and 82 deletions

View file

@ -8,12 +8,20 @@ precision mediump float;
//const float bloomTreshold = 3.0;
uniform sampler2D tex;
uniform vec2 texStep;
in vec2 texCoord;
out vec4 fragColor;
void main() {
vec4 col = texture(tex, texCoord);
// vec4 col = texture(tex, texCoord);
vec4 col = vec4(0.0);
col += texture(tex, vec2(texCoord.x - texStep.x * 1.5, texCoord.y));
col += texture(tex, vec2(texCoord.x + texStep.x * 1.5, texCoord.y));
col += texture(tex, vec2(texCoord.x, texCoord.y - texStep.y * 1.5));
col += texture(tex, vec2(texCoord.x, texCoord.y + texStep.y * 1.5));
col /= 4.0;
float brightness = dot(col.rgb, vec3(0.2126, 0.7152, 0.0722));
if (brightness > bloomTreshold) {
fragColor.rgb = vec3(col.rgb);

View file

@ -5,7 +5,12 @@
"depth_write": false,
"compare_mode": "always",
"cull_mode": "none",
"links": [],
"links": [
{
"name": "texStep",
"link": "_windowSizeInv"
}
],
"texture_params": [],
"vertex_shader": "bloom_pass.vert.glsl",
"vertex_shader_path": "../include/pass.vert.glsl",

View file

@ -17,12 +17,33 @@ out vec4 fragColor;
// const float weight[5] = float[] (0.227027, 0.1945946, 0.1216216, 0.054054, 0.016216);
// const float weight[8] = float[] (0.197448, 0.174697, 0.120999, 0.065602, 0.02784, 0.009246, 0.002403, 0.000489);
const float weight[10] = float[] (0.132572, 0.125472, 0.106373, 0.08078, 0.05495, 0.033482, 0.018275, 0.008934, 0.003912, 0.001535);
// const float weight[10] = float[] (0.132572, 0.125472, 0.106373, 0.08078, 0.05495, 0.033482, 0.018275, 0.008934, 0.003912, 0.001535);
const float weight[20] = float[] (0.06649, 0.065575, 0.062905, 0.058694, 0.053269, 0.047023, 0.040375, 0.033719, 0.027391, 0.021642, 0.016633, 0.012433, 0.00904, 0.006393, 0.004398, 0.002943, 0.001915, 0.001212, 0.000746, 0.000447);
void main() {
vec2 step = dir / screenSize;
vec2 step = dir / 400.0 * bloomRadius; //screenSize.xy;
vec3 result = texture(tex, texCoord).rgb * weight[0];
// result += texture(tex, texCoord + step * 1.5).rgb * weight[1] * bloomStrength;
// result += texture(tex, texCoord - step * 1.5).rgb * weight[1] * bloomStrength;
// result += texture(tex, texCoord + step * 2.5).rgb * weight[2] * bloomStrength;
// result += texture(tex, texCoord - step * 2.5).rgb * weight[2] * bloomStrength;
// result += texture(tex, texCoord + step * 3.5).rgb * weight[3] * bloomStrength;
// result += texture(tex, texCoord - step * 3.5).rgb * weight[3] * bloomStrength;
// result += texture(tex, texCoord + step * 4.5).rgb * weight[4] * bloomStrength;
// result += texture(tex, texCoord - step * 4.5).rgb * weight[4] * bloomStrength;
// result += texture(tex, texCoord + step * 5.5).rgb * weight[5] * bloomStrength;
// result += texture(tex, texCoord - step * 5.5).rgb * weight[5] * bloomStrength;
// result += texture(tex, texCoord + step * 6.5).rgb * weight[6] * bloomStrength;
// result += texture(tex, texCoord - step * 6.5).rgb * weight[6] * bloomStrength;
// result += texture(tex, texCoord + step * 7.5).rgb * weight[7] * bloomStrength;
// result += texture(tex, texCoord - step * 7.5).rgb * weight[7] * bloomStrength;
// result += texture(tex, texCoord + step * 8.5).rgb * weight[8] * bloomStrength;
// result += texture(tex, texCoord - step * 8.5).rgb * weight[8] * bloomStrength;
// result += texture(tex, texCoord + step * 9.5).rgb * weight[9] * bloomStrength;
// result += texture(tex, texCoord - step * 9.5).rgb * weight[9] * bloomStrength;
result += texture(tex, texCoord + step * 1.5).rgb * weight[1] * bloomStrength;
result += texture(tex, texCoord - step * 1.5).rgb * weight[1] * bloomStrength;
result += texture(tex, texCoord + step * 2.5).rgb * weight[2] * bloomStrength;
@ -37,6 +58,30 @@ void main() {
result += texture(tex, texCoord - step * 6.5).rgb * weight[6] * bloomStrength;
result += texture(tex, texCoord + step * 7.5).rgb * weight[7] * bloomStrength;
result += texture(tex, texCoord - step * 7.5).rgb * weight[7] * bloomStrength;
result += texture(tex, texCoord + step * 8.5).rgb * weight[8] * bloomStrength;
result += texture(tex, texCoord - step * 8.5).rgb * weight[8] * bloomStrength;
result += texture(tex, texCoord + step * 9.5).rgb * weight[9] * bloomStrength;
result += texture(tex, texCoord - step * 9.5).rgb * weight[9] * bloomStrength;
result += texture(tex, texCoord + step * 10.5).rgb * weight[10] * bloomStrength;
result += texture(tex, texCoord - step * 10.5).rgb * weight[10] * bloomStrength;
result += texture(tex, texCoord + step * 11.5).rgb * weight[11] * bloomStrength;
result += texture(tex, texCoord - step * 11.5).rgb * weight[11] * bloomStrength;
result += texture(tex, texCoord + step * 12.5).rgb * weight[12] * bloomStrength;
result += texture(tex, texCoord - step * 12.5).rgb * weight[12] * bloomStrength;
result += texture(tex, texCoord + step * 13.5).rgb * weight[13] * bloomStrength;
result += texture(tex, texCoord - step * 13.5).rgb * weight[13] * bloomStrength;
result += texture(tex, texCoord + step * 14.5).rgb * weight[14] * bloomStrength;
result += texture(tex, texCoord - step * 14.5).rgb * weight[14] * bloomStrength;
result += texture(tex, texCoord + step * 15.5).rgb * weight[15] * bloomStrength;
result += texture(tex, texCoord - step * 15.5).rgb * weight[15] * bloomStrength;
result += texture(tex, texCoord + step * 16.5).rgb * weight[16] * bloomStrength;
result += texture(tex, texCoord - step * 16.5).rgb * weight[16] * bloomStrength;
result += texture(tex, texCoord + step * 17.5).rgb * weight[17] * bloomStrength;
result += texture(tex, texCoord - step * 17.5).rgb * weight[17] * bloomStrength;
result += texture(tex, texCoord + step * 18.5).rgb * weight[18] * bloomStrength;
result += texture(tex, texCoord - step * 18.5).rgb * weight[18] * bloomStrength;
result += texture(tex, texCoord + step * 19.5).rgb * weight[19] * bloomStrength;
result += texture(tex, texCoord - step * 19.5).rgb * weight[19] * bloomStrength;
fragColor.rgb = vec3(result);
}

View file

@ -12,27 +12,8 @@
},
{
"name": "screenSize",
"link": "_screenSize"
}
],
"texture_params": [],
"vertex_shader": "blur_gaus_pass.vert.glsl",
"vertex_shader_path": "../include/pass.vert.glsl",
"fragment_shader": "blur_gaus_pass.frag.glsl"
},
{
"name": "blur_gaus_pass_y",
"depth_write": false,
"compare_mode": "always",
"cull_mode": "none",
"links": [
{
"name": "dir",
"link": "_vec2y"
},
{
"name": "screenSize",
"link": "_screenSize"
"link": "_screenSize",
"ifdef": ["_Disabled"]
}
],
"texture_params": [],
@ -55,7 +36,8 @@
},
{
"name": "screenSize",
"link": "_screenSize"
"link": "_screenSize",
"ifdef": ["_Disabled"]
}
],
"texture_params": [],

View file

@ -8,6 +8,11 @@ precision highp float;
#include "../std/tonemap.glsl"
// tonemapUncharted2()
// tonemapFilmic()
#include "../std/math.glsl"
// linearize()
#ifdef _CompoDOF
#include "../std/dof.glsl"
#endif
uniform sampler2D tex;
uniform sampler2D gbufferD;
@ -24,9 +29,9 @@ uniform vec3 light;
uniform mat4 VP;
#endif
#ifdef _CompoFXAA
// #ifdef _CompoFXAA
uniform vec2 texStep;
#endif
// #endif
#ifdef _CompoGrain
uniform float time;
@ -36,21 +41,14 @@ uniform float time;
uniform float dynamicScale;
#endif
uniform float aspectRatio;
in vec2 texCoord;
#ifdef _CompoPos
in vec3 viewRay;
#endif
out vec4 fragColor;
const float focus_depth = 0.5;
const float vignout = 1.8; // vignetting outer border
const float vignin = 0.0; // vignetting inner border
const float vignfade = 90.0; // f-stops till vignete fades
const float fstop = 20; // f-stop value
const float aspectRatio = 800.0 / 600.0;
#ifdef _CompoFog
// const vec3 compoFogColor = vec3(0.5, 0.6, 0.7);
// const float compoFogAmountA = 1.0; // b = 0.01
@ -70,33 +68,11 @@ vec3 applyFog(vec3 rgb, float distance) {
#endif
float vignette() {
// float dist = distance(texCoord, vec2(0.5,0.5));
// dist = smoothstep(vignout + (fstop / vignfade), vignin + (fstop / vignfade), dist);
// return clamp(dist, 0.0, 1.0);
// 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 _CompoDOF
vec3 sampleBox(float size) {
vec3 color = vec3(texture(tex, vec2(texCoord.x - size, texCoord.y - size)).rgb) * 0.075;
color += texture(tex, vec2(texCoord.x, texCoord.y - size)).rgb * 0.1;
color += texture(tex, vec2(texCoord.x + size, texCoord.y - size)).rgb * 0.075;
color += texture(tex, vec2(texCoord.x - size, texCoord.y)).rgb * 0.1;
color += texture(tex, vec2(texCoord.x, texCoord.y)).rgb * 0.30;
color += texture(tex, vec2(texCoord.x + size, texCoord.y)).rgb * 0.1;
color += texture(tex, vec2(texCoord.x - size, texCoord.y + size)).rgb * 0.075;
color += texture(tex, vec2(texCoord.x, texCoord.y + size)).rgb * 0.1;
color += texture(tex, vec2(texCoord.x + size, texCoord.y + size)).rgb * 0.075;
return color;
}
// #endif
float linearize(float depth) {
return -cameraPlane.y * cameraPlane.x / (depth * (cameraPlane.y - cameraPlane.x) - cameraPlane.y);
}
// Based on lense flare implementation by musk
// https://www.shadertoy.com/view/4sX3Rs
vec3 lensflare(vec2 uv, vec2 pos) {
@ -132,6 +108,7 @@ void main() {
#ifdef _DynRes
texCo *= dynamicScale;
#endif
#ifdef _CompoFishEye
const float fishEyeStrength = -0.01;
const vec2 m = vec2(0.5, 0.5);
@ -149,6 +126,10 @@ void main() {
}
#endif
#ifdef _CompoDepth
float depth = texture(gbufferD, texCo).r * 2.0 - 1.0;
#endif
#ifdef _CompoFXAA
const float FXAA_REDUCE_MIN = 1.0 / 128.0;
const float FXAA_REDUCE_MUL = 1.0 / 8.0;
@ -198,23 +179,15 @@ void main() {
float lumaB = dot(rgbB, luma);
if ((lumaB < lumaMin) || (lumaB > lumaMax)) col = vec4(rgbA, texColor.a);
else col = vec4(rgbB, texColor.a);
#else
vec4 col = texture(tex, texCo);
#endif
#ifdef _CompoDOF
vec3 col = dof(texCo, depth, tex, gbufferD, texStep);
#else
vec3 col = texture(tex, texCo).rgb;
#endif
#ifdef _CompoDepth
float depth = texture(gbufferD, texCoord).r * 2.0 - 1.0;
#endif
#ifdef _CompoDOF
// if (depth < 1.0) {
float linDepth = linearize(depth);
float blur_amount = abs(linDepth - compoDOFDistance) / cameraPlane.y;
// float blur_amount = abs(linDepth - 4.0);
float blurSize = compoDOFSize * blur_amount;
// float blurSize = 0.0005 * blur_amount;
col.rgb = 0.75 * sampleBox(blurSize * 0.5) + 0.25 * sampleBox(blurSize * 1.0);
// }
#endif
#ifdef _CompoFog
@ -284,5 +257,5 @@ void main() {
col.rgb *= 1.0 - step(0.5 - compoLetterboxSize, abs(0.5 - texCoord.y));
#endif
fragColor = col;
fragColor = vec4(col, 1.0);
}

View file

@ -36,15 +36,27 @@
"link": "_time",
"ifdef": ["_CompoGrain"]
},
{
"name": "texStep",
"link": "_screenSizeInv"
},
{
"name": "texStep",
"link": "_screenSizeInv",
"ifdef": ["_CompoFXAA"]
},
{
"name": "dynamicScale",
"link": "_dynamicScale",
"ifdef": ["_DynRes"]
},
{
"name": "aspectRatio",
"link": "_aspectRatio"
}
],
"texture_params": [],

224
Shaders/std/dof.glsl Normal file
View file

@ -0,0 +1,224 @@
// 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 * 0.5 + 0.5);
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,4 +1,7 @@
#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);
@ -12,6 +15,20 @@ vec2 envMapEquirect(const vec3 normal) {
return vec2(theta / PI2, phi / PI);
}
float rand(vec2 co) { // Unreliable
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

Binary file not shown.

View file

@ -236,7 +236,7 @@ def make_draw_compositor(stage, node_group, node, with_fxaa=False):
if wrd.generate_fog:
compositor_defs += '_CompoFog'
compo_pos = True
if build_node_tree.cam.cycles.aperture_size > 0.0:
if build_node_tree.cam.dof_distance > 0.0:
compositor_defs += '_CompoDOF'
compo_depth = True
if compo_pos:

View file

@ -178,8 +178,9 @@ def init_properties():
bpy.types.World.generate_ssao_texture_scale = bpy.props.FloatProperty(name="Texture Scale", default=1.0, min=0.0, max=1.0, update=assets.invalidate_shader_cache)
bpy.types.World.generate_shadows = bpy.props.BoolProperty(name="Shadows", default=True, update=assets.invalidate_shader_cache)
bpy.types.World.generate_bloom = bpy.props.BoolProperty(name="Bloom", default=True, update=assets.invalidate_shader_cache)
bpy.types.World.generate_bloom_treshold = bpy.props.FloatProperty(name="Treshold", default=3.0, update=assets.invalidate_shader_cache)
bpy.types.World.generate_bloom_strength = bpy.props.FloatProperty(name="Strength", default=0.15, update=assets.invalidate_shader_cache)
bpy.types.World.generate_bloom_treshold = bpy.props.FloatProperty(name="Treshold", default=4.0, update=assets.invalidate_shader_cache)
bpy.types.World.generate_bloom_strength = bpy.props.FloatProperty(name="Strength", default=1.0, update=assets.invalidate_shader_cache)
bpy.types.World.generate_bloom_radius = bpy.props.FloatProperty(name="Radius", default=1.0, update=assets.invalidate_shader_cache)
bpy.types.World.generate_motion_blur = bpy.props.BoolProperty(name="Motion Blur", default=True, update=assets.invalidate_shader_cache)
bpy.types.World.generate_motion_blur_intensity = bpy.props.FloatProperty(name="Intensity", default=1.0, update=assets.invalidate_shader_cache)
bpy.types.World.generate_ssr = bpy.props.BoolProperty(name="SSR", description="Screen-Space Reflections", default=True, update=assets.invalidate_shader_cache)
@ -213,6 +214,7 @@ def init_properties():
# Lighting flags
bpy.types.World.diffuse_oren_nayar = bpy.props.BoolProperty(name="Oren Nayar Diffuse", default=False, update=assets.invalidate_shader_cache)
bpy.types.World.voxelgi = bpy.props.BoolProperty(name="VGI", description="Voxel-based Global Illumination", default=False, update=assets.invalidate_shader_cache)
bpy.types.World.voxelgi_dimensions = bpy.props.FloatVectorProperty(name="Dimensions", description="3D texture size", size=3, default=[128, 128, 128], update=assets.invalidate_shader_cache)
# For material
bpy.types.Material.receive_shadow = bpy.props.BoolProperty(name="Receive Shadow", default=True)
bpy.types.Material.override_shader = bpy.props.BoolProperty(name="Override Shader", default=False)

View file

@ -341,6 +341,7 @@ class WorldPropsPanel(bpy.types.Panel):
# if wrd.generate_bloom:
layout.prop(wrd, 'generate_bloom_treshold')
layout.prop(wrd, 'generate_bloom_strength')
layout.prop(wrd, 'generate_bloom_radius')
layout.label('Motion Blur')
# layout.prop(wrd, 'generate_motion_blur')
@ -382,6 +383,8 @@ class WorldPropsPanel(bpy.types.Panel):
layout.prop(wrd, 'npot_texture_repeat')
layout.prop(wrd, 'diffuse_oren_nayar')
layout.prop(wrd, 'voxelgi')
if wrd.voxelgi:
layout.prop(wrd, 'voxelgi_dimensions')
# Menu in render region
class ArmoryPlayPanel(bpy.types.Panel):

View file

@ -274,6 +274,7 @@ const float ssaoTextureScale = """ + str(round(wrd.generate_ssao_texture_scale *
f.write(
"""const float bloomTreshold = """ + str(round(wrd.generate_bloom_treshold * 100) / 100) + """;
const float bloomStrength = """ + str(round(wrd.generate_bloom_strength * 100) / 100) + """;
const float bloomRadius = """ + str(round(wrd.generate_bloom_radius * 100) / 100) + """;
""")
if wrd.generate_motion_blur:
f.write(
@ -323,10 +324,11 @@ const float compoFogAmountB = """ + str(round(wrd.generate_fog_amountb * 100) /
const vec3 compoFogColor = vec3(""" + str(round(wrd.generate_fog_color[0] * 100) / 100) + """, """ + str(round(wrd.generate_fog_color[1] * 100) / 100) + """, """ + str(round(wrd.generate_fog_color[2] * 100) / 100) + """);
""")
if bpy.data.cameras[0].cycles.aperture_size > 0.0:
if bpy.data.cameras[0].dof_distance > 0.0:
f.write(
"""const float compoDOFDistance = """ + str(round(bpy.data.cameras[0].dof_distance * 100) / 100) + """;
const float compoDOFSize = """ + str(round(bpy.data.cameras[0].cycles.aperture_size * 100) / 100) + """;
const float compoDOFFstop = """ + str(round(bpy.data.cameras[0].gpu_dof.fstop * 100) / 100) + """;
const float compoDOFLength = """ + str(round(bpy.data.cameras[0].lens * 100) / 100) + """;
""")
# Skinning