Commit for 2021.04.27.7z

This commit is contained in:
mrq 2021-04-27 00:00:00 -05:00
parent 1fbf98155f
commit 89296ac169
6 changed files with 69 additions and 28 deletions

View File

@ -502,7 +502,7 @@ void main() {
const vec3 diffuseBRDF = mix( vec3(1.0) - F, vec3(0.0), M ) * A.rgb; 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); const vec3 specularBRDF = (F * D * G) / max(EPSILON, 4.0 * cosLi * cosLo);
if ( light.type >= 0 && 0 <= material.indexLightmap ) fragColor.rgb += (specularBRDF) * Lr * cosLi; 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; else fragColor.rgb += (diffuseBRDF + specularBRDF) * Lr * cosLi;
litFactor += light.power * La * Ls; litFactor += light.power * La * Ls;
} }

View File

@ -2,7 +2,9 @@
#extension GL_EXT_samplerless_texture_functions : require #extension GL_EXT_samplerless_texture_functions : require
#define MULTISAMPLING 1 #define MULTISAMPLING 1
#define FOG 1
#define RAY_MARCH_FOG 1 #define RAY_MARCH_FOG 1
#define WHITENOISE 1
#define DEFERRED_SAMPLING 0 #define DEFERRED_SAMPLING 0
#define SHADOW_CONE_TRACED 0 #define SHADOW_CONE_TRACED 0
#define VOXEL_TRACE_IN_NDC 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 = 1) in flat uint inPushConstantPass;
layout (location = 0) out vec4 outFragColor; layout (location = 0) out vec4 outFragColor;
layout (location = 1) out vec4 outDebugValue;
// GGX/Towbridge-Reitz normal distribution function. // GGX/Towbridge-Reitz normal distribution function.
// Uses Disney's reparametrization of alpha = roughness^2. // 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 ) ); rayO = vec3( ubo.matrices.voxel * vec4( rayO, 1.0 ) );
rayD = vec3( ubo.matrices.voxel * vec4( rayD, 0.0 ) ); rayD = vec3( ubo.matrices.voxel * vec4( rayD, 0.0 ) );
#endif #endif
const float granularity = 1.0 / 6.0; // (2.0 * sqrt(2.0) ); const float granularity = 12.0f;
// box // box
const vec2 rayBoxInfo = rayBoxDst( voxelInfo.min, voxelInfo.max, rayO, rayD ); const vec2 rayBoxInfo = rayBoxDst( voxelInfo.min, voxelInfo.max, rayO, rayD );
const float tStart = rayBoxInfo.x; const float tStart = rayBoxInfo.x;
const float tEnd = maxDistance > 0 ? min(maxDistance, rayBoxInfo.y) : rayBoxInfo.y; const float tEnd = maxDistance > 0 ? min(maxDistance, rayBoxInfo.y) : rayBoxInfo.y;
// steps // steps
const float tDelta = voxelInfo.voxelSize * granularity; const float tDelta = voxelInfo.voxelSize / granularity;
const uint maxSteps = uint(voxelInfo.albedoSize / granularity); const uint maxSteps = uint(voxelInfo.albedoSize * granularity);
// marcher // marcher
float t = tStart + tDelta * 2.0; float t = tStart + tDelta * 2.0;
vec3 rayPos = vec3(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; if ( abs(uvw.x) > 1.0 || abs(uvw.y) > 1.0 || abs(uvw.z) > 1.0 ) break;
coneDiameter = coneCoefficient * t; coneDiameter = coneCoefficient * t;
level = log2( coneDiameter / voxelInfo.albedoSize ); 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; color += (1.0 - color.a) * radiance;
occlusion += ((1.0f - occlusion) * radiance.a) / (1.0f + falloff * coneDiameter); occlusion += ((1.0f - occlusion) * radiance.a) / (1.0f + falloff * coneDiameter);
@ -568,10 +571,10 @@ void main() {
const vec3 N = normal.world; const vec3 N = normal.world;
const float DIFFUSE_CONE_APERTURE = 0.57735f; 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_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[] = { const vec4 CONES[] = {
vec4(0.0f, 1.0f, 0.0f, PI / 4.0f), 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.50937f, 0.5f, -0.7006629f, 3.0f * PI / 20.0f),
vec4(-0.823639f, 0.5f, 0.267617f, 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.albedoSize = textureSize( voxelAlbedo, 0 ).x;
voxelInfo.mipmapLevels = textureQueryLod( voxelAlbedo, vec3(0) ).x; voxelInfo.mipmapLevels = textureQueryLod( voxelAlbedo, vec3(0) ).x;
#if VOXEL_TRACE_IN_NDC #if VOXEL_TRACE_IN_NDC
@ -595,7 +598,10 @@ void main() {
voxelInfo.voxelSize = 1; voxelInfo.voxelSize = 1;
#endif #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); vec3 guide = vec3(0.0f, 1.0f, 0.0f);
if (abs(dot(N,guide)) == 1.0f) guide = vec3(0.0f, 0.0f, 1.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; AO = indirectDiffuse.a;
// outFragColor.rgb = indirectDiffuse.rgb; return; // outFragColor.rgb = indirectDiffuse.rgb; return;
} }
{ 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 ); indirectSpecular = voxelConeTrace( P, R, SPECULAR_CONE_APERTURE );
indirectLighting = indirectDiffuse * DIFFUSE_INDIRECT_FACTOR + indirectSpecular * SPECULAR_INDIRECT_FACTOR;
// outFragColor.rgb = indirectSpecular.rgb; return; // outFragColor.rgb = indirectSpecular.rgb; return;
} }
indirectLighting = indirectDiffuse * DIFFUSE_INDIRECT_FACTOR + indirectSpecular * SPECULAR_INDIRECT_FACTOR;
// outFragColor.rgb = indirectLighting.rgb; return; // outFragColor.rgb = indirectLighting.rgb; return;
} }
@ -625,11 +631,11 @@ void main() {
fragColor = A.rgb * ubo.ambient.rgb * (1 - AO) + indirectLighting.rgb; fragColor = A.rgb * ubo.ambient.rgb * (1 - AO) + indirectLighting.rgb;
} }
{ {
const float R = material.factorRoughness * 2.0f;
const vec3 N = normal.eye; const vec3 N = normal.eye;
const vec3 F0 = mix(vec3(0.04), A.rgb, M); const vec3 F0 = mix(vec3(0.04), A.rgb, M);
const vec3 Lo = normalize( -position.eye ); const vec3 Lo = normalize( -position.eye );
const float cosLo = max(0.0, dot(N, Lo)); const float cosLo = max(0.0, dot(N, Lo));
#if 0
for ( uint i = 0; i < ubo.lights; ++i ) { for ( uint i = 0; i < ubo.lights; ++i ) {
const Light light = lights[i]; const Light light = lights[i];
if ( light.power <= LIGHT_POWER_CUTOFF ) continue; if ( light.power <= LIGHT_POWER_CUTOFF ) continue;
@ -651,26 +657,27 @@ void main() {
const float G = gaSchlickGGX(cosLi, cosLo, R); const float G = gaSchlickGGX(cosLi, cosLo, R);
const vec3 diffuseBRDF = mix( vec3(1.0) - F, vec3(0.0), M ) * A.rgb; 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); const vec3 specularBRDF = (F * D * G) / max(EPSILON, 4.0 * cosLi * cosLo);
if ( light.type >= 0 && 0 <= material.indexLightmap ) fragColor.rgb += (specularBRDF) * Lr * cosLi; if ( light.type >= 0 && 0 <= material.indexLightmap ) fragColor.rgb += (specularBRDF) * Lr * cosLi;
// else if ( abs(light.type) == 1 ) fragColor.rgb += (diffuseBRDF) * Lr * cosLi; // else if ( abs(light.type) == 1 ) fragColor.rgb += (diffuseBRDF) * Lr * cosLi;
else fragColor.rgb += (diffuseBRDF + specularBRDF) * Lr * cosLi; else fragColor.rgb += (diffuseBRDF + specularBRDF) * Lr * cosLi;
// if ( !(0 <= material.indexLightmap) ) fragColor.rgb += (diffuseBRDF) * Lr * cosLi;
litFactor += light.power * La * Ls; litFactor += light.power * La * Ls;
} }
#endif
} }
#if FOG
fog(rayO, rayD, fragColor, 1.0 ); //litFactor); fog(rayO, rayD, fragColor, 1.0 ); //litFactor);
#endif
#if TONE_MAP #if TONE_MAP
fragColor = vec3(1.0) - exp(-fragColor * ubo.exposure); fragColor = vec3(1.0) - exp(-fragColor * ubo.exposure);
#endif #endif
#if GAMMA_CORRECT #if GAMMA_CORRECT
fragColor = pow(fragColor, vec3(1.0 / ubo.gamma)); fragColor = pow(fragColor, vec3(1.0 / ubo.gamma));
#endif #endif
#if WHITENOISE
if ( (ubo.mode.type & (0x1 << 1)) == (0x1 << 1) ) { if ( (ubo.mode.type & (0x1 << 1)) == (0x1 << 1) ) whitenoise(fragColor);
whitenoise(fragColor); #endif
}
outFragColor = vec4(fragColor,1); outFragColor = vec4(fragColor,1);
} }

