Renderer speedup round 2

This commit is contained in:
Lubos Lenco 2017-03-12 17:29:22 +01:00
parent fc167d2885
commit 359bb45871
29 changed files with 210 additions and 203 deletions

View file

@ -6,10 +6,7 @@ precision mediump float;
#include "../compiled.glsl"
#include "../std/gbuffer.glsl"
// octahedronWrap()
// unpackFloat()
#include "../std/math.glsl"
// envMapEquirect()
#include "../std/brdf.glsl"
#ifdef _Irr
#include "../std/shirr.glsl"
@ -81,9 +78,10 @@ void main() {
vec3 indirectSpecular = traceSpecularVoxelCone(p / voxelgiDimensions.x, reflectWorld, n, metrough.y * 10.0);
indirectSpecular *= f0 * envBRDF.x + envBRDF.y;
fragColor.rgb = indirectDiffuse.rgb * 1.0 * albedo + indirectSpecular;
fragColor.rgb *= indirectDiffuse.a / 2.0; // Occ
// fragColor.rgb *= texture(ssaotex, texCoord).r;
// fragColor.rgb = indirectDiffuse.rgb * 60.0 * albedo + indirectSpecular;
fragColor.rgb = max(vec3(1.0 - (indirectDiffuse.a / 2.0)), 0.05) * albedo;
// fragColor.rgb *= 1.0 - (indirectDiffuse.a / 2.0); // Occ
fragColor.rgb *= texture(ssaotex, texCoord).r * 0.5 + 0.5;
// if (opacity < 1.0) fragColor.rgb = mix(indirectRefractiveLight(-v), fragColor.rgb); // Transparency
return;
@ -91,9 +89,9 @@ void main() {
// Envmap
#ifdef _Irr
fragColor.rgb = shIrradiance(n, 2.2) / PI;
vec3 envl = shIrradiance(n, 2.2) / PI;
#else
fragColor.rgb = vec3(1.0);
vec3 envl = vec3(1.0);
#endif
#ifdef _Rad
@ -103,21 +101,28 @@ void main() {
#endif
#ifdef _EnvLDR
fragColor.rgb = pow(fragColor.rgb, vec3(2.2));
envl.rgb = pow(envl.rgb, vec3(2.2));
#ifdef _Rad
prefilteredColor = pow(prefilteredColor, vec3(2.2));
#endif
#endif
fragColor.rgb *= albedo;
envl.rgb *= albedo;
#ifdef _Rad // Indirect specular
fragColor.rgb += prefilteredColor * (f0 * envBRDF.x + envBRDF.y);
envl.rgb += prefilteredColor * (f0 * envBRDF.x + envBRDF.y);
#endif
fragColor.rgb *= envmapStrength * g0.a; // Occlusion
envl.rgb *= envmapStrength * g0.a; // Occlusion
#ifdef _SSAO
fragColor.rgb *= texture(ssaotex, texCoord).r; // SSAO
envl.rgb *= texture(ssaotex, texCoord).r; // SSAO
#endif
#ifdef _VoxelGI
float m = (fragColor.r + fragColor.g + fragColor.b) / 3.0;
fragColor.rgb += (envl / 5.0) * m;
#else
fragColor.rgb = envl;
#endif
}

View file

@ -10,21 +10,17 @@ precision mediump float;
// #ifdef _VoxelGI
// #include "../std/conetrace.glsl"
// #endif
// #ifdef _PolyLight
#include "../std/ltc.glsl"
// #endif
#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()
// #ifdef _VoxelGI
//-!uniform sampler3D voxels;
@ -44,11 +40,10 @@ uniform sampler2D gbuffer1;
uniform mat4 invVP;
uniform mat4 LWVP;
uniform vec3 lightPos;
uniform vec3 lightDir;
uniform int lightType;
// uniform int lightIndex;
uniform vec3 lightColor;
uniform vec3 lightDir;
uniform vec3 lightPos;
uniform int lightType;
uniform int lightShadow;
uniform float shadowsBias;
uniform vec2 spotlightData;
@ -219,7 +214,6 @@ void main() {
// float dotLV = dot(l, v);
// float dotLH = dot(l, h);
// Direct
#ifdef _PolyLight
if (lightType == 3) { // Area
float theta = acos(dotNV);

View file

@ -29,11 +29,6 @@
"name": "lightType",
"link": "_lampType"
},
{
"name": "lightIndex",
"link": "_lampIndex",
"ifdef": ["_Disabled"]
},
{
"name": "lightColor",
"link": "_lampColor"

View file

@ -34,17 +34,15 @@ vec2 getVelocity(vec2 coord, float depth) {
}
void main() {
vec4 color = texture(tex, texCoord);
fragColor.rgb = texture(tex, texCoord).rgb;
// Do not blur masked objects
if (texture(gbuffer0, texCoord).a == 1.0) {
fragColor = color;
return;
}
float depth = texture(gbufferD, texCoord).r * 2.0 - 1.0;
if (depth == 1.0) {
fragColor = color;
return;
}
@ -57,53 +55,52 @@ void main() {
// for(int i = 1; i < samples; ++i) {
offset += velocity;
if (texture(gbuffer0, offset).a != 1.0) {
color += texture(tex, offset);
fragColor.rgb += texture(tex, offset).rgb;
processed++;
}
offset += velocity;
if (texture(gbuffer0, offset).a != 1.0) {
color += texture(tex, offset);
fragColor.rgb += texture(tex, offset).rgb;
processed++;
}
offset += velocity;
if (texture(gbuffer0, offset).a != 1.0) {
color += texture(tex, offset);
fragColor.rgb += texture(tex, offset).rgb;
processed++;
}
offset += velocity;
if (texture(gbuffer0, offset).a != 1.0) {
color += texture(tex, offset);
fragColor.rgb += texture(tex, offset).rgb;
processed++;
}
offset += velocity;
if (texture(gbuffer0, offset).a != 1.0) {
color += texture(tex, offset);
fragColor.rgb += texture(tex, offset).rgb;
processed++;
}
offset += velocity;
if (texture(gbuffer0, offset).a != 1.0) {
color += texture(tex, offset);
fragColor.rgb += texture(tex, offset).rgb;
processed++;
}
offset += velocity;
if (texture(gbuffer0, offset).a != 1.0) {
color += texture(tex, offset);
fragColor.rgb += texture(tex, offset).rgb;
processed++;
}
offset += velocity;
if (texture(gbuffer0, offset).a != 1.0) {
color += texture(tex, offset);
fragColor.rgb += texture(tex, offset).rgb;
processed++;
}
// }
vec4 finalColor = color / processed;
fragColor = finalColor;
fragColor.rgb /= processed;
}

View file

@ -3,6 +3,7 @@
{
"name": "motion_blur_pass",
"depth_write": false,
"color_write_alpha": false,
"compare_mode": "always",
"cull_mode": "none",
"links": [

View file

@ -20,11 +20,10 @@ void main() {
vec2 velocity = texture(sveloc, texCoord).rg;
velocity *= motionBlurIntensity; // * (currentFps / targetFps);
vec4 col = texture(tex, texCoord);
fragColor.rgb = texture(tex, texCoord).rgb;
// Do not blur masked objects
if (texture(gbuffer0, texCoord).a == 1.0) {
fragColor = col;
return;
}
@ -34,24 +33,22 @@ void main() {
const int samples = 8;
// for (int i = 1; i < samples; ++i) {
vec2 offset = velocity * (float(0) / float(samples - 1) - 0.5);
col += texture(tex, texCoord + offset);
fragColor.rgb += texture(tex, texCoord + offset).rgb;
//
offset = velocity * (float(1) / float(samples - 1) - 0.5);
col += texture(tex, texCoord + offset);
fragColor.rgb += texture(tex, texCoord + offset).rgb;
offset = velocity * (float(2) / float(samples - 1) - 0.5);
col += texture(tex, texCoord + offset);
fragColor.rgb += texture(tex, texCoord + offset).rgb;
offset = velocity * (float(3) / float(samples - 1) - 0.5);
col += texture(tex, texCoord + offset);
fragColor.rgb += texture(tex, texCoord + offset).rgb;
offset = velocity * (float(4) / float(samples - 1) - 0.5);
col += texture(tex, texCoord + offset);
fragColor.rgb += texture(tex, texCoord + offset).rgb;
offset = velocity * (float(5) / float(samples - 1) - 0.5);
col += texture(tex, texCoord + offset);
fragColor.rgb += texture(tex, texCoord + offset).rgb;
offset = velocity * (float(6) / float(samples - 1) - 0.5);
col += texture(tex, texCoord + offset);
fragColor.rgb += texture(tex, texCoord + offset).rgb;
offset = velocity * (float(7) / float(samples - 1) - 0.5);
col += texture(tex, texCoord + offset);
fragColor.rgb += texture(tex, texCoord + offset).rgb;
// }
col /= float(samples + 1);
fragColor = col;
fragColor.rgb /= float(samples + 1);
}

View file

@ -3,6 +3,7 @@
{
"name": "motion_blur_veloc_pass",
"depth_write": false,
"color_write_alpha": false,
"compare_mode": "always",
"cull_mode": "none",
"links": [

View file

@ -19,7 +19,6 @@ precision mediump float;
#include "../compiled.glsl"
#include "../std/gbuffer.glsl"
// octahedronWrap
uniform sampler2D gbufferD;
uniform sampler2D gbuffer0;
@ -35,7 +34,7 @@ in vec2 texCoord;
// in vec3 viewRay;
out vec4 fragColor;
float doAO(vec2 kernelVec, vec2 randomVec, mat2 rotMat, vec3 currentPos, vec3 currentNormal, float currentDistance) {
float doAO(vec2 kernelVec, vec2 randomVec, mat2 rotMat, vec3 currentPos, vec3 n, float currentDistance) {
kernelVec.xy *= aspectRatio;
float radius = ssaoSize * randomVec.y;
kernelVec.xy = ((rotMat * kernelVec.xy) / currentDistance) * radius;
@ -43,7 +42,7 @@ float doAO(vec2 kernelVec, vec2 randomVec, mat2 rotMat, vec3 currentPos, vec3 cu
float depth = texture(gbufferD, coord).r * 2.0 - 1.0;
vec3 pos = getPos2NoEye(eye, invVP, depth, coord) - currentPos;
float angle = dot(pos, currentNormal);
float angle = dot(pos, n);
// angle *= step(0.3, angle / length(pos)); // Fix intersect
angle *= step(0.1, angle / length(pos));
angle -= currentDistance * 0.001;
@ -56,7 +55,7 @@ float doAO(vec2 kernelVec, vec2 randomVec, mat2 rotMat, vec3 currentPos, vec3 cu
void main() {
float depth = texture(gbufferD, texCoord).r * 2.0 - 1.0;
if (depth == 1.0) {
fragColor = vec4(1.0);
fragColor.r = 1.0;
return;
}
@ -95,10 +94,10 @@ void main() {
// 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 n;
n.z = 1.0 - abs(enc.x) - abs(enc.y);
n.xy = n.z >= 0.0 ? enc.xy : octahedronWrap(enc.xy);
n = normalize(n);
vec3 currentPos = getPos2NoEye(eye, invVP, depth, texCoord);
float currentDistance = length(currentPos);
@ -109,30 +108,28 @@ void main() {
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);
fragColor.r = doAO(kernel0, randomVec, rotMat, currentPos, n, currentDistance);
fragColor.r += doAO(kernel1, randomVec, rotMat, currentPos, n, currentDistance);
fragColor.r += doAO(kernel2, randomVec, rotMat, currentPos, n, currentDistance);
fragColor.r += doAO(kernel3, randomVec, rotMat, currentPos, n, currentDistance);
fragColor.r += doAO(kernel4, randomVec, rotMat, currentPos, n, currentDistance);
fragColor.r += doAO(kernel5, randomVec, rotMat, currentPos, n, currentDistance);
fragColor.r += doAO(kernel6, randomVec, rotMat, currentPos, n, currentDistance);
fragColor.r += doAO(kernel7, randomVec, rotMat, currentPos, n, currentDistance);
fragColor.r += doAO(kernel8, randomVec, rotMat, currentPos, n, currentDistance);
fragColor.r += doAO(kernel9, randomVec, rotMat, currentPos, n, currentDistance);
fragColor.r += doAO(kernel10, randomVec, rotMat, currentPos, n, currentDistance);
fragColor.r += doAO(kernel11, randomVec, rotMat, currentPos, n, currentDistance);
// fragColor.r += doAO(kernel12, randomVec, rotMat, currentPos, n, currentDistance);
// fragColor.r += doAO(kernel13, randomVec, rotMat, currentPos, n, currentDistance);
// fragColor.r += doAO(kernel14, randomVec, rotMat, currentPos, n, currentDistance);
// fragColor.r += doAO(kernel15, randomVec, rotMat, currentPos, n, currentDistance);
// fragColor.r += doAO(kernel16, randomVec, rotMat, currentPos, n, currentDistance);
// fragColor.r += doAO(kernel17, randomVec, rotMat, currentPos, n, currentDistance);
// fragColor.r += doAO(kernel18, randomVec, rotMat, currentPos, n, currentDistance);
// fragColor.r += doAO(kernel19, randomVec, rotMat, currentPos, n, currentDistance);
// }
amount *= ssaoStrength / kernelSize;
amount = 1.0 - amount;
amount = max(0.0, amount);
fragColor = vec4(amount, 0.0, 0.0, 1.0);
fragColor.r *= ssaoStrength / kernelSize;
fragColor.r = max(0.0, 1.0 - fragColor.r);
}

View file

@ -3,6 +3,9 @@
{
"name": "ssao_pass",
"depth_write": false,
"color_write_alpha": false,
"color_write_green": false,
"color_write_blue": false,
"compare_mode": "always",
"cull_mode": "none",
"links": [

View file

@ -6,7 +6,6 @@ precision mediump float;
#include "../compiled.glsl"
#include "../std/gbuffer.glsl"
// octahedronWrap
uniform sampler2D gbufferD;
uniform sampler2D gbuffer0;
@ -24,7 +23,7 @@ in vec2 texCoord;
in vec3 viewRay;
out vec4 fragColor;
float doAO(vec2 kernelVec, vec2 randomVec, mat2 rotMat, vec3 currentPos, vec3 currentNormal, float currentDistance) {
float doAO(vec2 kernelVec, vec2 randomVec, mat2 rotMat, vec3 currentPos, vec3 n, float currentDistance) {
kernelVec.xy *= aspectRatio;
float radius = ssaoSize * randomVec.y;
kernelVec.xy = ((rotMat * kernelVec.xy) / currentDistance) * radius;
@ -32,7 +31,7 @@ float doAO(vec2 kernelVec, vec2 randomVec, mat2 rotMat, vec3 currentPos, vec3 cu
float depth = texture(gbufferD, coord).r * 2.0 - 1.0;
vec3 pos = getPosNoEye(eyeLook, viewRay, depth) - currentPos;
float angle = dot(pos, currentNormal);
float angle = dot(pos, n);
// angle *= step(0.3, angle / length(pos)); // Fix intersect
angle *= step(0.1, angle / length(pos));
angle -= currentDistance * 0.001;
@ -45,7 +44,7 @@ float doAO(vec2 kernelVec, vec2 randomVec, mat2 rotMat, vec3 currentPos, vec3 cu
void main() {
float depth = texture(gbufferD, texCoord).r * 2.0 - 1.0;
if (depth == 1.0) {
fragColor = vec4(1.0);
fragColor.r = 1.0;
return;
}
@ -84,10 +83,10 @@ void main() {
// 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 n;
n.z = 1.0 - abs(enc.x) - abs(enc.y);
n.xy = n.z >= 0.0 ? enc.xy : octahedronWrap(enc.xy);
n = normalize(n);
vec3 currentPos = getPosNoEye(eyeLook, viewRay, depth);
float currentDistance = length(currentPos);
@ -98,35 +97,33 @@ void main() {
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);
fragColor.r = doAO(kernel0, randomVec, rotMat, currentPos, n, currentDistance);
fragColor.r += doAO(kernel1, randomVec, rotMat, currentPos, n, currentDistance);
fragColor.r += doAO(kernel2, randomVec, rotMat, currentPos, n, currentDistance);
fragColor.r += doAO(kernel3, randomVec, rotMat, currentPos, n, currentDistance);
fragColor.r += doAO(kernel4, randomVec, rotMat, currentPos, n, currentDistance);
fragColor.r += doAO(kernel5, randomVec, rotMat, currentPos, n, currentDistance);
fragColor.r += doAO(kernel6, randomVec, rotMat, currentPos, n, currentDistance);
fragColor.r += doAO(kernel7, randomVec, rotMat, currentPos, n, currentDistance);
fragColor.r += doAO(kernel8, randomVec, rotMat, currentPos, n, currentDistance);
fragColor.r += doAO(kernel9, randomVec, rotMat, currentPos, n, currentDistance);
fragColor.r += doAO(kernel10, randomVec, rotMat, currentPos, n, currentDistance);
fragColor.r += doAO(kernel11, randomVec, rotMat, currentPos, n, currentDistance);
// fragColor.r += doAO(kernel12, randomVec, rotMat, currentPos, n, currentDistance);
// fragColor.r += doAO(kernel13, randomVec, rotMat, currentPos, n, currentDistance);
// fragColor.r += doAO(kernel14, randomVec, rotMat, currentPos, n, currentDistance);
// fragColor.r += doAO(kernel15, randomVec, rotMat, currentPos, n, currentDistance);
// fragColor.r += doAO(kernel16, randomVec, rotMat, currentPos, n, currentDistance);
// fragColor.r += doAO(kernel17, randomVec, rotMat, currentPos, n, currentDistance);
// fragColor.r += doAO(kernel18, randomVec, rotMat, currentPos, n, currentDistance);
// fragColor.r += doAO(kernel19, randomVec, rotMat, currentPos, n, currentDistance);
// }
amount *= ssaoStrength / kernelSize;
amount = 1.0 - amount;
amount = max(0.0, amount);
// fragColor = vec4(amount, 0.0, 0.0, 1.0);
fragColor.r *= ssaoStrength / kernelSize;
fragColor.r = max(0.0, 1.0 - fragColor.r);
// Velocity is assumed to be calculated for motion blur, so we need to inverse it for reprojection
vec2 velocity = -textureLod(sveloc, texCoord, 0.0).rg;
float last = texture(slast, texCoord + velocity).r;
fragColor = vec4((amount + last) * 0.5, 0.0, 0.0, 1.0);
fragColor.r = (fragColor.r + last) * 0.5;
}

View file

@ -2,6 +2,9 @@
"contexts": [
{
"name": "ssao_reproject_pass",
"color_write_alpha": false,
"color_write_green": false,
"color_write_blue": false,
"depth_write": false,
"compare_mode": "always",
"cull_mode": "none",

View file

@ -7,7 +7,6 @@ precision mediump float;
#include "../compiled.glsl"
#include "../std/gbuffer.glsl"
// octahedronWrap
uniform sampler2D gbufferD;
uniform sampler2D gbuffer0;
@ -54,7 +53,7 @@ vec4 doDO(vec3 point, vec3 noise, float radius, vec3 center_pos, float max_dista
void main() {
float depth = texture(gbufferD, texCoord).r * 2.0 - 1.0;
if (depth == 1.0) {
fragColor = vec4(1.0);
fragColor.rgb = vec3(1.0);
return;
}
@ -93,10 +92,10 @@ void main() {
points[31] = vec3(0.534, 0.157, -0.250);
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 n;
n.z = 1.0 - abs(enc.x) - abs(enc.y);
n.xy = n.z >= 0.0 ? enc.xy : octahedronWrap(enc.xy);
n = normalize(n);
vec3 currentPos = getPos2(invVP, depth, texCoord);
// float currentDistance = length(currentPos);
@ -110,7 +109,7 @@ void main() {
// float attenuation_angle_threshold = 0.1;
vec3 noise = texture(snoise, (texCoord * screenSize) / noise_texture_size).xyz * 2.0 - 1.0;
vec3 center_normal = currentNormal;
vec3 center_normal = n;
vec4 occlusion_sh2 = vec4(0.0);
@ -149,5 +148,5 @@ void main() {
occlusion_sh2 += doDO(points[31], noise, radius, center_pos, max_distance_inv, center_normal);
// }
fragColor = vec4(vec3(1.0 - occlusion_sh2.rgb), 1.0);
fragColor.rgb = vec3(1.0 - occlusion_sh2.rgb);
}

View file

@ -6,10 +6,7 @@ precision mediump float;
#include "../compiled.glsl"
#include "../std/math.glsl"
// rand()
#include "../std/gbuffer.glsl"
// octahedronWrap()
// unpackFloat()
uniform sampler2D tex;
uniform sampler2D gbufferD;
@ -165,23 +162,21 @@ vec4 rayCast(vec3 dir) {
// hitCoord += dir;
// if (getDeltaDepth(hitCoord) > 0.0) return binarySearch(dir);
// }
return vec4(0.0, 0.0, 0.0, 0.0);
return vec4(0.0);
}
void main() {
vec4 g0 = texture(gbuffer0, texCoord);
float roughness = unpackFloat(g0.b).y;
if (roughness == 1.0) {
fragColor = vec4(0.0);
fragColor.rgb = vec3(0.0);
return;
}
float reflectivity = 1.0 - roughness;
float d = texture(gbufferD, texCoord).r * 2.0 - 1.0;
if (d == 1.0) {
fragColor = vec4(0.0);
fragColor.rgb = vec3(0.0);
return;
}
@ -191,17 +186,16 @@ void main() {
n.xy = n.z >= 0.0 ? enc.xy : octahedronWrap(enc.xy);
n = normalize(n);
vec4 viewNormal = vec4(n, 1.0);
if (viewNormal.z <= 0.9) {
fragColor = vec4(0.0);
return; // Only up facing surfaces for now
if (n.z <= 0.9) { // Only up facing surfaces for now
fragColor.rgb = vec3(0.0);
return;
}
viewNormal = tiV * normalize(viewNormal);
vec4 viewNormal = vec4(n, 1.0);
viewNormal = tiV * viewNormal;
vec3 viewPos = getPosView(viewRay, d);
vec3 reflected = normalize(reflect((viewPos.xyz), normalize(viewNormal.xyz)));
vec3 reflected = normalize(reflect((viewPos), normalize(viewNormal.xyz)));
hitCoord = viewPos.xyz;
vec3 dir = reflected * max(ssrMinRayStep, -viewPos.z) * (1.0 - rand(texCoord) * ssrJitter * roughness);
@ -210,6 +204,7 @@ void main() {
vec2 deltaCoords = abs(vec2(0.5, 0.5) - coords.xy);
float screenEdgeFactor = clamp(1.0 - (deltaCoords.x + deltaCoords.y), 0.0, 1.0);
float reflectivity = 1.0 - roughness;
float intensity = pow(reflectivity, ssrFalloffExp) *
screenEdgeFactor * clamp(-reflected.z, 0.0, 1.0) *
clamp((ssrSearchDist - length(viewPos.xyz - hitCoord)) * (1.0 / ssrSearchDist), 0.0, 1.0) * coords.w;
@ -220,12 +215,12 @@ void main() {
intensity = clamp(intensity, 0.0, 1.0);
if (intensity == 0.0) {
fragColor = vec4(0.0);
fragColor.rgb = vec3(0.0);
return;
}
vec4 reflCol = vec4(texture(tex, coords.xy).rgb, 1.0);
vec3 reflCol = texture(tex, coords.xy).rgb;
reflCol = clamp(reflCol, 0.0, 1.0);
// fragColor = texColor * (1.0 - intensity) + reflCol * intensity;
fragColor = reflCol * intensity * 0.5; //
// fragColor.rgb = texColor * (1.0 - intensity) + reflCol * intensity;
fragColor.rgb = reflCol * intensity * 0.5; //
}

View file

@ -3,6 +3,7 @@
{
"name": "ssr_pass",
"depth_write": false,
"color_write_alpha": false,
"compare_mode": "always",
"cull_mode": "none",
"links": [

View file

@ -22,7 +22,7 @@ vec2 LightingFuncGGX_FV(const float dotLH, const float roughness) {
float LightingFuncGGX_D(const float dotNH, const float roughness) {
float alpha = roughness * roughness;
float alphaSqr = alpha * alpha;
float pi = 3.14159;
const float pi = 3.14159;
float denom = dotNH * dotNH * (alphaSqr - 1.0) + 1.0;
float D = alphaSqr / (pi * denom * denom);
@ -46,16 +46,16 @@ float LightingFuncGGX_OPT3(const float dotNL, const float dotLH, const float dot
}
vec3 f_schlick(const vec3 f0, const float vh) {
return f0 + (1.0-f0)*exp2((-5.55473 * vh - 6.98316)*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) );
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);
float a2 = a * a;
float denom = pow(nh * nh * (a2 - 1.0) + 1.0, 2.0);
return a2 * (1.0 / 3.1415926535) / denom;
}

View file

@ -21,10 +21,9 @@ vec4 traceDiffuseVoxelCone(const vec3 from, vec3 direction) {
vec4 acc = vec4(0.0);
// Controls bleeding from close surfaces
// Low values look rather bad if using shadow cone tracing
// Might be a better choice to use shadow maps and lower this value
float dist = 0.1953125;
const float SQRT2 = 1.414213;
while (dist < SQRT2 && acc.a < 1) {
float dist = 0.1953125 / 9.0;
const float SQRT2 = 1.414213 / 9.0;
while (dist < SQRT2 && acc.a < 1.0) {
vec3 c = vec3(from + dist * direction) * 0.5 + vec3(0.5);
float l = (1.0 + CONE_SPREAD * dist / VOXEL_SIZE);
float level = log2(l);

View file

@ -3,8 +3,6 @@
#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

View file

@ -19,7 +19,7 @@ mat4 getBoneMat(const int boneIndex) {
0.0, 0.0, 0.0, 1.0);
}
mat4 getSkinningMat(ivec4 bone, vec4 weight) {
mat4 getSkinningMat(const ivec4 bone, const vec4 weight) {
return weight.x * getBoneMat(bone.x) +
weight.y * getBoneMat(bone.y) +
weight.z * getBoneMat(bone.z) +

View file

@ -2,7 +2,7 @@ uniform mat4 U; // Undistortion
uniform float maxRadSq;
// GoogleVR Distortion using Vertex Displacement
float distortionFactor(float rSquared) {
float distortionFactor(const float rSquared) {
float ret = 0.0;
ret = rSquared * (ret + U[1][1]);
ret = rSquared * (ret + U[0][1]);

View file

@ -7,7 +7,6 @@ precision mediump float;
#include "../compiled.glsl"
#ifdef _EnvTex
#include "../std/math.glsl"
// envMapEquirect()
#endif
#ifdef _EnvCol
@ -184,7 +183,7 @@ void main() {
// }
#ifdef _EnvCol
vec3 R = backgroundCol;
fragColor.rgb = backgroundCol;
#ifdef _EnvClouds
vec3 n = normalize(normal);
#endif
@ -193,9 +192,9 @@ void main() {
#ifndef _EnvSky // Prevent case when sky radiance is enabled
#ifdef _EnvTex
vec3 n = normalize(normal);
vec3 R = texture(envmap, envMapEquirect(n)).rgb * envmapStrength;
fragColor.rgb = texture(envmap, envMapEquirect(n)).rgb * envmapStrength;
#ifdef _EnvLDR
R = pow(R, vec3(2.2));
fragColor.rgb = pow(fragColor.rgb, vec3(2.2));
#endif
#endif
#endif
@ -203,7 +202,7 @@ void main() {
#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;
fragColor.rgb = texture(envmap, vec2(texco.x, 1.0 - texco.y)).rgb * envmapStrength;
#endif
#ifdef _EnvSky
@ -216,18 +215,16 @@ void main() {
float cos_gamma = dot(n, sunDir);
float gamma_val = acos(cos_gamma);
vec3 R = Z * hosekWilkie(cos_theta, gamma_val, cos_gamma) * envmapStrength;
fragColor.rgb = Z * hosekWilkie(cos_theta, gamma_val, cos_gamma) * envmapStrength;
#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);
// cloudsColor(fragColor.rgb, eye, n)
vec3 clouds = cloudsColor(fragColor.rgb, vec3(0.0), n);
if (n.z > 0.0) fragColor.rgb = mix(fragColor.rgb, clouds, n.z * 5.0 * envmapStrength);
#endif
#ifdef _LDR
R = pow(R, vec3(1.0 / 2.2));
fragColor.rgb = pow(fragColor.rgb, vec3(1.0 / 2.2));
#endif
fragColor = vec4(R, 1.0);
}

View file

@ -60,6 +60,10 @@ class Console extends Trait {
var avgMin = Math.round(frameTimeAvgMin * 10000) / 10;
var avgMax = Math.round(frameTimeAvgMax * 10000) / 10;
ui.text('frame: $avg ($avgMin/$avgMax)');
var fpsAvg = avg > 0 ? Math.round(1000 / avg) : 0;
var fpsAvgMin = avgMin > 0 ? Math.round(1000 / avgMin) : 0;
var fpsAvgMax = avgMax > 0 ? Math.round(1000 / avgMax) : 0;
ui.text('fps: $fpsAvg ($fpsAvgMin/$fpsAvgMax)');
var gpuTime = frameTimeAvg - renderTimeAvg - updateTimeAvg;
if (gpuTime < renderTimeAvg) gpuTime = renderTimeAvg;
ui.text("gpu: " + Math.round(gpuTime * 10000) / 10);
@ -74,6 +78,8 @@ class Console extends Trait {
if (ui.panel(Id.handle(), "Render Path")) {
ui.text("draw calls: " + RenderPath.drawCalls);
ui.text("batch calls: " + RenderPath.batchCalls);
ui.text("batch buckets: " + RenderPath.batchBuckets);
ui.text("render targets: " + path.data.pathdata.raw.render_targets.length);
}
ui.separator();

View file

@ -178,8 +178,7 @@ class RigidBody extends Trait {
var q = trans.getRotation();
transform.loc.set(p.x(), p.y(), p.z());
transform.rot.set(q.x(), q.y(), q.z(), q.w());
transform.dirty = true;
transform.update();
transform.buildMatrix();
}
}

View file

@ -41,15 +41,10 @@ def make_base(con_mesh, parse_opacity):
frag.ins = tese.outs
const = {}
const['name'] = 'innerLevel'
const['float'] = mat_state.material.height_tess_inner
const['name'] = 'tessLevel'
const['float'] = [mat_state.material.height_tess_inner, mat_state.material.height_tess_outer]
mat_state.mat_context['bind_constants'].append(const)
const = {}
const['name'] = 'outerLevel'
const['float'] = mat_state.material.height_tess_outer
mat_state.mat_context['bind_constants'].append(const)
tesc.add_uniform('float innerLevel')
tesc.add_uniform('float outerLevel')
tesc.add_uniform('vec2 tessLevel')
make_tess.tesc_levels(tesc)
tese.add_out('vec3 eyeDir')
make_tess.interpolate(tese, 'wposition', 3, declare_out=True)
@ -216,6 +211,7 @@ def make_forward_base(con_mesh, parse_opacity=False):
frag.add_uniform('vec3 lightDir', '_lampDirection')
frag.add_uniform('vec3 lightPos', '_lampPosition')
frag.add_uniform('int lightType', '_lampType')
frag.add_uniform('vec2 spotlightData', '_spotlampData') # cutoff, cutoff - exponent
frag.add_uniform('float envmapStrength', link='_envmapStrength')
if '_Irr' in wrd.world_defs:
@ -275,7 +271,6 @@ def make_forward_base(con_mesh, parse_opacity=False):
frag.tab -= 1
frag.write('}')
frag.add_uniform('vec2 spotlightData', '_spotlampData') # cutoff, cutoff - exponent
frag.write('if (lightType == 2) {')
frag.write(' float spotEffect = dot(lightDir, l);')
frag.write(' if (spotEffect < spotlightData.x) {')

View file

@ -48,15 +48,10 @@ def make(context_id, rpasses):
vert.write('wposition = vec4(W * spos).xyz;')
const = {}
const['name'] = 'innerLevel'
const['float'] = mat_state.material.height_tess_shadows_inner
const['name'] = 'tessLevel'
const['vec2'] = [mat_state.material.height_tess_shadows_inner, mat_state.material.height_tess_shadows_outer]
mat_state.mat_context['bind_constants'].append(const)
const = {}
const['name'] = 'outerLevel'
const['float'] = mat_state.material.height_tess_shadows_outer
mat_state.mat_context['bind_constants'].append(const)
tesc.add_uniform('float innerLevel')
tesc.add_uniform('float outerLevel')
tesc.add_uniform('vec2 tessLevel')
make_tess.tesc_levels(tesc)
make_tess.interpolate(tese, 'wposition', 3)

View file

@ -1,12 +1,12 @@
def tesc_levels(tesc):
tesc.write('if (gl_InvocationID == 0) {')
tesc.write(' gl_TessLevelInner[0] = innerLevel;')
tesc.write(' gl_TessLevelInner[1] = innerLevel;')
tesc.write(' gl_TessLevelOuter[0] = outerLevel;')
tesc.write(' gl_TessLevelOuter[1] = outerLevel;')
tesc.write(' gl_TessLevelOuter[2] = outerLevel;')
tesc.write(' gl_TessLevelOuter[3] = outerLevel;')
tesc.write(' gl_TessLevelInner[0] = tessLevel.x; // inner level')
tesc.write(' gl_TessLevelInner[1] = tessLevel.x;')
tesc.write(' gl_TessLevelOuter[0] = tessLevel.y; // outer level')
tesc.write(' gl_TessLevelOuter[1] = tessLevel.y;')
tesc.write(' gl_TessLevelOuter[2] = tessLevel.y;')
tesc.write(' gl_TessLevelOuter[3] = tessLevel.y;')
tesc.write('}')
def interpolate(tese, var, size, normalize=False, declare_out=False):

View file

@ -1,9 +1,16 @@
import material.cycles as cycles
import material.mat_state as mat_state
import material.mat_utils as mat_utils
import bpy
def make(context_id):
con_voxel = mat_state.data.add_context({ 'name': context_id, 'depth_write': False, 'compare_mode': 'always', 'cull_mode': 'none', 'color_write_red': False, 'color_write_green': False, 'color_write_blue': False, 'color_write_alpha': False })
wrd = bpy.data.worlds['Arm']
if '_NoShadows' in wrd.world_defs:
is_shadows = False
else:
is_shadows = True
vert = con_voxel.make_vert()
frag = con_voxel.make_frag()
@ -30,8 +37,15 @@ def make(context_id):
vert.write('wnormalGeom = normalize(N * nor);')
vert.write('gl_Position = vec4(0.0, 0.0, 0.0, 1.0);')
if is_shadows:
vert.add_out('vec4 lampPosGeom')
vert.add_uniform('mat4 LWVP', '_biasLampWorldViewProjectionMatrix')
vert.write('lampPosGeom = LWVP * vec4(pos, 1.0);')
geom.add_out('vec3 wposition')
geom.add_out('vec3 wnormal')
if is_shadows:
geom.add_out('vec4 lampPos')
if mat_state.data.is_elem('tex'):
geom.add_out('vec2 texCoord')
@ -41,6 +55,8 @@ def make(context_id):
geom.write('for (uint i = 0; i < 3; ++i) {')
geom.write(' wposition = wpositionGeom[i];')
geom.write(' wnormal = wnormalGeom[i];')
if is_shadows:
geom.write(' lampPos = lampPosGeom[i];')
if mat_state.data.is_elem('tex'):
geom.write(' texCoord = texCoordGeom[i];')
geom.write(' if (p.z > p.x && p.z > p.y) {')
@ -56,6 +72,17 @@ def make(context_id):
geom.write('}')
geom.write('EndPrimitive();')
frag.write('float visibility = 1.0;')
if is_shadows:
frag.add_uniform('sampler2D shadowMap')
#frag.add_uniform('bool receiveShadow')
frag.add_uniform('float shadowsBias', '_lampShadowsBias')
# frag.write('if (receiveShadow && lampPos.w > 0.0) {')
frag.write('if (lampPos.w > 0.0) {')
frag.write(' vec3 lpos = lampPos.xyz / lampPos.w;')
frag.write(' if (texture(shadowMap, lpos.xy).r < lpos.z - shadowsBias) visibility = 0.0;')
frag.write('}')
frag.add_include('../../Shaders/compiled.glsl')
frag.add_include('../../Shaders/std/math.glsl')
frag.write_header('#extension GL_ARB_shader_image_load_store : enable')
@ -74,7 +101,7 @@ def make(context_id):
frag.write('mat3 TBN;') # TODO: discard, parse basecolor only
frag.write_pre = False
cycles.parse(mat_state.nodes, vert, frag, geom, tesc, tese, parse_opacity=False, parse_displacement=False)
frag.write('vec3 color = basecol * lightColor * max(dot(wnormal, normalize(lightPos - wposition * voxelgiDimensions.x)), 0.0) * attenuate(distance(wposition * voxelgiDimensions.x, lightPos));')
frag.write('vec3 color = basecol * visibility * lightColor * max(dot(wnormal, normalize(lightPos - wposition * voxelgiDimensions.x)), 0.0) * attenuate(distance(wposition * voxelgiDimensions.x, lightPos));')
frag.write('vec3 voxel = wposition * 0.5 + vec3(0.5);')
frag.write('imageStore(voxels, ivec3(voxelgiResolution * voxel), vec4(color, 1.0));') # , alpha

View file

@ -132,6 +132,7 @@ def init_properties():
bpy.types.World.arm_optimize_mesh = BoolProperty(name="Optimize Meshes", description="Export more efficient geometry indices, can prolong build times", default=False, update=assets.invalidate_mesh_data)
bpy.types.World.arm_sampled_animation = BoolProperty(name="Sampled Animation", description="Export object animation as raw matrices", default=False, update=assets.invalidate_compiled_data)
bpy.types.World.arm_deinterleaved_buffers = BoolProperty(name="Deinterleaved Buffers", description="Use deinterleaved vertex buffers", default=False)
bpy.types.World.arm_batch_meshes = BoolProperty(name="Batch Meshes", description="Group meshes by materials to speed up rendering", default=False)
bpy.types.World.arm_export_hide_render = BoolProperty(name="Export Hidden Renders", description="Export hidden objects", default=True)
bpy.types.World.arm_spawn_all_layers = BoolProperty(name="Spawn All Layers", description="Spawn objects from all scene layers", default=False)
bpy.types.World.arm_play_advanced = BoolProperty(name="Advanced", default=False)
@ -401,7 +402,7 @@ def init_properties():
bpy.types.World.generate_ssr_search_dist = bpy.props.FloatProperty(name="Search Dist", default=5.0, update=assets.invalidate_shader_cache)
bpy.types.World.generate_ssr_falloff_exp = bpy.props.FloatProperty(name="Falloff Exp", default=5.0, update=assets.invalidate_shader_cache)
bpy.types.World.generate_ssr_jitter = bpy.props.FloatProperty(name="Jitter", default=0.6, update=assets.invalidate_shader_cache)
bpy.types.World.generate_ssr_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_ssr_texture_scale = bpy.props.FloatProperty(name="Texture Scale", default=0.5, min=0.0, max=1.0, update=assets.invalidate_shader_cache)
bpy.types.World.generate_volumetric_light = bpy.props.BoolProperty(name="Volumetric Light", description="", default=True, update=assets.invalidate_shader_cache)
bpy.types.World.generate_volumetric_light_air_turbidity = bpy.props.FloatProperty(name="Air Turbidity", default=1.0, update=assets.invalidate_shader_cache)
bpy.types.World.generate_volumetric_light_air_color = bpy.props.FloatVectorProperty(name="Air Color", size=3, default=[1.0, 1.0, 1.0], subtype='COLOR', update=assets.invalidate_shader_cache)

View file

@ -409,7 +409,9 @@ class ArmoryPlayerPanel(bpy.types.Panel):
row = layout.row(align=True)
row.prop(wrd, 'arm_gpu_processing')
row.prop(wrd, 'arm_sampled_animation')
layout.prop(wrd, 'arm_deinterleaved_buffers')
row = layout.row(align=True)
row.prop(wrd, 'arm_deinterleaved_buffers')
row.prop(wrd, 'arm_batch_meshes')
layout.label('Libraries')
layout.prop(wrd, 'arm_physics')
layout.prop(wrd, 'arm_navigation')

View file

@ -94,6 +94,9 @@ project.addSources('Sources');
if wrd.arm_deinterleaved_buffers == True:
f.write("project.addDefine('arm_deinterleaved');\n")
if wrd.arm_batch_meshes == True:
f.write("project.addDefine('arm_batch');\n")
if wrd.generate_gpu_skin == False:
f.write("project.addDefine('arm_cpu_skin');\n")