From 6a08c74463a94cc3658c5e822317c43c322c3aa4 Mon Sep 17 00:00:00 2001 From: samcake Date: Wed, 7 Sep 2016 18:39:07 -0700 Subject: [PATCH] Several experimetations without success --- libraries/audio/src/AudioInjector.cpp | 2 +- .../gpu-gl/src/gpu/gl/GLBackendState.cpp | 6 +- .../src/DeferredLightingEffect.cpp | 81 +++++++++++++------ libraries/render-utils/src/LightingModel.h | 3 +- .../render-utils/src/RenderDeferredTask.cpp | 2 +- .../render-utils/src/deferred_light_point.slv | 8 +- .../render-utils/src/deferred_light_spot.slv | 7 +- 7 files changed, 68 insertions(+), 41 deletions(-) diff --git a/libraries/audio/src/AudioInjector.cpp b/libraries/audio/src/AudioInjector.cpp index c6368259c0..5fc07adb8d 100644 --- a/libraries/audio/src/AudioInjector.cpp +++ b/libraries/audio/src/AudioInjector.cpp @@ -26,7 +26,7 @@ #include "SoundCache.h" #include "AudioSRC.h" -int audioInjectorPtrMetaTypeId = qRegisterMetaType(); +//int audioInjectorPtrMetaTypeId = qRegisterMetaType(); AudioInjectorState operator& (AudioInjectorState lhs, AudioInjectorState rhs) { return static_cast(static_cast(lhs) & static_cast(rhs)); diff --git a/libraries/gpu-gl/src/gpu/gl/GLBackendState.cpp b/libraries/gpu-gl/src/gpu/gl/GLBackendState.cpp index f41570ef7b..1b40af6174 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLBackendState.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLBackendState.cpp @@ -213,13 +213,13 @@ void GLBackend::do_setStateStencil(State::StencilActivation activation, State::S GL_DECR }; if (testFront != testBack) { - glStencilOpSeparate(GL_FRONT, STENCIL_OPS[testFront.getFailOp()], STENCIL_OPS[testFront.getPassOp()], STENCIL_OPS[testFront.getDepthFailOp()]); + glStencilOpSeparate(GL_FRONT, STENCIL_OPS[testFront.getFailOp()], STENCIL_OPS[testFront.getDepthFailOp()], STENCIL_OPS[testFront.getPassOp()]); glStencilFuncSeparate(GL_FRONT, COMPARISON_TO_GL[testFront.getFunction()], testFront.getReference(), testFront.getReadMask()); - glStencilOpSeparate(GL_BACK, STENCIL_OPS[testBack.getFailOp()], STENCIL_OPS[testBack.getPassOp()], STENCIL_OPS[testBack.getDepthFailOp()]); + glStencilOpSeparate(GL_BACK, STENCIL_OPS[testBack.getFailOp()], STENCIL_OPS[testBack.getDepthFailOp()], STENCIL_OPS[testBack.getPassOp()]); glStencilFuncSeparate(GL_BACK, COMPARISON_TO_GL[testBack.getFunction()], testBack.getReference(), testBack.getReadMask()); } else { - glStencilOp(STENCIL_OPS[testFront.getFailOp()], STENCIL_OPS[testFront.getPassOp()], STENCIL_OPS[testFront.getDepthFailOp()]); + glStencilOp(STENCIL_OPS[testFront.getFailOp()], STENCIL_OPS[testFront.getDepthFailOp()], STENCIL_OPS[testFront.getPassOp()]); glStencilFunc(COMPARISON_TO_GL[testFront.getFunction()], testFront.getReference(), testFront.getReadMask()); } diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 4f14b76ac0..3c6608b011 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -78,6 +78,31 @@ enum DeferredShader_BufferSlot { static void loadLightProgram(const char* vertSource, const char* fragSource, bool lightVolume, gpu::PipelinePointer& program, LightLocationsPtr& locations); static void loadLightVolumeProgram(const char* vertSource, const char* fragSource, bool front, gpu::PipelinePointer& program, LightLocationsPtr& locations); +const char no_light_frag[] = +R"SCRIBE( +//PC 410 core +// Generated on Wed Sep 07 12:11:58 2016 +// +// point_light.frag +// fragment shader +// +// Created by Sam Gateau on 9/18/15. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// +out vec4 _fragColor; + +void main(void) { + _fragColor = vec4(1.0, 1.0, 1.0, 1.0); + + } + + +)SCRIBE" +; + void DeferredLightingEffect::init() { _directionalLightLocations = std::make_shared(); _directionalAmbientSphereLightLocations = std::make_shared(); @@ -99,12 +124,12 @@ void DeferredLightingEffect::init() { loadLightProgram(deferred_light_vert, directional_ambient_light_shadow_frag, false, _directionalAmbientSphereLightShadow, _directionalAmbientSphereLightShadowLocations); loadLightProgram(deferred_light_vert, directional_skybox_light_shadow_frag, false, _directionalSkyboxLightShadow, _directionalSkyboxLightShadowLocations); - loadLightProgram(deferred_light_vert, local_lights_shading_frag, false, _localLight, _localLightLocations); + loadLightProgram(deferred_light_vert, local_lights_shading_frag, true, _localLight, _localLightLocations); - loadLightVolumeProgram(deferred_light_point_vert, point_light_frag, false, _pointLightBack, _pointLightLocations); - loadLightVolumeProgram(deferred_light_point_vert, point_light_frag, true, _pointLightFront, _pointLightLocations); - loadLightVolumeProgram(deferred_light_spot_vert, spot_light_frag, false, _spotLightBack, _spotLightLocations); - loadLightVolumeProgram(deferred_light_spot_vert, spot_light_frag, true, _spotLightFront, _spotLightLocations); + loadLightVolumeProgram(deferred_light_point_vert, no_light_frag, false, _pointLightBack, _pointLightLocations); + loadLightVolumeProgram(deferred_light_point_vert, no_light_frag, true, _pointLightFront, _pointLightLocations); + loadLightVolumeProgram(deferred_light_spot_vert, no_light_frag, false, _spotLightBack, _spotLightLocations); + loadLightVolumeProgram(deferred_light_spot_vert, no_light_frag, true, _spotLightFront, _spotLightLocations); // Allocate a global light representing the Global Directional light casting shadow (the sun) and the ambient light _allocatedLights.push_back(std::make_shared()); @@ -223,12 +248,14 @@ static void loadLightProgram(const char* vertSource, const char* fragSource, boo auto state = std::make_shared(); state->setColorWriteMask(true, true, true, false); - // Stencil test all the light passes 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)); + // state->setStencilTest(true, 0xFF, gpu::State::StencilTest(0, 0xFF, gpu::ALWAYS, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); if (lightVolume) { - state->setCullMode(gpu::State::CULL_FRONT); - state->setDepthTest(true, false, gpu::GREATER_EQUAL); + state->setStencilTest(true, 0x00, gpu::State::StencilTest(1, 0xFF, gpu::GREATER_EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); + + state->setCullMode(gpu::State::CULL_BACK); + // state->setCullMode(gpu::State::CULL_FRONT); + // state->setDepthTest(true, false, gpu::GREATER_EQUAL); //state->setDepthClampEnable(true); // TODO: We should use DepthClamp and avoid changing geometry for inside /outside cases @@ -236,6 +263,9 @@ static void loadLightProgram(const char* vertSource, const char* fragSource, boo state->setBlendFunction(true, gpu::State::ONE, gpu::State::BLEND_OP_ADD, gpu::State::ONE); } else { + // Stencil test all the light passes for objects pixels only, not the background + state->setStencilTest(true, 0x00, gpu::State::StencilTest(0, 0x01, gpu::NOT_EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); + state->setCullMode(gpu::State::CULL_BACK); // additive blending state->setBlendFunction(true, gpu::State::ONE, gpu::State::BLEND_OP_ADD, gpu::State::ONE); @@ -289,25 +319,25 @@ static void loadLightVolumeProgram(const char* vertSource, const char* fragSourc locations->shadowTransformBuffer = program->getBuffers().findLocation("shadowTransformBuffer"); auto state = std::make_shared(); - state->setColorWriteMask(true, true, true, false); - // state->setColorWriteMask(false, false, false, false); + // state->setColorWriteMask(true, true, true, false); + state->setColorWriteMask(false, false, false, false); // Stencil test all the light passes for objects pixels only, not the background if (front) { - state->setCullMode(gpu::State::CULL_FRONT); + state->setCullMode(gpu::State::CULL_BACK); state->setDepthTest(true, false, gpu::LESS_EQUAL); - state->setStencilTest(true, 0xFF, gpu::State::StencilTest(0, 0xFF, gpu::ALWAYS, gpu::State::STENCIL_OP_INCR, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_INCR)); + 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_DECR)); - //state->setDepthClampEnable(true); + // state->setDepthClampEnable(true); // TODO: We should use DepthClamp and avoid changing geometry for inside /outside cases // additive blending // state->setBlendFunction(true, gpu::State::ONE, gpu::State::BLEND_OP_ADD, gpu::State::ONE); } else { - state->setCullMode(gpu::State::CULL_BACK); - state->setDepthTest(true, false, gpu::GREATER_EQUAL); - state->setStencilTest(true, 0xFF, gpu::State::StencilTest(0, 0xFF, gpu::ALWAYS, gpu::State::STENCIL_OP_INCR, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_INCR)); + state->setCullMode(gpu::State::CULL_FRONT); + state->setDepthTest(true, false, gpu::LESS_EQUAL); + 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_INCR)); // additive blending // state->setBlendFunction(true, gpu::State::ONE, gpu::State::BLEND_OP_ADD, gpu::State::ONE); } @@ -690,6 +720,9 @@ void RenderDeferredLocals::run(const render::SceneContextPointer& sceneContext, auto textureFrameTransform = gpu::Framebuffer::evalSubregionTexcoordTransformCoefficients(deferredFramebuffer->getFrameSize(), viewport); + batch.setProjectionTransform(projMat); + batch.setViewTransform(viewTransform, true); + // gather lights auto& srcPointLights = deferredLightingEffect->_pointLights; auto& srcSpotLights = deferredLightingEffect->_spotLights; @@ -720,8 +753,8 @@ void RenderDeferredLocals::run(const render::SceneContextPointer& sceneContext, // before we get to the real lighting, let s try to cull down the number of pixels - { - /* if (numPointLights > 0) { + if (false) { + if (numPointLights > 0) { auto mesh = deferredLightingEffect->getPointLightMesh(); batch.setIndexBuffer(mesh->getIndexBuffer()); batch.setInputBuffer(0, mesh->getVertexBuffer()); @@ -730,16 +763,14 @@ void RenderDeferredLocals::run(const render::SceneContextPointer& sceneContext, // Point light pipeline batch.setPipeline(deferredLightingEffect->_pointLightBack); - batch._glUniform4fv(deferredLightingEffect->_pointLightLocations->texcoordFrameTransform, 1, reinterpret_cast(&textureFrameTransform)); batch.drawIndexedInstanced(numPointLights, model::Mesh::topologyToPrimitive(pointPart._topology), pointPart._numIndices, pointPart._startIndex, offsetPointLights); batch.setPipeline(deferredLightingEffect->_pointLightFront); - batch._glUniform4fv(deferredLightingEffect->_pointLightLocations->texcoordFrameTransform, 1, reinterpret_cast(&textureFrameTransform)); batch.drawIndexedInstanced(numPointLights, model::Mesh::topologyToPrimitive(pointPart._topology), pointPart._numIndices, pointPart._startIndex, offsetPointLights); - } */ - /* + } + if (numSpotLights > 0) { auto mesh = deferredLightingEffect->getSpotLightMesh(); batch.setIndexBuffer(mesh->getIndexBuffer()); @@ -749,15 +780,13 @@ void RenderDeferredLocals::run(const render::SceneContextPointer& sceneContext, // Spot light pipeline batch.setPipeline(deferredLightingEffect->_spotLightBack); - batch._glUniform4fv(deferredLightingEffect->_spotLightLocations->texcoordFrameTransform, 1, reinterpret_cast(&textureFrameTransform)); batch.drawIndexedInstanced(numSpotLights, model::Mesh::topologyToPrimitive(conePart._topology), conePart._numIndices, conePart._startIndex, offsetSpotLights); batch.setPipeline(deferredLightingEffect->_spotLightFront); - batch._glUniform4fv(deferredLightingEffect->_spotLightLocations->texcoordFrameTransform, 1, reinterpret_cast(&textureFrameTransform)); batch.drawIndexedInstanced(numSpotLights, model::Mesh::topologyToPrimitive(conePart._topology), conePart._numIndices, conePart._startIndex, offsetSpotLights); - }*/ + } } // Local light pipeline diff --git a/libraries/render-utils/src/LightingModel.h b/libraries/render-utils/src/LightingModel.h index 87a6703dc6..5bb0e621a4 100644 --- a/libraries/render-utils/src/LightingModel.h +++ b/libraries/render-utils/src/LightingModel.h @@ -143,7 +143,8 @@ public: bool enablePointLight{ true }; bool enableSpotLight{ true }; - bool showLightContour{ false }; // false by default + // bool showLightContour { false }; // false by default + bool showLightContour { true }; // false by default signals: void dirty(); diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index 32aa2b6e16..942419a8a4 100755 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -390,7 +390,7 @@ gpu::PipelinePointer DrawStencilDeferred::getOpaquePipeline() { auto state = std::make_shared(); 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->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_KEEP)); state->setColorWriteMask(0); _opaquePipeline = gpu::Pipeline::create(program, state); diff --git a/libraries/render-utils/src/deferred_light_point.slv b/libraries/render-utils/src/deferred_light_point.slv index f6d4de3954..6bdc6fe42f 100644 --- a/libraries/render-utils/src/deferred_light_point.slv +++ b/libraries/render-utils/src/deferred_light_point.slv @@ -30,17 +30,19 @@ out vec4 _texCoord0; void main(void) { - instanceID = lightIndex[gl_InstanceID]; + int instanceID = lightIndex[gl_InstanceID]; Light light = getLight(instanceID); vec4 sphereVertex = inPosition; + vec3 lightOrigin = getLightPosition(light); vec4 sphereParam = getLightVolumeGeometry(light); sphereVertex.xyz *= sphereParam.w; + sphereVertex.xyz += lightOrigin; + // standard transform TransformCamera cam = getTransformCamera(); - TransformObject obj = getTransformObject(); - <$transformModelToClipPos(cam, obj, sphereVertex, gl_Position)$>; + <$transformWorldToClipPos(cam, sphereVertex, gl_Position)$>; vec4 projected = gl_Position / gl_Position.w; projected.xy = (projected.xy + 1.0) * 0.5; diff --git a/libraries/render-utils/src/deferred_light_spot.slv b/libraries/render-utils/src/deferred_light_spot.slv index cd70724e1f..c120fa28b1 100755 --- a/libraries/render-utils/src/deferred_light_spot.slv +++ b/libraries/render-utils/src/deferred_light_spot.slv @@ -25,11 +25,10 @@ uniform lightIndexBuffer { int lightIndex[120]; }; out vec4 _texCoord0; -flat out int instanceID; void main(void) { vec4 coneVertex = inPosition; - instanceID = lightIndex[gl_InstanceID]; + int instanceID = lightIndex[gl_InstanceID]; Light light = getLight(instanceID); vec3 lightPos = getLightPosition(light); vec4 coneParam = getLightVolumeGeometry(light); @@ -53,10 +52,6 @@ void main(void) { // standard transform TransformCamera cam = getTransformCamera(); - - ; !> - <$transformWorldToClipPos(cam, coneVertex, gl_Position)$>; vec4 projected = gl_Position / gl_Position.w;