From a4df8a84b7c26ef5a0ddba3a55741cb44dc8be9d Mon Sep 17 00:00:00 2001 From: sam Date: Thu, 8 Sep 2016 00:11:54 -0700 Subject: [PATCH] introducing the light Clusters --- .../src/DeferredLightingEffect.cpp | 69 +++---------------- libraries/render-utils/src/LightClusters.cpp | 12 ++++ libraries/render-utils/src/LightClusters.h | 28 ++++++++ 3 files changed, 50 insertions(+), 59 deletions(-) create mode 100644 libraries/render-utils/src/LightClusters.cpp create mode 100644 libraries/render-utils/src/LightClusters.h diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 3c6608b011..94c12f7d99 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -80,26 +80,11 @@ static void loadLightVolumeProgram(const char* vertSource, const char* fragSourc 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" ; @@ -201,8 +186,7 @@ void DeferredLightingEffect::setupKeyLightBatch(gpu::Batch& batch, int lightBuff batch.setResourceTexture(skyboxCubemapUnit, keyLight->getAmbientMap()); } } - -static void loadLightProgram(const char* vertSource, const char* fragSource, bool lightVolume, gpu::PipelinePointer& pipeline, LightLocationsPtr& locations) { +static gpu::ShaderPointer makeLightProgram(const char* vertSource, const char* fragSource, LightLocationsPtr& locations) { auto VS = gpu::Shader::createVertex(std::string(vertSource)); auto PS = gpu::Shader::createPixel(std::string(fragSource)); @@ -245,6 +229,13 @@ static void loadLightProgram(const char* vertSource, const char* fragSource, boo locations->subsurfaceScatteringParametersBuffer = program->getBuffers().findLocation("subsurfaceScatteringParametersBuffer"); locations->shadowTransformBuffer = program->getBuffers().findLocation("shadowTransformBuffer"); + return program; +} + +static void loadLightProgram(const char* vertSource, const char* fragSource, bool lightVolume, gpu::PipelinePointer& pipeline, LightLocationsPtr& locations) { + + gpu::ShaderPointer program = makeLightProgram(vertSource, fragSource, locations); + auto state = std::make_shared(); state->setColorWriteMask(true, true, true, false); @@ -276,47 +267,7 @@ static void loadLightProgram(const char* vertSource, const char* fragSource, boo static void loadLightVolumeProgram(const char* vertSource, const char* fragSource, bool front, gpu::PipelinePointer& pipeline, LightLocationsPtr& locations) { - auto VS = gpu::Shader::createVertex(std::string(vertSource)); - auto PS = gpu::Shader::createPixel(std::string(fragSource)); - - gpu::ShaderPointer program = gpu::Shader::createProgram(VS, PS); - - gpu::Shader::BindingSet slotBindings; - slotBindings.insert(gpu::Shader::Binding(std::string("colorMap"), DEFERRED_BUFFER_COLOR_UNIT)); - slotBindings.insert(gpu::Shader::Binding(std::string("normalMap"), DEFERRED_BUFFER_NORMAL_UNIT)); - slotBindings.insert(gpu::Shader::Binding(std::string("specularMap"), DEFERRED_BUFFER_EMISSIVE_UNIT)); - slotBindings.insert(gpu::Shader::Binding(std::string("depthMap"), DEFERRED_BUFFER_DEPTH_UNIT)); - slotBindings.insert(gpu::Shader::Binding(std::string("obscuranceMap"), DEFERRED_BUFFER_OBSCURANCE_UNIT)); - slotBindings.insert(gpu::Shader::Binding(std::string("shadowMap"), SHADOW_MAP_UNIT)); - slotBindings.insert(gpu::Shader::Binding(std::string("skyboxMap"), SKYBOX_MAP_UNIT)); - - slotBindings.insert(gpu::Shader::Binding(std::string("linearZeyeMap"), DEFERRED_BUFFER_LINEAR_DEPTH_UNIT)); - slotBindings.insert(gpu::Shader::Binding(std::string("curvatureMap"), DEFERRED_BUFFER_CURVATURE_UNIT)); - slotBindings.insert(gpu::Shader::Binding(std::string("diffusedCurvatureMap"), DEFERRED_BUFFER_DIFFUSED_CURVATURE_UNIT)); - slotBindings.insert(gpu::Shader::Binding(std::string("scatteringLUT"), SCATTERING_LUT_UNIT)); - slotBindings.insert(gpu::Shader::Binding(std::string("scatteringSpecularBeckmann"), SCATTERING_SPECULAR_UNIT)); - - - slotBindings.insert(gpu::Shader::Binding(std::string("cameraCorrectionBuffer"), CAMERA_CORRECTION_BUFFER_SLOT)); - slotBindings.insert(gpu::Shader::Binding(std::string("deferredFrameTransformBuffer"), DEFERRED_FRAME_TRANSFORM_BUFFER_SLOT)); - slotBindings.insert(gpu::Shader::Binding(std::string("lightingModelBuffer"), LIGHTING_MODEL_BUFFER_SLOT)); - slotBindings.insert(gpu::Shader::Binding(std::string("subsurfaceScatteringParametersBuffer"), SCATTERING_PARAMETERS_BUFFER_SLOT)); - slotBindings.insert(gpu::Shader::Binding(std::string("lightBuffer"), LIGHT_GPU_SLOT)); - slotBindings.insert(gpu::Shader::Binding(std::string("lightIndexBuffer"), LIGHT_INDEX_GPU_SLOT)); - - - gpu::Shader::makeProgram(*program, slotBindings); - - locations->radius = program->getUniforms().findLocation("radius"); - locations->ambientSphere = program->getUniforms().findLocation("ambientSphere.L00"); - - locations->texcoordFrameTransform = program->getUniforms().findLocation("texcoordFrameTransform"); - - locations->lightBufferUnit = program->getBuffers().findLocation("lightBuffer"); - locations->lightIndexBufferUnit = program->getBuffers().findLocation("lightIndexBuffer"); - locations->deferredFrameTransformBuffer = program->getBuffers().findLocation("deferredFrameTransformBuffer"); - locations->subsurfaceScatteringParametersBuffer = program->getBuffers().findLocation("subsurfaceScatteringParametersBuffer"); - locations->shadowTransformBuffer = program->getBuffers().findLocation("shadowTransformBuffer"); + gpu::ShaderPointer program = makeLightProgram(vertSource, fragSource, locations); auto state = std::make_shared(); // state->setColorWriteMask(true, true, true, false); diff --git a/libraries/render-utils/src/LightClusters.cpp b/libraries/render-utils/src/LightClusters.cpp new file mode 100644 index 0000000000..f266be988a --- /dev/null +++ b/libraries/render-utils/src/LightClusters.cpp @@ -0,0 +1,12 @@ +// +// LightClusters.cpp +// +// Created by Sam Gateau on 9/7/2016. +// Copyright 2015 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 +// + +#include "LightClusters.h" + diff --git a/libraries/render-utils/src/LightClusters.h b/libraries/render-utils/src/LightClusters.h new file mode 100644 index 0000000000..3557ec0ed0 --- /dev/null +++ b/libraries/render-utils/src/LightClusters.h @@ -0,0 +1,28 @@ +// +// LightClusters.h +// +// Created by Sam Gateau on 9/7/2016. +// Copyright 2015 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 +// + +#ifndef hifi_render_utils_LightClusters_h +#define hifi_render_utils_LightClusters_h + +#include "gpu/Framebuffer.h" + +#include "LightStage.h" + +class ViewFrustum; + +class LightClusters { +public: + + LightStagePointer _lightStage; + + gpu::BufferPointer _lightIndicesBuffer; +}; + +#endif