diff --git a/libraries/render-utils/src/DeferredLightingEffect.h b/libraries/render-utils/src/DeferredLightingEffect.h index 63d8f4d175..6428cc5742 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.h +++ b/libraries/render-utils/src/DeferredLightingEffect.h @@ -44,7 +44,7 @@ public: const glm::quat& orientation = glm::quat(), float exponent = 0.0f, float cutoff = PI); void prepare(RenderArgs* args); - void render(const render::RenderContextPointer& renderContext); + void render(const render::RenderContextPointer& renderContext, ); void setupKeyLightBatch(gpu::Batch& batch, int lightBufferUnit, int skyboxCubemapUnit); diff --git a/libraries/render-utils/src/LightStage.cpp b/libraries/render-utils/src/LightStage.cpp index fc6c3ff514..f1726feca6 100644 --- a/libraries/render-utils/src/LightStage.cpp +++ b/libraries/render-utils/src/LightStage.cpp @@ -88,8 +88,9 @@ const glm::mat4& LightStage::Shadow::getProjection() const { } const LightStage::LightPointer LightStage::addLight(model::LightPointer light) { - Shadow stageShadow{light}; - LightPointer stageLight = std::make_shared(std::move(stageShadow)); + // Shadow stageShadow{light}; + LightPointer stageLight = std::make_shared(Shadow(light)); + stageLight->light = light; lights.push_back(stageLight); return stageLight; } diff --git a/libraries/render-utils/src/LightStage.h b/libraries/render-utils/src/LightStage.h index 9ed9789965..76d9a3b268 100644 --- a/libraries/render-utils/src/LightStage.h +++ b/libraries/render-utils/src/LightStage.h @@ -52,6 +52,8 @@ public: glm::float32 scale = 1 / MAP_SIZE; }; UniformBufferView _schemaBuffer = nullptr; + + friend class Light; }; using ShadowPointer = std::shared_ptr; diff --git a/libraries/render-utils/src/SubsurfaceScattering.cpp b/libraries/render-utils/src/SubsurfaceScattering.cpp index 741c563555..5c728b7307 100644 --- a/libraries/render-utils/src/SubsurfaceScattering.cpp +++ b/libraries/render-utils/src/SubsurfaceScattering.cpp @@ -15,12 +15,15 @@ #include "FramebufferCache.h" +#include "DeferredLightingEffect.h" + #include "subsurfaceScattering_makeLUT_frag.h" #include "subsurfaceScattering_drawScattering_frag.h" enum ScatteringShaderBufferSlots { ScatteringTask_FrameTransformSlot = 0, ScatteringTask_ParamSlot, + ScatteringTask_LightSlot, }; enum ScatteringShaderMapSlots { ScatteringTask_ScatteringTableSlot = 0, @@ -30,6 +33,8 @@ enum ScatteringShaderMapSlots { ScatteringTask_AlbedoMapSlot, ScatteringTask_LinearMapSlot, + + SCatteringTask_IBLMapSlot, }; @@ -69,6 +74,7 @@ gpu::PipelinePointer SubsurfaceScattering::getScatteringPipeline() { gpu::Shader::BindingSet slotBindings; slotBindings.insert(gpu::Shader::Binding(std::string("deferredFrameTransformBuffer"), ScatteringTask_FrameTransformSlot)); slotBindings.insert(gpu::Shader::Binding(std::string("scatteringParamsBuffer"), ScatteringTask_ParamSlot)); + slotBindings.insert(gpu::Shader::Binding(std::string("lightBuffer"), ScatteringTask_LightSlot)); slotBindings.insert(gpu::Shader::Binding(std::string("scatteringLUT"), ScatteringTask_ScatteringTableSlot)); slotBindings.insert(gpu::Shader::Binding(std::string("curvatureMap"), ScatteringTask_CurvatureMapSlot)); @@ -174,6 +180,8 @@ void SubsurfaceScattering::run(const render::SceneContextPointer& sceneContext, return; } + const auto theLight = DependencyManager::get()->getLightStage().lights[0]; + gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { batch.enableStereo(false); @@ -186,7 +194,8 @@ void SubsurfaceScattering::run(const render::SceneContextPointer& sceneContext, batch.setUniformBuffer(ScatteringTask_FrameTransformSlot, frameTransform->getFrameTransformBuffer()); batch.setUniformBuffer(ScatteringTask_ParamSlot, _parametersBuffer); - + if (theLight->light) + batch.setUniformBuffer(ScatteringTask_LightSlot, theLight->light->getSchemaBuffer()); batch.setResourceTexture(ScatteringTask_ScatteringTableSlot, _scatteringTable); batch.setResourceTexture(ScatteringTask_CurvatureMapSlot, curvatureFramebuffer->getRenderBuffer(0)); batch.setResourceTexture(ScatteringTask_DiffusedCurvatureMapSlot, diffusedFramebuffer->getRenderBuffer(0)); diff --git a/libraries/render-utils/src/subsurfaceScattering_drawScattering.slf b/libraries/render-utils/src/subsurfaceScattering_drawScattering.slf index bbe4af7335..eac4da0709 100644 --- a/libraries/render-utils/src/subsurfaceScattering_drawScattering.slf +++ b/libraries/render-utils/src/subsurfaceScattering_drawScattering.slf @@ -14,6 +14,8 @@ <$declareDeferredFrameTransform()$> +<@include model/Light.slh@> + uniform sampler2D linearDepthMap; float getZEye(ivec2 pixel) { return -texelFetch(linearDepthMap, pixel, 0).x; @@ -109,7 +111,7 @@ float unpackCurvature(float packedCurvature) { in vec2 varTexCoord0; out vec4 _fragColor; -uniform vec3 uniformLightVector = vec3(1.0); +//uniform vec3 uniformLightVector = vec3(1.0); void main(void) { @@ -128,7 +130,9 @@ void main(void) { // _fragColor = vec4(vec3(diffusedCurvature.xyz), 1.0); // --> Calculate the light vector. - vec3 lightVector = normalize(uniformLightVector); //normalize(lightPos - sourcePos.xyz); + + Light light = getLight(); + vec3 lightVector = -getLightDirection(light); //normalize(uniformLightVector); //normalize(lightPos - sourcePos.xyz); // _fragColor = vec4(fetchBRDF(dot(bentNormalR, lightVector), abs(diffusedCurvature.w * 2 - 1)), 1.0); // _fragColor = vec4(vec3(abs(dot(bentNormalR, lightVector))), 1.0); @@ -160,19 +164,19 @@ void main(void) { // Fetch the z under the pixel (stereo or not) float Zeye = getZEye(framePixelPos); - vec3 worldNormal = getWorldNormal(frameTexcoordPos); + vec3 worldNormal = fragment.normal; // The position of the pixel fragment in Eye space then in world space vec3 eyePos = evalEyePositionFromZeye(stereoSide.x, Zeye, texcoordPos); vec3 fragEyeDir = -(frameTransform._viewInverse * vec4(normalize(eyePos), 0.0)).xyz; vec3 fresnel = vec3(0.03); // Default Di-electric fresnel value if (fragment.metallic > 0.5) { - fresnel = albedo; + fresnel = fragment.diffuse; fragment.metallic = 1.0; } - vec4 shading = evalPBRShading(rS, lightVector, fragEyeDir, fragment.metallic, fresnel, fragment.roughness); - _fragColor = vec4(shading.w * albedo * vec3(bdrf.xyz), 1.0); + //vec4 shading = evalPBRShading(rS, lightVector, fragEyeDir, fragment.metallic, fresnel, fragment.roughness); + _fragColor = vec4(fragment.diffuse * vec3(bdrf.xyz), 1.0); } diff --git a/libraries/render/src/render/BlurTask.cpp b/libraries/render/src/render/BlurTask.cpp index 3f9a1cf111..53129f16ba 100644 --- a/libraries/render/src/render/BlurTask.cpp +++ b/libraries/render/src/render/BlurTask.cpp @@ -306,8 +306,8 @@ void BlurGaussianDepthAware::run(const SceneContextPointer& sceneContext, const RenderArgs* args = renderContext->args; - auto& sourceFramebuffer = SourceAndDepth.first. template get();//getFirst(); - auto& depthTexture = SourceAndDepth.second. template get();//getSecond(); + auto& sourceFramebuffer = SourceAndDepth.getFirst(); + auto& depthTexture = SourceAndDepth.getSecond(); BlurInOutResource::Resources blurringResources; if (!_inOutResources.updateResources(sourceFramebuffer, blurringResources)) { diff --git a/libraries/render/src/render/Task.h b/libraries/render/src/render/Task.h index 28d8d6151b..5a67e68f20 100644 --- a/libraries/render/src/render/Task.h +++ b/libraries/render/src/render/Task.h @@ -117,14 +117,14 @@ public: VaryingTrio(const VaryingTrio& trio) : Parent(std::get<0>(trio), std::get<1>(trio), std::get<2>(trio)) {} VaryingTrio(const Varying& first, const Varying& second, const Varying& third) : Parent(first, second, third) {} - const T0& getFirst() const { return std::get<0>((*this)).get(); } - T0& editFirst() { return std::get<0>((*this)).edit(); } + const T0& getFirst() const { return std::get<0>((*this)).template get(); } + T0& editFirst() { return std::get<0>((*this)).template edit(); } - const T1& getSecond() const { return std::get<1>((*this)).get(); } - T1& editSecond() { return std::get<1>((*this)).edit(); } + const T1& getSecond() const { return std::get<1>((*this)).template get(); } + T1& editSecond() { return std::get<1>((*this)).template edit(); } - const T2& getThird() const { return std::get<2>((*this)).get(); } - T2& editThird() { return std::get<2>((*this)).edit(); } + const T2& getThird() const { return std::get<2>((*this)).template get(); } + T2& editThird() { return std::get<2>((*this)).template edit(); } }; /* template