diff --git a/bin/data/shaders/display/subpass.frag.glsl b/bin/data/shaders/display/subpass.frag.glsl index bf2dec1f..e74d28c7 100644 --- a/bin/data/shaders/display/subpass.frag.glsl +++ b/bin/data/shaders/display/subpass.frag.glsl @@ -502,7 +502,7 @@ void main() { 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 ( light.type == 0 ) fragColor.rgb += (diffuseBRDF) * Lr * cosLi; + else if ( abs(light.type) == 1 ) fragColor.rgb += (diffuseBRDF) * Lr * cosLi; else fragColor.rgb += (diffuseBRDF + specularBRDF) * Lr * cosLi; litFactor += light.power * La * Ls; } diff --git a/bin/data/shaders/display/subpass.vxgi.frag.glsl b/bin/data/shaders/display/subpass.vxgi.frag.glsl index 7292ecb2..447ed653 100644 --- a/bin/data/shaders/display/subpass.vxgi.frag.glsl +++ b/bin/data/shaders/display/subpass.vxgi.frag.glsl @@ -2,7 +2,9 @@ #extension GL_EXT_samplerless_texture_functions : require #define MULTISAMPLING 1 +#define FOG 1 #define RAY_MARCH_FOG 1 +#define WHITENOISE 1 #define DEFERRED_SAMPLING 0 #define SHADOW_CONE_TRACED 0 #define VOXEL_TRACE_IN_NDC 0 @@ -197,7 +199,6 @@ layout (location = 0) in vec2 inUv; layout (location = 1) in flat uint inPushConstantPass; layout (location = 0) out vec4 outFragColor; -layout (location = 1) out vec4 outDebugValue; // GGX/Towbridge-Reitz normal distribution function. // Uses Disney's reparametrization of alpha = roughness^2. @@ -422,14 +423,14 @@ vec4 voxelConeTrace( vec3 rayO, vec3 rayD, float aperture, float maxDistance ) { rayO = vec3( ubo.matrices.voxel * vec4( rayO, 1.0 ) ); rayD = vec3( ubo.matrices.voxel * vec4( rayD, 0.0 ) ); #endif - const float granularity = 1.0 / 6.0; // (2.0 * sqrt(2.0) ); + const float granularity = 12.0f; // 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 / granularity; + const uint maxSteps = uint(voxelInfo.albedoSize * granularity); // marcher float t = tStart + tDelta * 2.0; vec3 rayPos = vec3(0); @@ -456,7 +457,9 @@ vec4 voxelConeTrace( vec3 rayO, vec3 rayD, float aperture, float maxDistance ) { 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 = texture(voxelAlbedo, uvw, level); // / granularity; + // radiance /= granularity; + // if ( aperture < EPSILON && color.a > EPSILON ) radiance *= granularity; color += (1.0 - color.a) * radiance; occlusion += ((1.0f - occlusion) * radiance.a) / (1.0f + falloff * coneDiameter); @@ -568,10 +571,10 @@ void main() { const vec3 N = normal.world; const float DIFFUSE_CONE_APERTURE = 0.57735f; - const float DIFFUSE_INDIRECT_FACTOR = 1.0f; + const float DIFFUSE_INDIRECT_FACTOR = 0.125f; // 1.0f; const float SPECULAR_CONE_APERTURE = clamp(tan(PI * 0.5f * R), 0.0174533f, PI); - const float SPECULAR_INDIRECT_FACTOR = 1.0f; + const float SPECULAR_INDIRECT_FACTOR = 1.0 - M; // 1.0f; const vec4 CONES[] = { vec4(0.0f, 1.0f, 0.0f, PI / 4.0f), @@ -581,7 +584,7 @@ void main() { vec4(-0.50937f, 0.5f, -0.7006629f, 3.0f * PI / 20.0f), vec4(-0.823639f, 0.5f, 0.267617f, 3.0f * PI / 20.0f) }; - if ( DIFFUSE_INDIRECT_FACTOR > 0.0f ) { + { voxelInfo.albedoSize = textureSize( voxelAlbedo, 0 ).x; voxelInfo.mipmapLevels = textureQueryLod( voxelAlbedo, vec3(0) ).x; #if VOXEL_TRACE_IN_NDC @@ -595,7 +598,10 @@ void main() { voxelInfo.voxelSize = 1; #endif } - if ( SPECULAR_INDIRECT_FACTOR > 0.0f ) { + + // outFragColor.rgb = voxelConeTrace( rayO, rayD, 0 ).rgb; return; + + if ( DIFFUSE_INDIRECT_FACTOR > 0.0f ) { vec3 guide = vec3(0.0f, 1.0f, 0.0f); if (abs(dot(N,guide)) == 1.0f) guide = vec3(0.0f, 0.0f, 1.0f); @@ -609,12 +615,12 @@ void main() { AO = indirectDiffuse.a; // outFragColor.rgb = indirectDiffuse.rgb; return; } - { + if ( SPECULAR_INDIRECT_FACTOR > 0.0f ) { const vec3 R = reflect( normalize(P - rayO), N ); indirectSpecular = voxelConeTrace( P, R, SPECULAR_CONE_APERTURE ); - indirectLighting = indirectDiffuse * DIFFUSE_INDIRECT_FACTOR + indirectSpecular * SPECULAR_INDIRECT_FACTOR; // outFragColor.rgb = indirectSpecular.rgb; return; } + indirectLighting = indirectDiffuse * DIFFUSE_INDIRECT_FACTOR + indirectSpecular * SPECULAR_INDIRECT_FACTOR; // outFragColor.rgb = indirectLighting.rgb; return; } @@ -625,11 +631,11 @@ void main() { fragColor = A.rgb * ubo.ambient.rgb * (1 - AO) + indirectLighting.rgb; } { + const float R = material.factorRoughness * 2.0f; const vec3 N = normal.eye; 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)); - #if 0 for ( uint i = 0; i < ubo.lights; ++i ) { const Light light = lights[i]; if ( light.power <= LIGHT_POWER_CUTOFF ) continue; @@ -651,26 +657,27 @@ void main() { 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; litFactor += light.power * La * Ls; } - #endif } - +#if FOG fog(rayO, rayD, fragColor, 1.0 ); //litFactor); - +#endif #if TONE_MAP fragColor = vec3(1.0) - exp(-fragColor * ubo.exposure); #endif #if GAMMA_CORRECT fragColor = pow(fragColor, vec3(1.0 / ubo.gamma)); #endif - - if ( (ubo.mode.type & (0x1 << 1)) == (0x1 << 1) ) { - whitenoise(fragColor); - } +#if WHITENOISE + if ( (ubo.mode.type & (0x1 << 1)) == (0x1 << 1) ) whitenoise(fragColor); +#endif outFragColor = vec4(fragColor,1); } \ No newline at end of file diff --git a/bin/data/shaders/display/vxgi.comp.glsl b/bin/data/shaders/display/vxgi.comp.glsl index 59d8621f..95f35bb5 100644 --- a/bin/data/shaders/display/vxgi.comp.glsl +++ b/bin/data/shaders/display/vxgi.comp.glsl @@ -318,6 +318,8 @@ void main() { fragColor = A.rgb * ubo.ambient.rgb * (1 - AO); } { + 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 ); @@ -345,8 +347,10 @@ void main() { 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 ( light.type == 0 ) fragColor.rgb += (diffuseBRDF) * 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; litFactor += light.power * La * Ls; } } diff --git a/ext/behaviors/player/model/behavior.cpp b/ext/behaviors/player/model/behavior.cpp index 9b72c61c..9b7b4deb 100644 --- a/ext/behaviors/player/model/behavior.cpp +++ b/ext/behaviors/player/model/behavior.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include UF_BEHAVIOR_REGISTER_CPP(ext::PlayerModelBehavior) @@ -20,8 +21,20 @@ void ext::PlayerModelBehavior::initialize( uf::Object& self ) { auto& controller = scene.getController(); auto& controllerTransform = controller.getComponent>(); auto& transform = this->getComponent>(); - auto& metadata = this->getComponent(); + auto& metadataJson = this->getComponent(); transform.reference = &controllerTransform; + + auto& metadata = this->getComponent(); + metadata.serialize = [&]() { + metadataJson["hide player model"] = metadata.hide; + }; + metadata.deserialize = [&](){ + metadata.hide = metadataJson["hide player model"].as(); + metadata.scale = transform.scale; + }; + this->addHook( "object:UpdateMetadata.%UID%", metadata.deserialize); + this->addHook( "object:Reload.%UID%", metadata.deserialize); + metadata.deserialize(); } void ext::PlayerModelBehavior::tick( uf::Object& self ) { if ( this->getChildren().size() != 1 ) return; @@ -30,18 +43,26 @@ void ext::PlayerModelBehavior::tick( uf::Object& self ) { auto& controller = scene.getController(); auto& controllerTransform = controller.getComponent>(); auto& transform = this->getComponent>(); +/* if ( metadata["track via reference"].as() ) transform.reference = metadata["track player"].as() ? &controllerTransform : NULL; else if ( metadata["track player"].as() ) { transform.position = controllerTransform.position; transform.orientation = controllerTransform.orientation; } +*/ + +#if UF_ENTITY_METADATA_USE_JSON + metadata.deserialize(); +#endif } void ext::PlayerModelBehavior::render( uf::Object& self ){ if ( this->getChildren().size() != 1 ) return; - auto& metadata = this->getComponent(); - if ( !metadata["hide player model"].as() ) return; +// auto& metadata = this->getComponent(); +// if ( !metadata["hide player model"].as() ) return; + auto& metadata = this->getComponent(); + if ( !metadata.hide ) return; auto& scene = uf::scene::getCurrentScene(); auto& controller = scene.getController(); @@ -49,10 +70,12 @@ void ext::PlayerModelBehavior::render( uf::Object& self ){ auto& model = this->getChildren().front()->as(); auto& transform = this->getComponent>(); - if ( player.getUid() == controller.getUid() ) { +// auto& renderMode = *uf::renderer::currentRenderMode; +// if ( renderMode.getType() == "Deferred" ) { + if ( player.getUid() == controller.getUid() && uf::renderer::currentRenderMode->getName() != "RenderTarget" ) { transform.scale = { 0, 0, 0 }; } else { - transform.scale = uf::vector::decode( metadata["system"]["transform"]["scale"], pod::Vector3f{1,1,1} ); + transform.scale = metadata.scale; } } void ext::PlayerModelBehavior::destroy( uf::Object& self ){ diff --git a/ext/behaviors/player/model/behavior.h b/ext/behaviors/player/model/behavior.h index de6ce387..fc9c860e 100644 --- a/ext/behaviors/player/model/behavior.h +++ b/ext/behaviors/player/model/behavior.h @@ -4,6 +4,7 @@ #include #include #include +#include namespace ext { namespace PlayerModelBehavior { @@ -13,5 +14,13 @@ namespace ext { void tick( uf::Object& ); void render( uf::Object& ); void destroy( uf::Object& ); + + struct Metadata { + bool hide = true; + pod::Vector3f scale = {1,1,1}; + + std::function serialize; + std::function deserialize; + }; } } \ No newline at end of file diff --git a/ext/behaviors/scene/behavior.cpp b/ext/behaviors/scene/behavior.cpp index e2e9597d..774b119d 100644 --- a/ext/behaviors/scene/behavior.cpp +++ b/ext/behaviors/scene/behavior.cpp @@ -242,8 +242,6 @@ void ext::ExtSceneBehavior::initialize( uf::Object& self ) { metadata.fog.density.threshold = metadataJson["light"]["fog"]["density"]["threshold"].as(); metadata.fog.density.multiplier = metadataJson["light"]["fog"]["density"]["multiplier"].as(); metadata.fog.density.scale = metadataJson["light"]["fog"]["density"]["scale"].as(); - - UF_DEBUG_MSG( metadata.light.exposure << " | " << metadata.light.gamma ); #if UF_USE_OPENGL_FIXED_FUNCTION uf::renderer::states::rebuild = true; #endif