From a2ca1c033dc77010673c71fcc5034739e174b73f Mon Sep 17 00:00:00 2001 From: samcake Date: Wed, 7 Oct 2015 19:04:03 -0700 Subject: [PATCH 1/5] FIxing the rear view mirror issue with background and fooling around with Lighting equations --- libraries/fbx/src/FBXReader_Material.cpp | 2 +- libraries/gpu/src/gpu/DrawUnitQuadTexcoord.slv | 9 +++++---- libraries/render-utils/src/DeferredBufferWrite.slh | 6 +++--- libraries/render-utils/src/DeferredGlobalLight.slh | 3 ++- libraries/render-utils/src/DeferredLighting.slh | 7 +++++-- libraries/render-utils/src/FramebufferCache.cpp | 12 ++++++++---- libraries/render-utils/src/RenderDeferredTask.cpp | 12 +++++++----- libraries/render-utils/src/drawOpaqueStencil.slf | 11 +++++++---- 8 files changed, 38 insertions(+), 24 deletions(-) diff --git a/libraries/fbx/src/FBXReader_Material.cpp b/libraries/fbx/src/FBXReader_Material.cpp index e947a0356e..2f15efbc91 100644 --- a/libraries/fbx/src/FBXReader_Material.cpp +++ b/libraries/fbx/src/FBXReader_Material.cpp @@ -146,7 +146,7 @@ void FBXReader::consolidateFBXMaterials() { // FIXME: Do not use the Specular Factor yet as some FBX models have it set to 0 // metallic *= material.specularFactor; material._material->setMetallic(metallic); - material._material->setGloss(material.shininess); + material._material->setGloss(material.shininess / 100.0f); if (material.opacity <= 0.0f) { material._material->setOpacity(1.0f); diff --git a/libraries/gpu/src/gpu/DrawUnitQuadTexcoord.slv b/libraries/gpu/src/gpu/DrawUnitQuadTexcoord.slv index 60ab0bd7dd..1426ae48fd 100644 --- a/libraries/gpu/src/gpu/DrawUnitQuadTexcoord.slv +++ b/libraries/gpu/src/gpu/DrawUnitQuadTexcoord.slv @@ -14,11 +14,12 @@ out vec2 varTexCoord0; void main(void) { + const float depth = 1.0; const vec4 UNIT_QUAD[4] = vec4[4]( - vec4(-1.0, -1.0, 0.0, 1.0), - vec4(1.0, -1.0, 0.0, 1.0), - vec4(-1.0, 1.0, 0.0, 1.0), - vec4(1.0, 1.0, 0.0, 1.0) + vec4(-1.0, -1.0, depth, 1.0), + vec4(1.0, -1.0, depth, 1.0), + vec4(-1.0, 1.0, depth, 1.0), + vec4(1.0, 1.0, depth, 1.0) ); vec4 pos = UNIT_QUAD[gl_VertexID]; diff --git a/libraries/render-utils/src/DeferredBufferWrite.slh b/libraries/render-utils/src/DeferredBufferWrite.slh index 1c1330f0c0..e8a589c323 100755 --- a/libraries/render-utils/src/DeferredBufferWrite.slh +++ b/libraries/render-utils/src/DeferredBufferWrite.slh @@ -53,7 +53,7 @@ void packDeferredFragment(vec3 normal, float alpha, vec3 diffuse, vec3 specular, _fragColor0 = vec4(diffuse.rgb, alpha); _fragColor1 = vec4(bestFitNormal(normal), 1.0); - _fragColor2 = vec4(specular, shininess / 128.0); + _fragColor2 = vec4(specular, shininess); } void packDeferredFragmentLightmap(vec3 normal, float alpha, vec3 diffuse, vec3 specular, float shininess, vec3 emissive) { @@ -64,7 +64,7 @@ void packDeferredFragmentLightmap(vec3 normal, float alpha, vec3 diffuse, vec3 s _fragColor0 = vec4(diffuse.rgb, alpha); //_fragColor1 = vec4(normal, 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0); _fragColor1 = vec4(bestFitNormal(normal), 0.5); - _fragColor2 = vec4(emissive, shininess / 128.0); + _fragColor2 = vec4(emissive, shininess); } void packDeferredFragmentTranslucent(vec3 normal, float alpha, vec3 diffuse, vec3 specular, float shininess) { @@ -74,7 +74,7 @@ void packDeferredFragmentTranslucent(vec3 normal, float alpha, vec3 diffuse, vec _fragColor0 = vec4(diffuse.rgb, alpha); // _fragColor1 = vec4(normal, 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0); - // _fragColor2 = vec4(specular, shininess / 128.0); + // _fragColor2 = vec4(specular, shininess); } <@endif@> diff --git a/libraries/render-utils/src/DeferredGlobalLight.slh b/libraries/render-utils/src/DeferredGlobalLight.slh index 983b8002f7..40428c5a4e 100755 --- a/libraries/render-utils/src/DeferredGlobalLight.slh +++ b/libraries/render-utils/src/DeferredGlobalLight.slh @@ -131,7 +131,8 @@ vec3 evalSkyboxGlobalColor(mat4 invViewMat, float shadowAttenuation, vec3 positi color += vec3(diffuse + shading.rgb) * shading.w * shadowAttenuation * getLightColor(light) * getLightIntensity(light); - return color; + // return color; + return shading.rgb; } <@endfunc@> diff --git a/libraries/render-utils/src/DeferredLighting.slh b/libraries/render-utils/src/DeferredLighting.slh index 888742bb18..af13a17575 100755 --- a/libraries/render-utils/src/DeferredLighting.slh +++ b/libraries/render-utils/src/DeferredLighting.slh @@ -30,8 +30,11 @@ vec4 evalPBRShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, vec3 sp float shlickPower = (1.0 - dot(fragLightDir,halfDir)); float shlickPower2 = shlickPower * shlickPower; float shlickPower5 = shlickPower2 * shlickPower2 * shlickPower; - vec3 schlick = specular * (1.0 - shlickPower5) + vec3(shlickPower5); - vec3 reflect = specularPower * schlick; + // vec3 fresnel = specular + (1.0 - specular) * shlickPower5; + vec3 fresnel = vec3( 0.1 + (1.0 - 0.1) * shlickPower5 ); + + // vec3 reflect = specularPower * fresnel; + vec3 reflect = fresnel; return vec4(reflect, diffuse); } diff --git a/libraries/render-utils/src/FramebufferCache.cpp b/libraries/render-utils/src/FramebufferCache.cpp index 7b20a3696a..543078a4bd 100644 --- a/libraries/render-utils/src/FramebufferCache.cpp +++ b/libraries/render-utils/src/FramebufferCache.cpp @@ -68,17 +68,21 @@ void FramebufferCache::createPrimaryFramebuffer() { _primaryFramebufferStencilColor->setRenderBuffer(0, _primaryColorTexture); - auto depthFormat = gpu::Element(gpu::SCALAR, gpu::FLOAT, gpu::DEPTH); + // auto depthFormat = gpu::Element(gpu::SCALAR, gpu::FLOAT, gpu::DEPTH); + auto depthFormat = gpu::Element(gpu::SCALAR, gpu::UINT32, gpu::DEPTH_STENCIL); // Depth24_Stencil8 texel format _primaryDepthTexture = gpu::TexturePointer(gpu::Texture::create2D(depthFormat, width, height, defaultSampler)); - auto stencilFormat = gpu::Element(gpu::SCALAR, gpu::UINT32, gpu::DEPTH_STENCIL); // Depth24_Stencil8 texel format - _primaryStencilTexture = gpu::TexturePointer(gpu::Texture::create2D(stencilFormat, width, height, defaultSampler)); + // auto stencilFormat = gpu::Element(gpu::SCALAR, gpu::UINT32, gpu::DEPTH_STENCIL); // Depth24_Stencil8 texel format + auto stencilFormat = depthFormat; + // _primaryStencilTexture = gpu::TexturePointer(gpu::Texture::create2D(stencilFormat, width, height, defaultSampler)); + _primaryStencilTexture = _primaryDepthTexture; _primaryFramebufferFull->setDepthStencilBuffer(_primaryDepthTexture, depthFormat); _primaryFramebufferDepthColor->setDepthStencilBuffer(_primaryDepthTexture, depthFormat); - _primaryFramebufferStencilColor->setDepthStencilBuffer(_primaryStencilTexture, stencilFormat); + // _primaryFramebufferStencilColor->setDepthStencilBuffer(_primaryStencilTexture, stencilFormat); + _primaryFramebufferStencilColor = _primaryFramebufferDepthColor; _selfieFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create()); auto tex = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width * 0.5, height * 0.5, defaultSampler)); diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index 0f79dc8b8d..a85cd3fbca 100755 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -44,15 +44,16 @@ void SetupDeferred::run(const SceneContextPointer& sceneContext, const RenderCon batch.setViewportTransform(args->_viewport); batch.setStateScissorRect(args->_viewport); - batch.setFramebuffer(primaryFboStencil); + /* batch.setFramebuffer(primaryFboStencil); batch.clearFramebuffer( gpu::Framebuffer::BUFFER_STENCIL, vec4(vec3(0), 1), 1.0, 0.0, true); - + */ batch.setFramebuffer(primaryFbo); batch.clearFramebuffer( gpu::Framebuffer::BUFFER_COLOR0 | - gpu::Framebuffer::BUFFER_DEPTH, + gpu::Framebuffer::BUFFER_DEPTH | + gpu::Framebuffer::BUFFER_STENCIL, vec4(vec3(0), 1), 1.0, 0.0, true); }); } @@ -313,7 +314,8 @@ const gpu::PipelinePointer& DrawStencilDeferred::getOpaquePipeline() { gpu::Shader::makeProgram((*program)); auto state = std::make_shared(); - state->setStencilTest(true, 0xFF, gpu::State::StencilTest(STENCIL_OPAQUE, 0xFF, gpu::ALWAYS, gpu::State::STENCIL_OP_REPLACE, gpu::State::STENCIL_OP_REPLACE, gpu::State::STENCIL_OP_REPLACE)); + state->setDepthTest(true, false, gpu::LESS_EQUAL); + state->setStencilTest(true, 0xFF, gpu::State::StencilTest(STENCIL_OPAQUE, 0xFF, gpu::ALWAYS, gpu::State::STENCIL_OP_REPLACE, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_REPLACE)); state->setColorWriteMask(0); _opaquePipeline.reset(gpu::Pipeline::create(program, state)); @@ -340,7 +342,7 @@ void DrawStencilDeferred::run(const SceneContextPointer& sceneContext, const Ren batch.setStateScissorRect(args->_viewport); batch.setPipeline(getOpaquePipeline()); - batch.setResourceTexture(0, primaryDepth); + // batch.setResourceTexture(0, primaryDepth); batch.draw(gpu::TRIANGLE_STRIP, 4); batch.setResourceTexture(0, nullptr); diff --git a/libraries/render-utils/src/drawOpaqueStencil.slf b/libraries/render-utils/src/drawOpaqueStencil.slf index 14feda21e9..033c2fec5a 100644 --- a/libraries/render-utils/src/drawOpaqueStencil.slf +++ b/libraries/render-utils/src/drawOpaqueStencil.slf @@ -14,11 +14,14 @@ in vec2 varTexCoord0; -uniform sampler2D depthTexture; - +//uniform sampler2D depthTexture; +out vec4 outFragColor; void main(void) { - float depth = texture(depthTexture, varTexCoord0.xy).r; +/* float depth = texture(depthTexture, varTexCoord0.xy).r; if (depth >= 1.0) { discard; - } + }*/ + + outFragColor = vec4(1.0); + } From c7049bad398558cf3aa38a333a8695ba07f18e39 Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 8 Oct 2015 09:32:05 -0700 Subject: [PATCH 2/5] Backing up on any changes regarding shading, focus on the rearr view mirror and stencil bug --- libraries/fbx/src/FBXReader_Material.cpp | 2 +- libraries/render-utils/src/DeferredBufferWrite.slh | 6 +++--- libraries/render-utils/src/DeferredGlobalLight.slh | 3 +-- libraries/render-utils/src/DeferredLighting.slh | 7 ++----- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/libraries/fbx/src/FBXReader_Material.cpp b/libraries/fbx/src/FBXReader_Material.cpp index 2f15efbc91..e947a0356e 100644 --- a/libraries/fbx/src/FBXReader_Material.cpp +++ b/libraries/fbx/src/FBXReader_Material.cpp @@ -146,7 +146,7 @@ void FBXReader::consolidateFBXMaterials() { // FIXME: Do not use the Specular Factor yet as some FBX models have it set to 0 // metallic *= material.specularFactor; material._material->setMetallic(metallic); - material._material->setGloss(material.shininess / 100.0f); + material._material->setGloss(material.shininess); if (material.opacity <= 0.0f) { material._material->setOpacity(1.0f); diff --git a/libraries/render-utils/src/DeferredBufferWrite.slh b/libraries/render-utils/src/DeferredBufferWrite.slh index e8a589c323..1c1330f0c0 100755 --- a/libraries/render-utils/src/DeferredBufferWrite.slh +++ b/libraries/render-utils/src/DeferredBufferWrite.slh @@ -53,7 +53,7 @@ void packDeferredFragment(vec3 normal, float alpha, vec3 diffuse, vec3 specular, _fragColor0 = vec4(diffuse.rgb, alpha); _fragColor1 = vec4(bestFitNormal(normal), 1.0); - _fragColor2 = vec4(specular, shininess); + _fragColor2 = vec4(specular, shininess / 128.0); } void packDeferredFragmentLightmap(vec3 normal, float alpha, vec3 diffuse, vec3 specular, float shininess, vec3 emissive) { @@ -64,7 +64,7 @@ void packDeferredFragmentLightmap(vec3 normal, float alpha, vec3 diffuse, vec3 s _fragColor0 = vec4(diffuse.rgb, alpha); //_fragColor1 = vec4(normal, 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0); _fragColor1 = vec4(bestFitNormal(normal), 0.5); - _fragColor2 = vec4(emissive, shininess); + _fragColor2 = vec4(emissive, shininess / 128.0); } void packDeferredFragmentTranslucent(vec3 normal, float alpha, vec3 diffuse, vec3 specular, float shininess) { @@ -74,7 +74,7 @@ void packDeferredFragmentTranslucent(vec3 normal, float alpha, vec3 diffuse, vec _fragColor0 = vec4(diffuse.rgb, alpha); // _fragColor1 = vec4(normal, 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0); - // _fragColor2 = vec4(specular, shininess); + // _fragColor2 = vec4(specular, shininess / 128.0); } <@endif@> diff --git a/libraries/render-utils/src/DeferredGlobalLight.slh b/libraries/render-utils/src/DeferredGlobalLight.slh index 40428c5a4e..983b8002f7 100755 --- a/libraries/render-utils/src/DeferredGlobalLight.slh +++ b/libraries/render-utils/src/DeferredGlobalLight.slh @@ -131,8 +131,7 @@ vec3 evalSkyboxGlobalColor(mat4 invViewMat, float shadowAttenuation, vec3 positi color += vec3(diffuse + shading.rgb) * shading.w * shadowAttenuation * getLightColor(light) * getLightIntensity(light); - // return color; - return shading.rgb; + return color; } <@endfunc@> diff --git a/libraries/render-utils/src/DeferredLighting.slh b/libraries/render-utils/src/DeferredLighting.slh index af13a17575..888742bb18 100755 --- a/libraries/render-utils/src/DeferredLighting.slh +++ b/libraries/render-utils/src/DeferredLighting.slh @@ -30,11 +30,8 @@ vec4 evalPBRShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, vec3 sp float shlickPower = (1.0 - dot(fragLightDir,halfDir)); float shlickPower2 = shlickPower * shlickPower; float shlickPower5 = shlickPower2 * shlickPower2 * shlickPower; - // vec3 fresnel = specular + (1.0 - specular) * shlickPower5; - vec3 fresnel = vec3( 0.1 + (1.0 - 0.1) * shlickPower5 ); - - // vec3 reflect = specularPower * fresnel; - vec3 reflect = fresnel; + vec3 schlick = specular * (1.0 - shlickPower5) + vec3(shlickPower5); + vec3 reflect = specularPower * schlick; return vec4(reflect, diffuse); } From dff598ebd16c9806493c7a521b9f102a5585788d Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 8 Oct 2015 12:06:09 -0700 Subject: [PATCH 3/5] clening and getting ready for pr --- libraries/gpu/src/gpu/Batch.cpp | 7 +++++++ libraries/gpu/src/gpu/Batch.h | 2 ++ libraries/gpu/src/gpu/GLBackend.h | 2 ++ libraries/gpu/src/gpu/GLBackendTransform.cpp | 15 ++++++++++++++- 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/libraries/gpu/src/gpu/Batch.cpp b/libraries/gpu/src/gpu/Batch.cpp index 966182c7d3..c3e186a630 100644 --- a/libraries/gpu/src/gpu/Batch.cpp +++ b/libraries/gpu/src/gpu/Batch.cpp @@ -205,6 +205,13 @@ void Batch::setViewportTransform(const Vec4i& viewport) { _params.push_back(cacheData(sizeof(Vec4i), &viewport)); } +void Batch::setDepthRangeTransform(float nearDepth, float farDepth) { + ADD_COMMAND(setDepthRangeTransform); + + _params.push_back(farDepth); + _params.push_back(nearDepth); +} + void Batch::setPipeline(const PipelinePointer& pipeline) { ADD_COMMAND(setPipeline); diff --git a/libraries/gpu/src/gpu/Batch.h b/libraries/gpu/src/gpu/Batch.h index e1b76e2e81..deb70f7a68 100644 --- a/libraries/gpu/src/gpu/Batch.h +++ b/libraries/gpu/src/gpu/Batch.h @@ -187,6 +187,7 @@ public: void setProjectionTransform(const Mat4& proj); // Viewport is xy = low left corner in framebuffer, zw = width height of the viewport, expressed in pixels void setViewportTransform(const Vec4i& viewport); + void setDepthRangeTransform(float nearDepth, float farDepth); // Pipeline Stage void setPipeline(const PipelinePointer& pipeline); @@ -285,6 +286,7 @@ public: COMMAND_setViewTransform, COMMAND_setProjectionTransform, COMMAND_setViewportTransform, + COMMAND_setDepthRangeTransform, COMMAND_setPipeline, COMMAND_setStateBlendFactor, diff --git a/libraries/gpu/src/gpu/GLBackend.h b/libraries/gpu/src/gpu/GLBackend.h index e01dbcd0dc..9cb988a431 100644 --- a/libraries/gpu/src/gpu/GLBackend.h +++ b/libraries/gpu/src/gpu/GLBackend.h @@ -314,6 +314,7 @@ protected: void do_setViewTransform(Batch& batch, uint32 paramOffset); void do_setProjectionTransform(Batch& batch, uint32 paramOffset); void do_setViewportTransform(Batch& batch, uint32 paramOffset); + void do_setDepthRangeTransform(Batch& batch, uint32 paramOffset); void initTransform(); void killTransform(); @@ -339,6 +340,7 @@ protected: Transform _view; Mat4 _projection; Vec4i _viewport{ 0, 0, 1, 1 }; + Vec2 _depthRange{ 0.0f, 1.0f }; bool _invalidModel{true}; bool _invalidView{false}; bool _invalidProj{false}; diff --git a/libraries/gpu/src/gpu/GLBackendTransform.cpp b/libraries/gpu/src/gpu/GLBackendTransform.cpp index 5e16421c6a..963cab778f 100755 --- a/libraries/gpu/src/gpu/GLBackendTransform.cpp +++ b/libraries/gpu/src/gpu/GLBackendTransform.cpp @@ -45,10 +45,21 @@ void GLBackend::do_setViewportTransform(Batch& batch, uint32 paramOffset) { glViewport(vp.x, vp.y, vp.z, vp.w); - // The Viewport is tagged invalid because the CameraTransformUBO is not up to date and willl need update on next drawcall + // The Viewport is tagged invalid because the CameraTransformUBO is not up to date and will need update on next drawcall _transform._invalidViewport = true; } +void GLBackend::do_setDepthRangeTransform(Batch& batch, uint32 paramOffset) { + + Vec2 depthRange(batch._params[paramOffset + 0]._float, batch._params[paramOffset + 1]._float); + + if ((depthRange.x != _transform._depthRange.x) || (depthRange.y != _transform._depthRange.y)) { + _transform._depthRange = depthRange; + + glDepthRangef(depthRange.x, depthRange.y); + } +} + void GLBackend::initTransform() { glGenBuffers(1, &_transform._objectBuffer); glGenBuffers(1, &_transform._cameraBuffer); @@ -75,6 +86,8 @@ void GLBackend::syncTransformStateCache() { glGetIntegerv(GL_VIEWPORT, (GLint*) &_transform._viewport); + glGetFloatv(GL_DEPTH_RANGE, (GLfloat*)&_transform._depthRange); + Mat4 modelView; auto modelViewInv = glm::inverse(modelView); _transform._view.evalFromRawMatrix(modelViewInv); From bad5ea7d53ae5de7757655f2060d1600f6c46ac5 Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 8 Oct 2015 16:47:33 -0700 Subject: [PATCH 4/5] grouping the depth and stencil buffer into a single buffer --- libraries/gpu/src/gpu/GLBackend.cpp | 1 + .../render-utils/src/FramebufferCache.cpp | 31 ++----------------- libraries/render-utils/src/FramebufferCache.h | 5 +-- .../render-utils/src/RenderDeferredTask.cpp | 16 +++------- 4 files changed, 8 insertions(+), 45 deletions(-) diff --git a/libraries/gpu/src/gpu/GLBackend.cpp b/libraries/gpu/src/gpu/GLBackend.cpp index 37135ccd98..19edbaee5f 100644 --- a/libraries/gpu/src/gpu/GLBackend.cpp +++ b/libraries/gpu/src/gpu/GLBackend.cpp @@ -35,6 +35,7 @@ GLBackend::CommandCall GLBackend::_commandCalls[Batch::NUM_COMMANDS] = (&::gpu::GLBackend::do_setViewTransform), (&::gpu::GLBackend::do_setProjectionTransform), (&::gpu::GLBackend::do_setViewportTransform), + (&::gpu::GLBackend::do_setDepthRangeTransform), (&::gpu::GLBackend::do_setPipeline), (&::gpu::GLBackend::do_setStateBlendFactor), diff --git a/libraries/render-utils/src/FramebufferCache.cpp b/libraries/render-utils/src/FramebufferCache.cpp index 543078a4bd..5907d3fa27 100644 --- a/libraries/render-utils/src/FramebufferCache.cpp +++ b/libraries/render-utils/src/FramebufferCache.cpp @@ -35,9 +35,7 @@ void FramebufferCache::setFrameBufferSize(QSize frameBufferSize) { _frameBufferSize = frameBufferSize; _primaryFramebufferFull.reset(); _primaryFramebufferDepthColor.reset(); - _primaryFramebufferStencilColor.reset(); _primaryDepthTexture.reset(); - _primaryStencilTexture.reset(); _primaryColorTexture.reset(); _primaryNormalTexture.reset(); _primarySpecularTexture.reset(); @@ -49,7 +47,6 @@ void FramebufferCache::setFrameBufferSize(QSize frameBufferSize) { void FramebufferCache::createPrimaryFramebuffer() { _primaryFramebufferFull = gpu::FramebufferPointer(gpu::Framebuffer::create()); _primaryFramebufferDepthColor = gpu::FramebufferPointer(gpu::Framebuffer::create()); - _primaryFramebufferStencilColor = gpu::FramebufferPointer(gpu::Framebuffer::create()); auto colorFormat = gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA); auto width = _frameBufferSize.width(); @@ -66,24 +63,14 @@ void FramebufferCache::createPrimaryFramebuffer() { _primaryFramebufferDepthColor->setRenderBuffer(0, _primaryColorTexture); - _primaryFramebufferStencilColor->setRenderBuffer(0, _primaryColorTexture); - // auto depthFormat = gpu::Element(gpu::SCALAR, gpu::FLOAT, gpu::DEPTH); auto depthFormat = gpu::Element(gpu::SCALAR, gpu::UINT32, gpu::DEPTH_STENCIL); // Depth24_Stencil8 texel format _primaryDepthTexture = gpu::TexturePointer(gpu::Texture::create2D(depthFormat, width, height, defaultSampler)); - - // auto stencilFormat = gpu::Element(gpu::SCALAR, gpu::UINT32, gpu::DEPTH_STENCIL); // Depth24_Stencil8 texel format - auto stencilFormat = depthFormat; - // _primaryStencilTexture = gpu::TexturePointer(gpu::Texture::create2D(stencilFormat, width, height, defaultSampler)); - _primaryStencilTexture = _primaryDepthTexture; - + _primaryFramebufferFull->setDepthStencilBuffer(_primaryDepthTexture, depthFormat); _primaryFramebufferDepthColor->setDepthStencilBuffer(_primaryDepthTexture, depthFormat); - - // _primaryFramebufferStencilColor->setDepthStencilBuffer(_primaryStencilTexture, stencilFormat); - _primaryFramebufferStencilColor = _primaryFramebufferDepthColor; - + _selfieFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create()); auto tex = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width * 0.5, height * 0.5, defaultSampler)); _selfieFramebuffer->setRenderBuffer(0, tex); @@ -103,13 +90,6 @@ gpu::FramebufferPointer FramebufferCache::getPrimaryFramebufferDepthColor() { return _primaryFramebufferDepthColor; } -gpu::FramebufferPointer FramebufferCache::getPrimaryFramebufferStencilColor() { - if (!_primaryFramebufferStencilColor) { - createPrimaryFramebuffer(); - } - return _primaryFramebufferStencilColor; -} - gpu::TexturePointer FramebufferCache::getPrimaryDepthTexture() { if (!_primaryDepthTexture) { createPrimaryFramebuffer(); @@ -117,13 +97,6 @@ gpu::TexturePointer FramebufferCache::getPrimaryDepthTexture() { return _primaryDepthTexture; } -gpu::TexturePointer FramebufferCache::getPrimaryStencilTexture() { - if (!_primaryStencilTexture) { - createPrimaryFramebuffer(); - } - return _primaryStencilTexture; -} - gpu::TexturePointer FramebufferCache::getPrimaryColorTexture() { if (!_primaryColorTexture) { createPrimaryFramebuffer(); diff --git a/libraries/render-utils/src/FramebufferCache.h b/libraries/render-utils/src/FramebufferCache.h index 8951ceee80..e9a1bbf8e8 100644 --- a/libraries/render-utils/src/FramebufferCache.h +++ b/libraries/render-utils/src/FramebufferCache.h @@ -31,10 +31,8 @@ public: /// used for scene rendering. gpu::FramebufferPointer getPrimaryFramebuffer(); gpu::FramebufferPointer getPrimaryFramebufferDepthColor(); - gpu::FramebufferPointer getPrimaryFramebufferStencilColor(); gpu::TexturePointer getPrimaryDepthTexture(); - gpu::TexturePointer getPrimaryStencilTexture(); gpu::TexturePointer getPrimaryColorTexture(); gpu::TexturePointer getPrimaryNormalTexture(); gpu::TexturePointer getPrimarySpecularTexture(); @@ -60,9 +58,8 @@ private: gpu::FramebufferPointer _primaryFramebufferFull; gpu::FramebufferPointer _primaryFramebufferDepthColor; - gpu::FramebufferPointer _primaryFramebufferStencilColor; + gpu::TexturePointer _primaryDepthTexture; - gpu::TexturePointer _primaryStencilTexture; gpu::TexturePointer _primaryColorTexture; gpu::TexturePointer _primaryNormalTexture; gpu::TexturePointer _primarySpecularTexture; diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index a85cd3fbca..73a487c2df 100755 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -37,18 +37,12 @@ void SetupDeferred::run(const SceneContextPointer& sceneContext, const RenderCon RenderArgs* args = renderContext->args; gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { - auto primaryFboStencil = DependencyManager::get()->getPrimaryFramebufferStencilColor(); auto primaryFbo = DependencyManager::get()->getPrimaryFramebufferDepthColor(); batch.enableStereo(false); batch.setViewportTransform(args->_viewport); batch.setStateScissorRect(args->_viewport); - /* batch.setFramebuffer(primaryFboStencil); - batch.clearFramebuffer( - gpu::Framebuffer::BUFFER_STENCIL, - vec4(vec3(0), 1), 1.0, 0.0, true); - */ batch.setFramebuffer(primaryFbo); batch.clearFramebuffer( gpu::Framebuffer::BUFFER_COLOR0 | @@ -332,9 +326,8 @@ void DrawStencilDeferred::run(const SceneContextPointer& sceneContext, const Ren doInBatch(args->_context, [=](gpu::Batch& batch) { args->_batch = &batch; - auto primaryFboColorDepthStencil = DependencyManager::get()->getPrimaryFramebufferStencilColor(); - auto primaryDepth = DependencyManager::get()->getPrimaryDepthTexture(); - + auto primaryFboColorDepthStencil = DependencyManager::get()->getPrimaryFramebufferDepthColor(); + batch.enableStereo(false); batch.setFramebuffer(primaryFboColorDepthStencil); @@ -342,7 +335,6 @@ void DrawStencilDeferred::run(const SceneContextPointer& sceneContext, const Ren batch.setStateScissorRect(args->_viewport); batch.setPipeline(getOpaquePipeline()); - // batch.setResourceTexture(0, primaryDepth); batch.draw(gpu::TRIANGLE_STRIP, 4); batch.setResourceTexture(0, nullptr); @@ -369,12 +361,12 @@ void DrawBackgroundDeferred::run(const SceneContextPointer& sceneContext, const doInBatch(args->_context, [=](gpu::Batch& batch) { args->_batch = &batch; - auto primaryFboColorStencil = DependencyManager::get()->getPrimaryFramebufferStencilColor(); + auto primaryFboColorDepthStencil = DependencyManager::get()->getPrimaryFramebufferDepthColor(); auto primaryFboFull = DependencyManager::get()->getPrimaryFramebuffer(); batch.enableSkybox(true); - batch.setFramebuffer(primaryFboColorStencil); + batch.setFramebuffer(primaryFboColorDepthStencil); batch.setViewportTransform(args->_viewport); batch.setStateScissorRect(args->_viewport); From 3897716ff5730c0f3ffb21c963599857be7366ff Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 8 Oct 2015 17:49:55 -0700 Subject: [PATCH 5/5] Simplifying the DrawOpaqueStencil Pixel shader --- libraries/render-utils/src/drawOpaqueStencil.slf | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/libraries/render-utils/src/drawOpaqueStencil.slf b/libraries/render-utils/src/drawOpaqueStencil.slf index 033c2fec5a..43e9c5c27a 100644 --- a/libraries/render-utils/src/drawOpaqueStencil.slf +++ b/libraries/render-utils/src/drawOpaqueStencil.slf @@ -12,16 +12,5 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -in vec2 varTexCoord0; - -//uniform sampler2D depthTexture; -out vec4 outFragColor; void main(void) { -/* float depth = texture(depthTexture, varTexCoord0.xy).r; - if (depth >= 1.0) { - discard; - }*/ - - outFragColor = vec4(1.0); - }