From 3ec14fd746a88abc3984397505a84a5aeea6ba47 Mon Sep 17 00:00:00 2001 From: samcake Date: Wed, 22 Jun 2016 18:06:55 -0700 Subject: [PATCH] MErging and still trying to understand the curvature isssue --- libraries/fbx/src/FBXReader.h | 1 + libraries/fbx/src/FBXReader_Material.cpp | 4 + libraries/gpu-gl/src/gpu/gl/GLShared.cpp | 2 +- .../src/model-networking/ModelCache.cpp | 12 +++ .../src/model-networking/TextureCache.h | 1 + .../src/DeferredLightingEffect.cpp | 33 +++++++-- .../render-utils/src/DeferredLightingEffect.h | 46 +++++++++++- .../render-utils/src/FramebufferCache.cpp | 2 +- .../render-utils/src/MaterialTextures.slh | 21 +++++- .../render-utils/src/MeshPartPayload.cpp | 14 ++++ .../render-utils/src/RenderDeferredTask.cpp | 6 +- .../render-utils/src/model_normal_map.slf | 5 +- .../src/surfaceGeometry_makeCurvature.slf | 74 +++++++++++++------ libraries/render/src/render/ShapePipeline.cpp | 1 + libraries/render/src/render/ShapePipeline.h | 1 + .../utilities/render/surfaceGeometryPass.qml | 28 +------ 16 files changed, 186 insertions(+), 65 deletions(-) diff --git a/libraries/fbx/src/FBXReader.h b/libraries/fbx/src/FBXReader.h index 483e6d9ba5..606c6832d0 100644 --- a/libraries/fbx/src/FBXReader.h +++ b/libraries/fbx/src/FBXReader.h @@ -167,6 +167,7 @@ public: FBXTexture metallicTexture; FBXTexture emissiveTexture; FBXTexture occlusionTexture; + FBXTexture scatteringTexture; FBXTexture lightmapTexture; glm::vec2 lightmapParams{ 0.0f, 1.0f }; diff --git a/libraries/fbx/src/FBXReader_Material.cpp b/libraries/fbx/src/FBXReader_Material.cpp index 6ad12e4d9a..0517dcd4ec 100644 --- a/libraries/fbx/src/FBXReader_Material.cpp +++ b/libraries/fbx/src/FBXReader_Material.cpp @@ -255,6 +255,10 @@ void FBXReader::consolidateFBXMaterials() { if (material.name.contains("body_mat") || material.name.contains("skin")) { material._material->setScattering(1.0); + if (!material.emissiveTexture.isNull()) { + material.scatteringTexture = material.emissiveTexture; + material.emissiveTexture = FBXTexture(); + } } if (material.opacity <= 0.0f) { diff --git a/libraries/gpu-gl/src/gpu/gl/GLShared.cpp b/libraries/gpu-gl/src/gpu/gl/GLShared.cpp index 17152733d1..d4ecfe0b55 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLShared.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLShared.cpp @@ -700,7 +700,7 @@ bool compileShader(GLenum shaderDomain, const std::string& shaderSource, const s } qCWarning(gpugllogging) << "GLShader::compileShader - errors:"; qCWarning(gpugllogging) << temp; - delete[] temp; + delete[] temp; glDeleteShader(glshader); return false; diff --git a/libraries/model-networking/src/model-networking/ModelCache.cpp b/libraries/model-networking/src/model-networking/ModelCache.cpp index 40388e6123..971c5f927b 100644 --- a/libraries/model-networking/src/model-networking/ModelCache.cpp +++ b/libraries/model-networking/src/model-networking/ModelCache.cpp @@ -487,6 +487,11 @@ NetworkMaterial::NetworkMaterial(const FBXMaterial& material, const QUrl& textur setTextureMap(MapChannel::EMISSIVE_MAP, map); } + if (!material.scatteringTexture.filename.isEmpty()) { + auto map = fetchTextureMap(textureBaseUrl, material.scatteringTexture, NetworkTexture::SCATTERING_TEXTURE, MapChannel::SCATTERING_MAP); + setTextureMap(MapChannel::SCATTERING_MAP, map); + } + if (!material.lightmapTexture.filename.isEmpty()) { auto map = fetchTextureMap(textureBaseUrl, material.lightmapTexture, NetworkTexture::LIGHTMAP_TEXTURE, MapChannel::LIGHTMAP_MAP); _lightmapTransform = material.lightmapTexture.transform; @@ -507,6 +512,7 @@ void NetworkMaterial::setTextures(const QVariantMap& textureMap) { const auto& occlusionName = getTextureName(MapChannel::OCCLUSION_MAP); const auto& emissiveName = getTextureName(MapChannel::EMISSIVE_MAP); const auto& lightmapName = getTextureName(MapChannel::LIGHTMAP_MAP); + const auto& scatteringName = getTextureName(MapChannel::SCATTERING_MAP); if (!albedoName.isEmpty()) { auto url = textureMap.contains(albedoName) ? textureMap[albedoName].toUrl() : QUrl(); @@ -549,6 +555,12 @@ void NetworkMaterial::setTextures(const QVariantMap& textureMap) { setTextureMap(MapChannel::EMISSIVE_MAP, map); } + if (!scatteringName.isEmpty()) { + auto url = textureMap.contains(scatteringName) ? textureMap[scatteringName].toUrl() : QUrl(); + auto map = fetchTextureMap(url, NetworkTexture::SCATTERING_TEXTURE, MapChannel::SCATTERING_MAP); + setTextureMap(MapChannel::SCATTERING_MAP, map); + } + if (!lightmapName.isEmpty()) { auto url = textureMap.contains(lightmapName) ? textureMap[lightmapName].toUrl() : QUrl(); auto map = fetchTextureMap(url, NetworkTexture::LIGHTMAP_TEXTURE, MapChannel::LIGHTMAP_MAP); diff --git a/libraries/model-networking/src/model-networking/TextureCache.h b/libraries/model-networking/src/model-networking/TextureCache.h index f3c6a86b49..0108a3dd6c 100644 --- a/libraries/model-networking/src/model-networking/TextureCache.h +++ b/libraries/model-networking/src/model-networking/TextureCache.h @@ -51,6 +51,7 @@ public: EMISSIVE_TEXTURE, CUBE_TEXTURE, OCCLUSION_TEXTURE, + SCATTERING_TEXTURE = OCCLUSION_TEXTURE, LIGHTMAP_TEXTURE, CUSTOM_TEXTURE }; diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 3e2607413e..cefceb901e 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -450,7 +450,10 @@ void RenderDeferredSetup::run(const render::SceneContextPointer& sceneContext, c } -void RenderDeferredLocals::run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext, const DeferredFrameTransformPointer& frameTransform) { +void RenderDeferredLocals::run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext, const DeferredFrameTransformPointer& frameTransform, bool points, bool spots) { + if (!points && !spots) { + return; + } auto args = renderContext->args; gpu::doInBatch(args->_context, [&](gpu::Batch& batch) { @@ -492,7 +495,7 @@ void RenderDeferredLocals::run(const render::SceneContextPointer& sceneContext, batch.setViewTransform(monoViewTransform); // Splat Point lights - if (!deferredLightingEffect->_pointLights.empty()) { + if (points && !deferredLightingEffect->_pointLights.empty()) { // POint light pipeline batch.setPipeline(deferredLightingEffect->_pointLight); @@ -524,7 +527,7 @@ void RenderDeferredLocals::run(const render::SceneContextPointer& sceneContext, } // Splat spot lights - if (!deferredLightingEffect->_spotLights.empty()) { + if (spots && !deferredLightingEffect->_spotLights.empty()) { // Spot light pipeline batch.setPipeline(deferredLightingEffect->_spotLight); @@ -603,16 +606,34 @@ void RenderDeferredCleanup::run(const render::SceneContextPointer& sceneContext, } } +RenderDeferred::RenderDeferred() : +_subsurfaceScatteringResource(std::make_shared()) +{ +} + + +void RenderDeferred::configure(const Config& config) { + + glm::vec4 bentInfo(config.bentRed, config.bentGreen, config.bentBlue, config.bentScale); + _subsurfaceScatteringResource->setBentNormalFactors(bentInfo); + + glm::vec2 curvatureInfo(config.curvatureOffset, config.curvatureScale); + _subsurfaceScatteringResource->setCurvatureFactors(curvatureInfo); + + + _enablePointLights = config.enablePointLights; + _enableSpotLights = config.enableSpotLights; +} void RenderDeferred::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const DeferredFrameTransformPointer& deferredTransform) { - if (!_subsurfaceScatteringResource) { - _subsurfaceScatteringResource = std::make_shared(); + if (!_subsurfaceScatteringResource->getScatteringTable()) { _subsurfaceScatteringResource->generateScatteringTable(renderContext->args); } setupJob.run(sceneContext, renderContext, deferredTransform, _subsurfaceScatteringResource); - lightsJob.run(sceneContext, renderContext, deferredTransform); + + lightsJob.run(sceneContext, renderContext, deferredTransform, _enablePointLights, _enableSpotLights); cleanupJob.run(sceneContext, renderContext); } diff --git a/libraries/render-utils/src/DeferredLightingEffect.h b/libraries/render-utils/src/DeferredLightingEffect.h index da59a98e37..223b356d49 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.h +++ b/libraries/render-utils/src/DeferredLightingEffect.h @@ -122,7 +122,7 @@ class RenderDeferredLocals { public: using JobModel = render::Job::ModelI; - void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext, const DeferredFrameTransformPointer& frameTransform); + void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext, const DeferredFrameTransformPointer& frameTransform, bool points, bool spots); }; @@ -133,9 +133,47 @@ public: void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext); }; + +class RenderDeferredConfig : public render::Job::Config { + Q_OBJECT + Q_PROPERTY(float bentRed MEMBER bentRed NOTIFY dirty) + Q_PROPERTY(float bentGreen MEMBER bentGreen NOTIFY dirty) + Q_PROPERTY(float bentBlue MEMBER bentBlue NOTIFY dirty) + Q_PROPERTY(float bentScale MEMBER bentScale NOTIFY dirty) + + Q_PROPERTY(float curvatureOffset MEMBER curvatureOffset NOTIFY dirty) + Q_PROPERTY(float curvatureScale MEMBER curvatureScale NOTIFY dirty) + + + Q_PROPERTY(bool enablePointLights MEMBER enablePointLights NOTIFY dirty) + Q_PROPERTY(bool enableSpotLights MEMBER enableSpotLights NOTIFY dirty) +public: + RenderDeferredConfig() : render::Job::Config(true) {} + + float bentRed{ 1.5f }; + float bentGreen{ 0.8f }; + float bentBlue{ 0.3f }; + float bentScale{ 1.5f }; + + float curvatureOffset{ 0.08f }; + float curvatureScale{ 0.8f }; + + bool enablePointLights{ true }; + bool enableSpotLights{ true }; + +signals: + void dirty(); +}; + + class RenderDeferred { public: - using JobModel = render::Job::ModelI; + using Config = RenderDeferredConfig; + using JobModel = render::Job::ModelI; + + RenderDeferred(); + + void configure(const Config& config); void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext, const DeferredFrameTransformPointer& frameTransform); @@ -143,7 +181,11 @@ public: RenderDeferredLocals lightsJob; RenderDeferredCleanup cleanupJob; +protected: SubsurfaceScatteringResourcePointer _subsurfaceScatteringResource; + + bool _enablePointLights{ true }; + bool _enableSpotLights{ true }; }; #endif // hifi_DeferredLightingEffect_h diff --git a/libraries/render-utils/src/FramebufferCache.cpp b/libraries/render-utils/src/FramebufferCache.cpp index 79a8af8eb7..21b0b4e052 100644 --- a/libraries/render-utils/src/FramebufferCache.cpp +++ b/libraries/render-utils/src/FramebufferCache.cpp @@ -107,7 +107,7 @@ void FramebufferCache::createPrimaryFramebuffer() { // For AO: auto pointMipSampler = gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_POINT); - _depthPyramidTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element(gpu::SCALAR, gpu::FLOAT, gpu::RGB), width, height, pointMipSampler)); + _depthPyramidTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element(gpu::SCALAR, gpu::FLOAT, gpu::RGB), width, height, gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR))); _depthPyramidFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create()); _depthPyramidFramebuffer->setRenderBuffer(0, _depthPyramidTexture); _depthPyramidFramebuffer->setDepthStencilBuffer(_primaryDepthTexture, depthFormat); diff --git a/libraries/render-utils/src/MaterialTextures.slh b/libraries/render-utils/src/MaterialTextures.slh index 5cede16e13..97f0ed6e96 100644 --- a/libraries/render-utils/src/MaterialTextures.slh +++ b/libraries/render-utils/src/MaterialTextures.slh @@ -44,7 +44,7 @@ TexMapArray getTexMapArray() { <@endfunc@> -<@func declareMaterialTextures(withAlbedo, withRoughness, withNormal, withMetallic, withEmissive, withOcclusion)@> +<@func declareMaterialTextures(withAlbedo, withRoughness, withNormal, withMetallic, withEmissive, withOcclusion, withScattering)@> <@if withAlbedo@> uniform sampler2D albedoMap; @@ -87,10 +87,18 @@ float fetchOcclusionMap(vec2 uv) { return texture(occlusionMap, uv).r; } <@endif@> + +<@if withScattering@> +uniform sampler2D scatteringMap; +float fetchScatteringMap(vec2 uv) { + return step(0.5, texture(scatteringMap, uv).r); // boolean scattering for now +} +<@endif@> + <@endfunc@> -<@func fetchMaterialTexturesCoord0(matKey, texcoord0, albedo, roughness, normal, metallic, emissive)@> +<@func fetchMaterialTexturesCoord0(matKey, texcoord0, albedo, roughness, normal, metallic, emissive, scattering)@> <@if albedo@> vec4 <$albedo$> = (((<$matKey$> & (ALBEDO_MAP_BIT | OPACITY_MASK_MAP_BIT | OPACITY_TRANSLUCENT_MAP_BIT)) != 0) ? fetchAlbedoMap(<$texcoord0$>) : vec4(1.0)); <@endif@> @@ -106,6 +114,9 @@ float fetchOcclusionMap(vec2 uv) { <@if emissive@> vec3 <$emissive$> = (((<$matKey$> & EMISSIVE_MAP_BIT) != 0) ? fetchEmissiveMap(<$texcoord0$>) : vec3(0.0)); <@endif@> +<@if scattering@> + float <$scattering$> = (((<$matKey$> & SCATTERING_MAP_BIT) != 0) ? fetchScatteringMap(<$texcoord0$>) : 0.0); +<@endif@> <@endfunc@> <@func fetchMaterialTexturesCoord1(matKey, texcoord1, occlusion, lightmapVal)@> @@ -191,4 +202,10 @@ vec3 fetchLightmapMap(vec2 uv) { } <@endfunc@> +<@func evalMaterialScattering(fetchedScattering, materialScattering, matKey, scattering)@> +{ + <$scattering$> = (((<$matKey$> & SCATTERING_MAP_BIT) != 0) ? <$fetchedScattering$> : <$materialScattering$>); +} +<@endfunc@> + <@endif@> \ No newline at end of file diff --git a/libraries/render-utils/src/MeshPartPayload.cpp b/libraries/render-utils/src/MeshPartPayload.cpp index 08c8dc23b4..f554e1aa39 100644 --- a/libraries/render-utils/src/MeshPartPayload.cpp +++ b/libraries/render-utils/src/MeshPartPayload.cpp @@ -217,6 +217,20 @@ void MeshPartPayload::bindMaterial(gpu::Batch& batch, const ShapePipeline::Locat batch.setResourceTexture(ShapePipeline::Slot::MAP::OCCLUSION, nullptr); } + // Scattering map + if (materialKey.isScatteringMap()) { + auto scatteringMap = textureMaps[model::MaterialKey::SCATTERING_MAP]; + if (scatteringMap && scatteringMap->isDefined()) { + batch.setResourceTexture(ShapePipeline::Slot::MAP::SCATTERING, scatteringMap->getTextureView()); + + // texcoord are assumed to be the same has albedo + } else { + batch.setResourceTexture(ShapePipeline::Slot::MAP::SCATTERING, textureCache->getWhiteTexture()); + } + } else { + batch.setResourceTexture(ShapePipeline::Slot::MAP::SCATTERING, nullptr); + } + // Emissive / Lightmap if (materialKey.isLightmapMap()) { auto lightmapMap = textureMaps[model::MaterialKey::LIGHTMAP_MAP]; diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index 4d04814954..09129209c4 100755 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -123,8 +123,8 @@ RenderDeferredTask::RenderDeferredTask(CullFunctor cullFunctor) { // Draw Lights just add the lights to the current list of lights to deal with. NOt really gpu job for now. addJob("DrawLight", lights); - const auto scatteringInputs = render::Varying(SubsurfaceScattering::Inputs(deferredFrameTransform, curvatureFramebuffer, diffusedCurvatureFramebuffer)); - const auto scatteringFramebuffer = addJob("Scattering", scatteringInputs); + // const auto scatteringInputs = render::Varying(SubsurfaceScattering::Inputs(deferredFrameTransform, curvatureFramebuffer, diffusedCurvatureFramebuffer)); + // const auto scatteringFramebuffer = addJob("Scattering", scatteringInputs); // DeferredBuffer is complete, now let's shade it into the LightingBuffer addJob("RenderDeferred", deferredFrameTransform); @@ -147,7 +147,7 @@ RenderDeferredTask::RenderDeferredTask(CullFunctor cullFunctor) { // Debugging stages { // Debugging Deferred buffer job - const auto debugFramebuffers = render::Varying(DebugDeferredBuffer::Inputs(diffusedCurvatureFramebuffer, scatteringFramebuffer)); + const auto debugFramebuffers = render::Varying(DebugDeferredBuffer::Inputs(diffusedCurvatureFramebuffer, curvatureFramebuffer)); addJob("DebugDeferredBuffer", debugFramebuffers); // Scene Octree Debuging job diff --git a/libraries/render-utils/src/model_normal_map.slf b/libraries/render-utils/src/model_normal_map.slf index e6baac4e04..3acdedab2a 100755 --- a/libraries/render-utils/src/model_normal_map.slf +++ b/libraries/render-utils/src/model_normal_map.slf @@ -17,7 +17,7 @@ <@include model/Material.slh@> <@include MaterialTextures.slh@> -<$declareMaterialTextures(ALBEDO, ROUGHNESS, NORMAL, _SCRIBE_NULL, EMISSIVE, OCCLUSION)$> +<$declareMaterialTextures(ALBEDO, ROUGHNESS, NORMAL, _SCRIBE_NULL, EMISSIVE, OCCLUSION, SCATTERING)$> in vec4 _position; in vec2 _texCoord0; @@ -29,7 +29,7 @@ in vec3 _color; void main(void) { Material mat = getMaterial(); int matKey = getMaterialKey(mat); - <$fetchMaterialTexturesCoord0(matKey, _texCoord0, albedoTex, roughnessTex, normalTex, _SCRIBE_NULL, emissiveTex)$> + <$fetchMaterialTexturesCoord0(matKey, _texCoord0, albedoTex, roughnessTex, normalTex, _SCRIBE_NULL, emissiveTex, scatteringTex)$> <$fetchMaterialTexturesCoord1(matKey, _texCoord1, occlusionTex)$> float opacity = 1.0; @@ -50,6 +50,7 @@ void main(void) { <$tangentToViewSpace(normalTex, _normal, _tangent, viewNormal)$> float scattering = getMaterialScattering(mat); + <$evalMaterialScattering(scatteringTex, scattering, matKey, scattering)$>; packDeferredFragment( viewNormal, diff --git a/libraries/render-utils/src/surfaceGeometry_makeCurvature.slf b/libraries/render-utils/src/surfaceGeometry_makeCurvature.slf index 5316ef4211..d4694b4c94 100644 --- a/libraries/render-utils/src/surfaceGeometry_makeCurvature.slf +++ b/libraries/render-utils/src/surfaceGeometry_makeCurvature.slf @@ -91,14 +91,10 @@ vec3 getWorldNormal(vec2 texcoord) { } vec3 getWorldNormalDiff(vec2 texcoord, vec2 delta) { - vec3 normal0 = getWorldNormal(texcoord - delta); - vec3 normal1 = getWorldNormal(texcoord + delta); - return normal1 - normal0; + return getWorldNormal(texcoord + delta) - getWorldNormal(texcoord - delta); } float getEyeDepthDiff(vec2 texcoord, vec2 delta) { - vec3 normal0 = getWorldNormal(texcoord - delta); - vec3 normal1 = getWorldNormal(texcoord + delta); return getZEyeLinear(texcoord + delta) - getZEyeLinear(texcoord - delta); } @@ -118,18 +114,19 @@ void main(void) { // Fetch the z under the pixel (stereo or not) float Zeye = getZEye(framePixelPos); - float nearPlaneScale = min(-Zeye / getCurvatureBasisScale(), 1.0); + // float nearPlaneScale = min(-Zeye / getCurvatureBasisScale(), 1.0); + float nearPlaneScale = 0.5 * getProjectionNear(); vec3 worldNormal = getWorldNormal(frameTexcoordPos); // The position of the pixel fragment in Eye space then in world space vec3 eyePos = evalEyePositionFromZeye(stereoSide.x, Zeye, texcoordPos); - vec3 worldPos = (frameTransform._viewInverse * vec4(eyePos, 1.0)).xyz; + // vec3 worldPos = (frameTransform._viewInverse * vec4(eyePos, 1.0)).xyz; // Calculate the perspective scale. // Clamp to 0.5 - float perspectiveScale = max(0.5, (-getProjScaleEye() / Zeye)); - // float perspectiveScale = max(0.5, (-getProjectionNear() / Zeye)); + // float perspectiveScale = max(0.5, (-getProjScaleEye() / Zeye)); + float perspectiveScale = max(0.5, (-getCurvatureBasisScale() * getProjectionNear() / Zeye)); // Calculate dF/du and dF/dv vec2 viewportScale = perspectiveScale * getInvWidthHeight(); @@ -141,7 +138,7 @@ void main(void) { float threshold = getCurvatureDepthThreshold(); dFdu *= step(abs(dFdu.w), threshold); - dFdv *= step(abs(dFdv.w), threshold); + dFdv *= step(abs(dFdv.w), threshold); //outFragColor = vec4(du.x, du.y, 0.0, 1.0); // outFragColor = vec4(viewportScale, 0.0, 1.0); @@ -160,14 +157,15 @@ void main(void) { // Calculate ( du/dx, du/dy, du/dz ) and ( dv/dx, dv/dy, dv/dz ) // Eval px, py, pz world positions of the basis centered on the world pos of the fragment - float dist = getCurvatureBasisScale() * nearPlaneScale; - vec4 px = vec4(worldPos, 1.0) + vec4(dist, 0.0f, 0.0f, 0.0f); - vec4 py = vec4(worldPos, 1.0) + vec4(0.0f, dist, 0.0f, 0.0f); - vec4 pz = vec4(worldPos, 1.0) + vec4(0.0f, 0.0f, dist, 0.0f); + float axeLength = /*getCurvatureBasisScale() * */ nearPlaneScale; - px = frameTransform._view * px; - py = frameTransform._view * py; - pz = frameTransform._view * pz; + vec3 ax = (frameTransform._view[0].xyz * axeLength); + vec3 ay = (frameTransform._view[1].xyz * axeLength); + vec3 az = (frameTransform._view[2].xyz * axeLength); + + vec4 px = vec4(eyePos + ax, 0.0); + vec4 py = vec4(eyePos + ay, 0.0); + vec4 pz = vec4(eyePos + az, 0.0); /* if (texcoordPos.y > 0.5) { @@ -178,6 +176,33 @@ void main(void) { return; */ + float nearZ = -getProjectionNear(); + vec3 axeSign = vec3(1.0); + /* if (px.z >= nearZ) { + px = vec4(eyePos - ax, 0.0); + axeSign.x = -1.0; + } + if (py.z >= nearZ) { + py = vec4(eyePos - ay, 0.0); + axeSign.y = -1.0; + } + if (pz.z >= nearZ) { + pz = vec4(eyePos - az, 0.0); + axeSign.z = -1.0; + }*/ + + if (px.z >= -nearPlaneScale) { + outFragColor = vec4(1.0, 0.0, 0.0, 1.0); + return; + } else if (py.z >= -nearPlaneScale) { + outFragColor = vec4(0.0, 1.0, 0.0, 1.0); + return; + } else if (pz.z >= -nearPlaneScale) { + outFragColor = vec4(0.0, 0.0, 1.0, 1.0); + return; + } + + // Project px, py pz to homogeneous clip space mat4 viewProj = getProjection(stereoSide.x); px = viewProj * px; @@ -200,17 +225,24 @@ void main(void) { */ float pixPerspectiveScaleInv = 1.0 / (perspectiveScale * nearPlaneScale); - px.xy = (px.xy - nclipPos) * pixPerspectiveScaleInv; - py.xy = (py.xy - nclipPos) * pixPerspectiveScaleInv; - pz.xy = (pz.xy - nclipPos) * pixPerspectiveScaleInv; + px.xy = (px.xy - nclipPos) * pixPerspectiveScaleInv * axeSign.x; + py.xy = (py.xy - nclipPos) * pixPerspectiveScaleInv * axeSign.y; + pz.xy = (pz.xy - nclipPos) * pixPerspectiveScaleInv * axeSign.z; // Calculate dF/dx, dF/dy and dF/dz using chain rule vec4 dFdx = dFdu * px.x + dFdv * px.y; vec4 dFdy = dFdu * py.x + dFdv * py.y; vec4 dFdz = dFdu * pz.x + dFdv * pz.y; + vec3 trace = vec3(dFdx.x, dFdy.y, dFdz.z); + + if (dot(trace, trace) > params.curvatureInfo.w) { + outFragColor = vec4(dFdx.x, dFdy.y, dFdz.z, 1.0); + return; + } + // Calculate the mean curvature - float meanCurvature = ((dFdx.x + dFdy.y + dFdz.z) * 0.33333333333333333) * params.curvatureInfo.w; + float meanCurvature = ((trace.x + trace.y + trace.z) * 0.33333333333333333) * params.curvatureInfo.w; outFragColor = vec4(vec3(worldNormal + 1.0) * 0.5, (meanCurvature + 1.0) * 0.5); } diff --git a/libraries/render/src/render/ShapePipeline.cpp b/libraries/render/src/render/ShapePipeline.cpp index 37c8db8364..5245992ec4 100644 --- a/libraries/render/src/render/ShapePipeline.cpp +++ b/libraries/render/src/render/ShapePipeline.cpp @@ -60,6 +60,7 @@ void ShapePlumber::addPipeline(const Filter& filter, const gpu::ShaderPointer& p slotBindings.insert(gpu::Shader::Binding(std::string("metallicMap"), Slot::MAP::METALLIC)); slotBindings.insert(gpu::Shader::Binding(std::string("emissiveMap"), Slot::MAP::EMISSIVE_LIGHTMAP)); 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("skyboxMap"), Slot::MAP::LIGHT_AMBIENT)); slotBindings.insert(gpu::Shader::Binding(std::string("normalFittingMap"), Slot::NORMAL_FITTING)); diff --git a/libraries/render/src/render/ShapePipeline.h b/libraries/render/src/render/ShapePipeline.h index bed3bd7c68..e65281fd33 100644 --- a/libraries/render/src/render/ShapePipeline.h +++ b/libraries/render/src/render/ShapePipeline.h @@ -209,6 +209,7 @@ public: EMISSIVE_LIGHTMAP, ROUGHNESS, OCCLUSION, + SCATTERING, LIGHT_AMBIENT, NORMAL_FITTING = 10, diff --git a/scripts/developer/utilities/render/surfaceGeometryPass.qml b/scripts/developer/utilities/render/surfaceGeometryPass.qml index b99605978c..7a061da65b 100644 --- a/scripts/developer/utilities/render/surfaceGeometryPass.qml +++ b/scripts/developer/utilities/render/surfaceGeometryPass.qml @@ -19,7 +19,7 @@ Column { Column{ Repeater { - model: [ "Depth Threshold:depthThreshold:1.0", "Basis Scale:basisScale:1.0", "Curvature Scale:curvatureScale:200.0" ] + model: [ "Depth Threshold:depthThreshold:0.1", "Basis Scale:basisScale:2.0", "Curvature Scale:curvatureScale:10.0" ] ConfigSlider { label: qsTr(modelData.split(":")[0]) integral: false @@ -44,31 +44,5 @@ Column { } } } - - Column{ - Repeater { - model: [ "Scattering Bent Red:Scattering:bentRed:2.0", - "Scattering Bent Green:Scattering:bentGreen:2.0", - "Scattering Bent Blue:Scattering:bentBlue:2.0", - "Scattering Bent Scale:Scattering:bentScale:2.0", - "Scattering Curvature Offset:Scattering:curvatureOffset:1.0", - "Scattering Curvature Scale:Scattering:curvatureScale:1.0", - ] - ConfigSlider { - label: qsTr(modelData.split(":")[0]) - integral: false - config: Render.getConfig(modelData.split(":")[1]) - property: modelData.split(":")[2] - max: modelData.split(":")[3] - min: 0.0 - } - } - } - CheckBox { - text: "Show scatteringLUT" - checked: false - onCheckedChanged: { Render.getConfig("Scattering").showLUT = checked } - } - } }