From a619a142ed3ac771670ff27a2fef7743bd493276 Mon Sep 17 00:00:00 2001 From: samcake Date: Fri, 24 Jun 2016 17:48:40 -0700 Subject: [PATCH] Friday night build, working on getting the LUT generated on the GPU --- libraries/fbx/src/FBXReader.cpp | 2 +- .../render-utils/src/DeferredGlobalLight.slh | 4 +- .../render-utils/src/DeferredLightingEffect.h | 2 +- .../render-utils/src/SubsurfaceScattering.cpp | 11 ++--- .../render-utils/src/SubsurfaceScattering.h | 2 +- .../render-utils/src/SubsurfaceScattering.slh | 1 + .../render-utils/src/SurfaceGeometryPass.h | 2 +- .../src/subsurfaceScattering_makeLUT.slf | 48 ++++++++++++++++--- .../src/surfaceGeometry_makeCurvature.slf | 2 +- libraries/ui/src/QmlWindowClass.cpp | 2 +- .../render/configSlider/ConfigSlider.qml | 4 +- .../utilities/render/deferredLighting.qml | 5 ++ 12 files changed, 62 insertions(+), 23 deletions(-) diff --git a/libraries/fbx/src/FBXReader.cpp b/libraries/fbx/src/FBXReader.cpp index 1fb67f1ace..8c9cdb2110 100644 --- a/libraries/fbx/src/FBXReader.cpp +++ b/libraries/fbx/src/FBXReader.cpp @@ -462,7 +462,7 @@ FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QS QVector blendshapes; QHash models; - QHash clusters; + QHash clusters; QHash animationCurves; QHash typeFlags; diff --git a/libraries/render-utils/src/DeferredGlobalLight.slh b/libraries/render-utils/src/DeferredGlobalLight.slh index 7bb3c9f35d..a5396958ea 100755 --- a/libraries/render-utils/src/DeferredGlobalLight.slh +++ b/libraries/render-utils/src/DeferredGlobalLight.slh @@ -228,8 +228,8 @@ vec3 evalSkyboxGlobalColorScattering(mat4 invViewMat, float shadowAttenuation, f if ( showBRDF()) return brdf; - vec3 debugNdotL = 0.5 * (NdotLSpectrum + vec3(1.0)); - return vec3(debugNdotL.z, curvature, 0.0 ); + //vec3 debugNdotL = 0.5 * (NdotLSpectrum + vec3(1.0)); + //return vec3(debugNdotL.z, curvature, 0.0 ); return vec3(color); } diff --git a/libraries/render-utils/src/DeferredLightingEffect.h b/libraries/render-utils/src/DeferredLightingEffect.h index da1f4ddfd7..85b9038046 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.h +++ b/libraries/render-utils/src/DeferredLightingEffect.h @@ -165,7 +165,7 @@ public: float curvatureScale{ 0.8f }; bool enableScattering{ true }; - bool showScatteringBRDF{ false }; + bool showScatteringBRDF{ true }; bool enablePointLights{ true }; bool enableSpotLights{ true }; diff --git a/libraries/render-utils/src/SubsurfaceScattering.cpp b/libraries/render-utils/src/SubsurfaceScattering.cpp index 968cc1b42f..adc6136cd2 100644 --- a/libraries/render-utils/src/SubsurfaceScattering.cpp +++ b/libraries/render-utils/src/SubsurfaceScattering.cpp @@ -401,10 +401,7 @@ void diffuseScatterGPU(gpu::TexturePointer& profileMap, gpu::TexturePointer& lut gpu::Shader::makeProgram(*program, slotBindings); gpu::StatePointer state = gpu::StatePointer(new gpu::State()); - - // Stencil test the curvature pass for objects pixels only, not the background - // state->setStencilTest(true, 0xFF, gpu::State::StencilTest(0, 0xFF, gpu::NOT_EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); - + makePipeline = gpu::Pipeline::create(program, state); } @@ -469,8 +466,8 @@ gpu::TexturePointer SubsurfaceScatteringResource::generatePreIntegratedScatterin const int WIDTH = 128; const int HEIGHT = 128; - auto scatteringLUT = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element::COLOR_RGBA_32, WIDTH, HEIGHT, gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR))); - diffuseScatter(scatteringLUT); - //diffuseScatterGPU(profileMap, scatteringLUT, args); + auto scatteringLUT = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element::COLOR_SRGBA_32, WIDTH, HEIGHT, gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR))); + //diffuseScatter(scatteringLUT); + diffuseScatterGPU(profileMap, scatteringLUT, args); return scatteringLUT; } diff --git a/libraries/render-utils/src/SubsurfaceScattering.h b/libraries/render-utils/src/SubsurfaceScattering.h index c1d9a609b9..221cd96722 100644 --- a/libraries/render-utils/src/SubsurfaceScattering.h +++ b/libraries/render-utils/src/SubsurfaceScattering.h @@ -54,7 +54,7 @@ protected: glm::vec4 normalBentInfo{ 1.5f, 0.8f, 0.3f, 1.5f }; glm::vec2 curvatureInfo{ 0.08f, 0.8f }; float level{ 1.0f }; - float showBRDF{ 0.0f }; + float showBRDF{ 1.0f }; Parameters() {} }; diff --git a/libraries/render-utils/src/SubsurfaceScattering.slh b/libraries/render-utils/src/SubsurfaceScattering.slh index b002f2dcbd..ac759ab4a2 100644 --- a/libraries/render-utils/src/SubsurfaceScattering.slh +++ b/libraries/render-utils/src/SubsurfaceScattering.slh @@ -51,4 +51,5 @@ float unpackCurvature(float packedCurvature) { } + <@endfunc@> diff --git a/libraries/render-utils/src/SurfaceGeometryPass.h b/libraries/render-utils/src/SurfaceGeometryPass.h index c678ebba0f..697c93b745 100644 --- a/libraries/render-utils/src/SurfaceGeometryPass.h +++ b/libraries/render-utils/src/SurfaceGeometryPass.h @@ -26,7 +26,7 @@ class SurfaceGeometryPassConfig : public render::Job::Config { public: SurfaceGeometryPassConfig() : render::Job::Config(true) {} - float depthThreshold{ 0.1f }; + float depthThreshold{ 0.033f }; float basisScale{ 1.0f }; float curvatureScale{ 10.0f }; diff --git a/libraries/render-utils/src/subsurfaceScattering_makeLUT.slf b/libraries/render-utils/src/subsurfaceScattering_makeLUT.slf index 90c7bfbf4e..41969640b5 100644 --- a/libraries/render-utils/src/subsurfaceScattering_makeLUT.slf +++ b/libraries/render-utils/src/subsurfaceScattering_makeLUT.slf @@ -14,9 +14,40 @@ const float _PI = 3.14159265358979523846; uniform sampler2D profileMap; +/* +vec3 scatter(float r) { + return texture(profileMap, vec2(2.0 * r, 0.5)).xyz; +} +*/ + +float gaussian(float v, float r) { + return (1.0 / sqrt(2.0 * _PI * v)) * exp(-(r*r) / (2.0 * v)); +} vec3 scatter(float r) { - return texture(profileMap, vec2(r * 0.5, 0.5)).xyz; + // Values from GPU Gems 3 "Advanced Skin Rendering". + // Originally taken from real life samples. + vec4 profile[6] = vec4[6]( + vec4(0.0064, 0.233, 0.455, 0.649), + vec4(0.0484, 0.100, 0.336, 0.344), + vec4(0.1870, 0.118, 0.198, 0.000), + vec4(0.5670, 0.113, 0.007, 0.007), + vec4(1.9900, 0.358, 0.004, 0.000), + vec4(7.4100, 0.078, 0.000, 0.000) + ); + //const int profileNum = 6; + + + + + vec3 ret(0.0); + for (int i = 0; i < 6; i++) { + float v = profile[i].x * 1.414; + float g = gaussian(v, r); + ret += g * profile[i].yzw; + } + + return ret; } @@ -32,15 +63,15 @@ vec3 integrate(float cosTheta, float skinRadius) { while (a <= (_PI)) { float sampleAngle = theta + a; - float diffuse = cos(sampleAngle); - if (diffuse < 0.0) diffuse = 0.0; - if (diffuse > 1.0) diffuse = 1.0; + float diffuse = clamp(cos(sampleAngle), 0.0, 1.0); + //if (diffuse < 0.0) diffuse = 0.0; + //if (diffuse > 1.0) diffuse = 1.0; // Distance. float sampleDist = abs(2.0 * skinRadius * sin(a * 0.5)); // Profile Weight. - vec3 weights = scatter(sampleDist); + vec3 weights = scatter( sampleDist); totalWeights += weights; totalLight += diffuse * weights; @@ -48,7 +79,8 @@ vec3 integrate(float cosTheta, float skinRadius) { } vec3 result = (totalLight / totalWeights); - + return clamp(result, vec3(0.0), vec3(1.0)); + return min(sqrt(result), vec3(1.0)); return scatter(skinRadius); @@ -59,6 +91,10 @@ out vec4 outFragColor; void main(void) { + // Lookup by: x: NDotL y: 1 / r + //float y = 2.0 * 1.0 / ((j + 1.0) / (double)height); + //float x = ((i / (double)width) * 2.0) - 1.0; + outFragColor = vec4(integrate(varTexCoord0.x * 2.0 - 1.0, 2.0 / varTexCoord0.y), 1.0); } diff --git a/libraries/render-utils/src/surfaceGeometry_makeCurvature.slf b/libraries/render-utils/src/surfaceGeometry_makeCurvature.slf index 8ca4ddcd7a..f896cb657d 100644 --- a/libraries/render-utils/src/surfaceGeometry_makeCurvature.slf +++ b/libraries/render-utils/src/surfaceGeometry_makeCurvature.slf @@ -120,7 +120,7 @@ void main(void) { // Calculate dF/du and dF/dv vec2 viewportScale = perspectiveScale * getInvWidthHeight(); - vec2 du = vec2( viewportScale.x, 0.0f ); + vec2 du = vec2( viewportScale.x * (stereoSide.w > 0.0 ? 0.5 : 1.0), 0.0f ); vec2 dv = vec2( 0.0f, viewportScale.y ); vec4 dFdu = vec4(getWorldNormalDiff(frameTexcoordPos, du), getEyeDepthDiff(frameTexcoordPos, du)); diff --git a/libraries/ui/src/QmlWindowClass.cpp b/libraries/ui/src/QmlWindowClass.cpp index b8834f0549..c0eba4abf3 100644 --- a/libraries/ui/src/QmlWindowClass.cpp +++ b/libraries/ui/src/QmlWindowClass.cpp @@ -118,7 +118,7 @@ void QmlWindowClass::initQml(QVariantMap properties) { } bool visible = !properties.contains(VISIBILE_PROPERTY) || properties[VISIBILE_PROPERTY].toBool(); - object->setProperty(VISIBILE_PROPERTY, visible); + object->setProperty(OFFSCREEN_VISIBILITY_PROPERTY, visible); object->setProperty(SOURCE_PROPERTY, _source); // Forward messages received from QML on to the script diff --git a/scripts/developer/utilities/render/configSlider/ConfigSlider.qml b/scripts/developer/utilities/render/configSlider/ConfigSlider.qml index 02135056f8..996cf4b34c 100644 --- a/scripts/developer/utilities/render/configSlider/ConfigSlider.qml +++ b/scripts/developer/utilities/render/configSlider/ConfigSlider.qml @@ -39,8 +39,8 @@ Item { Label { text: sliderControl.value.toFixed(root.integral ? 0 : 2) - anchors.left: root.labelControl.right - anchors.leftMargin: 8 + anchors.left: root.left + anchors.leftMargin: 200 anchors.top: root.top anchors.topMargin: 7 } diff --git a/scripts/developer/utilities/render/deferredLighting.qml b/scripts/developer/utilities/render/deferredLighting.qml index 3cb91f54ce..1c9b10a0c3 100644 --- a/scripts/developer/utilities/render/deferredLighting.qml +++ b/scripts/developer/utilities/render/deferredLighting.qml @@ -57,6 +57,11 @@ Column { min: 0.0 } } + CheckBox { + text: "Scattering Table" + checked: Render.getConfig("Scattering").showLUT + onCheckedChanged: { Render.getConfig("Scattering").showLUT = checked } + } } } }