diff --git a/libraries/model/src/model/Light.h b/libraries/model/src/model/Light.h index 893467866a..b57b8c6095 100755 --- a/libraries/model/src/model/Light.h +++ b/libraries/model/src/model/Light.h @@ -111,7 +111,8 @@ public: float getIntensity() const { return _lightSchemaBuffer->irradiance.intensity; } void setIntensity(float intensity); - bool isRanged() const { return (getType() == POINT) || (getType() == SPOT ); } + bool isRanged() const { return (getType() == POINT) || (getType() == SPOT); } + bool hasAmbient() const { return (getType() == SUN); } // FalloffRradius is the physical radius of the light sphere through which energy shines, // expressed in meters. It is used only to calculate the falloff curve of the light. diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 01c5a81732..b1833764dd 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -45,6 +45,7 @@ struct LightLocations { int radius{ -1 }; int ambientSphere{ -1 }; int lightBufferUnit{ -1 }; + int ambientBufferUnit { -1 }; int lightIndexBufferUnit { -1 }; int texcoordFrameTransform{ -1 }; int deferredFrameTransformBuffer{ -1 }; @@ -72,6 +73,7 @@ enum DeferredShader_BufferSlot { SCATTERING_PARAMETERS_BUFFER_SLOT, LIGHTING_MODEL_BUFFER_SLOT = render::ShapePipeline::Slot::LIGHTING_MODEL, LIGHT_GPU_SLOT = render::ShapePipeline::Slot::LIGHT, + LIGHT_AMBIENT_SLOT, LIGHT_INDEX_GPU_SLOT, LIGHT_CLUSTER_GRID_FRUSTUM_GRID_SLOT, LIGHT_CLUSTER_GRID_CLUSTER_GRID_SLOT, @@ -182,13 +184,16 @@ void DeferredLightingEffect::addSpotLight(const glm::vec3& position, float radiu } } -void DeferredLightingEffect::setupKeyLightBatch(gpu::Batch& batch, int lightBufferUnit, int skyboxCubemapUnit) { +void DeferredLightingEffect::setupKeyLightBatch(gpu::Batch& batch, int lightBufferUnit, int ambientBufferUnit, int skyboxCubemapUnit) { PerformanceTimer perfTimer("DLE->setupBatch()"); auto keyLight = _allocatedLights[_globalLights.front()]; if (lightBufferUnit >= 0) { batch.setUniformBuffer(lightBufferUnit, keyLight->getLightSchemaBuffer()); } + if (keyLight->hasAmbient() && (ambientBufferUnit >= 0)) { + batch.setUniformBuffer(ambientBufferUnit, keyLight->getAmbientSchemaBuffer()); + } if (keyLight->getAmbientMap() && (skyboxCubemapUnit >= 0)) { batch.setResourceTexture(skyboxCubemapUnit, keyLight->getAmbientMap()); @@ -221,6 +226,7 @@ static gpu::ShaderPointer makeLightProgram(const char* vertSource, const char* f 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("lightAmbientBuffer"), LIGHT_AMBIENT_SLOT)); slotBindings.insert(gpu::Shader::Binding(std::string("lightIndexBuffer"), LIGHT_INDEX_GPU_SLOT)); @@ -236,6 +242,7 @@ static gpu::ShaderPointer makeLightProgram(const char* vertSource, const char* f locations->texcoordFrameTransform = program->getUniforms().findLocation("texcoordFrameTransform"); locations->lightBufferUnit = program->getBuffers().findLocation("lightBuffer"); + locations->ambientBufferUnit = program->getBuffers().findLocation("lightAmbientBuffer"); locations->lightIndexBufferUnit = program->getBuffers().findLocation("lightIndexBuffer"); locations->deferredFrameTransformBuffer = program->getBuffers().findLocation("deferredFrameTransformBuffer"); locations->subsurfaceScatteringParametersBuffer = program->getBuffers().findLocation("subsurfaceScatteringParametersBuffer"); @@ -640,7 +647,7 @@ void RenderDeferredSetup::run(const render::SceneContextPointer& sceneContext, c batch._glUniform4fv(locations->texcoordFrameTransform, 1, reinterpret_cast< const float* >(&textureFrameTransform)); { // Setup the global lighting - deferredLightingEffect->setupKeyLightBatch(batch, locations->lightBufferUnit, SKYBOX_MAP_UNIT); + deferredLightingEffect->setupKeyLightBatch(batch, locations->lightBufferUnit, locations->ambientBufferUnit, SKYBOX_MAP_UNIT); } batch.draw(gpu::TRIANGLE_STRIP, 4); diff --git a/libraries/render-utils/src/DeferredLightingEffect.h b/libraries/render-utils/src/DeferredLightingEffect.h index 690d6ce5e0..1045cab30e 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.h +++ b/libraries/render-utils/src/DeferredLightingEffect.h @@ -56,7 +56,7 @@ public: float intensity = 0.5f, float falloffRadius = 0.01f, const glm::quat& orientation = glm::quat(), float exponent = 0.0f, float cutoff = PI); - void setupKeyLightBatch(gpu::Batch& batch, int lightBufferUnit, int skyboxCubemapUnit); + void setupKeyLightBatch(gpu::Batch& batch, int lightBufferUnit, int ambientBufferUnit, int skyboxCubemapUnit); // update global lighting void setGlobalLight(const model::LightPointer& light); diff --git a/libraries/render-utils/src/LightingModel.slh b/libraries/render-utils/src/LightingModel.slh index 9d5f78a581..5485224ab8 100644 --- a/libraries/render-utils/src/LightingModel.slh +++ b/libraries/render-utils/src/LightingModel.slh @@ -104,13 +104,17 @@ vec2 skinSpecular(vec3 N, vec3 L, vec3 V, float roughness, float intensity) { vec3 fresnelSchlickColor(vec3 fresnelColor, vec3 lightDir, vec3 halfDir) { float base = 1.0 - clamp(dot(lightDir, halfDir), 0.0, 1.0); - float exponential = pow(base, 5.0); + //float exponential = pow(base, 5.0); + float base2 = base * base; + float exponential = base * base2 * base2; return vec3(exponential) + fresnelColor * (1.0 - exponential); } float fresnelSchlickScalar(float fresnelScalar, vec3 lightDir, vec3 halfDir) { float base = 1.0 - clamp(dot(lightDir, halfDir), 0.0, 1.0); - float exponential = pow(base, 5.0); + //float exponential = pow(base, 5.0); + float base2 = base * base; + float exponential = base * base2 * base2; return (exponential) + fresnelScalar * (1.0 - exponential); } diff --git a/libraries/render-utils/src/RenderPipelines.cpp b/libraries/render-utils/src/RenderPipelines.cpp index e50492fd64..1f4b7ca445 100644 --- a/libraries/render-utils/src/RenderPipelines.cpp +++ b/libraries/render-utils/src/RenderPipelines.cpp @@ -78,6 +78,7 @@ void lightBatchSetter(const ShapePipeline& pipeline, gpu::Batch& batch) { if (pipeline.locations->lightBufferUnit >= 0) { DependencyManager::get()->setupKeyLightBatch(batch, pipeline.locations->lightBufferUnit, + pipeline.locations->lightAmbientBufferUnit, pipeline.locations->lightAmbientMapUnit); } } diff --git a/libraries/render/src/render/ShapePipeline.cpp b/libraries/render/src/render/ShapePipeline.cpp index 3b613e0f96..4bab517e30 100644 --- a/libraries/render/src/render/ShapePipeline.cpp +++ b/libraries/render/src/render/ShapePipeline.cpp @@ -63,6 +63,7 @@ void ShapePlumber::addPipeline(const Filter& filter, const gpu::ShaderPointer& p slotBindings.insert(gpu::Shader::Binding(std::string("occlusionMap"), Slot::MAP::OCCLUSION)); slotBindings.insert(gpu::Shader::Binding(std::string("scatteringMap"), Slot::MAP::SCATTERING)); slotBindings.insert(gpu::Shader::Binding(std::string("lightBuffer"), Slot::BUFFER::LIGHT)); + slotBindings.insert(gpu::Shader::Binding(std::string("lightAmbientBuffer"), Slot::BUFFER::LIGHT_AMBIENT_BUFFER)); slotBindings.insert(gpu::Shader::Binding(std::string("skyboxMap"), Slot::MAP::LIGHT_AMBIENT)); slotBindings.insert(gpu::Shader::Binding(std::string("normalFittingMap"), Slot::NORMAL_FITTING)); @@ -85,8 +86,9 @@ void ShapePlumber::addPipeline(const Filter& filter, const gpu::ShaderPointer& p locations->materialBufferUnit = program->getBuffers().findLocation("materialBuffer"); locations->texMapArrayBufferUnit = program->getBuffers().findLocation("texMapArrayBuffer"); locations->lightBufferUnit = program->getBuffers().findLocation("lightBuffer"); + locations->lightAmbientBufferUnit = program->getBuffers().findLocation("lightAmbientBuffer"); locations->lightAmbientMapUnit = program->getTextures().findLocation("skyboxMap"); - + ShapeKey key{filter._flags}; auto gpuPipeline = gpu::Pipeline::create(program, state); auto shapePipeline = std::make_shared(gpuPipeline, locations, batchSetter); diff --git a/libraries/render/src/render/ShapePipeline.h b/libraries/render/src/render/ShapePipeline.h index 5b60521068..e7a14d2f2b 100644 --- a/libraries/render/src/render/ShapePipeline.h +++ b/libraries/render/src/render/ShapePipeline.h @@ -201,6 +201,7 @@ public: TEXMAPARRAY, LIGHTING_MODEL, LIGHT, + LIGHT_AMBIENT_BUFFER, }; enum MAP { @@ -231,6 +232,7 @@ public: int materialBufferUnit; int texMapArrayBufferUnit; int lightBufferUnit; + int lightAmbientBufferUnit; int lightAmbientMapUnit; }; using LocationsPointer = std::shared_ptr;