From 378f4576fac407012a4bf4bcbe130f35a9ac18ad Mon Sep 17 00:00:00 2001 From: samcake Date: Sun, 17 Jul 2016 20:18:06 -0700 Subject: [PATCH] a bit better making the curvature and diffusion passes --- .../render-utils/src/SurfaceGeometryPass.cpp | 8 +++--- .../src/surfaceGeometry_makeCurvature.slf | 27 +++++++++---------- libraries/render/src/render/BlurTask.cpp | 2 +- libraries/render/src/render/BlurTask.slh | 4 +-- 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/libraries/render-utils/src/SurfaceGeometryPass.cpp b/libraries/render-utils/src/SurfaceGeometryPass.cpp index 369341403f..d34d9108d4 100644 --- a/libraries/render-utils/src/SurfaceGeometryPass.cpp +++ b/libraries/render-utils/src/SurfaceGeometryPass.cpp @@ -143,7 +143,7 @@ void LinearDepthPass::run(const render::SceneContextPointer& sceneContext, const batch.draw(gpu::TRIANGLE_STRIP, 4); // batch.setResourceTexture(DepthLinearPass_DepthMapSlot, nullptr); - batch.generateTextureMips(linearDepthFBO->getRenderBuffer(0)); + // batch.generateTextureMips(linearDepthFBO->getRenderBuffer(0)); _gpuTimer.end(batch); }); @@ -293,7 +293,7 @@ void SurfaceGeometryPass::run(const render::SceneContextPointer& sceneContext, c if (curvatureFBO->getDepthStencilBuffer() != deferredFramebuffer->getPrimaryDepthTexture()) { curvatureFBO->setDepthStencilBuffer(deferredFramebuffer->getPrimaryDepthTexture(), deferredFramebuffer->getPrimaryDepthTexture()->getTexelFormat()); } - auto curvatureTexture = _surfaceGeometryFramebuffer->getCurvatureTexture(); + auto curvatureTexture = _surfaceGeometryFramebuffer->getCurvatureTexture(); outputs.edit0() = _surfaceGeometryFramebuffer; outputs.edit1() = curvatureFBO; @@ -318,7 +318,9 @@ void SurfaceGeometryPass::run(const render::SceneContextPointer& sceneContext, c // Curvature pass batch.setFramebuffer(curvatureFBO); - // batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, glm::vec4(0.0)); + + // We can avoid the clear by drawing the same clear vallue from the makeCUrvature shader. slightly better than adding the clear + // batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, glm::vec4(0.0)); batch.setPipeline(curvaturePipeline); batch.setResourceTexture(SurfaceGeometryPass_DepthMapSlot, linearDepthTexture); diff --git a/libraries/render-utils/src/surfaceGeometry_makeCurvature.slf b/libraries/render-utils/src/surfaceGeometry_makeCurvature.slf index 552481304f..bb3a073a2e 100644 --- a/libraries/render-utils/src/surfaceGeometry_makeCurvature.slf +++ b/libraries/render-utils/src/surfaceGeometry_makeCurvature.slf @@ -110,9 +110,8 @@ void main(void) { // Fetch the z under the pixel (stereo or not) float Zeye = getZEye(framePixelPos); if (Zeye <= -getPosLinearDepthFar()) { - // outFragColor = vec4(0.0); - // return; - discard; + outFragColor = vec4(0.0); + return; } float nearPlaneScale = 0.5 * getProjectionNear(); @@ -121,13 +120,13 @@ void main(void) { // The position of the pixel fragment in Eye space then in world space vec3 eyePos = evalEyePositionFromZeye(stereoSide.x, Zeye, texcoordPos); - vec3 worldPos = (frameTransform._viewInverse * vec4(eyePos, 1.0)).xyz; + // vec3 worldPos = (frameTransform._viewInverse * vec4(eyePos, 1.0)).xyz; - if (texcoordPos.y > 0.5) { + /* if (texcoordPos.y > 0.5) { outFragColor = vec4(fract(10.0 * worldPos.xyz), 1.0); } else { outFragColor = vec4(fract(10.0 * eyePos.xyz), 1.0); - } + }*/ // return; // Calculate the perspective scale. @@ -160,11 +159,11 @@ void main(void) { vec4 pz = vec4(eyePos + az, 0.0); - if (texcoordPos.y > 0.5) { + /* if (texcoordPos.y > 0.5) { outFragColor = vec4(fract(px.xyz), 1.0); } else { outFragColor = vec4(fract(eyePos.xyz), 1.0); - } + }*/ // return; @@ -201,14 +200,14 @@ void main(void) { vec4 clipPos = getProjectionMono() * vec4(eyePos, 1.0); nclipPos = clipPos.xy / clipPos.w; - if (texcoordPos.y > 0.5) { + /* if (texcoordPos.y > 0.5) { // outFragColor = vec4(fract(10.0 * worldPos.xyz), 1.0); outFragColor = vec4(fract(10.0 * (nclipPos)), 0.0, 1.0); } else { outFragColor = vec4(fract(10.0 * (clipPos.xy / clipPos.w)), 0.0, 1.0); // outFragColor = vec4(nclipPos * 0.5 + 0.5, 0.0, 1.0); - } + }*/ //return; @@ -217,14 +216,14 @@ void main(void) { py.xy = (py.xy - nclipPos) * pixPerspectiveScaleInv; pz.xy = (pz.xy - nclipPos) * pixPerspectiveScaleInv; - if (texcoordPos.y > 0.5) { + /* if (texcoordPos.y > 0.5) { // outFragColor = vec4(fract(10.0 * worldPos.xyz), 1.0); outFragColor = vec4(fract(10.0 * (px.xy)), 0.0, 1.0); } else { outFragColor = vec4(fract(10.0 * (py.xy)), 0.0, 1.0); // outFragColor = vec4(nclipPos * 0.5 + 0.5, 0.0, 1.0); - } + }*/ // return; // Calculate dF/dx, dF/dy and dF/dz using chain rule @@ -234,10 +233,10 @@ void main(void) { vec3 trace = vec3(dFdx.x, dFdy.y, dFdz.z); - if (dot(trace, trace) > params.curvatureInfo.w) { + /*if (dot(trace, trace) > params.curvatureInfo.w) { outFragColor = vec4(dFdx.x, dFdy.y, dFdz.z, 1.0); return; - } + }*/ // Calculate the mean curvature float meanCurvature = ((trace.x + trace.y + trace.z) * 0.33333333333333333) * params.curvatureInfo.w; diff --git a/libraries/render/src/render/BlurTask.cpp b/libraries/render/src/render/BlurTask.cpp index 64f960f957..4a3118d0d3 100644 --- a/libraries/render/src/render/BlurTask.cpp +++ b/libraries/render/src/render/BlurTask.cpp @@ -228,7 +228,6 @@ void BlurGaussian::run(const SceneContextPointer& sceneContext, const RenderCont _parameters->setWidthHeight(args->_viewport.z, args->_viewport.w, args->_context->isStereo()); glm::ivec2 textureSize(blurringResources.sourceTexture->getDimensions()); _parameters->setTexcoordTransform(gpu::Framebuffer::evalSubregionTexcoordTransformCoefficients(textureSize, args->_viewport)); - _parameters->setLinearDepthPosFar(args->getViewFrustum().getFarClip()); gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { batch.enableStereo(false); @@ -341,6 +340,7 @@ void BlurGaussianDepthAware::run(const SceneContextPointer& sceneContext, const glm::ivec2 textureSize(blurringResources.sourceTexture->getDimensions()); _parameters->setTexcoordTransform(gpu::Framebuffer::evalSubregionTexcoordTransformCoefficients(textureSize, args->_viewport)); _parameters->setDepthPerspective(args->getViewFrustum().getProjection()[1][1]); + _parameters->setLinearDepthPosFar(args->getViewFrustum().getFarClip()); gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { batch.enableStereo(false); diff --git a/libraries/render/src/render/BlurTask.slh b/libraries/render/src/render/BlurTask.slh index 8ba1126413..de40740c19 100644 --- a/libraries/render/src/render/BlurTask.slh +++ b/libraries/render/src/render/BlurTask.slh @@ -97,9 +97,9 @@ uniform sampler2D depthMap; vec4 pixelShaderGaussianDepthAware(vec2 texcoord, vec2 direction, vec2 pixelStep) { texcoord = evalTexcoordTransformed(texcoord); - float sampleDepth = -texture(depthMap, texcoord).x; + float sampleDepth = texture(depthMap, texcoord).x; vec4 sampleCenter = texture(sourceMap, texcoord); - if (sampleDepth <= getPosLinearDepthFar()) { + if (sampleDepth >= getPosLinearDepthFar()) { discard; //return sampleCenter; }