View File

@ -318,6 +318,8 @@ void main() {
fragColor = A.rgb * ubo.ambient.rgb * (1 - AO); fragColor = A.rgb * ubo.ambient.rgb * (1 - AO);
} }
{ {
const float R = material.factorRoughness * 2.0f;
const vec3 N = normal.world; const vec3 N = normal.world;
const vec3 F0 = mix(vec3(0.04), A.rgb, M); const vec3 F0 = mix(vec3(0.04), A.rgb, M);
const vec3 Lo = normalize( -position.world ); 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 diffuseBRDF = mix( vec3(1.0) - F, vec3(0.0), M ) * A.rgb;
const vec3 specularBRDF = (F * D * G) / max(EPSILON, 4.0 * cosLi * cosLo); const vec3 specularBRDF = (F * D * G) / max(EPSILON, 4.0 * cosLi * cosLo);
if ( light.type >= 0 && 0 <= material.indexLightmap ) fragColor.rgb += (specularBRDF) * Lr * cosLi; 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; else fragColor.rgb += (diffuseBRDF + specularBRDF) * Lr * cosLi;
if ( !(0 <= material.indexLightmap) ) fragColor.rgb += (diffuseBRDF) * Lr * cosLi;
litFactor += light.power * La * Ls; litFactor += light.power * La * Ls;
} }
} }

