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 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;
}

View File

@ -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);
}

View File

@ -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;
}
}

View File

@ -10,6 +10,7 @@
#include <uf/utils/audio/audio.h>
#include <uf/ext/openvr/openvr.h>
#include <uf/utils/math/physics.h>
#include <uf/utils/renderer/renderer.h>
#include <mutex>
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<pod::Transform<>>();
auto& transform = this->getComponent<pod::Transform<>>();
auto& metadata = this->getComponent<uf::Serializer>();
auto& metadataJson = this->getComponent<uf::Serializer>();
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 ) {
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<pod::Transform<>>();
auto& transform = this->getComponent<pod::Transform<>>();
/*
if ( metadata["track via reference"].as<bool>() )
transform.reference = metadata["track player"].as<bool>() ? &controllerTransform : NULL;
else if ( metadata["track player"].as<bool>() ) {
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<uf::Serializer>();
if ( !metadata["hide player model"].as<bool>() ) return;
// auto& metadata = this->getComponent<uf::Serializer>();
// 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& controller = scene.getController();
@ -49,10 +70,12 @@ void ext::PlayerModelBehavior::render( uf::Object& self ){
auto& model = this->getChildren().front()->as<uf::Object>();
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 };
} 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 ){

View File

@ -4,6 +4,7 @@
#include <uf/ext/ext.h>
#include <uf/engine/entity/entity.h>
#include <uf/engine/scene/scene.h>
#include <uf/utils/math/vector.h>
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<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.multiplier = metadataJson["light"]["fog"]["density"]["multiplier"].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
uf::renderer::states::rebuild = true;
#endif