From 08fcd6c357bfa41492307cdfe758aecf81d69983 Mon Sep 17 00:00:00 2001 From: Olivier Prat Date: Mon, 5 Jun 2017 16:32:36 +0200 Subject: [PATCH] Added new shaders --- libraries/render-utils/src/Fade.slh | 6 +- .../render-utils/src/MeshPartPayload.cpp | 14 +-- .../render-utils/src/RenderDeferredTask.cpp | 19 +++- .../render-utils/src/RenderDeferredTask.h | 33 ++++--- .../render-utils/src/RenderPipelines.cpp | 78 ++++++++++++++- libraries/render-utils/src/model_fade.slf | 2 +- .../render-utils/src/model_lightmap_fade.slf | 50 ++++++++++ .../render-utils/src/model_lightmap_fade.slv | 48 +++++++++ .../src/model_lightmap_normal_map_fade.slf | 53 ++++++++++ .../src/model_lightmap_normal_map_fade.slv | 48 +++++++++ ...odel_lightmap_normal_specular_map_fade.slf | 53 ++++++++++ .../src/model_lightmap_specular_map_fade.slf | 49 ++++++++++ .../src/model_normal_map_fade.slf | 2 +- .../src/model_normal_specular_map_fade.slf | 72 ++++++++++++++ .../src/model_specular_map_fade.slf | 68 +++++++++++++ .../render-utils/src/model_unlit_fade.slf | 50 ++++++++++ libraries/render-utils/src/simple_fade.slf | 97 +++++++++++++++++++ libraries/render-utils/src/simple_fade.slv | 42 ++++++++ .../render-utils/src/simple_textured_fade.slf | 60 ++++++++++++ .../src/simple_textured_unlit_fade.slf | 54 +++++++++++ .../render-utils/src/skin_model_fade.slv | 55 +++++++++++ .../src/skin_model_normal_map_fade.slv | 64 ++++++++++++ plugins/openvr/src/ViveControllerManager.h | 2 +- .../developer/utilities/render/debugFade.js | 2 +- scripts/developer/utilities/render/fade.qml | 53 +++++++--- 25 files changed, 1030 insertions(+), 44 deletions(-) create mode 100644 libraries/render-utils/src/model_lightmap_fade.slf create mode 100644 libraries/render-utils/src/model_lightmap_fade.slv create mode 100644 libraries/render-utils/src/model_lightmap_normal_map_fade.slf create mode 100644 libraries/render-utils/src/model_lightmap_normal_map_fade.slv create mode 100644 libraries/render-utils/src/model_lightmap_normal_specular_map_fade.slf create mode 100644 libraries/render-utils/src/model_lightmap_specular_map_fade.slf create mode 100644 libraries/render-utils/src/model_normal_specular_map_fade.slf create mode 100644 libraries/render-utils/src/model_specular_map_fade.slf create mode 100644 libraries/render-utils/src/model_unlit_fade.slf create mode 100644 libraries/render-utils/src/simple_fade.slf create mode 100644 libraries/render-utils/src/simple_fade.slv create mode 100644 libraries/render-utils/src/simple_textured_fade.slf create mode 100644 libraries/render-utils/src/simple_textured_unlit_fade.slf create mode 100644 libraries/render-utils/src/skin_model_fade.slv create mode 100644 libraries/render-utils/src/skin_model_normal_map_fade.slv diff --git a/libraries/render-utils/src/Fade.slh b/libraries/render-utils/src/Fade.slh index 8c64710fde..06eed5b21f 100644 --- a/libraries/render-utils/src/Fade.slh +++ b/libraries/render-utils/src/Fade.slh @@ -33,7 +33,7 @@ vec2 hash2D(vec3 position) { return position.xy* vec2(0.1677, 0.221765) + position.z*0.561; } -float evalFadeMask(vec3 position, vec3 normal) { +float evalFadeMask(vec3 position) { const float FADE_MASK_INV_SCALE = 1.0; // Do tri-linear interpolation @@ -56,8 +56,8 @@ float evalFadeMask(vec3 position, vec3 normal) { return mix(maskY.x, maskY.y, noisePositionFraction.y); } -void applyFade(vec3 position, vec3 normal) { - if (evalFadeMask(position, normal) < fade._Percent) { +void applyFade(vec3 position) { + if (evalFadeMask(position) > fade._Percent) { discard; } } diff --git a/libraries/render-utils/src/MeshPartPayload.cpp b/libraries/render-utils/src/MeshPartPayload.cpp index 81f8dc3228..39f07e0232 100644 --- a/libraries/render-utils/src/MeshPartPayload.cpp +++ b/libraries/render-utils/src/MeshPartPayload.cpp @@ -400,10 +400,6 @@ ItemKey ModelMeshPartPayload::getKey() const { builder.withTransparent(); } } - - if (_fadeState != FADE_COMPLETE) { - builder.withTransparent(); - } } return builder.build(); } @@ -537,9 +533,9 @@ float ModelMeshPartPayload::computeFadePercent() const { return 0.0f; } float fadeAlpha = 1.0f; - const float INV_FADE_PERIOD = 1.0f / (float)(3 * USECS_PER_SECOND); - float fraction = (float)(usecTimestampNow() - _fadeStartTime) * INV_FADE_PERIOD; - if (fraction < 1.0f) { + const double INV_FADE_PERIOD = 1.0 / (double)(10 * USECS_PER_SECOND); + double fraction = (double)(usecTimestampNow() - _fadeStartTime) * INV_FADE_PERIOD; + if (fraction < 1.0) { fadeAlpha = Interpolate::simpleNonLinearBlend(fraction); } if (fadeAlpha >= 1.0f) { @@ -549,9 +545,9 @@ float ModelMeshPartPayload::computeFadePercent() const { if (model) { model->setRenderItemsNeedUpdate(); } - return 1.0f; + fadeAlpha = 1.0f; } - return Interpolate::simpleNonLinearBlend(fadeAlpha); + return fadeAlpha; } void ModelMeshPartPayload::bindFade(gpu::Batch& batch, const RenderArgs* args) const { diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index fa6f72f3b5..412d74fe87 100644 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -147,7 +147,7 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren // Render transparent objects forward in LightingBuffer const auto transparentsInputs = DrawDeferred::Inputs(transparents, lightingModel).hasVarying(); - task.addJob("DrawTransparentDeferred", transparentsInputs, shapePlumber); + task.addJob("DrawTransparentDeferred", transparentsInputs, shapePlumber, fadeMaskMap); // LIght Cluster Grid Debuging job { @@ -276,6 +276,16 @@ void DrawDeferred::run(const RenderContextPointer& renderContext, const Inputs& if (lightingModel->isWireframeEnabled()) { keyBuilder.withWireframe(); } + // Prepare fade effect + batch.setResourceTexture(ShapePipeline::Slot::MAP::FADE_MASK, _fadeMaskMap); + if (_debugFade) { + args->_debugFlags = static_cast(args->_debugFlags | + static_cast(RenderArgs::RENDER_DEBUG_FADE)); + args->_debugFadePercent = _debugFadePercent; + // Force fade for everyone + keyBuilder.withFade(); + } + ShapeKey globalKey = keyBuilder.build(); args->_globalShapeKey = globalKey._flags.to_ulong(); @@ -283,6 +293,13 @@ void DrawDeferred::run(const RenderContextPointer& renderContext, const Inputs& args->_batch = nullptr; args->_globalShapeKey = 0; + + // Not sure this is really needed... + if (_debugFade) { + // Turn off fade debug + args->_debugFlags = static_cast(args->_debugFlags & + ~static_cast(RenderArgs::RENDER_DEBUG_FADE)); + } }); config->setNumDrawn((int)inItems.size()); diff --git a/libraries/render-utils/src/RenderDeferredTask.h b/libraries/render-utils/src/RenderDeferredTask.h index 4ab4915358..ebb7d34606 100644 --- a/libraries/render-utils/src/RenderDeferredTask.h +++ b/libraries/render-utils/src/RenderDeferredTask.h @@ -45,17 +45,31 @@ protected: }; +class DrawFadableDeferred { +protected: + DrawFadableDeferred(gpu::TexturePointer fadeMaskMap) : _fadeMaskMap{ fadeMaskMap } {} + + gpu::TexturePointer _fadeMaskMap; + float _debugFadePercent; + bool _stateSort; + bool _debugFade; +}; + class DrawConfig : public render::Job::Config { Q_OBJECT Q_PROPERTY(int numDrawn READ getNumDrawn NOTIFY newStats) - Q_PROPERTY(int maxDrawn MEMBER maxDrawn NOTIFY dirty) + Q_PROPERTY(bool debugFade MEMBER debugFade NOTIFY dirty) + Q_PROPERTY(float debugFadePercent MEMBER debugFadePercent NOTIFY dirty) + public: int getNumDrawn() { return _numDrawn; } void setNumDrawn(int numDrawn) { _numDrawn = numDrawn; emit newStats(); } int maxDrawn{ -1 }; + float debugFadePercent{ 0.f }; + bool debugFade{ false }; signals: void newStats(); @@ -65,15 +79,15 @@ protected: int _numDrawn{ 0 }; }; -class DrawDeferred { +class DrawDeferred : public DrawFadableDeferred { public: using Inputs = render::VaryingSet2 ; using Config = DrawConfig; using JobModel = render::Job::ModelI; - DrawDeferred(render::ShapePlumberPointer shapePlumber) : _shapePlumber{ shapePlumber } {} + DrawDeferred(render::ShapePlumberPointer shapePlumber, gpu::TexturePointer fadeMaskMap) : _shapePlumber{ shapePlumber }, DrawFadableDeferred{ fadeMaskMap } {} - void configure(const Config& config) { _maxDrawn = config.maxDrawn; } + void configure(const Config& config) { _maxDrawn = config.maxDrawn; _debugFadePercent = config.debugFadePercent; _debugFade = config.debugFade; } void run(const render::RenderContextPointer& renderContext, const Inputs& inputs); protected: @@ -94,8 +108,8 @@ public: void setNumDrawn(int num) { numDrawn = num; emit numDrawnChanged(); } int maxDrawn{ -1 }; - float debugFadePercent{ 0.f }; bool stateSort{ true }; + float debugFadePercent{ 0.f }; bool debugFade{ false }; signals: @@ -106,25 +120,21 @@ protected: int numDrawn{ 0 }; }; -class DrawStateSortDeferred { +class DrawStateSortDeferred : public DrawFadableDeferred { public: using Inputs = render::VaryingSet2 ; using Config = DrawStateSortConfig; using JobModel = render::Job::ModelI; - DrawStateSortDeferred(render::ShapePlumberPointer shapePlumber, gpu::TexturePointer fadeMaskMap) : _shapePlumber{ shapePlumber }, _fadeMaskMap{ fadeMaskMap } {} + DrawStateSortDeferred(render::ShapePlumberPointer shapePlumber, gpu::TexturePointer fadeMaskMap) : _shapePlumber{ shapePlumber }, DrawFadableDeferred{ fadeMaskMap } {} void configure(const Config& config) { _maxDrawn = config.maxDrawn; _stateSort = config.stateSort; _debugFadePercent = config.debugFadePercent; _debugFade = config.debugFade; } void run(const render::RenderContextPointer& renderContext, const Inputs& inputs); protected: render::ShapePlumberPointer _shapePlumber; - gpu::TexturePointer _fadeMaskMap; int _maxDrawn; // initialized by Config - float _debugFadePercent; - bool _stateSort; - bool _debugFade; }; class DeferredFramebuffer; @@ -207,6 +217,7 @@ public: RenderDeferredTask() {} void build(JobModel& task, const render::Varying& inputs, render::Varying& outputs); + }; #endif // hifi_RenderDeferredTask_h diff --git a/libraries/render-utils/src/RenderPipelines.cpp b/libraries/render-utils/src/RenderPipelines.cpp index 763fca04ed..d771b0f5cc 100644 --- a/libraries/render-utils/src/RenderPipelines.cpp +++ b/libraries/render-utils/src/RenderPipelines.cpp @@ -28,12 +28,22 @@ #include "skin_model_shadow_vert.h" #include "skin_model_normal_map_vert.h" +#include "skin_model_fade_vert.h" +#include "skin_model_normal_map_fade_vert.h" + +#include "model_lightmap_fade_vert.h" +#include "model_lightmap_normal_map_fade_vert.h" + #include "simple_vert.h" #include "simple_textured_frag.h" #include "simple_textured_unlit_frag.h" #include "simple_transparent_textured_frag.h" #include "simple_transparent_textured_unlit_frag.h" +#include "simple_fade_vert.h" +#include "simple_textured_fade_frag.h" +#include "simple_textured_unlit_fade_frag.h" + #include "model_frag.h" #include "model_unlit_frag.h" #include "model_shadow_frag.h" @@ -45,7 +55,10 @@ #include "model_normal_map_fade_vert.h" #include "model_fade_frag.h" +#include "model_unlit_fade_frag.h" #include "model_normal_map_fade_frag.h" +#include "model_normal_specular_map_fade_frag.h" +#include "model_specular_map_fade_frag.h" #include "forward_model_frag.h" #include "forward_model_unlit_frag.h" @@ -60,6 +73,11 @@ #include "model_translucent_frag.h" #include "model_translucent_unlit_frag.h" +#include "model_lightmap_fade_frag.h" +#include "model_lightmap_normal_map_fade_frag.h" +#include "model_lightmap_normal_specular_map_fade_frag.h" +#include "model_lightmap_specular_map_fade_frag.h" + #include "overlay3D_vert.h" #include "overlay3D_frag.h" #include "overlay3D_model_frag.h" @@ -156,10 +174,15 @@ void initDeferredPipelines(render::ShapePlumber& plumber) { auto skinModelVertex = gpu::Shader::createVertex(std::string(skin_model_vert)); auto skinModelNormalMapVertex = gpu::Shader::createVertex(std::string(skin_model_normal_map_vert)); auto skinModelShadowVertex = gpu::Shader::createVertex(std::string(skin_model_shadow_vert)); + auto modelLightmapFadeVertex = gpu::Shader::createVertex(std::string(model_lightmap_fade_vert)); + auto modelLightmapNormalMapFadeVertex = gpu::Shader::createVertex(std::string(model_lightmap_normal_map_fade_vert)); + auto skinModelFadeVertex = gpu::Shader::createVertex(std::string(skin_model_fade_vert)); + auto skinModelNormalMapFadeVertex = gpu::Shader::createVertex(std::string(skin_model_normal_map_fade_vert)); // Only models can have fade applied to them (?) auto modelFadeVertex = gpu::Shader::createVertex(std::string(model_fade_vert)); auto modelNormalMapFadeVertex = gpu::Shader::createVertex(std::string(model_normal_map_fade_vert)); + auto simpleFadeVertex = gpu::Shader::createVertex(std::string(simple_fade_vert)); // Pixel shaders auto simplePixel = gpu::Shader::createPixel(std::string(simple_textured_frag)); @@ -178,10 +201,18 @@ void initDeferredPipelines(render::ShapePlumber& plumber) { auto modelLightmapNormalMapPixel = gpu::Shader::createPixel(std::string(model_lightmap_normal_map_frag)); auto modelLightmapSpecularMapPixel = gpu::Shader::createPixel(std::string(model_lightmap_specular_map_frag)); auto modelLightmapNormalSpecularMapPixel = gpu::Shader::createPixel(std::string(model_lightmap_normal_specular_map_frag)); + auto modelLightmapFadePixel = gpu::Shader::createPixel(std::string(model_lightmap_fade_frag)); + auto modelLightmapNormalMapFadePixel = gpu::Shader::createPixel(std::string(model_lightmap_normal_map_fade_frag)); + auto modelLightmapSpecularMapFadePixel = gpu::Shader::createPixel(std::string(model_lightmap_specular_map_fade_frag)); + auto modelLightmapNormalSpecularMapFadePixel = gpu::Shader::createPixel(std::string(model_lightmap_normal_specular_map_fade_frag)); - // Only models can have fade applied to them (?) auto modelFadePixel = gpu::Shader::createPixel(std::string(model_fade_frag)); + auto modelUnlitFadePixel = gpu::Shader::createPixel(std::string(model_unlit_fade_frag)); auto modelNormalMapFadePixel = gpu::Shader::createPixel(std::string(model_normal_map_fade_frag)); + auto modelSpecularMapFadePixel = gpu::Shader::createPixel(std::string(model_specular_map_fade_frag)); + auto modelNormalSpecularMapFadePixel = gpu::Shader::createPixel(std::string(model_normal_specular_map_fade_frag)); + auto simpleFadePixel = gpu::Shader::createPixel(std::string(simple_textured_fade_frag)); + auto simpleUnlitFadePixel = gpu::Shader::createPixel(std::string(simple_textured_unlit_fade_frag)); using Key = render::ShapeKey; auto addPipeline = std::bind(&addPlumberPipeline, std::ref(plumber), _1, _2, _3); @@ -212,9 +243,24 @@ void initDeferredPipelines(render::ShapePlumber& plumber) { addPipeline( Key::Builder().withMaterial().withFade(), modelFadeVertex, modelFadePixel); + addPipeline( + Key::Builder().withFade(), + simpleFadeVertex, simpleFadePixel); + addPipeline( + Key::Builder().withMaterial().withUnlit().withFade(), + modelFadeVertex, modelUnlitFadePixel); + addPipeline( + Key::Builder().withUnlit().withFade(), + simpleFadeVertex, simpleUnlitFadePixel); addPipeline( Key::Builder().withMaterial().withTangents().withFade(), modelNormalMapFadeVertex, modelNormalMapFadePixel); + addPipeline( + Key::Builder().withMaterial().withSpecular().withFade(), + modelFadeVertex, modelSpecularMapFadePixel); + addPipeline( + Key::Builder().withMaterial().withTangents().withSpecular().withFade(), + modelNormalMapFadeVertex, modelNormalSpecularMapFadePixel); // Translucents addPipeline( @@ -242,6 +288,7 @@ void initDeferredPipelines(render::ShapePlumber& plumber) { // FIXME: Ignore lightmap for translucents meshpart Key::Builder().withMaterial().withTranslucent().withLightmap(), modelVertex, modelTranslucentPixel); + // Lightmapped addPipeline( Key::Builder().withMaterial().withLightmap(), @@ -255,6 +302,20 @@ void initDeferredPipelines(render::ShapePlumber& plumber) { addPipeline( Key::Builder().withMaterial().withLightmap().withTangents().withSpecular(), modelLightmapNormalMapVertex, modelLightmapNormalSpecularMapPixel); + // Same thing but with Fade on + addPipeline( + Key::Builder().withMaterial().withLightmap().withFade(), + modelLightmapFadeVertex, modelLightmapFadePixel); + addPipeline( + Key::Builder().withMaterial().withLightmap().withTangents().withFade(), + modelLightmapNormalMapFadeVertex, modelLightmapNormalMapFadePixel); + addPipeline( + Key::Builder().withMaterial().withLightmap().withSpecular().withFade(), + modelLightmapFadeVertex, modelLightmapSpecularMapFadePixel); + addPipeline( + Key::Builder().withMaterial().withLightmap().withTangents().withSpecular().withFade(), + modelLightmapNormalMapFadeVertex, modelLightmapNormalSpecularMapFadePixel); + // Skinned addPipeline( Key::Builder().withMaterial().withSkinned(), @@ -268,6 +329,20 @@ void initDeferredPipelines(render::ShapePlumber& plumber) { addPipeline( Key::Builder().withMaterial().withSkinned().withTangents().withSpecular(), skinModelNormalMapVertex, modelNormalSpecularMapPixel); + // Same thing but with Fade on + addPipeline( + Key::Builder().withMaterial().withSkinned().withFade(), + skinModelFadeVertex, modelFadePixel); + addPipeline( + Key::Builder().withMaterial().withSkinned().withTangents().withFade(), + skinModelNormalMapFadeVertex, modelNormalMapFadePixel); + addPipeline( + Key::Builder().withMaterial().withSkinned().withSpecular().withFade(), + skinModelFadeVertex, modelSpecularMapFadePixel); + addPipeline( + Key::Builder().withMaterial().withSkinned().withTangents().withSpecular().withFade(), + skinModelNormalMapFadeVertex, modelNormalSpecularMapFadePixel); + // Skinned and Translucent addPipeline( Key::Builder().withMaterial().withSkinned().withTranslucent(), @@ -281,6 +356,7 @@ void initDeferredPipelines(render::ShapePlumber& plumber) { addPipeline( Key::Builder().withMaterial().withSkinned().withTranslucent().withTangents().withSpecular(), skinModelNormalMapVertex, modelTranslucentPixel); + // Depth-only addPipeline( Key::Builder().withDepthOnly(), diff --git a/libraries/render-utils/src/model_fade.slf b/libraries/render-utils/src/model_fade.slf index 4c497228c8..1526dea7c2 100644 --- a/libraries/render-utils/src/model_fade.slf +++ b/libraries/render-utils/src/model_fade.slf @@ -30,7 +30,7 @@ in vec2 _texCoord1; void main(void) { - applyFade(_worldFadePosition.xyz, _normal); + applyFade(_worldFadePosition.xyz); Material mat = getMaterial(); int matKey = getMaterialKey(mat); diff --git a/libraries/render-utils/src/model_lightmap_fade.slf b/libraries/render-utils/src/model_lightmap_fade.slf new file mode 100644 index 0000000000..f2055e7ffc --- /dev/null +++ b/libraries/render-utils/src/model_lightmap_fade.slf @@ -0,0 +1,50 @@ +<@include gpu/Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// model_lightmap_fade.frag +// fragment shader +// +// Created by Olivier Prat on 06/05/17. +// Copyright 2017 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 DeferredBufferWrite.slh@> + +<@include model/Material.slh@> + +<@include MaterialTextures.slh@> +<$declareMaterialTextures(ALBEDO, ROUGHNESS)$> +<$declareMaterialLightmap()$> + +<@include Fade.slh@> +<$declareFadeFragment()$> + +in vec4 _position; +in vec2 _texCoord0; +in vec2 _texCoord1; +in vec3 _normal; +in vec3 _color; +in vec4 _worldFadePosition; + +void main(void) { + applyFade(_worldFadePosition.xyz); + + Material mat = getMaterial(); + int matKey = getMaterialKey(mat); + <$fetchMaterialTexturesCoord0(matKey, _texCoord0, albedo, roughness)$> + <$fetchMaterialTexturesCoord1(matKey, _texCoord1, _SCRIBE_NULL, lightmapVal)$> + + + packDeferredFragmentLightmap( + normalize(_normal), + evalOpaqueFinalAlpha(getMaterialOpacity(mat), albedo.a), + getMaterialAlbedo(mat) * albedo.rgb * _color, + getMaterialRoughness(mat) * roughness, + getMaterialMetallic(mat), + getMaterialFresnel(mat), + lightmapVal); +} diff --git a/libraries/render-utils/src/model_lightmap_fade.slv b/libraries/render-utils/src/model_lightmap_fade.slv new file mode 100644 index 0000000000..8ba9717b4c --- /dev/null +++ b/libraries/render-utils/src/model_lightmap_fade.slv @@ -0,0 +1,48 @@ +<@include gpu/Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// model_lightmap_fade.vert +// vertex shader +// +// Created by Olivier Prat on 06/05/17. +// Copyright 2017 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 gpu/Inputs.slh@> +<@include gpu/Color.slh@> +<@include gpu/Transform.slh@> +<$declareStandardTransform()$> + +<@include Fade.slh@> + +<@include MaterialTextures.slh@> +<$declareMaterialTexMapArrayBuffer()$> + +out vec4 _position; +out vec2 _texCoord0; +out vec2 _texCoord1; +out vec3 _normal; +out vec3 _color; +out vec4 _worldFadePosition; + +void main(void) { + // pass along the color in linear space + _color = colorToLinearRGB(inColor.xyz); + + // and the texture coordinates + TexMapArray texMapArray = getTexMapArray(); + <$evalTexMapArrayTexcoord0(texMapArray, inTexCoord0, _texCoord0)$> + <$evalTexMapArrayTexcoord1(texMapArray, inTexCoord1, _texCoord1)$> + + // standard transform + TransformCamera cam = getTransformCamera(); + TransformObject obj = getTransformObject(); + <$transformModelToEyeAndClipPos(cam, obj, inPosition, _position, gl_Position)$> + <$transformModelToFadePos(obj, inPosition, _worldFadePosition)$> + <$transformModelToWorldDir(cam, obj, inNormal.xyz, _normal)$> +} + diff --git a/libraries/render-utils/src/model_lightmap_normal_map_fade.slf b/libraries/render-utils/src/model_lightmap_normal_map_fade.slf new file mode 100644 index 0000000000..137e40dd3c --- /dev/null +++ b/libraries/render-utils/src/model_lightmap_normal_map_fade.slf @@ -0,0 +1,53 @@ +<@include gpu/Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// model_lightmap_normal_map_fade.frag +// fragment shader +// +// Created by Olivier Prat on 06/05/17. +// Copyright 2017 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 DeferredBufferWrite.slh@> + +<@include model/Material.slh@> + +<@include MaterialTextures.slh@> +<$declareMaterialTextures(ALBEDO, ROUGHNESS, NORMAL)$> +<$declareMaterialLightmap()$> + +<@include Fade.slh@> +<$declareFadeFragment()$> + +in vec4 _position; +in vec2 _texCoord0; +in vec2 _texCoord1; +in vec3 _normal; +in vec3 _tangent; +in vec3 _color; +in vec4 _worldFadePosition; + +void main(void) { + applyFade(_worldFadePosition.xyz); + + Material mat = getMaterial(); + int matKey = getMaterialKey(mat); + <$fetchMaterialTexturesCoord0(matKey, _texCoord0, albedo, roughness, normalTexel)$> + <$fetchMaterialTexturesCoord1(matKey, _texCoord1, _SCRIBE_NULL, lightmapVal)$> + + vec3 viewNormal; + <$tangentToViewSpaceLOD(_position, normalTexel, _normal, _tangent, viewNormal)$> + + packDeferredFragmentLightmap( + normalize(viewNormal.xyz), + evalOpaqueFinalAlpha(getMaterialOpacity(mat), albedo.a), + getMaterialAlbedo(mat) * albedo.rgb * _color, + getMaterialRoughness(mat), + getMaterialMetallic(mat), + getMaterialFresnel(mat), + lightmapVal); +} diff --git a/libraries/render-utils/src/model_lightmap_normal_map_fade.slv b/libraries/render-utils/src/model_lightmap_normal_map_fade.slv new file mode 100644 index 0000000000..e081db103b --- /dev/null +++ b/libraries/render-utils/src/model_lightmap_normal_map_fade.slv @@ -0,0 +1,48 @@ +<@include gpu/Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// model_lightmap_normal_map_fade.vert +// vertex shader +// +// Created by Olivier Prat on 06/05/17. +// Copyright 2017 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 gpu/Inputs.slh@> +<@include gpu/Color.slh@> +<@include gpu/Transform.slh@> +<$declareStandardTransform()$> + +<@include Fade.slh@> + +<@include MaterialTextures.slh@> +<$declareMaterialTexMapArrayBuffer()$> + +out vec4 _position; +out vec2 _texCoord0; +out vec2 _texCoord1; +out vec3 _normal; +out vec3 _tangent; +out vec3 _color; +out vec4 _worldFadePosition; + +void main(void) { + // pass along the color in linear space + _color = colorToLinearRGB(inColor.xyz); + + TexMapArray texMapArray = getTexMapArray(); + <$evalTexMapArrayTexcoord0(texMapArray, inTexCoord0, _texCoord0)$> + <$evalTexMapArrayTexcoord1(texMapArray, inTexCoord1, _texCoord1)$> + + // standard transform + TransformCamera cam = getTransformCamera(); + TransformObject obj = getTransformObject(); + <$transformModelToEyeAndClipPos(cam, obj, inPosition, _position, gl_Position)$> + <$transformModelToFadePos(obj, inPosition, _worldFadePosition)$> + <$transformModelToWorldDir(cam, obj, inNormal.xyz, _normal)$> + <$transformModelToWorldDir(cam, obj, inTangent.xyz, _tangent)$> +} diff --git a/libraries/render-utils/src/model_lightmap_normal_specular_map_fade.slf b/libraries/render-utils/src/model_lightmap_normal_specular_map_fade.slf new file mode 100644 index 0000000000..b6cdfbd2a2 --- /dev/null +++ b/libraries/render-utils/src/model_lightmap_normal_specular_map_fade.slf @@ -0,0 +1,53 @@ +<@include gpu/Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// model_lightmap_normal_specular_map_fade.frag +// fragment shader +// +// Created by Olivier Prat on 06/05/17. +// Copyright 2017 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 DeferredBufferWrite.slh@> + +<@include model/Material.slh@> + +<@include MaterialTextures.slh@> +<$declareMaterialTextures(ALBEDO, ROUGHNESS, NORMAL, METALLIC)$> +<$declareMaterialLightmap()$> + +<@include Fade.slh@> +<$declareFadeFragment()$> + +in vec4 _position; +in vec2 _texCoord0; +in vec2 _texCoord1; +in vec3 _normal; +in vec3 _tangent; +in vec3 _color; +in vec4 _worldFadePosition; + +void main(void) { + applyFade(_worldFadePosition.xyz); + + Material mat = getMaterial(); + int matKey = getMaterialKey(mat); + <$fetchMaterialTexturesCoord0(matKey, _texCoord0, albedo, roughness, normalTexel, metallicTex)$> + <$fetchMaterialTexturesCoord1(matKey, _texCoord1, _SCRIBE_NULL, lightmapVal)$> + + vec3 viewNormal; + <$tangentToViewSpaceLOD(_position, normalTexel, _normal, _tangent, viewNormal)$> + + packDeferredFragmentLightmap( + normalize(viewNormal.xyz), + evalOpaqueFinalAlpha(getMaterialOpacity(mat), albedo.a), + getMaterialAlbedo(mat) * albedo.rgb * _color, + getMaterialRoughness(mat) * roughness, + getMaterialMetallic(mat) * metallicTex, + /*specular, // no use of */ getMaterialFresnel(mat), + lightmapVal); +} diff --git a/libraries/render-utils/src/model_lightmap_specular_map_fade.slf b/libraries/render-utils/src/model_lightmap_specular_map_fade.slf new file mode 100644 index 0000000000..e6d82b778d --- /dev/null +++ b/libraries/render-utils/src/model_lightmap_specular_map_fade.slf @@ -0,0 +1,49 @@ +<@include gpu/Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// model_lightmap_specular_map_fade.frag +// fragment shader +// +// Created by Olivier Prat on 06/05/17. +// Copyright 2017 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 DeferredBufferWrite.slh@> + +<@include model/Material.slh@> + +<@include MaterialTextures.slh@> +<$declareMaterialTextures(ALBEDO, ROUGHNESS, _SCRIBE_NULL, METALLIC)$> +<$declareMaterialLightmap()$> + +<@include Fade.slh@> +<$declareFadeFragment()$> + +in vec4 _position; +in vec2 _texCoord0; +in vec2 _texCoord1; +in vec3 _normal; +in vec3 _color; +in vec4 _worldFadePosition; + +void main(void) { + applyFade(_worldFadePosition.xyz); + + Material mat = getMaterial(); + int matKey = getMaterialKey(mat); + <$fetchMaterialTexturesCoord0(matKey, _texCoord0, albedo, roughness, _SCRIBE_NULL, metallicTex)$> + <$fetchMaterialTexturesCoord1(matKey, _texCoord1, _SCRIBE_NULL, lightmapVal)$> + + packDeferredFragmentLightmap( + normalize(_normal), + evalOpaqueFinalAlpha(getMaterialOpacity(mat), albedo.a), + getMaterialAlbedo(mat) * albedo.rgb * _color, + getMaterialRoughness(mat) * roughness, + getMaterialMetallic(mat) * metallicTex, + /*metallicTex, // no use of */getMaterialFresnel(mat), + lightmapVal); +} diff --git a/libraries/render-utils/src/model_normal_map_fade.slf b/libraries/render-utils/src/model_normal_map_fade.slf index 9f85a956d0..61314fc834 100644 --- a/libraries/render-utils/src/model_normal_map_fade.slf +++ b/libraries/render-utils/src/model_normal_map_fade.slf @@ -31,7 +31,7 @@ in vec3 _tangent; in vec3 _color; void main(void) { - applyFade(_worldFadePosition.xyz, _normal); + applyFade(_worldFadePosition.xyz); Material mat = getMaterial(); int matKey = getMaterialKey(mat); diff --git a/libraries/render-utils/src/model_normal_specular_map_fade.slf b/libraries/render-utils/src/model_normal_specular_map_fade.slf new file mode 100644 index 0000000000..d9c4288e29 --- /dev/null +++ b/libraries/render-utils/src/model_normal_specular_map_fade.slf @@ -0,0 +1,72 @@ +<@include gpu/Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// model_normal_specular_map_fade.frag +// fragment shader +// +// Created by Olivier Prat on 06/05/17. +// Copyright 2017 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 DeferredBufferWrite.slh@> + +<@include model/Material.slh@> + +<@include MaterialTextures.slh@> +<$declareMaterialTextures(ALBEDO, ROUGHNESS, NORMAL, METALLIC, EMISSIVE, OCCLUSION)$> + +<@include Fade.slh@> +<$declareFadeFragment()$> + +in vec4 _position; +in vec2 _texCoord0; +in vec2 _texCoord1; +in vec3 _normal; +in vec3 _tangent; +in vec3 _color; +in vec4 _worldFadePosition; + +void main(void) { + applyFade(_worldFadePosition.xyz); + + Material mat = getMaterial(); + int matKey = getMaterialKey(mat); + <$fetchMaterialTexturesCoord0(matKey, _texCoord0, albedoTex, roughnessTex, normalTex, metallicTex, emissiveTex)$> + <$fetchMaterialTexturesCoord1(matKey, _texCoord1, occlusionTex)$> + + float opacity = 1.0; + <$evalMaterialOpacity(albedoTex.a, opacity, matKey, opacity)&>; + <$discardTransparent(opacity)$>; + + vec3 albedo = getMaterialAlbedo(mat); + <$evalMaterialAlbedo(albedoTex, albedo, matKey, albedo)$>; + albedo *= _color; + + float roughness = getMaterialRoughness(mat); + <$evalMaterialRoughness(roughnessTex, roughness, matKey, roughness)$>; + + vec3 emissive = getMaterialEmissive(mat); + <$evalMaterialEmissive(emissiveTex, emissive, matKey, emissive)$>; + + vec3 viewNormal; + <$tangentToViewSpaceLOD(_position, normalTex, _normal, _tangent, viewNormal)$> + + float metallic = getMaterialMetallic(mat); + <$evalMaterialMetallic(metallicTex, metallic, matKey, metallic)$>; + + float scattering = getMaterialScattering(mat); + + packDeferredFragment( + normalize(viewNormal.xyz), + opacity, + albedo, + roughness, + metallic, + emissive, + occlusionTex, + scattering); +} diff --git a/libraries/render-utils/src/model_specular_map_fade.slf b/libraries/render-utils/src/model_specular_map_fade.slf new file mode 100644 index 0000000000..3579cf1059 --- /dev/null +++ b/libraries/render-utils/src/model_specular_map_fade.slf @@ -0,0 +1,68 @@ +<@include gpu/Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// model_specular_map_fade.frag +// fragment shader +// +// Created by Olivier Prat on 06/05/17. +// Copyright 2017 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 DeferredBufferWrite.slh@> + +<@include model/Material.slh@> + +<@include MaterialTextures.slh@> +<$declareMaterialTextures(ALBEDO, ROUGHNESS, _SCRIBE_NULL, METALLIC, EMISSIVE, OCCLUSION)$> + +<@include Fade.slh@> +<$declareFadeFragment()$> + +in vec4 _position; +in vec2 _texCoord0; +in vec2 _texCoord1; +in vec3 _normal; +in vec3 _color; +in vec4 _worldFadePosition; + +void main(void) { + applyFade(_worldFadePosition.xyz); + + Material mat = getMaterial(); + int matKey = getMaterialKey(mat); + <$fetchMaterialTexturesCoord0(matKey, _texCoord0, albedoTex, roughnessTex, _SCRIBE_NULL, metallicTex, emissiveTex)$> + <$fetchMaterialTexturesCoord1(matKey, _texCoord1, occlusionTex)$> + + float opacity = 1.0; + <$evalMaterialOpacity(albedoTex.a, opacity, matKey, opacity)$>; + <$discardTransparent(opacity)$>; + + vec3 albedo = getMaterialAlbedo(mat); + <$evalMaterialAlbedo(albedoTex, albedo, matKey, albedo)$>; + albedo *= _color; + + float roughness = getMaterialRoughness(mat); + <$evalMaterialRoughness(roughnessTex, roughness, matKey, roughness)$>; + + vec3 emissive = getMaterialEmissive(mat); + <$evalMaterialEmissive(emissiveTex, emissive, matKey, emissive)$>; + + float metallic = getMaterialMetallic(mat); + <$evalMaterialMetallic(metallicTex, metallic, matKey, metallic)$>; + + float scattering = getMaterialScattering(mat); + + packDeferredFragment( + normalize(_normal), + opacity, + albedo, + roughness, + metallic, + emissive, + occlusionTex, + scattering); +} diff --git a/libraries/render-utils/src/model_unlit_fade.slf b/libraries/render-utils/src/model_unlit_fade.slf new file mode 100644 index 0000000000..be0af7afea --- /dev/null +++ b/libraries/render-utils/src/model_unlit_fade.slf @@ -0,0 +1,50 @@ +<@include gpu/Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// model_unlit_fade.frag +// fragment shader +// +// Created by Olivier Prat on 06/05/17. +// Copyright 2017 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 DeferredBufferWrite.slh@> +<@include LightingModel.slh@> +<@include model/Material.slh@> + +<@include Fade.slh@> +<$declareFadeFragment()$> + +<@include MaterialTextures.slh@> +<$declareMaterialTextures(ALBEDO)$> + +in vec2 _texCoord0; +in vec3 _normal; +in vec3 _color; +in float _alpha; +in vec4 _worldFadePosition; + +void main(void) { + applyFade(_worldFadePosition.xyz); + + Material mat = getMaterial(); + int matKey = getMaterialKey(mat); + <$fetchMaterialTexturesCoord0(matKey, _texCoord0, albedoTex)$> + + float opacity = 1.0; + <$evalMaterialOpacity(albedoTex.a, opacity, matKey, opacity)$>; + <$discardTransparent(opacity)$>; + + vec3 albedo = getMaterialAlbedo(mat); + <$evalMaterialAlbedo(albedoTex, albedo, matKey, albedo)$>; + albedo *= _color; + + packDeferredFragmentUnlit( + normalize(_normal), + opacity, + albedo * isUnlitEnabled()); +} diff --git a/libraries/render-utils/src/simple_fade.slf b/libraries/render-utils/src/simple_fade.slf new file mode 100644 index 0000000000..c082ea26f3 --- /dev/null +++ b/libraries/render-utils/src/simple_fade.slf @@ -0,0 +1,97 @@ +<@include gpu/Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// simple_fade.frag +// fragment shader +// +// Created by Olivier Prat on 06/05/17. +// Copyright 2017 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 DeferredBufferWrite.slh@> +<@include model/Material.slh@> + +<@include Fade.slh@> +<$declareFadeFragment()$> + +// the interpolated normal +in vec3 _normal; +in vec3 _modelNormal; +in vec4 _color; +in vec2 _texCoord0; +in vec4 _position; +in vec4 _worldFadePosition; + +//PROCEDURAL_COMMON_BLOCK + +#line 1001 +//PROCEDURAL_BLOCK + +#line 2030 +void main(void) { + applyFade(_worldFadePosition.xyz); + + Material material = getMaterial(); + vec3 normal = normalize(_normal.xyz); + vec3 diffuse = _color.rgb; + vec3 specular = DEFAULT_SPECULAR; + float shininess = DEFAULT_SHININESS; + float emissiveAmount = 0.0; + +#ifdef PROCEDURAL + +#ifdef PROCEDURAL_V1 + specular = getProceduralColor().rgb; + // Procedural Shaders are expected to be Gamma corrected so let's bring back the RGB in linear space for the rest of the pipeline + //specular = pow(specular, vec3(2.2)); + emissiveAmount = 1.0; +#else + emissiveAmount = getProceduralColors(diffuse, specular, shininess); +#endif + +#endif + + const float ALPHA_THRESHOLD = 0.999; + if (_color.a < ALPHA_THRESHOLD) { + if (emissiveAmount > 0.0) { + packDeferredFragmentTranslucent( + normal, + _color.a, + specular, + DEFAULT_FRESNEL, + DEFAULT_ROUGHNESS); + } else { + packDeferredFragmentTranslucent( + normal, + _color.a, + diffuse, + DEFAULT_FRESNEL, + DEFAULT_ROUGHNESS); + } + } else { + if (emissiveAmount > 0.0) { + packDeferredFragmentLightmap( + normal, + 1.0, + diffuse, + max(0, 1.0 - shininess / 128.0), + DEFAULT_METALLIC, + specular, + specular); + } else { + packDeferredFragment( + normal, + 1.0, + diffuse, + max(0, 1.0 - shininess / 128.0), + length(specular), + DEFAULT_EMISSIVE, + DEFAULT_OCCLUSION, + DEFAULT_SCATTERING); + } + } +} diff --git a/libraries/render-utils/src/simple_fade.slv b/libraries/render-utils/src/simple_fade.slv new file mode 100644 index 0000000000..866d4cc35e --- /dev/null +++ b/libraries/render-utils/src/simple_fade.slv @@ -0,0 +1,42 @@ +<@include gpu/Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// simple_fade.vert +// vertex shader +// +// Created by Olivier Prat on 06/045/17. +// Copyright 2017 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 gpu/Inputs.slh@> +<@include gpu/Color.slh@> +<@include gpu/Transform.slh@> +<$declareStandardTransform()$> + +<@include Fade.slh@> + +// the interpolated normal +out vec3 _normal; +out vec3 _modelNormal; +out vec4 _color; +out vec2 _texCoord0; +out vec4 _position; +out vec4 _worldFadePosition; + +void main(void) { + _color = colorToLinearRGBA(inColor); + _texCoord0 = inTexCoord0.st; + _position = inPosition; + _modelNormal = inNormal.xyz; + + // standard transform + TransformCamera cam = getTransformCamera(); + TransformObject obj = getTransformObject(); + <$transformModelToClipPos(cam, obj, inPosition, gl_Position)$> + <$transformModelToFadePos(obj, inPosition, _worldFadePosition)$> + <$transformModelToWorldDir(cam, obj, inNormal.xyz, _normal)$> +} \ No newline at end of file diff --git a/libraries/render-utils/src/simple_textured_fade.slf b/libraries/render-utils/src/simple_textured_fade.slf new file mode 100644 index 0000000000..c939a8d676 --- /dev/null +++ b/libraries/render-utils/src/simple_textured_fade.slf @@ -0,0 +1,60 @@ +<@include gpu/Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// simple_textured_fade.slf +// fragment shader +// +// Created by Olivier Prat on 06/05/17. +// Copyright 2017 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 gpu/Color.slh@> +<@include DeferredBufferWrite.slh@> +<@include model/Material.slh@> + +<@include Fade.slh@> +<$declareFadeFragment()$> + +// the albedo texture +uniform sampler2D originalTexture; + +// the interpolated normal +in vec3 _normal; +in vec4 _color; +in vec2 _texCoord0; +in vec4 _worldFadePosition; + +void main(void) { + applyFade(_worldFadePosition.xyz); + + vec4 texel = texture(originalTexture, _texCoord0); + float colorAlpha = _color.a; + if (_color.a <= 0.0) { + texel = colorToLinearRGBA(texel); + colorAlpha = -_color.a; + } + + const float ALPHA_THRESHOLD = 0.999; + if (colorAlpha * texel.a < ALPHA_THRESHOLD) { + packDeferredFragmentTranslucent( + normalize(_normal), + colorAlpha * texel.a, + _color.rgb * texel.rgb, + DEFAULT_FRESNEL, + DEFAULT_ROUGHNESS); + } else { + packDeferredFragment( + normalize(_normal), + 1.0, + _color.rgb * texel.rgb, + DEFAULT_ROUGHNESS, + DEFAULT_METALLIC, + DEFAULT_EMISSIVE, + DEFAULT_OCCLUSION, + DEFAULT_SCATTERING); + } +} \ No newline at end of file diff --git a/libraries/render-utils/src/simple_textured_unlit_fade.slf b/libraries/render-utils/src/simple_textured_unlit_fade.slf new file mode 100644 index 0000000000..2db2dfa222 --- /dev/null +++ b/libraries/render-utils/src/simple_textured_unlit_fade.slf @@ -0,0 +1,54 @@ +<@include gpu/Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// simple_textured_unlit_fade.frag +// fragment shader +// +// Created by Olivier Prat on 06/05/17. +// Copyright 2017 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 gpu/Color.slh@> +<@include DeferredBufferWrite.slh@> + +<@include Fade.slh@> +<$declareFadeFragment()$> + +// the albedo texture +uniform sampler2D originalTexture; + +// the interpolated normal +in vec3 _normal; +in vec4 _color; +in vec2 _texCoord0; +in vec4 _worldFadePosition; + +void main(void) { + applyFade(_worldFadePosition.xyz); + + vec4 texel = texture(originalTexture, _texCoord0.st); + float colorAlpha = _color.a; + if (_color.a <= 0.0) { + texel = colorToLinearRGBA(texel); + colorAlpha = -_color.a; + } + + const float ALPHA_THRESHOLD = 0.999; + if (colorAlpha * texel.a < ALPHA_THRESHOLD) { + packDeferredFragmentTranslucent( + normalize(_normal), + colorAlpha * texel.a, + _color.rgb * texel.rgb, + DEFAULT_FRESNEL, + DEFAULT_ROUGHNESS); + } else { + packDeferredFragmentUnlit( + normalize(_normal), + 1.0, + _color.rgb * texel.rgb); + } +} \ No newline at end of file diff --git a/libraries/render-utils/src/skin_model_fade.slv b/libraries/render-utils/src/skin_model_fade.slv new file mode 100644 index 0000000000..a96c948470 --- /dev/null +++ b/libraries/render-utils/src/skin_model_fade.slv @@ -0,0 +1,55 @@ +<@include gpu/Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// skin_model_fade.vert +// vertex shader +// +// Created by Olivier Prat on 06/045/17. +// Copyright 2017 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 gpu/Inputs.slh@> +<@include gpu/Color.slh@> +<@include gpu/Transform.slh@> +<$declareStandardTransform()$> + +<@include Skinning.slh@> + +<@include MaterialTextures.slh@> +<$declareMaterialTexMapArrayBuffer()$> + +<@include Fade.slh@> + +out vec4 _position; +out vec2 _texCoord0; +out vec2 _texCoord1; +out vec3 _normal; +out vec3 _color; +out float _alpha; +out vec4 _worldFadePosition; + +void main(void) { + vec4 position = vec4(0.0, 0.0, 0.0, 0.0); + vec3 interpolatedNormal = vec3(0.0, 0.0, 0.0); + + skinPositionNormal(inSkinClusterIndex, inSkinClusterWeight, inPosition, inNormal.xyz, position, interpolatedNormal); + + // pass along the color + _color = colorToLinearRGB(inColor.rgb); + _alpha = inColor.a; + + TexMapArray texMapArray = getTexMapArray(); + <$evalTexMapArrayTexcoord0(texMapArray, inTexCoord0, _texCoord0)$> + <$evalTexMapArrayTexcoord1(texMapArray, inTexCoord0, _texCoord1)$> + + // standard transform + TransformCamera cam = getTransformCamera(); + TransformObject obj = getTransformObject(); + <$transformModelToEyeAndClipPos(cam, obj, position, _position, gl_Position)$> + <$transformModelToFadePos(obj, inPosition, _worldFadePosition)$> + <$transformModelToWorldDir(cam, obj, interpolatedNormal.xyz, _normal.xyz)$> +} diff --git a/libraries/render-utils/src/skin_model_normal_map_fade.slv b/libraries/render-utils/src/skin_model_normal_map_fade.slv new file mode 100644 index 0000000000..5169aa5d75 --- /dev/null +++ b/libraries/render-utils/src/skin_model_normal_map_fade.slv @@ -0,0 +1,64 @@ +<@include gpu/Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// skin_model_normal_map_fade.vert +// vertex shader +// +// Created by Olivier Prat on 06/045/17. +// Copyright 2017 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 gpu/Inputs.slh@> +<@include gpu/Color.slh@> +<@include gpu/Transform.slh@> +<$declareStandardTransform()$> + +<@include Skinning.slh@> + +<@include MaterialTextures.slh@> +<$declareMaterialTexMapArrayBuffer()$> + +<@include Fade.slh@> + +out vec4 _position; +out vec2 _texCoord0; +out vec2 _texCoord1; +out vec3 _normal; +out vec3 _tangent; +out vec3 _color; +out float _alpha; +out vec4 _worldFadePosition; + +void main(void) { + vec4 position = vec4(0.0, 0.0, 0.0, 0.0); + vec4 interpolatedNormal = vec4(0.0, 0.0, 0.0, 0.0); + vec4 interpolatedTangent = vec4(0.0, 0.0, 0.0, 0.0); + + skinPositionNormalTangent(inSkinClusterIndex, inSkinClusterWeight, inPosition, inNormal.xyz, inTangent.xyz, position, interpolatedNormal.xyz, interpolatedTangent.xyz); + + // pass along the color + _color = colorToLinearRGB(inColor.rgb); + _alpha = inColor.a; + + TexMapArray texMapArray = getTexMapArray(); + <$evalTexMapArrayTexcoord0(texMapArray, inTexCoord0, _texCoord0)$> + <$evalTexMapArrayTexcoord1(texMapArray, inTexCoord0, _texCoord1)$> + + interpolatedNormal = vec4(normalize(interpolatedNormal.xyz), 0.0); + interpolatedTangent = vec4(normalize(interpolatedTangent.xyz), 0.0); + + // standard transform + TransformCamera cam = getTransformCamera(); + TransformObject obj = getTransformObject(); + <$transformModelToEyeAndClipPos(cam, obj, position, _position, gl_Position)$> + <$transformModelToFadePos(obj, inPosition, _worldFadePosition)$> + <$transformModelToWorldDir(cam, obj, interpolatedNormal.xyz, interpolatedNormal.xyz)$> + <$transformModelToWorldDir(cam, obj, interpolatedTangent.xyz, interpolatedTangent.xyz)$> + + _normal = interpolatedNormal.xyz; + _tangent = interpolatedTangent.xyz; +} diff --git a/plugins/openvr/src/ViveControllerManager.h b/plugins/openvr/src/ViveControllerManager.h index c32579b0d8..f674fad50b 100644 --- a/plugins/openvr/src/ViveControllerManager.h +++ b/plugins/openvr/src/ViveControllerManager.h @@ -143,7 +143,7 @@ private: int _trackedControllers { 0 }; vr::IVRSystem*& _system; - quint64 _timeTilCalibration { 0.0f }; + quint64 _timeTilCalibration { 0 }; float _leftHapticStrength { 0.0f }; float _leftHapticDuration { 0.0f }; float _rightHapticStrength { 0.0f }; diff --git a/scripts/developer/utilities/render/debugFade.js b/scripts/developer/utilities/render/debugFade.js index 8b79905e11..064337dae1 100644 --- a/scripts/developer/utilities/render/debugFade.js +++ b/scripts/developer/utilities/render/debugFade.js @@ -14,7 +14,7 @@ var qml = Script.resolvePath('fade.qml'); var window = new OverlayWindow({ title: 'Fade', source: qml, - width: 400, + width: 500, height: 80 }); window.setPosition(50, 50); diff --git a/scripts/developer/utilities/render/fade.qml b/scripts/developer/utilities/render/fade.qml index 3d391923ff..d5622c353d 100644 --- a/scripts/developer/utilities/render/fade.qml +++ b/scripts/developer/utilities/render/fade.qml @@ -12,22 +12,45 @@ import QtQuick 2.5 import QtQuick.Controls 1.4 import "configSlider" -Column { - id: root - spacing: 8 - property var drawOpaqueConfig: Render.getConfig("DrawOpaqueDeferred"); +Row { + property var drawOpaqueConfig: Render.getConfig("DrawOpaqueDeferred"); + property var drawTransparentConfig: Render.getConfig("DrawDeferred"); + spacing: 4 + Column { + spacing: 8 - CheckBox { - text: "Force Fade" - checked: drawOpaqueConfig["debugFade"] - onCheckedChanged: { drawOpaqueConfig["debugFade"] = checked } + CheckBox { + text: "Force Fade Opaque" + checked: drawOpaqueConfig["debugFade"] + onCheckedChanged: { drawOpaqueConfig["debugFade"] = checked } + } + CheckBox { + text: "Force Fade Transparent" + checked: drawTransparentConfig["debugFade"] + onCheckedChanged: { drawTransparentConfig["debugFade"] = checked } + } } - ConfigSlider { - label: "Percent" - integral: false - config: drawOpaqueConfig - property: "debugFadePercent" - max: 1.0 - min: 0.0 + Column { + spacing: 8 + + ConfigSlider { + label: "Percent" + integral: false + config: drawOpaqueConfig + property: "debugFadePercent" + max: 1.0 + min: 0.0 + width: 250 + } + ConfigSlider { + label: "Percent" + integral: false + config: drawTransparentConfig + property: "debugFadePercent" + max: 1.0 + min: 0.0 + width: 250 + } } } +