View File

@ -10,6 +10,7 @@
#include <uf/utils/audio/audio.h> #include <uf/utils/audio/audio.h>
#include <uf/ext/openvr/openvr.h> #include <uf/ext/openvr/openvr.h>
#include <uf/utils/math/physics.h> #include <uf/utils/math/physics.h>
#include <uf/utils/renderer/renderer.h>
#include <mutex> #include <mutex>
UF_BEHAVIOR_REGISTER_CPP(ext::PlayerModelBehavior) UF_BEHAVIOR_REGISTER_CPP(ext::PlayerModelBehavior)
@ -20,8 +21,20 @@ void ext::PlayerModelBehavior::initialize( uf::Object& self ) {
auto& controller = scene.getController(); auto& controller = scene.getController();
auto& controllerTransform = controller.getComponent<pod::Transform<>>(); auto& controllerTransform = controller.getComponent<pod::Transform<>>();
auto& transform = this->getComponent<pod::Transform<>>(); auto& transform = this->getComponent<pod::Transform<>>();
auto& metadata = this->getComponent<uf::Serializer>(); auto& metadataJson = this->getComponent<uf::Serializer>();
transform.reference = &controllerTransform; transform.reference = &controllerTransform;
auto& metadata = this->getComponent<ext::PlayerModelBehavior::Metadata>();
metadata.serialize = [&]() {
metadataJson["hide player model"] = metadata.hide;
};
metadata.deserialize = [&](){
metadata.hide = metadataJson["hide player model"].as<bool>();
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 ) { void ext::PlayerModelBehavior::tick( uf::Object& self ) {
if ( this->getChildren().size() != 1 ) return; if ( this->getChildren().size() != 1 ) return;
@ -30,18 +43,26 @@ void ext::PlayerModelBehavior::tick( uf::Object& self ) {
auto& controller = scene.getController(); auto& controller = scene.getController();
auto& controllerTransform = controller.getComponent<pod::Transform<>>(); auto& controllerTransform = controller.getComponent<pod::Transform<>>();
auto& transform = this->getComponent<pod::Transform<>>(); auto& transform = this->getComponent<pod::Transform<>>();
/*
if ( metadata["track via reference"].as<bool>() ) if ( metadata["track via reference"].as<bool>() )
transform.reference = metadata["track player"].as<bool>() ? &controllerTransform : NULL; transform.reference = metadata["track player"].as<bool>() ? &controllerTransform : NULL;
else if ( metadata["track player"].as<bool>() ) { else if ( metadata["track player"].as<bool>() ) {
transform.position = controllerTransform.position; transform.position = controllerTransform.position;
transform.orientation = controllerTransform.orientation; transform.orientation = controllerTransform.orientation;
} }
*/
#if UF_ENTITY_METADATA_USE_JSON
metadata.deserialize();
#endif
} }
void ext::PlayerModelBehavior::render( uf::Object& self ){ void ext::PlayerModelBehavior::render( uf::Object& self ){
if ( this->getChildren().size() != 1 ) return; if ( this->getChildren().size() != 1 ) return;
auto& metadata = this->getComponent<uf::Serializer>(); // auto& metadata = this->getComponent<uf::Serializer>();
if ( !metadata["hide player model"].as<bool>() ) return; // if ( !metadata["hide player model"].as<bool>() ) return;
auto& metadata = this->getComponent<ext::PlayerModelBehavior::Metadata>();
if ( !metadata.hide ) return;
auto& scene = uf::scene::getCurrentScene(); auto& scene = uf::scene::getCurrentScene();
auto& controller = scene.getController(); auto& controller = scene.getController();
@ -49,10 +70,12 @@ void ext::PlayerModelBehavior::render( uf::Object& self ){
auto& model = this->getChildren().front()->as<uf::Object>(); auto& model = this->getChildren().front()->as<uf::Object>();
auto& transform = this->getComponent<pod::Transform<>>(); auto& transform = this->getComponent<pod::Transform<>>();
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 }; transform.scale = { 0, 0, 0 };
} else { } 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 ){ void ext::PlayerModelBehavior::destroy( uf::Object& self ){

View File

@ -4,6 +4,7 @@
#include <uf/ext/ext.h> #include <uf/ext/ext.h>
#include <uf/engine/entity/entity.h> #include <uf/engine/entity/entity.h>
#include <uf/engine/scene/scene.h> #include <uf/engine/scene/scene.h>
#include <uf/utils/math/vector.h>
namespace ext { namespace ext {
namespace PlayerModelBehavior { namespace PlayerModelBehavior {
@ -13,5 +14,13 @@ namespace ext {
void tick( uf::Object& ); void tick( uf::Object& );
void render( uf::Object& ); void render( uf::Object& );
void destroy( uf::Object& ); void destroy( uf::Object& );
struct Metadata {
bool hide = true;
pod::Vector3f scale = {1,1,1};
std::function<void()> serialize;
std::function<void()> deserialize;
};
} }
} }

View File

@ -242,8 +242,6 @@ void ext::ExtSceneBehavior::initialize( uf::Object& self ) {
metadata.fog.density.threshold = metadataJson["light"]["fog"]["density"]["threshold"].as<float>(); metadata.fog.density.threshold = metadataJson["light"]["fog"]["density"]["threshold"].as<float>();
metadata.fog.density.multiplier = metadataJson["light"]["fog"]["density"]["multiplier"].as<float>(); metadata.fog.density.multiplier = metadataJson["light"]["fog"]["density"]["multiplier"].as<float>();
metadata.fog.density.scale = metadataJson["light"]["fog"]["density"]["scale"].as<float>(); metadata.fog.density.scale = metadataJson["light"]["fog"]["density"]["scale"].as<float>();
UF_DEBUG_MSG( metadata.light.exposure << " | " << metadata.light.gamma );
#if UF_USE_OPENGL_FIXED_FUNCTION #if UF_USE_OPENGL_FIXED_FUNCTION
uf::renderer::states::rebuild = true; uf::renderer::states::rebuild = true;
#endif #endif