Commit for 2021.04.28.7z
This commit is contained in:
parent
89296ac169
commit
891301fc24
@ -5,6 +5,9 @@
|
||||
#define DEFERRED_SAMPLING 0
|
||||
#define RAY_MARCH_FOG 1
|
||||
|
||||
#define LAMBERT 0
|
||||
#define PBR 1
|
||||
|
||||
const float PI = 3.14159265359;
|
||||
const float EPSILON = 0.00001;
|
||||
|
||||
@ -491,19 +494,25 @@ void main() {
|
||||
if ( light.power * La * Ls <= LIGHT_POWER_CUTOFF ) continue;
|
||||
|
||||
const float cosLi = max(0.0, dot(N, Li));
|
||||
|
||||
const vec3 Lr = light.color.rgb * light.power * La * Ls;
|
||||
#if LAMBERT
|
||||
const vec3 diffuse = A.rgb;
|
||||
const vec3 specular = vec3(0);
|
||||
#elif PBR
|
||||
const vec3 Lh = normalize(Li + Lo);
|
||||
const float cosLh = max(0.0, dot(N, Lh));
|
||||
|
||||
const vec3 Lr = light.color.rgb * light.power * La * Ls;
|
||||
const vec3 F = fresnelSchlick( F0, max( 0.0, dot(Lh, Lo) ) );
|
||||
const float D = ndfGGX( cosLh, R );
|
||||
const float G = gaSchlickGGX(cosLi, cosLo, R);
|
||||
const vec3 diffuseBRDF = mix( vec3(1.0) - F, vec3(0.0), M ) * A.rgb;
|
||||
const vec3 specularBRDF = (F * D * G) / max(EPSILON, 4.0 * cosLi * cosLo);
|
||||
if ( light.type >= 0 && 0 <= material.indexLightmap ) fragColor.rgb += (specularBRDF) * Lr * cosLi;
|
||||
else if ( abs(light.type) == 1 ) fragColor.rgb += (diffuseBRDF) * Lr * cosLi;
|
||||
else fragColor.rgb += (diffuseBRDF + specularBRDF) * Lr * cosLi;
|
||||
const vec3 diffuse = mix( vec3(1.0) - F, vec3(0.0), M ) * A.rgb;
|
||||
const vec3 specular = (F * D * G) / max(EPSILON, 4.0 * cosLi * cosLo);
|
||||
#endif
|
||||
// lightmapped, compute only specular
|
||||
if ( light.type >= 0 && 0 <= material.indexLightmap ) fragColor.rgb += (specular) * Lr * cosLi;
|
||||
// point light, compute only diffuse
|
||||
// else if ( abs(light.type) == 1 ) fragColor.rgb += (diffuse) * Lr * cosLi;
|
||||
else fragColor.rgb += (diffuse + specular) * Lr * cosLi;
|
||||
litFactor += light.power * La * Ls;
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,13 +7,17 @@
|
||||
#define WHITENOISE 1
|
||||
#define DEFERRED_SAMPLING 0
|
||||
#define SHADOW_CONE_TRACED 0
|
||||
#define VOXEL_TRACE_IN_NDC 0
|
||||
#define VOXEL_TRACE_IN_NDC 1
|
||||
|
||||
#define GAMMA_CORRECT 1
|
||||
#define TONE_MAP 1
|
||||
|
||||
#define LAMBERT 0
|
||||
#define PBR 1
|
||||
|
||||
const float PI = 3.14159265359;
|
||||
const float EPSILON = 0.00001;
|
||||
const float SQRT2 = 1.41421356237;
|
||||
|
||||
const float LIGHT_POWER_CUTOFF = 0.005;
|
||||
|
||||
@ -415,6 +419,9 @@ struct VoxelInfo {
|
||||
float mipmapLevels;
|
||||
float albedoSize;
|
||||
float voxelSize;
|
||||
|
||||
float albedoSizeRecip;
|
||||
float voxelSizeRecip;
|
||||
};
|
||||
VoxelInfo voxelInfo;
|
||||
|
||||
@ -422,32 +429,38 @@ vec4 voxelConeTrace( vec3 rayO, vec3 rayD, float aperture, float maxDistance ) {
|
||||
#if VOXEL_TRACE_IN_NDC
|
||||
rayO = vec3( ubo.matrices.voxel * vec4( rayO, 1.0 ) );
|
||||
rayD = vec3( ubo.matrices.voxel * vec4( rayD, 0.0 ) );
|
||||
const float granularity = 1.0f / 8.0f;
|
||||
const uint maxSteps = uint(voxelInfo.albedoSize * 2);
|
||||
#else
|
||||
const float granularity = 8.0f;
|
||||
const uint maxSteps = uint(voxelInfo.albedoSize * granularity);
|
||||
#endif
|
||||
const float granularity = 12.0f;
|
||||
const float granularityRecip = 1.0f / granularity;
|
||||
// box
|
||||
const vec2 rayBoxInfo = rayBoxDst( voxelInfo.min, voxelInfo.max, rayO, rayD );
|
||||
const float tStart = rayBoxInfo.x;
|
||||
const float tEnd = maxDistance > 0 ? min(maxDistance, rayBoxInfo.y) : rayBoxInfo.y;
|
||||
// steps
|
||||
const float tDelta = voxelInfo.voxelSize / granularity;
|
||||
const uint maxSteps = uint(voxelInfo.albedoSize * granularity);
|
||||
const float tDelta = voxelInfo.voxelSize * granularityRecip;
|
||||
// marcher
|
||||
float t = tStart + tDelta * 2.0;
|
||||
float t = tStart + 2.0 * SQRT2;
|
||||
vec3 rayPos = vec3(0);
|
||||
vec4 radiance = vec4(0);
|
||||
vec3 uvw = vec3(0);
|
||||
// cone mipmap shit
|
||||
const float coneCoefficient = 2.0 * tan(aperture * 0.5);
|
||||
float coneDiameter = coneCoefficient * t;
|
||||
float level = aperture > 0 ? log2( coneDiameter / voxelInfo.albedoSize ) : 0;
|
||||
float level = aperture > 0 ? log2( coneDiameter ) : 0;
|
||||
// results
|
||||
vec4 color = vec4(0);
|
||||
float occlusion = 0.0;
|
||||
uint stepCounter = 0;
|
||||
float tD;
|
||||
const float falloff = 256.0f;
|
||||
const vec3 voxelBoundsRecip = 1.0f / (voxelInfo.max - voxelInfo.min);
|
||||
while ( t < tEnd && color.a < 1.0 && occlusion < 1.0 && stepCounter++ < maxSteps ) {
|
||||
t += tDelta * pow(2, coneDiameter / voxelInfo.albedoSize);
|
||||
// while ( t < tEnd && color.a < 1.0 && occlusion < 1.0 && stepCounter++ < maxSteps ) {
|
||||
while ( t < tEnd && color.a < 1.0 && occlusion < 1.0 ) {
|
||||
t += tDelta * (aperture > 0 ? coneDiameter : 1);
|
||||
rayPos = rayO + rayD * t;
|
||||
#if VOXEL_TRACE_IN_NDC
|
||||
uvw = rayPos * 0.5 + 0.5;
|
||||
@ -456,11 +469,10 @@ vec4 voxelConeTrace( vec3 rayO, vec3 rayD, float aperture, float maxDistance ) {
|
||||
#endif
|
||||
if ( abs(uvw.x) > 1.0 || abs(uvw.y) > 1.0 || abs(uvw.z) > 1.0 ) break;
|
||||
coneDiameter = coneCoefficient * t;
|
||||
level = log2( coneDiameter / voxelInfo.albedoSize );
|
||||
radiance = texture(voxelAlbedo, uvw, level); // / granularity;
|
||||
// radiance /= granularity;
|
||||
// if ( aperture < EPSILON && color.a > EPSILON ) radiance *= granularity;
|
||||
|
||||
level = log2( coneDiameter );
|
||||
if ( level >= voxelInfo.mipmapLevels ) break;
|
||||
radiance = texture(voxelAlbedo, uvw, level);
|
||||
|
||||
color += (1.0 - color.a) * radiance;
|
||||
occlusion += ((1.0f - occlusion) * radiance.a) / (1.0f + falloff * coneDiameter);
|
||||
}
|
||||
@ -571,10 +583,10 @@ void main() {
|
||||
const vec3 N = normal.world;
|
||||
|
||||
const float DIFFUSE_CONE_APERTURE = 0.57735f;
|
||||
const float DIFFUSE_INDIRECT_FACTOR = 0.125f; // 1.0f;
|
||||
const float DIFFUSE_INDIRECT_FACTOR = 1.0f / 6.0f; // 1.0f;
|
||||
|
||||
const float SPECULAR_CONE_APERTURE = clamp(tan(PI * 0.5f * R), 0.0174533f, PI);
|
||||
const float SPECULAR_INDIRECT_FACTOR = 1.0 - M; // 1.0f;
|
||||
const float SPECULAR_CONE_APERTURE = clamp(tan(PI * 0.5f * R), 0.0174533f, PI); // tan( R * PI * 0.5f * 0.1f );
|
||||
const float SPECULAR_INDIRECT_FACTOR = (1.0 - M) * 0.5; // 1.0f;
|
||||
|
||||
const vec4 CONES[] = {
|
||||
vec4(0.0f, 1.0f, 0.0f, PI / 4.0f),
|
||||
@ -586,20 +598,22 @@ void main() {
|
||||
};
|
||||
{
|
||||
voxelInfo.albedoSize = textureSize( voxelAlbedo, 0 ).x;
|
||||
voxelInfo.mipmapLevels = textureQueryLod( voxelAlbedo, vec3(0) ).x;
|
||||
voxelInfo.albedoSizeRecip = 1.0 / voxelInfo.albedoSize;
|
||||
voxelInfo.mipmapLevels = log2(voxelInfo.albedoSize) + 1; //textureQueryLod( voxelAlbedo, vec3(0) ).x;
|
||||
#if VOXEL_TRACE_IN_NDC
|
||||
voxelInfo.min = vec3( -1 );
|
||||
voxelInfo.max = vec3( 1 );
|
||||
voxelInfo.voxelSize = 1.0 / voxelInfo.albedoSize;
|
||||
voxelInfo.voxelSize = voxelInfo.albedoSizeRecip;
|
||||
#else
|
||||
const mat4 inverseOrtho = inverse( ubo.matrices.voxel );
|
||||
voxelInfo.min = vec3( inverseOrtho * vec4( -1, -1, -1, 1 ) );
|
||||
voxelInfo.max = vec3( inverseOrtho * vec4( 1, 1, 1, 1 ) );
|
||||
voxelInfo.voxelSize = 1;
|
||||
#endif
|
||||
voxelInfo.voxelSizeRecip = 1.0 / voxelInfo.voxelSize;
|
||||
}
|
||||
|
||||
// outFragColor.rgb = voxelConeTrace( rayO, rayD, 0 ).rgb; return;
|
||||
// outFragColor.rgb = voxelConeTrace( rayO, rayD, 0 ).rgb; return;
|
||||
|
||||
if ( DIFFUSE_INDIRECT_FACTOR > 0.0f ) {
|
||||
vec3 guide = vec3(0.0f, 1.0f, 0.0f);
|
||||
@ -609,13 +623,14 @@ void main() {
|
||||
const vec3 up = cross(right, N);
|
||||
for ( uint i = 0; i < 6; ++i ) {
|
||||
const vec3 coneDirection = normalize(N + CONES[i].x * right + CONES[i].z * up);
|
||||
indirectDiffuse += voxelConeTrace(P, coneDirection, DIFFUSE_CONE_APERTURE ) * CONES[i].w;
|
||||
indirectDiffuse += voxelConeTrace(P, coneDirection * ( dot(coneDirection, N) < 0 ? -1 : 1 ), DIFFUSE_CONE_APERTURE ) * CONES[i].w;
|
||||
}
|
||||
indirectDiffuse.rgb *= A.rgb;
|
||||
AO = indirectDiffuse.a;
|
||||
// indirectDiffuse.rgb *= A.rgb;
|
||||
// outFragColor.rgb = indirectDiffuse.rgb; return;
|
||||
AO = indirectDiffuse.a;
|
||||
}
|
||||
if ( SPECULAR_INDIRECT_FACTOR > 0.0f ) {
|
||||
// const vec3 R = reflect( normalize(P - rayO), N );
|
||||
const vec3 R = reflect( normalize(P - rayO), N );
|
||||
indirectSpecular = voxelConeTrace( P, R, SPECULAR_CONE_APERTURE );
|
||||
// outFragColor.rgb = indirectSpecular.rgb; return;
|
||||
@ -636,6 +651,7 @@ void main() {
|
||||
const vec3 F0 = mix(vec3(0.04), A.rgb, M);
|
||||
const vec3 Lo = normalize( -position.eye );
|
||||
const float cosLo = max(0.0, dot(N, Lo));
|
||||
|
||||
for ( uint i = 0; i < ubo.lights; ++i ) {
|
||||
const Light light = lights[i];
|
||||
if ( light.power <= LIGHT_POWER_CUTOFF ) continue;
|
||||
@ -647,25 +663,29 @@ void main() {
|
||||
if ( light.power * La * Ls <= LIGHT_POWER_CUTOFF ) continue;
|
||||
|
||||
const float cosLi = max(0.0, dot(N, Li));
|
||||
|
||||
const vec3 Lr = light.color.rgb * light.power * La * Ls;
|
||||
#if LAMBERT
|
||||
const vec3 diffuse = A.rgb;
|
||||
const vec3 specular = vec3(0);
|
||||
#elif PBR
|
||||
const vec3 Lh = normalize(Li + Lo);
|
||||
const float cosLh = max(0.0, dot(N, Lh));
|
||||
|
||||
const vec3 Lr = light.color.rgb * light.power * La * Ls;
|
||||
const vec3 F = fresnelSchlick( F0, max( 0.0, dot(Lh, Lo) ) );
|
||||
const float D = ndfGGX( cosLh, R );
|
||||
const float G = gaSchlickGGX(cosLi, cosLo, R);
|
||||
const vec3 diffuseBRDF = mix( vec3(1.0) - F, vec3(0.0), M ) * A.rgb;
|
||||
const vec3 specularBRDF = (F * D * G) / max(EPSILON, 4.0 * cosLi * cosLo);
|
||||
|
||||
if ( light.type >= 0 && 0 <= material.indexLightmap ) fragColor.rgb += (specularBRDF) * Lr * cosLi;
|
||||
// else if ( abs(light.type) == 1 ) fragColor.rgb += (diffuseBRDF) * Lr * cosLi;
|
||||
else fragColor.rgb += (diffuseBRDF + specularBRDF) * Lr * cosLi;
|
||||
|
||||
// if ( !(0 <= material.indexLightmap) ) fragColor.rgb += (diffuseBRDF) * Lr * cosLi;
|
||||
const vec3 diffuse = mix( vec3(1.0) - F, vec3(0.0), M ) * A.rgb;
|
||||
const vec3 specular = (F * D * G) / max(EPSILON, 4.0 * cosLi * cosLo);
|
||||
#endif
|
||||
// lightmapped, compute only specular
|
||||
if ( light.type >= 0 && 0 <= material.indexLightmap ) fragColor.rgb += (specular) * Lr * cosLi;
|
||||
// point light, compute only diffuse
|
||||
// else if ( abs(light.type) == 1 ) fragColor.rgb += (diffuse) * Lr * cosLi;
|
||||
else fragColor.rgb += (diffuse + specular) * Lr * cosLi;
|
||||
litFactor += light.power * La * Ls;
|
||||
}
|
||||
}
|
||||
|
||||
#if FOG
|
||||
fog(rayO, rayD, fragColor, 1.0 ); //litFactor);
|
||||
#endif
|
||||
|
||||
@ -7,6 +7,9 @@ layout (local_size_x = 8, local_size_y = 8, local_size_z = 8) in;
|
||||
#define RAY_MARCH_FOG 1
|
||||
#define DEFERRED_SAMPLING 0
|
||||
|
||||
#define LAMBERT 1
|
||||
#define PBR 0
|
||||
|
||||
const float PI = 3.14159265359;
|
||||
const float EPSILON = 0.00001;
|
||||
|
||||
@ -251,13 +254,15 @@ float shadowFactor( const Light light, float def ) {
|
||||
const float bias = light.depthBias;
|
||||
const float eyeDepth = positionClip.z;
|
||||
const int samples = int(ubo.poissonSamples);
|
||||
if ( samples <= 1 ) return eyeDepth < texture(samplerTextures[light.mapIndex], uv).r - bias ? 0.0 : factor;
|
||||
return eyeDepth < texture(samplerTextures[light.mapIndex], uv).r - bias ? 0.0 : factor;
|
||||
#if 0
|
||||
for ( int i = 0; i < samples; ++i ) {
|
||||
const int index = int( float(samples) * random(floor(position.world.xyz * 1000.0), i)) % samples;
|
||||
const float lightDepth = texture(samplerTextures[light.mapIndex], uv + poissonDisk[index] / 700.0 ).r;
|
||||
if ( eyeDepth < lightDepth - bias ) factor -= 1.0 / samples;
|
||||
}
|
||||
return factor;
|
||||
#endif
|
||||
}
|
||||
|
||||
void main() {
|
||||
@ -278,6 +283,25 @@ void main() {
|
||||
imageStore(voxelAlbedo, ivec3(tUvw), vec4(0));
|
||||
return;
|
||||
}
|
||||
#if 0
|
||||
{
|
||||
const uvec3 dim = imageSize(voxelAlbedo);
|
||||
float sdf = max(dim.x, max(dim.y, dim.z)) * 2.82842712;
|
||||
|
||||
uvec2 ID;
|
||||
ivec3 coord;
|
||||
for ( uint z = 0; z < dim.z; ++z ) {
|
||||
for ( uint y = 0; y < dim.y; ++y ) {
|
||||
for ( uint x = 0; x < dim.x; ++x ) {
|
||||
coord = ivec3(x,y,z);
|
||||
ID = imageLoad( voxelID, coord ).xy;
|
||||
if ( ID.x == 0 || ID.y == 0 ) continue;
|
||||
sdf = min(distance(tUvw, coord), sdf);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
const uint drawId = ID.x - 1;
|
||||
const DrawCall drawCall = drawCalls[drawId];
|
||||
const uint materialId = ID.y + drawCall.materialIndex - 1;
|
||||
@ -319,15 +343,14 @@ void main() {
|
||||
}
|
||||
{
|
||||
const float R = material.factorRoughness * 2.0f;
|
||||
|
||||
const vec3 N = normal.world;
|
||||
const vec3 F0 = mix(vec3(0.04), A.rgb, M);
|
||||
const vec3 Lo = normalize( -position.world );
|
||||
const vec3 Lo = normalize( position.world );
|
||||
const float cosLo = max(0.0, dot(N, Lo));
|
||||
|
||||
for ( uint i = 0; i < ubo.lights; ++i ) {
|
||||
const Light light = lights[i];
|
||||
if ( light.power <= LIGHT_POWER_CUTOFF ) continue;
|
||||
if ( light.type >= 0 && 0 <= material.indexLightmap ) continue;
|
||||
const vec3 Lp = light.position;
|
||||
const vec3 Liu = light.position - position.world;
|
||||
const vec3 Li = normalize(Liu);
|
||||
@ -336,21 +359,25 @@ void main() {
|
||||
if ( light.power * La * Ls <= LIGHT_POWER_CUTOFF ) continue;
|
||||
|
||||
const float cosLi = max(0.0, dot(N, Li));
|
||||
|
||||
const vec3 Lr = light.color.rgb * light.power * La * Ls;
|
||||
#if LAMBERT
|
||||
const vec3 diffuse = A.rgb;
|
||||
const vec3 specular = vec3(0);
|
||||
#elif PBR
|
||||
const vec3 Lh = normalize(Li + Lo);
|
||||
const float cosLh = max(0.0, dot(N, Lh));
|
||||
|
||||
const vec3 Lr = light.color.rgb * light.power * La * Ls;
|
||||
const vec3 F = fresnelSchlick( F0, max( 0.0, dot(Lh, Lo) ) );
|
||||
const float D = ndfGGX( cosLh, R );
|
||||
const float G = gaSchlickGGX(cosLi, cosLo, R);
|
||||
const vec3 diffuseBRDF = mix( vec3(1.0) - F, vec3(0.0), M ) * A.rgb;
|
||||
const vec3 specularBRDF = (F * D * G) / max(EPSILON, 4.0 * cosLi * cosLo);
|
||||
if ( light.type >= 0 && 0 <= material.indexLightmap ) fragColor.rgb += (specularBRDF) * Lr * cosLi;
|
||||
// else if ( abs(light.type) == 1 ) fragColor.rgb += (diffuseBRDF) * Lr * cosLi;
|
||||
else fragColor.rgb += (diffuseBRDF + specularBRDF) * Lr * cosLi;
|
||||
|
||||
if ( !(0 <= material.indexLightmap) ) fragColor.rgb += (diffuseBRDF) * Lr * cosLi;
|
||||
const vec3 diffuse = mix( vec3(1.0) - F, vec3(0.0), M ) * A.rgb;
|
||||
const vec3 specular = (F * D * G) / max(EPSILON, 4.0 * cosLi * cosLo);
|
||||
#endif
|
||||
// lightmapped, compute only specular
|
||||
if ( light.type >= 0 && 0 <= material.indexLightmap ) fragColor.rgb += (specular) * Lr * cosLi;
|
||||
// point light, compute only diffuse
|
||||
// else if ( abs(light.type) == 1 ) fragColor.rgb += (diffuse) * Lr * cosLi;
|
||||
else fragColor.rgb += (diffuse + specular) * Lr * cosLi;
|
||||
litFactor += light.power * La * Ls;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,10 +1,14 @@
|
||||
#version 450
|
||||
|
||||
#define LAMBERT 1
|
||||
#define PBR 0
|
||||
|
||||
const float PI = 3.14159265359;
|
||||
const float EPSILON = 0.00001;
|
||||
|
||||
const float LIGHT_POWER_CUTOFF = 0.005;
|
||||
|
||||
|
||||
const vec2 poissonDisk[16] = vec2[](
|
||||
vec2( -0.94201624, -0.39906216 ),
|
||||
vec2( 0.94558609, -0.76890725 ),
|
||||
@ -242,7 +246,6 @@ void main() {
|
||||
const vec3 F0 = mix(vec3(0.04), A.rgb, M);
|
||||
const vec3 Lo = normalize( -P );
|
||||
const float cosLo = max(0.0, dot(N, Lo));
|
||||
|
||||
for ( uint i = 0; i < lights.length(); ++i ) {
|
||||
const Light light = lights[i];
|
||||
if ( light.power <= LIGHT_POWER_CUTOFF ) continue;
|
||||
@ -253,16 +256,22 @@ void main() {
|
||||
if ( light.power * La * Ls <= LIGHT_POWER_CUTOFF ) continue;
|
||||
|
||||
const vec3 Li = normalize(Liu);
|
||||
const vec3 Lr = light.color.rgb * light.power * La * Ls;
|
||||
const float cosLi = abs(dot(N, Li));// max(0.0, dot(N, Li));
|
||||
#if LAMBERT
|
||||
const vec3 diffuse = A.rgb;
|
||||
const vec3 specular = vec3(0);
|
||||
#elif PBR
|
||||
const vec3 Lh = normalize(Li + Lo);
|
||||
const float cosLi = max(0.0, dot(N, Li));
|
||||
const float cosLh = max(0.0, dot(N, Lh));
|
||||
|
||||
const vec3 Lr = light.color.rgb * light.power * La * Ls;
|
||||
const vec3 F = fresnelSchlick( F0, max( 0.0, dot(Lh, Lo) ) );
|
||||
const float D = ndfGGX( cosLh, R );
|
||||
const float G = gaSchlickGGX(cosLi, cosLo, R);
|
||||
const vec3 diffuseBRDF = mix( vec3(1.0) - F, vec3(0.0), M ) * A.rgb;
|
||||
fragColor.rgb += (diffuseBRDF) * Lr * cosLi;
|
||||
const vec3 diffuse = mix( vec3(1.0) - F, vec3(0.0), M ) * A.rgb;
|
||||
const vec3 specular = (F * D * G) / max(EPSILON, 4.0 * cosLi * cosLo);
|
||||
#endif
|
||||
fragColor.rgb += (diffuse + specular) * Lr * cosLi;
|
||||
litFactor += light.power * La * Ls;
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,6 +14,7 @@ namespace pod {
|
||||
uf::renderer::Texture3D normal;
|
||||
uf::renderer::Texture3D albedo;
|
||||
uf::renderer::Texture3D uv;
|
||||
pod::Matrix4f matrix;
|
||||
} voxels;
|
||||
};
|
||||
|
||||
|
||||
@ -131,6 +131,7 @@ void uf::GltfBehavior::tick( uf::Object& self ) {
|
||||
}
|
||||
if ( graphic.material.hasShader("geometry", "vxgi") ) {
|
||||
auto& shader = graphic.material.getShader("geometry", "vxgi");
|
||||
/*
|
||||
pod::Vector3f min = uf::vector::decode( graph.metadata["extents"]["min"], pod::Vector3f{} );
|
||||
pod::Vector3f max = uf::vector::decode( graph.metadata["extents"]["max"], pod::Vector3f{} );
|
||||
|
||||
@ -141,13 +142,16 @@ void uf::GltfBehavior::tick( uf::Object& self ) {
|
||||
max.x += floor(controllerTransform.position.x);
|
||||
max.y -= floor(controllerTransform.position.y);
|
||||
max.z -= floor(controllerTransform.position.z);
|
||||
|
||||
// uniforms.matrix = uf::matrix::translate( uf::matrix::identity(), -controllerTransform.position )
|
||||
uniforms.matrix = uf::matrix::ortho<float>( min.x, max.x, min.y, max.y, min.z, max.z );
|
||||
*/
|
||||
auto& sceneTextures = scene.getComponent<pod::SceneTextures>();
|
||||
struct UniformDescriptor {
|
||||
alignas(16) pod::Matrix4f matrix;
|
||||
};
|
||||
auto& uniform = shader.getUniform("UBO");
|
||||
auto& uniforms = uniform.get<UniformDescriptor>();
|
||||
uniforms.matrix = /*uf::matrix::translate( uf::matrix::identity(), -controllerTransform.position ) **/ uf::matrix::ortho<float>( min.x, max.x, min.y, max.y, min.z, max.z );
|
||||
uniforms.matrix = sceneTextures.voxels.matrix;
|
||||
shader.updateUniform( "UBO", uniform );
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -505,8 +505,10 @@ void uf::graph::process( pod::Graph& graph ) {
|
||||
}
|
||||
});
|
||||
|
||||
if ( ext::json::isNull( graph.metadata["extents"]["min"] ) ) graph.metadata["extents"]["min"] = uf::vector::encode( extentMin * graph.metadata["extents"]["scale"].as<float>(1.0f) );
|
||||
if ( ext::json::isNull( graph.metadata["extents"]["max"] ) ) graph.metadata["extents"]["max"] = uf::vector::encode( extentMax * graph.metadata["extents"]["scale"].as<float>(1.0f) );
|
||||
// if ( ext::json::isNull( graph.metadata["extents"]["min"] ) )
|
||||
graph.metadata["extents"]["min"] = uf::vector::encode( extentMin * graph.metadata["extents"]["scale"].as<float>(1.0f) );
|
||||
// if ( ext::json::isNull( graph.metadata["extents"]["max"] ) )
|
||||
graph.metadata["extents"]["max"] = uf::vector::encode( extentMax * graph.metadata["extents"]["scale"].as<float>(1.0f) );
|
||||
}
|
||||
void uf::graph::process( pod::Graph& graph, int32_t index, uf::Object& parent ) {
|
||||
auto& node = graph.nodes[index];
|
||||
@ -527,6 +529,9 @@ void uf::graph::process( pod::Graph& graph, int32_t index, uf::Object& parent )
|
||||
// tie to tag
|
||||
if ( !ext::json::isNull( graph.metadata["tags"][node.name] ) ) {
|
||||
auto& info = graph.metadata["tags"][node.name];
|
||||
if ( info["ignore"].as<bool>() ) {
|
||||
return;
|
||||
}
|
||||
if ( info["action"].as<std::string>() == "load" ) {
|
||||
if ( info["filename"].is<std::string>() ) {
|
||||
std::string filename = uf::io::resolveURI( info["filename"].as<std::string>(), graph.metadata["root"].as<std::string>() );
|
||||
@ -1429,7 +1434,7 @@ void uf::graph::save( const pod::Graph& graph, const std::string& filename ) {
|
||||
if ( saveSeparately ) {
|
||||
for ( size_t i = 0; i < graph.images.size(); ++i ) {
|
||||
std::string f = "image."+std::to_string(i)+(compression?".jpg":".png");
|
||||
graph.images[i].save(directory + "/" + f);
|
||||
graph.images[i].save(directory + "/" + f, true);
|
||||
serializer["images"].emplace_back(f);
|
||||
}
|
||||
} else {
|
||||
@ -1518,7 +1523,7 @@ void uf::graph::save( const pod::Graph& graph, const std::string& filename ) {
|
||||
if ( saveSeparately ) {
|
||||
for ( size_t i = 0; i < graph.images.size(); ++i ) {
|
||||
std::string f = "image."+std::to_string(i)+(compression?".jpg":".png");
|
||||
graph.images[i].save(directory + "/" + f);
|
||||
graph.images[i].save(directory + "/" + f, true);
|
||||
serializer["images"].emplace_back(f);
|
||||
}
|
||||
} else {
|
||||
|
||||
@ -32,7 +32,7 @@ uf::Atlas::hash_t uf::Atlas::addImage( const uint8_t* pointer, const pod::Vector
|
||||
return this->addImage( std::move( image ), regenerate );
|
||||
}
|
||||
void uf::Atlas::generate( const uf::Atlas::images_t& images, float padding ) {
|
||||
for ( auto& image : images ) this->addImage( image, false );
|
||||
for ( auto& image : images ) this->addImage( image, true );
|
||||
generate( padding );
|
||||
}
|
||||
void uf::Atlas::generate( float padding ) {
|
||||
|
||||
@ -22,6 +22,8 @@
|
||||
|
||||
#include <uf/utils/math/collision.h>
|
||||
|
||||
#include <uf/ext/ext.h>
|
||||
|
||||
#include "../light/behavior.h"
|
||||
#include "../../ext.h"
|
||||
#include "../../gui/gui.h"
|
||||
@ -223,12 +225,12 @@ void ext::ExtSceneBehavior::initialize( uf::Object& self ) {
|
||||
metadataJson["light"]["fog"]["density"]["scale"] = metadata.fog.density.scale;
|
||||
};
|
||||
metadata.deserialize = [&](){
|
||||
metadata.max.textures = metadataJson["system"]["config"]["engine"]["scenes"]["textures"]["max"].as<size_t>();
|
||||
metadata.max.lights = metadataJson["system"]["config"]["engine"]["scenes"]["lights"]["max"].as<size_t>();
|
||||
metadata.light.enabled = metadataJson["system"]["config"]["engine"]["scenes"]["lights"]["enabled"].as<bool>() && metadataJson["light"]["should"].as<bool>();
|
||||
metadata.light.shadowSamples = metadataJson["system"]["config"]["engine"]["scenes"]["lights"]["shadow samples"].as<size_t>();
|
||||
metadata.light.shadowThreshold = metadataJson["system"]["config"]["engine"]["scenes"]["lights"]["shadow threshold"].as<size_t>();
|
||||
metadata.light.updateThreshold = metadataJson["system"]["config"]["engine"]["scenes"]["lights"]["update threshold"].as<size_t>();
|
||||
metadata.max.textures = ext::config["engine"]["scenes"]["textures"]["max"].as<size_t>();
|
||||
metadata.max.lights = ext::config["engine"]["scenes"]["lights"]["max"].as<size_t>();
|
||||
metadata.light.enabled = ext::config["engine"]["scenes"]["lights"]["enabled"].as<bool>() && metadataJson["light"]["should"].as<bool>();
|
||||
metadata.light.shadowSamples = ext::config["engine"]["scenes"]["lights"]["shadow samples"].as<size_t>();
|
||||
metadata.light.shadowThreshold = ext::config["engine"]["scenes"]["lights"]["shadow threshold"].as<size_t>();
|
||||
metadata.light.updateThreshold = ext::config["engine"]["scenes"]["lights"]["update threshold"].as<size_t>();
|
||||
metadata.light.ambient = uf::vector::decode( metadataJson["light"]["ambient"], pod::Vector4f{ 1, 1, 1, 1 } );
|
||||
metadata.light.specular = uf::vector::decode( metadataJson["light"]["specular"], pod::Vector4f{ 1, 1, 1, 1 } );
|
||||
metadata.light.exposure = metadataJson["light"]["exposure"].as<float>(1.0f);
|
||||
@ -360,12 +362,12 @@ void ext::ExtSceneBehavior::tick( uf::Object& self ) {
|
||||
#if UF_ENTITY_METADATA_USE_JSON
|
||||
metadata.deserialize();
|
||||
#else
|
||||
if ( !metadata.max.textures ) metadata.max.textures = metadataJson["system"]["config"]["engine"]["scenes"]["textures"]["max"].as<size_t>();
|
||||
if ( !metadata.max.lights ) metadata.max.lights = metadataJson["system"]["config"]["engine"]["scenes"]["lights"]["max"].as<size_t>();
|
||||
if ( !metadata.light.enabled ) metadata.light.enabled = metadataJson["system"]["config"]["engine"]["scenes"]["lights"]["enabled"].as<bool>() && metadataJson["light"]["should"].as<bool>();
|
||||
if ( !metadata.light.shadowSamples ) metadata.light.shadowSamples = metadataJson["system"]["config"]["engine"]["scenes"]["lights"]["shadow samples"].as<size_t>();
|
||||
if ( !metadata.light.shadowThreshold ) metadata.light.shadowThreshold = metadataJson["system"]["config"]["engine"]["scenes"]["lights"]["shadow threshold"].as<size_t>();
|
||||
if ( !metadata.light.updateThreshold ) metadata.light.updateThreshold = metadataJson["system"]["config"]["engine"]["scenes"]["lights"]["update threshold"].as<size_t>();
|
||||
if ( !metadata.max.textures ) metadata.max.textures = ext::config["engine"]["scenes"]["textures"]["max"].as<size_t>();
|
||||
if ( !metadata.max.lights ) metadata.max.lights = ext::config["engine"]["scenes"]["lights"]["max"].as<size_t>();
|
||||
if ( !metadata.light.enabled ) metadata.light.enabled = ext::config["engine"]["scenes"]["lights"]["enabled"].as<bool>() && metadataJson["light"]["should"].as<bool>();
|
||||
if ( !metadata.light.shadowSamples ) metadata.light.shadowSamples = ext::config["engine"]["scenes"]["lights"]["shadow samples"].as<size_t>();
|
||||
if ( !metadata.light.shadowThreshold ) metadata.light.shadowThreshold = ext::config["engine"]["scenes"]["lights"]["shadow threshold"].as<size_t>();
|
||||
if ( !metadata.light.updateThreshold ) metadata.light.updateThreshold = ext::config["engine"]["scenes"]["lights"]["update threshold"].as<size_t>();
|
||||
if ( !metadata.light.exposure ) metadata.light.exposure = metadataJson["light"]["exposure"].as<float>(1.0f);
|
||||
if ( !metadata.light.gamma ) metadata.light.gamma = metadataJson["light"]["gamma"].as<float>(2.2f);
|
||||
#endif
|
||||
@ -621,9 +623,10 @@ void ext::ExtSceneBehavior::bindBuffers( uf::Object& self, const std::string& re
|
||||
std::vector<pod::DrawCall::Storage> drawCalls;
|
||||
drawCalls.reserve(maxTextures);
|
||||
|
||||
// add materials
|
||||
pod::Vector3f min = { std::numeric_limits<float>::max(), std::numeric_limits<float>::max(), std::numeric_limits<float>::max() };
|
||||
pod::Vector3f max = { -std::numeric_limits<float>::max(), -std::numeric_limits<float>::max(), -std::numeric_limits<float>::max() };
|
||||
|
||||
// add materials
|
||||
for ( auto* g : graphs ) {
|
||||
auto& graph = *g;
|
||||
|
||||
@ -642,7 +645,10 @@ void ext::ExtSceneBehavior::bindBuffers( uf::Object& self, const std::string& re
|
||||
graphic.material.textures.emplace_back().aliasTexture(texture.texture);
|
||||
++textureSlot;
|
||||
}
|
||||
|
||||
#if 1
|
||||
}
|
||||
uniforms->matrices.ortho = sceneTextures.voxels.matrix;
|
||||
#else
|
||||
// calculate extents
|
||||
pod::Vector3f graphMin = uf::vector::decode( graph.metadata["extents"]["min"], pod::Vector3f{} );
|
||||
pod::Vector3f graphMax = uf::vector::decode( graph.metadata["extents"]["max"], pod::Vector3f{} );
|
||||
@ -665,7 +671,7 @@ void ext::ExtSceneBehavior::bindBuffers( uf::Object& self, const std::string& re
|
||||
max.z -= floor(controllerTransform.position.z );
|
||||
|
||||
uniforms->matrices.ortho = /*uf::matrix::translate( uf::matrix::identity(), controllerTransform.position ) **/ uf::matrix::ortho( min.x, max.x, min.y, max.y, min.z, max.z );
|
||||
|
||||
#endif
|
||||
uniforms->lengths.materials = std::min( materials.size(), maxTextures );
|
||||
uniforms->lengths.textures = std::min( textures.size(), maxTextures );
|
||||
uniforms->lengths.drawCalls = std::min( drawCalls.size(), maxTextures );
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
|
||||
#include "../light/behavior.h"
|
||||
#include "../scene/behavior.h"
|
||||
#include <uf/ext/ext.h>
|
||||
|
||||
#define COMP_SHADER_USED 1
|
||||
|
||||
@ -25,14 +26,23 @@ void ext::VoxelizerBehavior::initialize( uf::Object& self ) {
|
||||
auto& sceneTextures = this->getComponent<pod::SceneTextures>();
|
||||
// initialize voxel map
|
||||
{
|
||||
const uint32_t DEFAULT_VOXEL_SIZE = sceneMetadataJson["system"]["config"]["engine"]["scenes"]["vxgi"]["size"].as<uint32_t>();
|
||||
const float DEFAULT_VOXELIZE_LIMITER = sceneMetadataJson["system"]["config"]["engine"]["scenes"]["vxgi"]["limiter"].as<float>();
|
||||
const uint32_t DEFAULT_VOXEL_SIZE = ext::config["engine"]["scenes"]["vxgi"]["size"].as<uint32_t>(256);
|
||||
const float DEFAULT_VOXELIZE_LIMITER = ext::config["engine"]["scenes"]["vxgi"]["limiter"].as<float>(0);
|
||||
const uint32_t DEFAULT_DISPATCH_LIMITER = ext::config["engine"]["scenes"]["vxgi"]["dispatch"].as<uint32_t>(8);
|
||||
|
||||
if ( metadata.voxelSize.x == 0 ) metadata.voxelSize.x = DEFAULT_VOXEL_SIZE;
|
||||
if ( metadata.voxelSize.y == 0 ) metadata.voxelSize.y = DEFAULT_VOXEL_SIZE;
|
||||
if ( metadata.voxelSize.z == 0 ) metadata.voxelSize.z = DEFAULT_VOXEL_SIZE;
|
||||
|
||||
if ( metadata.renderer.limiter == 0 ) metadata.renderer.limiter = DEFAULT_VOXELIZE_LIMITER;
|
||||
|
||||
if ( metadata.dispatchSize.x == 0 ) metadata.dispatchSize.x = DEFAULT_DISPATCH_LIMITER;
|
||||
if ( metadata.dispatchSize.y == 0 ) metadata.dispatchSize.y = DEFAULT_DISPATCH_LIMITER;
|
||||
if ( metadata.dispatchSize.z == 0 ) metadata.dispatchSize.z = DEFAULT_DISPATCH_LIMITER;
|
||||
|
||||
metadata.extents.min = uf::vector::decode( ext::config["engine"]["scenes"]["vxgi"]["extents"]["min"], pod::Vector3f{-32, -32, -32} );
|
||||
metadata.extents.max = uf::vector::decode( ext::config["engine"]["scenes"]["vxgi"]["extents"]["max"], pod::Vector3f{ 32, 32, 32} );
|
||||
|
||||
std::vector<uint8_t> empty(metadata.voxelSize.x * metadata.voxelSize.y * metadata.voxelSize.z * sizeof(uint8_t) * 4);
|
||||
|
||||
sceneTextures.voxels.id.sampler.descriptor.filter.min = VK_FILTER_NEAREST;
|
||||
@ -131,6 +141,11 @@ void ext::VoxelizerBehavior::tick( uf::Object& self ) {
|
||||
|
||||
auto& metadata = this->getComponent<ext::VoxelizerBehavior::Metadata>();
|
||||
auto& renderMode = this->getComponent<uf::renderer::RenderTargetRenderMode>();
|
||||
|
||||
auto& scene = uf::scene::getCurrentScene();
|
||||
auto& sceneTextures = scene.getComponent<pod::SceneTextures>();
|
||||
auto& controller = scene.getController();
|
||||
auto& controllerTransform = controller.getComponent<pod::Transform<>>();
|
||||
renderMode.setTarget("");
|
||||
if ( renderMode.executed ) {
|
||||
if ( !metadata.initialized ) metadata.initialized = true;
|
||||
@ -144,14 +159,50 @@ void ext::VoxelizerBehavior::tick( uf::Object& self ) {
|
||||
renderMode.execute = false;
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
if ( renderMode.execute ) {
|
||||
pod::Vector3f min = metadata.extents.min;
|
||||
pod::Vector3f max = metadata.extents.max;
|
||||
|
||||
min.x += floor(controllerTransform.position.x);
|
||||
min.y -= floor(controllerTransform.position.y);
|
||||
min.z -= floor(controllerTransform.position.z);
|
||||
|
||||
max.x += floor(controllerTransform.position.x);
|
||||
max.y -= floor(controllerTransform.position.y);
|
||||
max.z -= floor(controllerTransform.position.z);
|
||||
sceneTextures.voxels.matrix = uf::matrix::ortho<float>( min.x, max.x, min.y, max.y, min.z, max.z );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#if COMP_SHADER_USED
|
||||
auto& scene = uf::scene::getCurrentScene();
|
||||
ext::ExtSceneBehavior::bindBuffers( scene, metadata.renderModeName, true );
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
void ext::VoxelizerBehavior::render( uf::Object& self ){}
|
||||
void ext::VoxelizerBehavior::render( uf::Object& self ){
|
||||
auto& metadata = this->getComponent<ext::VoxelizerBehavior::Metadata>();
|
||||
auto& renderMode = this->getComponent<uf::renderer::RenderTargetRenderMode>();
|
||||
|
||||
auto& scene = uf::scene::getCurrentScene();
|
||||
auto& sceneTextures = scene.getComponent<pod::SceneTextures>();
|
||||
auto& controller = scene.getController();
|
||||
auto& controllerTransform = controller.getComponent<pod::Transform<>>();
|
||||
|
||||
if ( uf::renderer::currentRenderMode->getName() != "RenderTarget" && renderMode.execute ) {
|
||||
pod::Vector3f min = metadata.extents.min;
|
||||
pod::Vector3f max = metadata.extents.max;
|
||||
|
||||
min.x += floor(controllerTransform.position.x);
|
||||
min.y -= floor(controllerTransform.position.y);
|
||||
min.z -= floor(controllerTransform.position.z);
|
||||
|
||||
max.x += floor(controllerTransform.position.x);
|
||||
max.y -= floor(controllerTransform.position.y);
|
||||
max.z -= floor(controllerTransform.position.z);
|
||||
sceneTextures.voxels.matrix = uf::matrix::ortho<float>( min.x, max.x, min.y, max.y, min.z, max.z );
|
||||
}
|
||||
}
|
||||
void ext::VoxelizerBehavior::destroy( uf::Object& self ){
|
||||
#if UF_USE_VULKAN
|
||||
if ( this->hasComponent<uf::renderer::RenderTargetRenderMode>() ) {
|
||||
|
||||
@ -17,8 +17,8 @@ namespace ext {
|
||||
void destroy( uf::Object& );
|
||||
struct Metadata {
|
||||
pod::Vector3ui fragmentSize = { 0, 0 };
|
||||
pod::Vector3ui voxelSize = { 256, 256, 256 };
|
||||
pod::Vector3ui dispatchSize = { 8, 8, 8 };
|
||||
pod::Vector3ui voxelSize = { 0, 0, 0 };
|
||||
pod::Vector3ui dispatchSize = { 0, 0, 0 };
|
||||
std::string renderModeName = "VXGI";
|
||||
struct {
|
||||
pod::Vector3f min = {};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user