[orx-dnk3] Add feature architecture and post processing effects

This commit is contained in:
Edwin Jakobs
2020-07-06 13:00:58 +02:00
parent 0b0691e9ae
commit 419c38cc25
63 changed files with 2164 additions and 187 deletions

View File

@@ -0,0 +1,17 @@
vec3 evaluateSH(vec3 direction, vec3[9] _SH) {
const float c1 = 0.42904276540489171563379376569857; // 4 * Â2.Y22 = 1/4 * sqrt(15.PI)
const float c2 = 0.51166335397324424423977581244463; // 0.5 * Â1.Y10 = 1/2 * sqrt(PI/3)
const float c3 = 0.24770795610037568833406429782001; // Â2.Y20 = 1/16 * sqrt(5.PI)
const float c4 = 0.88622692545275801364908374167057; // Â0.Y00 = 1/2 * sqrt(PI)
float x = direction.x;
float y = direction.y;
float z = direction.z;
return max(vec3(0.0),
_SH[8] * (c1 * (x * x - y * y)) // c1.L22.(x²-y²)
+ _SH[6] * (c3 * (3.0 * z * z - 1)) // c3.L20.(3.z² - 1)
+ _SH[0] * c4 // c4.L00
+ (_SH[4] * x * y + _SH[7] * x * z + _SH[5] * y * z) * 2.0 * c1 // 2.c1.(L2-2.xy + L21.xz + L2-1.yz)
+ (_SH[3] * x + _SH[1] * y + _SH[2] * z) * c2 * 2.0); // 2.c2.(L11.x + L1-1.y + L10.z)
}

View File

@@ -0,0 +1,12 @@
void fetchSH(samplerBuffer btex, int probeID, out vec3[9] _SH) {
int offset = probeID * 9;
_SH[0] = texelFetch(btex, offset).rgb;
_SH[1] = texelFetch(btex, offset+1).rgb;
_SH[2] = texelFetch(btex, offset+2).rgb;
_SH[3] = texelFetch(btex, offset+3).rgb;
_SH[4] = texelFetch(btex, offset+4).rgb;
_SH[5] = texelFetch(btex, offset+5).rgb;
_SH[6] = texelFetch(btex, offset+6).rgb;
_SH[7] = texelFetch(btex, offset+7).rgb;
_SH[8] = texelFetch(btex, offset+8).rgb;
}

View File

@@ -0,0 +1,4 @@
void fetchSH0(samplerBuffer btex, int probeID, out vec3 _SH) {
int offset = probeID * 9;
_SH = texelFetch(btex, offset).rgb;
}

View File

@@ -0,0 +1,26 @@
void gatherSH(samplerBuffer btex, vec3 p, ivec3 probeCounts, vec3 offset, float spacing, out vec3[9] blend) {
vec3[9] c000;
vec3[9] c001;
vec3[9] c010;
vec3[9] c011;
vec3[9] c100;
vec3[9] c101;
vec3[9] c110;
vec3[9] c111;
vec3 f;
ivec3 io = gridCoordinates(p, f, probeCounts, offset, spacing);
fetchSH(btex, gridIndex(io + ivec3(0,0,0), probeCounts), c000);
fetchSH(btex, gridIndex(io + ivec3(0,0,1), probeCounts), c001);
fetchSH(btex, gridIndex(io + ivec3(0,1,0), probeCounts), c010);
fetchSH(btex, gridIndex(io + ivec3(0,1,1), probeCounts), c011);
fetchSH(btex, gridIndex(io + ivec3(1,0,0), probeCounts), c100);
fetchSH(btex, gridIndex(io + ivec3(1,0,1), probeCounts), c101);
fetchSH(btex, gridIndex(io + ivec3(1,1,0), probeCounts), c110);
fetchSH(btex, gridIndex(io + ivec3(1,1,1), probeCounts), c111);
for (int i = 0; i < 9; ++i) {
blend[i] = mix( mix( mix(c000[i], c001[i], f.z), mix(c010[i], c011[i], f.z), f.y), mix( mix(c100[i], c101[i], f.z), mix(c110[i], c111[i], f.z), f.y), f.x);
}
}

View File

@@ -0,0 +1,25 @@
void gatherSH0(samplerBuffer btex, vec3 p, ivec3 probeCounts, vec3 offset, float spacing, out vec3 blend) {
vec3 c000;
vec3 c001;
vec3 c010;
vec3 c011;
vec3 c100;
vec3 c101;
vec3 c110;
vec3 c111;
vec3 f;
ivec3 io = gridCoordinates(p, f, probeCounts, offset, spacing);
fetchSH0(btex, gridIndex(io + ivec3(0,0,0), probeCounts), c000);
fetchSH0(btex, gridIndex(io + ivec3(0,0,1), probeCounts), c001);
fetchSH0(btex, gridIndex(io + ivec3(0,1,0), probeCounts), c010);
fetchSH0(btex, gridIndex(io + ivec3(0,1,1), probeCounts), c011);
fetchSH0(btex, gridIndex(io + ivec3(1,0,0), probeCounts), c100);
fetchSH0(btex, gridIndex(io + ivec3(1,0,1), probeCounts), c101);
fetchSH0(btex, gridIndex(io + ivec3(1,1,0), probeCounts), c110);
fetchSH0(btex, gridIndex(io + ivec3(1,1,1), probeCounts), c111);
blend = mix( mix( mix(c000, c001, f.z), mix(c010, c011, f.z), f.y), mix( mix(c100, c101, f.z), mix(c110, c111, f.z), f.y), f.x);
}

View File

@@ -0,0 +1,15 @@
ivec3 gridCoordinates(vec3 p, out vec3 f, ivec3 probeCounts, vec3 offset, float spacing) {
float x = (p.x - offset.x) / spacing;
float y = (p.y - offset.y)/ spacing;
float z = (p.z - offset.z) / spacing;
int ix = int(floor(x)) + probeCounts.x / 2;
int iy = int(floor(y)) + probeCounts.y / 2;
int iz = int(floor(z)) + probeCounts.z / 2;
f.x = fract((x));
f.y = fract((y));
f.z = fract((z));
return ivec3(ix, iy, iz);
}

View File

@@ -0,0 +1,4 @@
int gridIndex(ivec3 p, ivec3 probeCounts) {
ivec3 c = clamp(p, ivec3(0), probeCounts - ivec3(1));
return c.x + c.y * probeCounts.x + c.z * probeCounts.x * probeCounts.y;
}