From 09a6053044f065ae33d49fca51fdd78b94ee723a Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Wed, 26 Sep 2018 14:10:47 -0700 Subject: [PATCH 1/7] cleaning up fragment shaders --- .../entities-renderer/src/paintStroke.slf | 1 - .../src/paintStroke_fade.slf | 1 - libraries/fbx/src/OBJReader.cpp | 2 +- libraries/graphics/src/graphics/Material.cpp | 7 +--- libraries/graphics/src/graphics/Material.h | 23 +++++------ libraries/graphics/src/graphics/Material.slh | 13 +++--- .../src/graphics/MaterialTextures.slh | 4 +- .../render-utils/src/DeferredBufferWrite.slh | 5 ++- libraries/render-utils/src/model.slf | 13 +++--- libraries/render-utils/src/model_fade.slf | 29 +++++++------- libraries/render-utils/src/model_lightmap.slf | 28 ++++++++----- .../render-utils/src/model_lightmap_fade.slf | 34 +++++++++------- .../src/model_lightmap_normal_map.slf | 31 ++++++++------ .../src/model_lightmap_normal_map_fade.slf | 40 ++++++++++--------- .../render-utils/src/model_normal_map.slf | 21 +++++----- .../src/model_normal_map_fade.slf | 31 +++++++------- libraries/render-utils/src/model_shadow.slf | 4 +- .../render-utils/src/model_shadow_fade.slf | 8 +--- .../render-utils/src/model_translucent.slf | 21 +++++----- .../src/model_translucent_fade.slf | 29 +++++++++----- .../src/model_translucent_normal_map.slf | 27 +++++++------ .../src/model_translucent_normal_map_fade.slf | 31 +++++++------- .../src/model_translucent_unlit.slf | 10 ++--- .../src/model_translucent_unlit_fade.slf | 14 +++---- libraries/render-utils/src/model_unlit.slf | 10 ++--- .../render-utils/src/model_unlit_fade.slf | 13 +++--- .../render-utils/src/parabola_translucent.slf | 2 +- .../src/sdf_text3D_transparent.slf | 1 - libraries/render-utils/src/simple.slf | 1 - libraries/render-utils/src/simple_fade.slf | 3 -- .../render-utils/src/simple_textured_fade.slf | 1 - .../src/simple_textured_unlit.slf | 1 - .../src/simple_textured_unlit_fade.slf | 1 - .../src/simple_transparent_textured.slf | 1 - .../src/simple_transparent_web_browser.slf | 1 - 35 files changed, 229 insertions(+), 233 deletions(-) diff --git a/libraries/entities-renderer/src/paintStroke.slf b/libraries/entities-renderer/src/paintStroke.slf index 211685a9ba..0ab47045e5 100644 --- a/libraries/entities-renderer/src/paintStroke.slf +++ b/libraries/entities-renderer/src/paintStroke.slf @@ -30,6 +30,5 @@ void main(void) { float(frontCondition) * interpolatedNormal, texel.a * varColor.a, color * texel.rgb, - vec3(0.01, 0.01, 0.01), 10.0); } diff --git a/libraries/entities-renderer/src/paintStroke_fade.slf b/libraries/entities-renderer/src/paintStroke_fade.slf index e5f70c8038..6109207774 100644 --- a/libraries/entities-renderer/src/paintStroke_fade.slf +++ b/libraries/entities-renderer/src/paintStroke_fade.slf @@ -48,6 +48,5 @@ void main(void) { interpolatedNormal * float(frontCondition), texel.a * varColor.a, polyline.color * texel.rgb + fadeEmissive, - vec3(0.01, 0.01, 0.01), 10.0); } diff --git a/libraries/fbx/src/OBJReader.cpp b/libraries/fbx/src/OBJReader.cpp index c46a1e234c..37809585d2 100644 --- a/libraries/fbx/src/OBJReader.cpp +++ b/libraries/fbx/src/OBJReader.cpp @@ -981,7 +981,7 @@ FBXGeometry::Pointer OBJReader::readOBJ(QByteArray& model, const QVariantHash& m modelMaterial->setMetallic(ILLUMINATION_MODEL_APPLY_NON_METALLIC); } if (fresnelOn) { - modelMaterial->setFresnel(glm::vec3(1.0f)); + // TODO: how to turn fresnel on? } modelMaterial->setOpacity(fbxMaterial.opacity); diff --git a/libraries/graphics/src/graphics/Material.cpp b/libraries/graphics/src/graphics/Material.cpp index 2300bc5098..aa3716b3ee 100755 --- a/libraries/graphics/src/graphics/Material.cpp +++ b/libraries/graphics/src/graphics/Material.cpp @@ -70,7 +70,7 @@ Material& Material::operator= (const Material& material) { Material::~Material() { } -void Material::setEmissive(const Color& emissive, bool isSRGB) { +void Material::setEmissive(const Color& emissive, bool isSRGB) { _key.setEmissive(glm::any(glm::greaterThan(emissive, Color(0.0f)))); _schemaBuffer.edit()._key = (uint32) _key._flags.to_ulong(); _schemaBuffer.edit()._emissive = (isSRGB ? ColorUtils::sRGBToLinearVec3(emissive) : emissive); @@ -100,11 +100,6 @@ void Material::setRoughness(float roughness) { _schemaBuffer.edit()._roughness = roughness; } -void Material::setFresnel(const Color& fresnel, bool isSRGB) { - //_key.setAlbedo(glm::any(glm::greaterThan(albedo, Color(0.0f)))); - _schemaBuffer.edit()._fresnel = (isSRGB ? ColorUtils::sRGBToLinearVec3(fresnel) : fresnel); -} - void Material::setMetallic(float metallic) { metallic = glm::clamp(metallic, 0.0f, 1.0f); _key.setMetallic(metallic > 0.0f); diff --git a/libraries/graphics/src/graphics/Material.h b/libraries/graphics/src/graphics/Material.h index fd3f12e865..f1f209eeb2 100755 --- a/libraries/graphics/src/graphics/Material.h +++ b/libraries/graphics/src/graphics/Material.h @@ -291,9 +291,6 @@ public: void setAlbedo(const Color& albedo, bool isSRGB = true); Color getAlbedo(bool SRGB = true) const { return (SRGB ? ColorUtils::tosRGBVec3(_schemaBuffer.get()._albedo) : _schemaBuffer.get()._albedo); } - void setFresnel(const Color& fresnel, bool isSRGB = true); - Color getFresnel(bool SRGB = true) const { return (SRGB ? ColorUtils::tosRGBVec3(_schemaBuffer.get()._fresnel) : _schemaBuffer.get()._fresnel); } - void setMetallic(float metallic); float getMetallic() const { return _schemaBuffer.get()._metallic; } @@ -306,20 +303,18 @@ public: // Schema to access the attribute values of the material class Schema { public: - glm::vec3 _emissive{ 0.0f }; // No Emissive - float _opacity{ 1.0f }; // Opacity = 1 => Not Transparent + glm::vec3 _emissive { 0.0f }; // No Emissive + float _opacity { 1.0f }; // Opacity = 1 => Not Transparent - glm::vec3 _albedo{ 0.5f }; // Grey albedo => isAlbedo - float _roughness{ 1.0f }; // Roughness = 1 => Not Glossy + glm::vec3 _albedo { 0.5f }; // Grey albedo => isAlbedo + float _roughness { 1.0f }; // Roughness = 1 => Not Glossy - glm::vec3 _fresnel{ 0.03f }; // Fresnel value for a default non metallic - float _metallic{ 0.0f }; // Not Metallic + float _metallic { 0.0f }; // Not Metallic + float _scattering { 0.0f }; // Scattering info + glm::vec2 _spare { 0.0f }; - float _scattering{ 0.0f }; // Scattering info - - glm::vec2 _spare{ 0.0f }; - - uint32_t _key{ 0 }; // a copy of the materialKey + uint32_t _key { 0 }; // a copy of the materialKey + glm::vec3 _spare2 { 0.0f }; // for alignment beauty, Material size == Mat4x4 diff --git a/libraries/graphics/src/graphics/Material.slh b/libraries/graphics/src/graphics/Material.slh index fe273ed2a9..f0c6f5be3b 100644 --- a/libraries/graphics/src/graphics/Material.slh +++ b/libraries/graphics/src/graphics/Material.slh @@ -19,8 +19,8 @@ struct Material { vec4 _emissiveOpacity; vec4 _albedoRoughness; - vec4 _fresnelMetallic; - vec4 _scatteringSpare2Key; + vec4 _metallicScatteringSpare2; + vec4 _keySpare3; }; layout(binding=GRAPHICS_BUFFER_MATERIAL) uniform materialBuffer { @@ -36,15 +36,12 @@ float getMaterialOpacity(Material m) { return m._emissiveOpacity.a; } vec3 getMaterialAlbedo(Material m) { return m._albedoRoughness.rgb; } float getMaterialRoughness(Material m) { return m._albedoRoughness.a; } - -vec3 getMaterialFresnel(Material m) { return m._fresnelMetallic.rgb; } -float getMaterialMetallic(Material m) { return m._fresnelMetallic.a; } - float getMaterialShininess(Material m) { return 1.0 - getMaterialRoughness(m); } -float getMaterialScattering(Material m) { return m._scatteringSpare2Key.x; } +float getMaterialMetallic(Material m) { return m._metallicScatteringSpare2.x; } +float getMaterialScattering(Material m) { return m._metallicScatteringSpare2.y; } -BITFIELD getMaterialKey(Material m) { return floatBitsToInt(m._scatteringSpare2Key.w); } +BITFIELD getMaterialKey(Material m) { return floatBitsToInt(m._keySpare3.x); } const BITFIELD EMISSIVE_VAL_BIT = 0x00000001; const BITFIELD UNLIT_VAL_BIT = 0x00000002; diff --git a/libraries/graphics/src/graphics/MaterialTextures.slh b/libraries/graphics/src/graphics/MaterialTextures.slh index f76d65da96..106453877c 100644 --- a/libraries/graphics/src/graphics/MaterialTextures.slh +++ b/libraries/graphics/src/graphics/MaterialTextures.slh @@ -204,12 +204,12 @@ float fetchScatteringMap(vec2 uv) { <@endif@> <@endfunc@> -<@func fetchMaterialTexturesCoord1(matKey, texcoord1, occlusion, lightmapVal)@> +<@func fetchMaterialTexturesCoord1(matKey, texcoord1, occlusion, lightmap)@> <@if occlusion@> float <$occlusion$> = (((<$matKey$> & OCCLUSION_MAP_BIT) != 0) ? fetchOcclusionMap(<$texcoord1$>) : 1.0); <@endif@> <@if lightmapVal@> - vec3 <$lightmapVal$> = fetchLightmapMap(<$texcoord1$>); + vec3 <$lightmap$> = fetchLightmapMap(<$texcoord1$>); <@endif@> <@endfunc@> diff --git a/libraries/render-utils/src/DeferredBufferWrite.slh b/libraries/render-utils/src/DeferredBufferWrite.slh index 769e602dc5..04a65477b2 100644 --- a/libraries/render-utils/src/DeferredBufferWrite.slh +++ b/libraries/render-utils/src/DeferredBufferWrite.slh @@ -21,6 +21,7 @@ layout(location=3) out vec4 _fragColor3; // emissive // the alpha threshold const float alphaThreshold = 0.5; +// FIXME: is this correct? float evalOpaqueFinalAlpha(float alpha, float mapAlpha) { return mix(alpha, 1.0 - alpha, step(mapAlpha, alphaThreshold)); } @@ -39,7 +40,7 @@ void packDeferredFragment(vec3 normal, float alpha, vec3 albedo, float roughness _fragColor3 = vec4(isEmissiveEnabled() * emissive, 1.0); } -void packDeferredFragmentLightmap(vec3 normal, float alpha, vec3 albedo, float roughness, float metallic, vec3 fresnel, vec3 lightmap) { +void packDeferredFragmentLightmap(vec3 normal, float alpha, vec3 albedo, float roughness, float metallic, vec3 lightmap) { if (alpha != 1.0) { discard; } @@ -61,7 +62,7 @@ void packDeferredFragmentUnlit(vec3 normal, float alpha, vec3 color) { _fragColor3 = vec4(color, 1.0); } -void packDeferredFragmentTranslucent(vec3 normal, float alpha, vec3 albedo, vec3 fresnel, float roughness) { +void packDeferredFragmentTranslucent(vec3 normal, float alpha, vec3 albedo, float roughness) { if (alpha <= 0.0) { discard; } diff --git a/libraries/render-utils/src/model.slf b/libraries/render-utils/src/model.slf index 2c42ed6083..edf5064324 100644 --- a/libraries/render-utils/src/model.slf +++ b/libraries/render-utils/src/model.slf @@ -1,10 +1,8 @@ <@include gpu/Config.slh@> <$VERSION_HEADER$> +// <$_SCRIBE_FILENAME$> // Generated on <$_SCRIBE_DATE$> // -// model.frag -// fragment shader -// // Created by Andrzej Kapolka on 5/6/14. // Copyright 2014 High Fidelity, Inc. // @@ -42,11 +40,14 @@ void main(void) { float roughness = getMaterialRoughness(mat); <$evalMaterialRoughness(roughnessTex, roughness, matKey, roughness)$>; + float metallic = getMaterialMetallic(mat); + <$evalMaterialMetallic(metallicTex, metallic, matKey, metallic)$>; + vec3 emissive = getMaterialEmissive(mat); <$evalMaterialEmissive(emissiveTex, emissive, matKey, emissive)$>; - float metallic = getMaterialMetallic(mat); - <$evalMaterialMetallic(metallicTex, metallic, matKey, metallic)$>; + float occlusion = DEFAULT_OCCLUSION; + <$evalMaterialOcclusion(occlusionTex, matKey, occlusion)$>; float scattering = getMaterialScattering(mat); <$evalMaterialScattering(scatteringTex, scattering, matKey, scattering)$>; @@ -58,6 +59,6 @@ void main(void) { roughness, metallic, emissive, - occlusionTex, + occlusion, scattering); } diff --git a/libraries/render-utils/src/model_fade.slf b/libraries/render-utils/src/model_fade.slf index b5a2c8d3ef..e931ec4cf0 100644 --- a/libraries/render-utils/src/model_fade.slf +++ b/libraries/render-utils/src/model_fade.slf @@ -1,10 +1,8 @@ <@include gpu/Config.slh@> <$VERSION_HEADER$> +// <$_SCRIBE_FILENAME$> // Generated on <$_SCRIBE_DATE$> // -// model_fade.frag -// fragment shader -// // Created by Olivier Prat on 06/05/17. // Copyright 2017 High Fidelity, Inc. // @@ -13,17 +11,15 @@ // <@include DeferredBufferWrite.slh@> - <@include graphics/Material.slh@> - <@include graphics/MaterialTextures.slh@> -<$declareMaterialTextures(ALBEDO, ROUGHNESS, _SCRIBE_NULL, METALLIC, EMISSIVE, OCCLUSION)$> +<@include render-utils/ShaderConstants.h@> + +<$declareMaterialTextures(ALBEDO, ROUGHNESS, _SCRIBE_NULL, METALLIC, EMISSIVE, OCCLUSION, SCATTERING)$> <@include Fade.slh@> <$declareFadeFragment()$> -<@include render-utils/ShaderConstants.h@> - layout(location=RENDER_UTILS_ATTR_POSITION_WS) in vec4 _positionWS; layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01; #define _texCoord0 _texCoord01.xy @@ -34,13 +30,12 @@ layout(location=RENDER_UTILS_ATTR_COLOR) in vec4 _color; void main(void) { vec3 fadeEmissive; FadeObjectParams fadeParams; - <$fetchFadeObjectParams(fadeParams)$> applyFade(fadeParams, _positionWS.xyz, fadeEmissive); Material mat = getMaterial(); BITFIELD matKey = getMaterialKey(mat); - <$fetchMaterialTexturesCoord0(matKey, _texCoord0, albedoTex, roughnessTex, _SCRIBE_NULL, metallicTex, emissiveTex)$> + <$fetchMaterialTexturesCoord0(matKey, _texCoord0, albedoTex, roughnessTex, _SCRIBE_NULL, metallicTex, emissiveTex, scatteringTex)$> <$fetchMaterialTexturesCoord1(matKey, _texCoord1, occlusionTex)$> float opacity = 1.0; @@ -54,13 +49,17 @@ void main(void) { 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)$>; + vec3 emissive = getMaterialEmissive(mat); + <$evalMaterialEmissive(emissiveTex, emissive, matKey, emissive)$>; + + float occlusion = DEFAULT_OCCLUSION; + <$evalMaterialOcclusion(occlusionTex, matKey, occlusion)$>; + float scattering = getMaterialScattering(mat); + <$evalMaterialScattering(scatteringTex, scattering, matKey, scattering)$>; packDeferredFragment( normalize(_normalWS), @@ -68,7 +67,7 @@ void main(void) { albedo, roughness, metallic, - emissive+fadeEmissive, - occlusionTex, + emissive + fadeEmissive, + occlusion, scattering); } diff --git a/libraries/render-utils/src/model_lightmap.slf b/libraries/render-utils/src/model_lightmap.slf index efc36cc14a..ada49fdd08 100644 --- a/libraries/render-utils/src/model_lightmap.slf +++ b/libraries/render-utils/src/model_lightmap.slf @@ -1,10 +1,8 @@ <@include gpu/Config.slh@> <$VERSION_HEADER$> +// <$_SCRIBE_FILENAME$> // Generated on <$_SCRIBE_DATE$> // -// model_lightmap.frag -// fragment shader -// // Created by Samuel Gateau on 11/19/14. // Copyright 2014 High Fidelity, Inc. // @@ -20,7 +18,6 @@ <$declareMaterialTextures(ALBEDO, ROUGHNESS, _SCRIBE_NULL, METALLIC)$> <$declareMaterialLightmap()$> - layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01; #define _texCoord0 _texCoord01.xy #define _texCoord1 _texCoord01.zw @@ -30,15 +27,24 @@ layout(location=RENDER_UTILS_ATTR_COLOR) in vec4 _color; void main(void) { Material mat = getMaterial(); BITFIELD matKey = getMaterialKey(mat); - <$fetchMaterialTexturesCoord0(matKey, _texCoord0, albedo, roughness, _SCRIBE_NULL, metallicTex)$> - <$fetchMaterialTexturesCoord1(matKey, _texCoord1, _SCRIBE_NULL, lightmapVal)$> + <$fetchMaterialTexturesCoord0(matKey, _texCoord0, albedoTex, roughnessTex, _SCRIBE_NULL, metallicTex)$> + <$fetchMaterialTexturesCoord1(matKey, _texCoord1, _SCRIBE_NULL, lightmap)$> + + vec3 albedo = getMaterialAlbedo(mat); + <$evalMaterialAlbedo(albedoTex, albedo, matKey, albedo)$>; + albedo *= _color.rgb; + + float roughness = getMaterialRoughness(mat); + <$evalMaterialRoughness(roughnessTex, roughness, matKey, roughness)$>; + + float metallic = getMaterialMetallic(mat); + <$evalMaterialMetallic(metallicTex, metallic, matKey, metallic)$>; packDeferredFragmentLightmap( normalize(_normalWS), evalOpaqueFinalAlpha(getMaterialOpacity(mat), albedo.a), - getMaterialAlbedo(mat) * albedo.rgb * _color.rgb, - getMaterialRoughness(mat) * roughness, - getMaterialMetallic(mat) * metallicTex, - /*metallicTex, // no use of */getMaterialFresnel(mat), - lightmapVal); + albedo, + roughness, + metallic, + lightmap); } diff --git a/libraries/render-utils/src/model_lightmap_fade.slf b/libraries/render-utils/src/model_lightmap_fade.slf index 4cbf3dcdea..3819c4d4fa 100644 --- a/libraries/render-utils/src/model_lightmap_fade.slf +++ b/libraries/render-utils/src/model_lightmap_fade.slf @@ -1,10 +1,8 @@ <@include gpu/Config.slh@> <$VERSION_HEADER$> +// <$_SCRIBE_FILENAME$> // Generated on <$_SCRIBE_DATE$> // -// model_lightmap_fade.frag -// fragment shader -// // Created by Olivier Prat on 06/05/17. // Copyright 2017 High Fidelity, Inc. // @@ -13,18 +11,16 @@ // <@include DeferredBufferWrite.slh@> - <@include graphics/Material.slh@> - <@include graphics/MaterialTextures.slh@> +<@include render-utils/ShaderConstants.h@> + <$declareMaterialTextures(ALBEDO, ROUGHNESS, _SCRIBE_NULL, METALLIC)$> <$declareMaterialLightmap()$> <@include Fade.slh@> <$declareFadeFragment()$> -<@include render-utils/ShaderConstants.h@> - layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01; #define _texCoord0 _texCoord01.xy #define _texCoord1 _texCoord01.zw @@ -35,21 +31,29 @@ layout(location=RENDER_UTILS_ATTR_POSITION_WS) in vec4 _positionWS; void main(void) { vec3 fadeEmissive; FadeObjectParams fadeParams; - <$fetchFadeObjectParams(fadeParams)$> applyFade(fadeParams, _positionWS.xyz, fadeEmissive); Material mat = getMaterial(); BITFIELD matKey = getMaterialKey(mat); - <$fetchMaterialTexturesCoord0(matKey, _texCoord0, albedo, roughness, _SCRIBE_NULL, metallicTex)$> - <$fetchMaterialTexturesCoord1(matKey, _texCoord1, _SCRIBE_NULL, lightmapVal)$> + <$fetchMaterialTexturesCoord0(matKey, _texCoord0, albedoTex, roughnessTex, _SCRIBE_NULL, metallicTex)$> + <$fetchMaterialTexturesCoord1(matKey, _texCoord1, _SCRIBE_NULL, lightmap)$> + + vec3 albedo = getMaterialAlbedo(mat); + <$evalMaterialAlbedo(albedoTex, albedo, matKey, albedo)$>; + albedo *= _color.rgb; + + float roughness = getMaterialRoughness(mat); + <$evalMaterialRoughness(roughnessTex, roughness, matKey, roughness)$>; + + float metallic = getMaterialMetallic(mat); + <$evalMaterialMetallic(metallicTex, metallic, matKey, metallic)$>; packDeferredFragmentLightmap( normalize(_normalWS), evalOpaqueFinalAlpha(getMaterialOpacity(mat), albedo.a), - getMaterialAlbedo(mat) * albedo.rgb * _color.rgb, - getMaterialRoughness(mat) * roughness, - getMaterialMetallic(mat) * metallicTex, - /*metallicTex, // no use of */getMaterialFresnel(mat), - lightmapVal+fadeEmissive); + albedo, + roughness, + metallic, + lightmap + fadeEmissive); } diff --git a/libraries/render-utils/src/model_lightmap_normal_map.slf b/libraries/render-utils/src/model_lightmap_normal_map.slf index ebafc6dfe2..adeff463b5 100644 --- a/libraries/render-utils/src/model_lightmap_normal_map.slf +++ b/libraries/render-utils/src/model_lightmap_normal_map.slf @@ -1,10 +1,8 @@ <@include gpu/Config.slh@> <$VERSION_HEADER$> +// <$_SCRIBE_FILENAME$> // Generated on <$_SCRIBE_DATE$> // -// model_lightmap_normal_map.frag -// fragment shader -// // Created by Samuel Gateau on 11/19/14. // Copyright 2014 High Fidelity, Inc. // @@ -31,18 +29,27 @@ layout(location=RENDER_UTILS_ATTR_COLOR) in vec4 _color; void main(void) { Material mat = getMaterial(); BITFIELD matKey = getMaterialKey(mat); - <$fetchMaterialTexturesCoord0(matKey, _texCoord0, albedo, roughness, normalTexel, metallicTex)$> - <$fetchMaterialTexturesCoord1(matKey, _texCoord1, _SCRIBE_NULL, lightmapVal)$> + <$fetchMaterialTexturesCoord0(matKey, _texCoord0, albedoTex, roughnessTex, normalTex, metallicTex)$> + <$fetchMaterialTexturesCoord1(matKey, _texCoord1, _SCRIBE_NULL, lightmap)$> + + vec3 albedo = getMaterialAlbedo(mat); + <$evalMaterialAlbedo(albedoTex, albedo, matKey, albedo)$>; + albedo *= _color.rgb; + + float roughness = getMaterialRoughness(mat); + <$evalMaterialRoughness(roughnessTex, roughness, matKey, roughness)$>; + + float metallic = getMaterialMetallic(mat); + <$evalMaterialMetallic(metallicTex, metallic, matKey, metallic)$>; vec3 fragNormal; - <$evalMaterialNormalLOD(_positionES, normalTexel, _normalWS, _tangentWS, fragNormal)$> + <$evalMaterialNormalLOD(_positionES, normalTex, _normalWS, _tangentWS, fragNormal)$> packDeferredFragmentLightmap( - normalize(fragNormal.xyz), + normalize(fragNormal), evalOpaqueFinalAlpha(getMaterialOpacity(mat), albedo.a), - getMaterialAlbedo(mat) * albedo.rgb * _color.rgb, - getMaterialRoughness(mat) * roughness, - getMaterialMetallic(mat) * metallicTex, - /*specular, // no use of */ getMaterialFresnel(mat), - lightmapVal); + albedo, + roughness, + metallic, + lightmap); } diff --git a/libraries/render-utils/src/model_lightmap_normal_map_fade.slf b/libraries/render-utils/src/model_lightmap_normal_map_fade.slf index a9bac0e051..c46308fcf3 100644 --- a/libraries/render-utils/src/model_lightmap_normal_map_fade.slf +++ b/libraries/render-utils/src/model_lightmap_normal_map_fade.slf @@ -1,10 +1,8 @@ <@include gpu/Config.slh@> <$VERSION_HEADER$> +// <$_SCRIBE_FILENAME$> // 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. // @@ -13,18 +11,17 @@ // <@include DeferredBufferWrite.slh@> - <@include graphics/Material.slh@> - <@include graphics/MaterialTextures.slh@> +<@include render-utils/ShaderConstants.h@> + <$declareMaterialTextures(ALBEDO, ROUGHNESS, NORMAL, METALLIC)$> <$declareMaterialLightmap()$> <@include Fade.slh@> <$declareFadeFragment()$> -<@include render-utils/ShaderConstants.h@> - +layout(location=RENDER_UTILS_ATTR_POSITION_WS) in vec4 _positionWS; layout(location=RENDER_UTILS_ATTR_POSITION_ES) in vec4 _positionES; layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01; #define _texCoord0 _texCoord01.xy @@ -32,29 +29,36 @@ layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01; layout(location=RENDER_UTILS_ATTR_NORMAL_WS) in vec3 _normalWS; layout(location=RENDER_UTILS_ATTR_TANGENT_WS) in vec3 _tangentWS; layout(location=RENDER_UTILS_ATTR_COLOR) in vec4 _color; -layout(location=RENDER_UTILS_ATTR_POSITION_WS) in vec4 _positionWS; void main(void) { vec3 fadeEmissive; FadeObjectParams fadeParams; - <$fetchFadeObjectParams(fadeParams)$> applyFade(fadeParams, _positionWS.xyz, fadeEmissive); Material mat = getMaterial(); BITFIELD matKey = getMaterialKey(mat); - <$fetchMaterialTexturesCoord0(matKey, _texCoord0, albedo, roughness, normalTexel, metallicTex)$> - <$fetchMaterialTexturesCoord1(matKey, _texCoord1, _SCRIBE_NULL, lightmapVal)$> + <$fetchMaterialTexturesCoord0(matKey, _texCoord0, albedoTex, roughnessTex, normalTex, metallicTex)$> + <$fetchMaterialTexturesCoord1(matKey, _texCoord1, _SCRIBE_NULL, lightmap)$> + + vec3 albedo = getMaterialAlbedo(mat); + <$evalMaterialAlbedo(albedoTex, albedo, matKey, albedo)$>; + albedo *= _color.rgb; + + float roughness = getMaterialRoughness(mat); + <$evalMaterialRoughness(roughnessTex, roughness, matKey, roughness)$>; + + float metallic = getMaterialMetallic(mat); + <$evalMaterialMetallic(metallicTex, metallic, matKey, metallic)$>; vec3 fragNormal; - <$evalMaterialNormalLOD(_positionES, normalTexel, _normalWS, _tangentWS, fragNormal)$> + <$evalMaterialNormalLOD(_positionES, normalTex, _normalWS, _tangentWS, fragNormal)$> packDeferredFragmentLightmap( - normalize(fragNormal.xyz), + normalize(fragNormal), evalOpaqueFinalAlpha(getMaterialOpacity(mat), albedo.a), - getMaterialAlbedo(mat) * albedo.rgb * _color.rgb, - getMaterialRoughness(mat) * roughness, - getMaterialMetallic(mat) * metallicTex, - /*specular, // no use of */ getMaterialFresnel(mat), - lightmapVal+fadeEmissive); + albedo, + roughness, + metallic, + lightmap + fadeEmissive); } diff --git a/libraries/render-utils/src/model_normal_map.slf b/libraries/render-utils/src/model_normal_map.slf index 5f30830511..5fbc81e35b 100644 --- a/libraries/render-utils/src/model_normal_map.slf +++ b/libraries/render-utils/src/model_normal_map.slf @@ -1,10 +1,8 @@ <@include gpu/Config.slh@> <$VERSION_HEADER$> +// <$_SCRIBE_FILENAME$> // Generated on <$_SCRIBE_DATE$> // -// model_normal_map.frag -// fragment shader -// // Created by Andrzej Kapolka on 5/6/14. // Copyright 2014 High Fidelity, Inc. // @@ -44,25 +42,28 @@ void main(void) { float roughness = getMaterialRoughness(mat); <$evalMaterialRoughness(roughnessTex, roughness, matKey, roughness)$>; + float metallic = getMaterialMetallic(mat); + <$evalMaterialMetallic(metallicTex, metallic, matKey, metallic)$>; + vec3 emissive = getMaterialEmissive(mat); <$evalMaterialEmissive(emissiveTex, emissive, matKey, emissive)$>; - vec3 fragNormalWS; - <$evalMaterialNormalLOD(_positionES, normalTex, _normalWS, _tangentWS, fragNormalWS)$> - - float metallic = getMaterialMetallic(mat); - <$evalMaterialMetallic(metallicTex, metallic, matKey, metallic)$>; + float occlusion = DEFAULT_OCCLUSION; + <$evalMaterialOcclusion(occlusionTex, matKey, occlusion)$>; float scattering = getMaterialScattering(mat); <$evalMaterialScattering(scatteringTex, scattering, matKey, scattering)$>; + vec3 fragNormalWS; + <$evalMaterialNormalLOD(_positionES, normalTex, _normalWS, _tangentWS, fragNormalWS)$> + packDeferredFragment( - normalize(fragNormalWS.xyz), + normalize(fragNormalWS), opacity, albedo, roughness, metallic, emissive, - occlusionTex, + occlusion, scattering); } diff --git a/libraries/render-utils/src/model_normal_map_fade.slf b/libraries/render-utils/src/model_normal_map_fade.slf index 499f376efa..07b6f47b55 100644 --- a/libraries/render-utils/src/model_normal_map_fade.slf +++ b/libraries/render-utils/src/model_normal_map_fade.slf @@ -1,10 +1,8 @@ <@include gpu/Config.slh@> <$VERSION_HEADER$> +// <$_SCRIBE_FILENAME$> // Generated on <$_SCRIBE_DATE$> // -// model_normal_map_fade.frag -// fragment shader -// // Created by Olivier Prat on 06/05/17. // Copyright 2017 High Fidelity, Inc. // @@ -16,10 +14,10 @@ <@include graphics/Material.slh@> <@include graphics/MaterialTextures.slh@> <@include render-utils/ShaderConstants.h@> + +<$declareMaterialTextures(ALBEDO, ROUGHNESS, NORMAL, METALLIC, EMISSIVE, OCCLUSION, SCATTERING)$> + <@include Fade.slh@> - -<$declareMaterialTextures(ALBEDO, ROUGHNESS, NORMAL, METALLIC, EMISSIVE, OCCLUSION)$> - <$declareFadeFragment()$> layout(location=RENDER_UTILS_ATTR_POSITION_ES) in vec4 _positionES; @@ -34,13 +32,12 @@ layout(location=RENDER_UTILS_ATTR_COLOR) in vec4 _color; void main(void) { vec3 fadeEmissive; FadeObjectParams fadeParams; - <$fetchFadeObjectParams(fadeParams)$> applyFade(fadeParams, _positionWS.xyz, fadeEmissive); Material mat = getMaterial(); BITFIELD matKey = getMaterialKey(mat); - <$fetchMaterialTexturesCoord0(matKey, _texCoord0, albedoTex, roughnessTex, normalTex, metallicTex, emissiveTex)$> + <$fetchMaterialTexturesCoord0(matKey, _texCoord0, albedoTex, roughnessTex, normalTex, metallicTex, emissiveTex, scatteringTex)$> <$fetchMaterialTexturesCoord1(matKey, _texCoord1, occlusionTex)$> float opacity = 1.0; @@ -54,24 +51,28 @@ void main(void) { float roughness = getMaterialRoughness(mat); <$evalMaterialRoughness(roughnessTex, roughness, matKey, roughness)$>; + float metallic = getMaterialMetallic(mat); + <$evalMaterialMetallic(metallicTex, metallic, matKey, metallic)$>; + vec3 emissive = getMaterialEmissive(mat); <$evalMaterialEmissive(emissiveTex, emissive, matKey, emissive)$>; + float occlusion = DEFAULT_OCCLUSION; + <$evalMaterialOcclusion(occlusionTex, matKey, occlusion)$>; + + float scattering = getMaterialScattering(mat); + <$evalMaterialScattering(scatteringTex, scattering, matKey, scattering)$>; + vec3 fragNormalWS; <$evalMaterialNormalLOD(_positionES, normalTex, _normalWS, _tangentWS, fragNormalWS)$> - float metallic = getMaterialMetallic(mat); - <$evalMaterialMetallic(metallicTex, metallic, matKey, metallic)$>; - - float scattering = getMaterialScattering(mat); - packDeferredFragment( - normalize(fragNormalWS.xyz), + normalize(fragNormalWS), opacity, albedo, roughness, metallic, emissive + fadeEmissive, - occlusionTex, + occlusion, scattering); } diff --git a/libraries/render-utils/src/model_shadow.slf b/libraries/render-utils/src/model_shadow.slf index 6426759ec7..862fcd0cf6 100644 --- a/libraries/render-utils/src/model_shadow.slf +++ b/libraries/render-utils/src/model_shadow.slf @@ -1,10 +1,8 @@ <@include gpu/Config.slh@> <$VERSION_HEADER$> +// <$_SCRIBE_FILENAME$> // Generated on <$_SCRIBE_DATE$> // -// model_shadow.frag -// fragment shader -// // Created by Andrzej Kapolka on 3/24/14. // Copyright 2013 High Fidelity, Inc. // diff --git a/libraries/render-utils/src/model_shadow_fade.slf b/libraries/render-utils/src/model_shadow_fade.slf index c6c8c23f65..210b5482c8 100644 --- a/libraries/render-utils/src/model_shadow_fade.slf +++ b/libraries/render-utils/src/model_shadow_fade.slf @@ -1,10 +1,8 @@ <@include gpu/Config.slh@> <$VERSION_HEADER$> +// <$_SCRIBE_FILENAME$> // Generated on <$_SCRIBE_DATE$> // -// model_shadow_fade.frag -// fragment shader -// // Created by Olivier Prat on 06/05/17. // Copyright 2017 High Fidelity, Inc. // @@ -12,19 +10,17 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -<@include Fade.slh@> <@include render-utils/ShaderConstants.h@> +<@include Fade.slh@> <$declareFadeFragment()$> - layout(location=RENDER_UTILS_ATTR_POSITION_WS) in vec4 _positionWS; layout(location=0) out vec4 _fragColor; void main(void) { FadeObjectParams fadeParams; - <$fetchFadeObjectParams(fadeParams)$> applyFadeClip(fadeParams, _positionWS.xyz); diff --git a/libraries/render-utils/src/model_translucent.slf b/libraries/render-utils/src/model_translucent.slf index 00a871ace1..72f6b4c187 100644 --- a/libraries/render-utils/src/model_translucent.slf +++ b/libraries/render-utils/src/model_translucent.slf @@ -1,10 +1,8 @@ <@include gpu/Config.slh@> <$VERSION_HEADER$> +// <$_SCRIBE_FILENAME$> // Generated on <$_SCRIBE_DATE$> // -// model_translucent.frag -// fragment shader -// // Created by Sam Gateau on 2/15/2016. // Copyright 2014 High Fidelity, Inc. // @@ -12,19 +10,20 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -<@include gpu/Transform.slh@> +<@include DefaultMaterials.slh@> <@include graphics/Material.slh@> <@include graphics/MaterialTextures.slh@> <@include render-utils/ShaderConstants.h@> + <@include LightLocal.slh@> -<@include ShadingModel.slh@> <@include DeferredGlobalLight.slh@> <$declareEvalGlobalLightingAlphaBlendedWithHaze()$> +<@include gpu/Transform.slh@> <$declareStandardCameraTransform()$> -<$declareMaterialTextures(ALBEDO, ROUGHNESS, _SCRIBE_NULL, _SCRIBE_NULL, EMISSIVE, OCCLUSION)$> +<$declareMaterialTextures(ALBEDO, ROUGHNESS, _SCRIBE_NULL, METALLIC, EMISSIVE, OCCLUSION)$> layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01; #define _texCoord0 _texCoord01.xy @@ -39,7 +38,7 @@ layout(location=0) out vec4 _fragColor; void main(void) { Material mat = getMaterial(); BITFIELD matKey = getMaterialKey(mat); - <$fetchMaterialTexturesCoord0(matKey, _texCoord0, albedoTex, roughnessTex, _SCRIBE_NULL, _SCRIBE_NULL, emissiveTex)$> + <$fetchMaterialTexturesCoord0(matKey, _texCoord0, albedoTex, roughnessTex, _SCRIBE_NULL, metallicTex, emissiveTex)$> <$fetchMaterialTexturesCoord1(matKey, _texCoord1, occlusionTex)$> float opacity = getMaterialOpacity(mat) * _color.a; @@ -54,11 +53,16 @@ void main(void) { <$evalMaterialRoughness(roughnessTex, roughness, matKey, roughness)$>; float metallic = getMaterialMetallic(mat); + <$evalMaterialMetallic(metallicTex, metallic, matKey, metallic)$>; + vec3 fresnel = getFresnelF0(metallic, albedo); vec3 emissive = getMaterialEmissive(mat); <$evalMaterialEmissive(emissiveTex, emissive, matKey, emissive)$>; + float occlusion = DEFAULT_OCCLUSION; + <$evalMaterialOcclusion(occlusionTex, matKey, occlusion)$>; + vec3 fragPositionES = _positionES.xyz; vec3 fragPositionWS = _positionWS.xyz; // Lighting is done in world space @@ -70,7 +74,6 @@ void main(void) { SurfaceData surfaceWS = initSurfaceData(roughness, fragNormalWS, fragToEyeDirWS); vec4 localLighting = vec4(0.0); - <$fetchClusterInfo(_positionWS)$>; if (hasLocalLights(numLights, clusterPos, dims)) { localLighting = evalLocalLighting(cluster, numLights, fragPositionWS, surfaceWS, @@ -81,7 +84,7 @@ void main(void) { _fragColor = vec4(evalGlobalLightingAlphaBlendedWithHaze( cam._viewInverse, 1.0, - occlusionTex, + occlusion, fragPositionES, fragPositionWS, albedo, diff --git a/libraries/render-utils/src/model_translucent_fade.slf b/libraries/render-utils/src/model_translucent_fade.slf index 3cebc59ea7..7e170759c4 100644 --- a/libraries/render-utils/src/model_translucent_fade.slf +++ b/libraries/render-utils/src/model_translucent_fade.slf @@ -1,29 +1,33 @@ <@include gpu/Config.slh@> <$VERSION_HEADER$> +// <$_SCRIBE_FILENAME$> // Generated on <$_SCRIBE_DATE$> -// model_translucent_fade.frag +// // 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 +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// +<@include DefaultMaterials.slh@> <@include graphics/Material.slh@> +<@include graphics/MaterialTextures.slh@> +<@include render-utils/ShaderConstants.h@> + +<@include LightLocal.slh@> <@include DeferredGlobalLight.slh@> <$declareEvalGlobalLightingAlphaBlendedWithHaze()$> -<@include LightLocal.slh@> <@include gpu/Transform.slh@> <$declareStandardCameraTransform()$> -<@include graphics/MaterialTextures.slh@> -<$declareMaterialTextures(ALBEDO, ROUGHNESS, _SCRIBE_NULL, _SCRIBE_NULL, EMISSIVE, OCCLUSION)$> +<$declareMaterialTextures(ALBEDO, ROUGHNESS, _SCRIBE_NULL, METALLIC, EMISSIVE, OCCLUSION)$> <@include Fade.slh@> <$declareFadeFragment()$> -<@include render-utils/ShaderConstants.h@> - layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01; #define _texCoord0 _texCoord01.xy #define _texCoord1 _texCoord01.zw @@ -37,13 +41,12 @@ layout(location=0) out vec4 _fragColor; void main(void) { vec3 fadeEmissive; FadeObjectParams fadeParams; - <$fetchFadeObjectParams(fadeParams)$> applyFade(fadeParams, _positionWS.xyz, fadeEmissive); Material mat = getMaterial(); BITFIELD matKey = getMaterialKey(mat); - <$fetchMaterialTexturesCoord0(matKey, _texCoord0, albedoTex, roughnessTex, _SCRIBE_NULL, _SCRIBE_NULL, emissiveTex)$> + <$fetchMaterialTexturesCoord0(matKey, _texCoord0, albedoTex, roughnessTex, _SCRIBE_NULL, metallicTex, emissiveTex)$> <$fetchMaterialTexturesCoord1(matKey, _texCoord1, occlusionTex)$> float opacity = getMaterialOpacity(mat) * _color.a; @@ -58,11 +61,16 @@ void main(void) { <$evalMaterialRoughness(roughnessTex, roughness, matKey, roughness)$>; float metallic = getMaterialMetallic(mat); + <$evalMaterialMetallic(metallicTex, metallic, matKey, metallic)$>; + vec3 fresnel = getFresnelF0(metallic, albedo); vec3 emissive = getMaterialEmissive(mat); <$evalMaterialEmissive(emissiveTex, emissive, matKey, emissive)$>; + float occlusion = DEFAULT_OCCLUSION; + <$evalMaterialOcclusion(occlusionTex, matKey, occlusion)$>; + vec3 fragPositionES = _positionES.xyz; vec3 fragPositionWS = _positionWS.xyz; // Lighting is done in world space @@ -74,7 +82,6 @@ void main(void) { SurfaceData surfaceWS = initSurfaceData(roughness, fragNormalWS, fragToEyeDirWS); vec4 localLighting = vec4(0.0); - <$fetchClusterInfo(_positionWS)$>; if (hasLocalLights(numLights, clusterPos, dims)) { localLighting = evalLocalLighting(cluster, numLights, fragPositionWS, surfaceWS, @@ -85,7 +92,7 @@ void main(void) { _fragColor = vec4(evalGlobalLightingAlphaBlendedWithHaze( cam._viewInverse, 1.0, - occlusionTex, + occlusion, fragPositionES, fragPositionWS, albedo, diff --git a/libraries/render-utils/src/model_translucent_normal_map.slf b/libraries/render-utils/src/model_translucent_normal_map.slf index 7ac6982cfa..b3a9127acf 100644 --- a/libraries/render-utils/src/model_translucent_normal_map.slf +++ b/libraries/render-utils/src/model_translucent_normal_map.slf @@ -1,10 +1,8 @@ <@include gpu/Config.slh@> <$VERSION_HEADER$> +// <$_SCRIBE_FILENAME$> // Generated on <$_SCRIBE_DATE$> // -// model_translucent_normal_map.frag -// fragment shader -// // Created by Olivier Prat on 23/01/2018. // Copyright 2018 High Fidelity, Inc. // @@ -12,21 +10,20 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +<@include DefaultMaterials.slh@> <@include graphics/Material.slh@> +<@include graphics/MaterialTextures.slh@> +<@include render-utils/ShaderConstants.h@> +<@include LightLocal.slh@> <@include DeferredGlobalLight.slh@> <$declareEvalGlobalLightingAlphaBlendedWithHaze()$> -<@include LightLocal.slh@> - <@include gpu/Transform.slh@> <$declareStandardCameraTransform()$> -<@include graphics/MaterialTextures.slh@> -<$declareMaterialTextures(ALBEDO, ROUGHNESS, NORMAL, _SCRIBE_NULL, EMISSIVE, OCCLUSION)$> - -<@include render-utils/ShaderConstants.h@> +<$declareMaterialTextures(ALBEDO, ROUGHNESS, NORMAL, METALLIC, EMISSIVE, OCCLUSION)$> layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01; #define _texCoord0 _texCoord01.xy @@ -42,7 +39,7 @@ layout(location=0) out vec4 _fragColor; 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, metallicTex, emissiveTex)$> <$fetchMaterialTexturesCoord1(matKey, _texCoord1, occlusionTex)$> float opacity = getMaterialOpacity(mat) * _color.a; @@ -57,11 +54,16 @@ void main(void) { <$evalMaterialRoughness(roughnessTex, roughness, matKey, roughness)$>; float metallic = getMaterialMetallic(mat); + <$evalMaterialMetallic(metallicTex, metallic, matKey, metallic)$>; + vec3 fresnel = getFresnelF0(metallic, albedo); vec3 emissive = getMaterialEmissive(mat); <$evalMaterialEmissive(emissiveTex, emissive, matKey, emissive)$>; + float occlusion = DEFAULT_OCCLUSION; + <$evalMaterialOcclusion(occlusionTex, matKey, occlusion)$>; + vec3 fragPositionES = _positionES.xyz; vec3 fragPositionWS = _positionWS.xyz; // Lighting is done in world space @@ -71,10 +73,9 @@ void main(void) { TransformCamera cam = getTransformCamera(); vec3 fragToEyeWS = cam._viewInverse[3].xyz - fragPositionWS; vec3 fragToEyeDirWS = normalize(fragToEyeWS); - SurfaceData surfaceWS = initSurfaceData(roughness, fragNormalWS, fragToEyeDirWS); + SurfaceData surfaceWS = initSurfaceData(roughness, normalize(fragNormalWS), fragToEyeDirWS); vec4 localLighting = vec4(0.0); - <$fetchClusterInfo(_positionWS)$>; if (hasLocalLights(numLights, clusterPos, dims)) { localLighting = evalLocalLighting(cluster, numLights, fragPositionWS, surfaceWS, @@ -85,7 +86,7 @@ void main(void) { _fragColor = vec4(evalGlobalLightingAlphaBlendedWithHaze( cam._viewInverse, 1.0, - occlusionTex, + occlusion, fragPositionES, fragPositionWS, albedo, diff --git a/libraries/render-utils/src/model_translucent_normal_map_fade.slf b/libraries/render-utils/src/model_translucent_normal_map_fade.slf index 2c182aeb19..4c56ebda2e 100644 --- a/libraries/render-utils/src/model_translucent_normal_map_fade.slf +++ b/libraries/render-utils/src/model_translucent_normal_map_fade.slf @@ -1,10 +1,8 @@ <@include gpu/Config.slh@> <$VERSION_HEADER$> +// <$_SCRIBE_FILENAME$> // Generated on <$_SCRIBE_DATE$> // -// model_translucent_normal_map_fade.frag -// fragment shader -// // Created by Olivier Prat on 23/01/18. // Copyright 2018 High Fidelity, Inc. // @@ -12,47 +10,44 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -<@include render-utils/ShaderConstants.h@> +<@include DefaultMaterials.slh@> <@include graphics/Material.slh@> +<@include graphics/MaterialTextures.slh@> +<@include render-utils/ShaderConstants.h@> +<@include LightLocal.slh@> <@include DeferredGlobalLight.slh@> <$declareEvalGlobalLightingAlphaBlendedWithHaze()$> -<@include LightLocal.slh@> - <@include gpu/Transform.slh@> <$declareStandardCameraTransform()$> -<@include graphics/MaterialTextures.slh@> -<$declareMaterialTextures(ALBEDO, ROUGHNESS, NORMAL, _SCRIBE_NULL, EMISSIVE, OCCLUSION)$> +<$declareMaterialTextures(ALBEDO, ROUGHNESS, NORMAL, METALLIC, EMISSIVE, OCCLUSION)$> <@include Fade.slh@> <$declareFadeFragment()$> -<@include render-utils/ShaderConstants.h@> - layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01; #define _texCoord0 _texCoord01.xy #define _texCoord1 _texCoord01.zw layout(location=RENDER_UTILS_ATTR_POSITION_ES) in vec4 _positionES; +layout(location=RENDER_UTILS_ATTR_POSITION_WS) in vec4 _positionWS; layout(location=RENDER_UTILS_ATTR_NORMAL_WS) in vec3 _normalWS; layout(location=RENDER_UTILS_ATTR_TANGENT_WS) in vec3 _tangentWS; layout(location=RENDER_UTILS_ATTR_COLOR) in vec4 _color; -layout(location=RENDER_UTILS_ATTR_POSITION_WS) in vec4 _positionWS; layout(location=0) out vec4 _fragColor; void main(void) { vec3 fadeEmissive; FadeObjectParams fadeParams; - <$fetchFadeObjectParams(fadeParams)$> applyFade(fadeParams, _positionWS.xyz, fadeEmissive); Material mat = getMaterial(); int matKey = getMaterialKey(mat); - <$fetchMaterialTexturesCoord0(matKey, _texCoord0, albedoTex, roughnessTex, normalTex, _SCRIBE_NULL, emissiveTex)$> + <$fetchMaterialTexturesCoord0(matKey, _texCoord0, albedoTex, roughnessTex, normalTex, metallicTex, emissiveTex)$> <$fetchMaterialTexturesCoord1(matKey, _texCoord1, occlusionTex)$> float opacity = getMaterialOpacity(mat) * _color.a; @@ -67,11 +62,16 @@ void main(void) { <$evalMaterialRoughness(roughnessTex, roughness, matKey, roughness)$>; float metallic = getMaterialMetallic(mat); + <$evalMaterialMetallic(metallicTex, metallic, matKey, metallic)$>; + vec3 fresnel = getFresnelF0(metallic, albedo); vec3 emissive = getMaterialEmissive(mat); <$evalMaterialEmissive(emissiveTex, emissive, matKey, emissive)$>; + float occlusion = DEFAULT_OCCLUSION; + <$evalMaterialOcclusion(occlusionTex, matKey, occlusion)$>; + vec3 fragPositionES = _positionES.xyz; vec3 fragPositionWS = _positionWS.xyz; // Lighting is done in world space @@ -81,10 +81,9 @@ void main(void) { TransformCamera cam = getTransformCamera(); vec3 fragToEyeWS = cam._viewInverse[3].xyz - fragPositionWS; vec3 fragToEyeDirWS = normalize(fragToEyeWS); - SurfaceData surfaceWS = initSurfaceData(roughness, fragNormalWS, fragToEyeDirWS); + SurfaceData surfaceWS = initSurfaceData(roughness, normalize(fragNormalWS), fragToEyeDirWS); vec4 localLighting = vec4(0.0); - <$fetchClusterInfo(_positionWS)$>; if (hasLocalLights(numLights, clusterPos, dims)) { localLighting = evalLocalLighting(cluster, numLights, fragPositionWS, surfaceWS, @@ -95,7 +94,7 @@ void main(void) { _fragColor = vec4(evalGlobalLightingAlphaBlendedWithHaze( cam._viewInverse, 1.0, - occlusionTex, + occlusion, fragPositionES, fragPositionWS, albedo, diff --git a/libraries/render-utils/src/model_translucent_unlit.slf b/libraries/render-utils/src/model_translucent_unlit.slf index 1e468791f4..37f58d3da9 100644 --- a/libraries/render-utils/src/model_translucent_unlit.slf +++ b/libraries/render-utils/src/model_translucent_unlit.slf @@ -1,10 +1,8 @@ <@include gpu/Config.slh@> <$VERSION_HEADER$> +// <$_SCRIBE_FILENAME$> // Generated on <$_SCRIBE_DATE$> // -// model_translucent_unlit.frag -// fragment shader -// // Created by Zach Pomerantz on 2/3/2016. // Copyright 2016 High Fidelity, Inc. // @@ -13,12 +11,12 @@ // <@include graphics/Material.slh@> - <@include graphics/MaterialTextures.slh@> -<$declareMaterialTextures(ALBEDO, ROUGHNESS, _SCRIBE_NULL, _SCRIBE_NULL, EMISSIVE, OCCLUSION)$> +<@include render-utils/ShaderConstants.h@> + <@include LightingModel.slh@> -<@include render-utils/ShaderConstants.h@> +<$declareMaterialTextures(ALBEDO)$> layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01; #define _texCoord0 _texCoord01.xy diff --git a/libraries/render-utils/src/model_translucent_unlit_fade.slf b/libraries/render-utils/src/model_translucent_unlit_fade.slf index cbbaae8641..04d57b7c47 100644 --- a/libraries/render-utils/src/model_translucent_unlit_fade.slf +++ b/libraries/render-utils/src/model_translucent_unlit_fade.slf @@ -1,10 +1,8 @@ <@include gpu/Config.slh@> <$VERSION_HEADER$> +// <$_SCRIBE_FILENAME$> // Generated on <$_SCRIBE_DATE$> // -// model_translucent_unlit_fade.frag -// fragment shader -// // Created by Olivier Prat on 06/05/17. // Copyright 2017 High Fidelity, Inc. // @@ -13,16 +11,16 @@ // <@include graphics/Material.slh@> - <@include graphics/MaterialTextures.slh@> -<$declareMaterialTextures(ALBEDO, ROUGHNESS, _SCRIBE_NULL, _SCRIBE_NULL, EMISSIVE, OCCLUSION)$> +<@include render-utils/ShaderConstants.h@> + <@include LightingModel.slh@> +<$declareMaterialTextures(ALBEDO)$> + <@include Fade.slh@> <$declareFadeFragment()$> -<@include render-utils/ShaderConstants.h@> - layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01; #define _texCoord0 _texCoord01.xy #define _texCoord1 _texCoord01.zw @@ -34,7 +32,6 @@ layout(location=0) out vec4 _fragColor; void main(void) { vec3 fadeEmissive; FadeObjectParams fadeParams; - <$fetchFadeObjectParams(fadeParams)$> applyFade(fadeParams, _positionWS.xyz, fadeEmissive); @@ -50,5 +47,6 @@ void main(void) { <$evalMaterialAlbedo(albedoTex, albedo, matKey, albedo)$>; albedo *= _color.rgb; albedo += fadeEmissive; + _fragColor = vec4(albedo * isUnlitEnabled(), opacity); } diff --git a/libraries/render-utils/src/model_unlit.slf b/libraries/render-utils/src/model_unlit.slf index b14a807eb5..cbac67a72e 100644 --- a/libraries/render-utils/src/model_unlit.slf +++ b/libraries/render-utils/src/model_unlit.slf @@ -1,10 +1,8 @@ <@include gpu/Config.slh@> <$VERSION_HEADER$> +// <$_SCRIBE_FILENAME$> // Generated on <$_SCRIBE_DATE$> // -// material_opaque_unlit.frag -// fragment shader -// // Created by Sam Gateau on 5/5/2016. // Copyright 2016 High Fidelity, Inc. // @@ -12,12 +10,13 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -<@include DeferredBufferWrite.slh@> -<@include LightingModel.slh@> <@include graphics/Material.slh@> <@include graphics/MaterialTextures.slh@> <@include render-utils/ShaderConstants.h@> +<@include DeferredBufferWrite.slh@> +<@include LightingModel.slh@> + <$declareMaterialTextures(ALBEDO)$> layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01; @@ -27,7 +26,6 @@ layout(location=RENDER_UTILS_ATTR_NORMAL_WS) in vec3 _normalWS; layout(location=RENDER_UTILS_ATTR_COLOR) in vec4 _color; void main(void) { - Material mat = getMaterial(); BITFIELD matKey = getMaterialKey(mat); <$fetchMaterialTexturesCoord0(matKey, _texCoord0, albedoTex)$> diff --git a/libraries/render-utils/src/model_unlit_fade.slf b/libraries/render-utils/src/model_unlit_fade.slf index cb5c72bdf2..3097c04c26 100644 --- a/libraries/render-utils/src/model_unlit_fade.slf +++ b/libraries/render-utils/src/model_unlit_fade.slf @@ -1,10 +1,8 @@ <@include gpu/Config.slh@> <$VERSION_HEADER$> +// <$_SCRIBE_FILENAME$> // Generated on <$_SCRIBE_DATE$> // -// model_unlit_fade.frag -// fragment shader -// // Created by Olivier Prat on 06/05/17. // Copyright 2017 High Fidelity, Inc. // @@ -12,13 +10,14 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -<@include DeferredBufferWrite.slh@> -<@include LightingModel.slh@> <@include graphics/Material.slh@> <@include graphics/MaterialTextures.slh@> <@include render-utils/ShaderConstants.h@> -<@include Fade.slh@> +<@include DeferredBufferWrite.slh@> +<@include LightingModel.slh@> + +<@include Fade.slh@> <$declareFadeFragment()$> <$declareMaterialTextures(ALBEDO)$> @@ -33,7 +32,6 @@ layout(location=RENDER_UTILS_ATTR_COLOR) in vec4 _color; void main(void) { vec3 fadeEmissive; FadeObjectParams fadeParams; - <$fetchFadeObjectParams(fadeParams)$> applyFade(fadeParams, _positionWS.xyz, fadeEmissive); @@ -49,6 +47,7 @@ void main(void) { <$evalMaterialAlbedo(albedoTex, albedo, matKey, albedo)$>; albedo *= _color.rgb; albedo += fadeEmissive; + packDeferredFragmentUnlit( normalize(_normalWS), opacity, diff --git a/libraries/render-utils/src/parabola_translucent.slf b/libraries/render-utils/src/parabola_translucent.slf index 62b5b15193..01f4614172 100644 --- a/libraries/render-utils/src/parabola_translucent.slf +++ b/libraries/render-utils/src/parabola_translucent.slf @@ -14,5 +14,5 @@ layout(location=0) in vec4 _color; void main(void) { - packDeferredFragmentTranslucent(vec3(1.0, 0.0, 0.0), _color.a, _color.rgb, DEFAULT_FRESNEL, DEFAULT_ROUGHNESS); + packDeferredFragmentTranslucent(vec3(1.0, 0.0, 0.0), _color.a, _color.rgb, DEFAULT_ROUGHNESS); } diff --git a/libraries/render-utils/src/sdf_text3D_transparent.slf b/libraries/render-utils/src/sdf_text3D_transparent.slf index 9dffca2038..615f4e010f 100644 --- a/libraries/render-utils/src/sdf_text3D_transparent.slf +++ b/libraries/render-utils/src/sdf_text3D_transparent.slf @@ -60,6 +60,5 @@ void main() { normalize(_normalWS), a * params.color.a, params.color.rgb, - DEFAULT_FRESNEL, DEFAULT_ROUGHNESS); } \ No newline at end of file diff --git a/libraries/render-utils/src/simple.slf b/libraries/render-utils/src/simple.slf index a7f5151880..5cceec0ac2 100644 --- a/libraries/render-utils/src/simple.slf +++ b/libraries/render-utils/src/simple.slf @@ -65,7 +65,6 @@ void main(void) { diffuse, max(0.0, 1.0 - shininess / 128.0), DEFAULT_METALLIC, - specular, vec3(clamp(emissiveAmount, 0.0, 1.0))); } else { packDeferredFragment( diff --git a/libraries/render-utils/src/simple_fade.slf b/libraries/render-utils/src/simple_fade.slf index 97ed0c570c..140c6b698b 100644 --- a/libraries/render-utils/src/simple_fade.slf +++ b/libraries/render-utils/src/simple_fade.slf @@ -75,14 +75,12 @@ void main(void) { normal, _color.a, specular+fadeEmissive, - DEFAULT_FRESNEL, DEFAULT_ROUGHNESS); } else { packDeferredFragmentTranslucent( normal, _color.a, diffuse+fadeEmissive, - DEFAULT_FRESNEL, DEFAULT_ROUGHNESS); } } else { @@ -93,7 +91,6 @@ void main(void) { diffuse+fadeEmissive, max(0.0, 1.0 - shininess / 128.0), DEFAULT_METALLIC, - specular, specular); } else { packDeferredFragment( diff --git a/libraries/render-utils/src/simple_textured_fade.slf b/libraries/render-utils/src/simple_textured_fade.slf index 600f19be0f..79ba571671 100644 --- a/libraries/render-utils/src/simple_textured_fade.slf +++ b/libraries/render-utils/src/simple_textured_fade.slf @@ -53,7 +53,6 @@ void main(void) { normalize(_normalWS), colorAlpha * texel.a, _color.rgb * texel.rgb + fadeEmissive, - DEFAULT_FRESNEL, DEFAULT_ROUGHNESS); } else { packDeferredFragment( diff --git a/libraries/render-utils/src/simple_textured_unlit.slf b/libraries/render-utils/src/simple_textured_unlit.slf index e3d9b9daf6..c0d86e9b99 100644 --- a/libraries/render-utils/src/simple_textured_unlit.slf +++ b/libraries/render-utils/src/simple_textured_unlit.slf @@ -41,7 +41,6 @@ void main(void) { normalize(_normalWS), colorAlpha * texel.a, _color.rgb * texel.rgb, - DEFAULT_FRESNEL, DEFAULT_ROUGHNESS); } else { packDeferredFragmentUnlit( diff --git a/libraries/render-utils/src/simple_textured_unlit_fade.slf b/libraries/render-utils/src/simple_textured_unlit_fade.slf index bffadbe819..b7f03c5df5 100644 --- a/libraries/render-utils/src/simple_textured_unlit_fade.slf +++ b/libraries/render-utils/src/simple_textured_unlit_fade.slf @@ -53,7 +53,6 @@ void main(void) { normalize(_normalWS), colorAlpha * texel.a, _color.rgb * texel.rgb+fadeEmissive, - DEFAULT_FRESNEL, DEFAULT_ROUGHNESS); } else { packDeferredFragmentUnlit( diff --git a/libraries/render-utils/src/simple_transparent_textured.slf b/libraries/render-utils/src/simple_transparent_textured.slf index 5573a7aa22..39e40bb9a6 100644 --- a/libraries/render-utils/src/simple_transparent_textured.slf +++ b/libraries/render-utils/src/simple_transparent_textured.slf @@ -34,6 +34,5 @@ void main(void) { normalize(_normalWS), colorAlpha, _color.rgb * texel.rgb, - DEFAULT_FRESNEL, DEFAULT_ROUGHNESS); } \ No newline at end of file diff --git a/libraries/render-utils/src/simple_transparent_web_browser.slf b/libraries/render-utils/src/simple_transparent_web_browser.slf index df92d238bf..3c9b34fbfa 100644 --- a/libraries/render-utils/src/simple_transparent_web_browser.slf +++ b/libraries/render-utils/src/simple_transparent_web_browser.slf @@ -34,6 +34,5 @@ void main(void) { normalize(_normalWS), _color.a, _color.rgb * texel.rgb, - DEFAULT_FRESNEL, DEFAULT_ROUGHNESS); } From 0f24c18de538d58601a083b71b727963786f8591 Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Wed, 26 Sep 2018 14:44:19 -0700 Subject: [PATCH 2/7] slightly fix forward pipelines --- .../graphics/src/graphics/MaterialTextures.slh | 10 ---------- libraries/render-utils/src/RenderPipelines.cpp | 4 +++- libraries/render-utils/src/forward_model.slf | 15 +++++++++------ .../src/forward_model_normal_map.slf | 18 +++++++++++------- .../src/forward_model_translucent.slf | 15 ++++++++++----- .../render-utils/src/forward_model_unlit.slf | 11 +++-------- 6 files changed, 36 insertions(+), 37 deletions(-) diff --git a/libraries/graphics/src/graphics/MaterialTextures.slh b/libraries/graphics/src/graphics/MaterialTextures.slh index 106453877c..a01eb5dcd0 100644 --- a/libraries/graphics/src/graphics/MaterialTextures.slh +++ b/libraries/graphics/src/graphics/MaterialTextures.slh @@ -226,16 +226,6 @@ vec3 fetchLightmapMap(vec2 uv) { } <@endfunc@> -<@func evalMaterialNormal(fetchedNormal, interpolatedNormal, interpolatedTangent, normal)@> -{ - vec3 normalizedNormal = normalize(<$interpolatedNormal$>.xyz); - vec3 normalizedTangent = normalize(<$interpolatedTangent$>.xyz); - vec3 normalizedBitangent = cross(normalizedNormal, normalizedTangent); - vec3 localNormal = <$fetchedNormal$>; - <$normal$> = vec3(normalizedBitangent * localNormal.x + normalizedNormal * localNormal.y + normalizedTangent * localNormal.z); -} -<@endfunc@> - <@func evalMaterialNormalLOD(fragPosES, fetchedNormal, interpolatedNormal, interpolatedTangent, normal)@> { vec3 normalizedNormal = normalize(<$interpolatedNormal$>.xyz); diff --git a/libraries/render-utils/src/RenderPipelines.cpp b/libraries/render-utils/src/RenderPipelines.cpp index 704b1d7663..84f0835651 100644 --- a/libraries/render-utils/src/RenderPipelines.cpp +++ b/libraries/render-utils/src/RenderPipelines.cpp @@ -254,7 +254,7 @@ void initForwardPipelines(ShapePlumber& plumber) { // Opaques addPipeline(Key::Builder().withMaterial(), forward_model); addPipeline(Key::Builder().withMaterial().withUnlit(), forward_model_unlit); - addPipeline(Key::Builder().withMaterial().withTangents(), forward_model_translucent); + addPipeline(Key::Builder().withMaterial().withTangents(), forward_model_normal_map); // Skinned Opaques addPipeline(Key::Builder().withMaterial().withSkinned(), forward_skin_model); @@ -272,6 +272,8 @@ void initForwardPipelines(ShapePlumber& plumber) { addPipeline(Key::Builder().withMaterial().withSkinned().withTranslucent().withDualQuatSkinned(), forward_skin_translucent_dq); addPipeline(Key::Builder().withMaterial().withSkinned().withTranslucent().withTangents().withDualQuatSkinned(), forward_skin_translucent_normal_map_dq); + // FIXME: incorrent pipelines for normal mapped + translucent models + forceLightBatchSetter = false; } diff --git a/libraries/render-utils/src/forward_model.slf b/libraries/render-utils/src/forward_model.slf index f77ab358f2..daccd9c6d6 100644 --- a/libraries/render-utils/src/forward_model.slf +++ b/libraries/render-utils/src/forward_model.slf @@ -1,10 +1,8 @@ <@include gpu/Config.slh@> <$VERSION_HEADER$> +// <$_SCRIBE_FILENAME$> // Generated on <$_SCRIBE_DATE$> // -// forward_model.frag -// fragment shader -// // Created by Sam Gateau on 2/15/2016. // Copyright 2014 High Fidelity, Inc. // @@ -12,15 +10,16 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -<@include gpu/Transform.slh@> +<@include DefaultMaterials.slh@> <@include graphics/Material.slh@> <@include graphics/MaterialTextures.slh@> <@include render-utils/ShaderConstants.h@> + <@include ForwardGlobalLight.slh@> <$declareEvalSkyboxGlobalColor()$> - +<@include gpu/Transform.slh@> <$declareStandardCameraTransform()$> <$declareMaterialTextures(ALBEDO, ROUGHNESS, _SCRIBE_NULL, METALLIC, EMISSIVE, OCCLUSION)$> @@ -56,8 +55,12 @@ void main(void) { float metallic = getMaterialMetallic(mat); <$evalMaterialMetallic(metallicTex, metallic, matKey, metallic)$>; + vec3 fresnel = getFresnelF0(metallic, albedo); + float occlusion = DEFAULT_OCCLUSION; + <$evalMaterialOcclusion(occlusionTex, matKey, occlusion)$>; + vec3 fragPosition = _positionES.xyz; vec3 fragNormal = normalize(_normalWS); @@ -66,7 +69,7 @@ void main(void) { vec4 color = vec4(evalSkyboxGlobalColor( cam._viewInverse, 1.0, - occlusionTex, + occlusion, fragPosition, fragNormal, albedo, diff --git a/libraries/render-utils/src/forward_model_normal_map.slf b/libraries/render-utils/src/forward_model_normal_map.slf index 73fae33fb0..33e375c495 100644 --- a/libraries/render-utils/src/forward_model_normal_map.slf +++ b/libraries/render-utils/src/forward_model_normal_map.slf @@ -1,10 +1,8 @@ <@include gpu/Config.slh@> <$VERSION_HEADER$> +// <$_SCRIBE_FILENAME$> // Generated on <$_SCRIBE_DATE$> // -// forward_model_normal_map.frag -// fragment shader -// // Created by Sam Gateau on 2/15/2016. // Copyright 2014 High Fidelity, Inc. // @@ -12,13 +10,16 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -<@include gpu/Transform.slh@> +<@include DefaultMaterials.slh@> <@include graphics/Material.slh@> <@include graphics/MaterialTextures.slh@> <@include render-utils/ShaderConstants.h@> + <@include ForwardGlobalLight.slh@> <$declareEvalSkyboxGlobalColor()$> + +<@include gpu/Transform.slh@> <$declareStandardCameraTransform()$> <$declareMaterialTextures(ALBEDO, ROUGHNESS, NORMAL, METALLIC, EMISSIVE, OCCLUSION)$> @@ -55,18 +56,22 @@ void main(void) { float metallic = getMaterialMetallic(mat); <$evalMaterialMetallic(metallicTex, metallic, matKey, metallic)$>; + vec3 fresnel = getFresnelF0(metallic, albedo); + float occlusion = DEFAULT_OCCLUSION; + <$evalMaterialOcclusion(occlusionTex, matKey, occlusion)$>; + vec3 fragPosition = _positionES.xyz; vec3 fragNormal; - <$evalMaterialNormal(normalTex, _normalWS, _tangentWS, fragNormal)$> + <$evalMaterialNormalLOD(fragPosition, normalTex, _normalWS, _tangentWS, fragNormal)$> TransformCamera cam = getTransformCamera(); vec4 color = vec4(evalSkyboxGlobalColor( cam._viewInverse, 1.0, - occlusionTex, + occlusion, fragPosition, fragNormal, albedo, @@ -74,7 +79,6 @@ void main(void) { metallic, roughness), opacity); - color.rgb += emissive * isEmissiveEnabled(); _fragColor0 = color; diff --git a/libraries/render-utils/src/forward_model_translucent.slf b/libraries/render-utils/src/forward_model_translucent.slf index 5fb2c7c1a7..080ed7eea3 100644 --- a/libraries/render-utils/src/forward_model_translucent.slf +++ b/libraries/render-utils/src/forward_model_translucent.slf @@ -1,10 +1,8 @@ <@include gpu/Config.slh@> <$VERSION_HEADER$> +// <$_SCRIBE_FILENAME$> // Generated on <$_SCRIBE_DATE$> // -// forward_model_translucent.frag -// fragment shader -// // Created by Sam Gateau on 2/15/2016. // Copyright 2014 High Fidelity, Inc. // @@ -12,13 +10,16 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -<@include gpu/Transform.slh@> +<@include DefaultMaterials.slh@> <@include graphics/Material.slh@> <@include graphics/MaterialTextures.slh@> <@include render-utils/ShaderConstants.h@> + <@include ForwardGlobalLight.slh@> <$declareEvalGlobalLightingAlphaBlended()$> + +<@include gpu/Transform.slh@> <$declareStandardCameraTransform()$> <$declareMaterialTextures(ALBEDO, ROUGHNESS, _SCRIBE_NULL, METALLIC, EMISSIVE, OCCLUSION)$> @@ -51,8 +52,12 @@ void main(void) { float metallic = getMaterialMetallic(mat); <$evalMaterialMetallic(metallicTex, metallic, matKey, metallic)$>; + vec3 fresnel = getFresnelF0(metallic, albedo); + float occlusion = DEFAULT_OCCLUSION; + <$evalMaterialOcclusion(occlusionTex, matKey, occlusion)$>; + vec3 emissive = getMaterialEmissive(mat); <$evalMaterialEmissive(emissiveTex, emissive, matKey, emissive)$>; @@ -64,7 +69,7 @@ void main(void) { _fragColor0 = vec4(evalGlobalLightingAlphaBlendedWithHaze( cam._viewInverse, 1.0, - occlusionTex, + occlusion, fragPosition, fragNormal, albedo, diff --git a/libraries/render-utils/src/forward_model_unlit.slf b/libraries/render-utils/src/forward_model_unlit.slf index 19b40d884c..ccd264f0bf 100644 --- a/libraries/render-utils/src/forward_model_unlit.slf +++ b/libraries/render-utils/src/forward_model_unlit.slf @@ -1,10 +1,8 @@ <@include gpu/Config.slh@> <$VERSION_HEADER$> +// <$_SCRIBE_FILENAME$> // Generated on <$_SCRIBE_DATE$> // -// forward_model_unlit.frag -// fragment shader -// // Created by Sam Gateau on 5/5/2016. // Copyright 2016 High Fidelity, Inc. // @@ -12,11 +10,12 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -<@include LightingModel.slh@> <@include graphics/Material.slh@> <@include graphics/MaterialTextures.slh@> <@include render-utils/ShaderConstants.h@> +<@include LightingModel.slh@> + <$declareMaterialTextures(ALBEDO)$> layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01; @@ -27,7 +26,6 @@ layout(location=RENDER_UTILS_ATTR_COLOR) in vec4 _color; layout(location=0) out vec4 _fragColor0; void main(void) { - Material mat = getMaterial(); BITFIELD matKey = getMaterialKey(mat); <$fetchMaterialTexturesCoord0(matKey, _texCoord0, albedoTex)$> @@ -40,8 +38,5 @@ void main(void) { <$evalMaterialAlbedo(albedoTex, albedo, matKey, albedo)$>; albedo *= _color.rgb; - if (opacity != 1.0) { - discard; - } _fragColor0 = vec4(albedo * isUnlitEnabled(), 1.0); } From e0698179782a31e8ac823f9e32e8f0367cd81169 Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Thu, 27 Sep 2018 14:18:43 -0700 Subject: [PATCH 3/7] more fixes --- libraries/gpu/src/gpu/TextureTable.slh | 2 +- libraries/graphics/src/graphics/BufferViewHelpers.cpp | 2 +- libraries/graphics/src/graphics/MaterialTextures.slh | 2 +- libraries/render-utils/src/model_lightmap.slf | 2 +- libraries/render-utils/src/model_lightmap_fade.slf | 2 +- libraries/render-utils/src/model_lightmap_normal_map.slf | 2 +- libraries/render-utils/src/model_lightmap_normal_map_fade.slf | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libraries/gpu/src/gpu/TextureTable.slh b/libraries/gpu/src/gpu/TextureTable.slh index bedbff954b..f8cc4b0599 100644 --- a/libraries/gpu/src/gpu/TextureTable.slh +++ b/libraries/gpu/src/gpu/TextureTable.slh @@ -22,7 +22,7 @@ struct GPUTextureTable { #define tableTex(name, slot) sampler2D(name._textures[slot].xy) #define tableTexMinLod(name, slot) float(name._textures[slot].z) -#define tableTexValue(name, slot, uv) tableTexValueLod(tableTex(matTex, albedoMap), tableTexMinLod(matTex, albedoMap), uv) +#define tableTexValue(name, slot, uv) tableTexValueLod(tableTex(matTex, slot), tableTexMinLod(matTex, slot), uv) vec4 tableTexValueLod(sampler2D sampler, float minLod, vec2 uv) { float queryLod = textureQueryLod(sampler, uv).x; diff --git a/libraries/graphics/src/graphics/BufferViewHelpers.cpp b/libraries/graphics/src/graphics/BufferViewHelpers.cpp index 2fd0d90da3..4c57abdfd4 100644 --- a/libraries/graphics/src/graphics/BufferViewHelpers.cpp +++ b/libraries/graphics/src/graphics/BufferViewHelpers.cpp @@ -38,7 +38,7 @@ QMap ATTRIBUTES{ {"position", gpu::Stream::POSITION }, {"normal", gpu::Stream::NORMAL }, {"color", gpu::Stream::COLOR }, - {"tangent", gpu::Stream::TEXCOORD0 }, + {"tangent", gpu::Stream::TANGENT }, {"skin_cluster_index", gpu::Stream::SKIN_CLUSTER_INDEX }, {"skin_cluster_weight", gpu::Stream::SKIN_CLUSTER_WEIGHT }, {"texcoord0", gpu::Stream::TEXCOORD0 }, diff --git a/libraries/graphics/src/graphics/MaterialTextures.slh b/libraries/graphics/src/graphics/MaterialTextures.slh index a01eb5dcd0..555bfa9cf0 100644 --- a/libraries/graphics/src/graphics/MaterialTextures.slh +++ b/libraries/graphics/src/graphics/MaterialTextures.slh @@ -208,7 +208,7 @@ float fetchScatteringMap(vec2 uv) { <@if occlusion@> float <$occlusion$> = (((<$matKey$> & OCCLUSION_MAP_BIT) != 0) ? fetchOcclusionMap(<$texcoord1$>) : 1.0); <@endif@> -<@if lightmapVal@> +<@if lightmap@> vec3 <$lightmap$> = fetchLightmapMap(<$texcoord1$>); <@endif@> <@endfunc@> diff --git a/libraries/render-utils/src/model_lightmap.slf b/libraries/render-utils/src/model_lightmap.slf index ada49fdd08..1be247e3e9 100644 --- a/libraries/render-utils/src/model_lightmap.slf +++ b/libraries/render-utils/src/model_lightmap.slf @@ -42,7 +42,7 @@ void main(void) { packDeferredFragmentLightmap( normalize(_normalWS), - evalOpaqueFinalAlpha(getMaterialOpacity(mat), albedo.a), + evalOpaqueFinalAlpha(getMaterialOpacity(mat), albedoTex.a), albedo, roughness, metallic, diff --git a/libraries/render-utils/src/model_lightmap_fade.slf b/libraries/render-utils/src/model_lightmap_fade.slf index 3819c4d4fa..61568463a7 100644 --- a/libraries/render-utils/src/model_lightmap_fade.slf +++ b/libraries/render-utils/src/model_lightmap_fade.slf @@ -51,7 +51,7 @@ void main(void) { packDeferredFragmentLightmap( normalize(_normalWS), - evalOpaqueFinalAlpha(getMaterialOpacity(mat), albedo.a), + evalOpaqueFinalAlpha(getMaterialOpacity(mat), albedoTex.a), albedo, roughness, metallic, diff --git a/libraries/render-utils/src/model_lightmap_normal_map.slf b/libraries/render-utils/src/model_lightmap_normal_map.slf index adeff463b5..3d961584c2 100644 --- a/libraries/render-utils/src/model_lightmap_normal_map.slf +++ b/libraries/render-utils/src/model_lightmap_normal_map.slf @@ -47,7 +47,7 @@ void main(void) { packDeferredFragmentLightmap( normalize(fragNormal), - evalOpaqueFinalAlpha(getMaterialOpacity(mat), albedo.a), + evalOpaqueFinalAlpha(getMaterialOpacity(mat), albedoTex.a), albedo, roughness, metallic, diff --git a/libraries/render-utils/src/model_lightmap_normal_map_fade.slf b/libraries/render-utils/src/model_lightmap_normal_map_fade.slf index c46308fcf3..f873847474 100644 --- a/libraries/render-utils/src/model_lightmap_normal_map_fade.slf +++ b/libraries/render-utils/src/model_lightmap_normal_map_fade.slf @@ -56,7 +56,7 @@ void main(void) { packDeferredFragmentLightmap( normalize(fragNormal), - evalOpaqueFinalAlpha(getMaterialOpacity(mat), albedo.a), + evalOpaqueFinalAlpha(getMaterialOpacity(mat), albedoTex.a), albedo, roughness, metallic, From 09ea32dcc0e11ed7b7ec2fa4c5cfe1bd3c08cf14 Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Mon, 22 Oct 2018 14:10:50 -0700 Subject: [PATCH 4/7] fix fading and highlighting issues --- interface/src/avatar/AvatarManager.cpp | 14 +-- interface/src/avatar/AvatarManager.h | 2 +- interface/src/avatar/MyAvatar.cpp | 2 + .../src/avatars-renderer/Avatar.cpp | 9 +- .../src/avatars-renderer/Avatar.h | 2 +- libraries/render-utils/src/Fade.slh | 9 +- libraries/render-utils/src/GeometryCache.cpp | 2 +- .../render-utils/src/HighlightEffect.cpp | 81 +++++++++++------- .../render-utils/src/RenderPipelines.cpp | 30 +++---- .../render-utils/src/RenderShadowTask.cpp | 85 ++++++++++--------- 10 files changed, 127 insertions(+), 109 deletions(-) diff --git a/interface/src/avatar/AvatarManager.cpp b/interface/src/avatar/AvatarManager.cpp index c9b3449cec..4abd561dc5 100644 --- a/interface/src/avatar/AvatarManager.cpp +++ b/interface/src/avatar/AvatarManager.cpp @@ -188,7 +188,7 @@ void AvatarManager::updateOtherAvatars(float deltaTime) { { // lock the hash for read to check the size QReadLocker lock(&_hashLock); - if (_avatarHash.size() < 2 && _avatarsToFade.isEmpty()) { + if (_avatarHash.size() < 2 && _avatarsToFadeOut.isEmpty()) { return; } } @@ -346,23 +346,23 @@ void AvatarManager::sendIdentityRequest(const QUuid& avatarID) const { } void AvatarManager::simulateAvatarFades(float deltaTime) { - if (_avatarsToFade.empty()) { + if (_avatarsToFadeOut.empty()) { return; } QReadLocker locker(&_hashLock); - QVector::iterator avatarItr = _avatarsToFade.begin(); + QVector::iterator avatarItr = _avatarsToFadeOut.begin(); const render::ScenePointer& scene = qApp->getMain3DScene(); render::Transaction transaction; - while (avatarItr != _avatarsToFade.end()) { + while (avatarItr != _avatarsToFadeOut.end()) { auto avatar = std::static_pointer_cast(*avatarItr); - avatar->updateFadingStatus(scene); + avatar->updateFadingStatus(); if (!avatar->isFading()) { // fading to zero is such a rare event we push a unique transaction for each if (avatar->isInScene()) { avatar->removeFromScene(*avatarItr, scene, transaction); } - avatarItr = _avatarsToFade.erase(avatarItr); + avatarItr = _avatarsToFadeOut.erase(avatarItr); } else { ++avatarItr; } @@ -457,7 +457,7 @@ void AvatarManager::handleRemovedAvatar(const AvatarSharedPointer& removedAvatar DependencyManager::get()->avatarDisconnected(avatar->getSessionUUID()); avatar->fadeOut(qApp->getMain3DScene(), removalReason); } - _avatarsToFade.push_back(removedAvatar); + _avatarsToFadeOut.push_back(removedAvatar); } void AvatarManager::clearOtherAvatars() { diff --git a/interface/src/avatar/AvatarManager.h b/interface/src/avatar/AvatarManager.h index 34aa4f2cc0..9d5b02d748 100644 --- a/interface/src/avatar/AvatarManager.h +++ b/interface/src/avatar/AvatarManager.h @@ -222,7 +222,7 @@ private: void handleRemovedAvatar(const AvatarSharedPointer& removedAvatar, KillAvatarReason removalReason = KillAvatarReason::NoReason) override; - QVector _avatarsToFade; + QVector _avatarsToFadeOut; using SetOfOtherAvatars = std::set; SetOfOtherAvatars _avatarsToChangeInPhysics; diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index a7c8c3e179..38df7b9b06 100755 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -857,6 +857,8 @@ void MyAvatar::simulate(float deltaTime) { } updateAvatarEntities(); + + updateFadingStatus(); } // As far as I know no HMD system supports a play area of a kilometer in radius. diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp index 6770cd7f96..c6e6a5e8ca 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp @@ -612,6 +612,8 @@ void Avatar::simulate(float deltaTime, bool inView) { PROFILE_RANGE(simulation, "entities"); updateAvatarEntities(); } + + updateFadingStatus(); } float Avatar::getSimulationRate(const QString& rateName) const { @@ -775,14 +777,15 @@ void Avatar::fade(render::Transaction& transaction, render::Transition::Type typ _isFading = true; } -void Avatar::updateFadingStatus(render::ScenePointer scene) { +void Avatar::updateFadingStatus() { render::Transaction transaction; transaction.queryTransitionOnItem(_renderItemID, [this](render::ItemID id, const render::Transition* transition) { - if (transition == nullptr || transition->isFinished) { + if (!transition || transition->isFinished) { + AbstractViewStateInterface::instance()->getMain3DScene()->resetItemTransition(id); _isFading = false; } }); - scene->enqueueTransaction(transaction); + AbstractViewStateInterface::instance()->getMain3DScene()->enqueueTransaction(transaction); } void Avatar::removeFromScene(AvatarSharedPointer self, const render::ScenePointer& scene, render::Transaction& transaction) { diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.h b/libraries/avatars-renderer/src/avatars-renderer/Avatar.h index 3f4cf7b8c2..014be23fa5 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.h +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.h @@ -402,7 +402,7 @@ public: void fadeIn(render::ScenePointer scene); void fadeOut(render::ScenePointer scene, KillAvatarReason reason); bool isFading() const { return _isFading; } - void updateFadingStatus(render::ScenePointer scene); + void updateFadingStatus(); // JSDoc is in AvatarData.h. Q_INVOKABLE virtual float getEyeHeight() const override; diff --git a/libraries/render-utils/src/Fade.slh b/libraries/render-utils/src/Fade.slh index 47347ba135..940aabe2bd 100644 --- a/libraries/render-utils/src/Fade.slh +++ b/libraries/render-utils/src/Fade.slh @@ -85,7 +85,11 @@ float evalFadeGradient(FadeObjectParams params, vec3 position) { } float evalFadeAlpha(FadeObjectParams params, vec3 position) { - return evalFadeGradient(params, position)-params.threshold; + float alpha = evalFadeGradient(params, position)-params.threshold; + if (fadeParameters[params.category]._isInverted != 0) { + alpha = -alpha; + } + return alpha; } void applyFadeClip(FadeObjectParams params, vec3 position) { @@ -96,9 +100,6 @@ void applyFadeClip(FadeObjectParams params, vec3 position) { void applyFade(FadeObjectParams params, vec3 position, out vec3 emissive) { float alpha = evalFadeAlpha(params, position); - if (fadeParameters[params.category]._isInverted!=0) { - alpha = -alpha; - } if (alpha < 0.0) { discard; diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 1215c9abea..38c3106af6 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -826,7 +826,7 @@ render::ShapePipelinePointer GeometryCache::getFadingShapePipeline(bool textured bool unlit, bool depthBias) { auto fadeEffect = DependencyManager::get(); auto fadeBatchSetter = fadeEffect->getBatchSetter(); - auto fadeItemSetter = fadeEffect->getItemStoredSetter(); + auto fadeItemSetter = fadeEffect->getItemUniformSetter(); return std::make_shared(getSimplePipeline(textured, transparent, culled, unlit, depthBias, true), nullptr, [fadeBatchSetter, fadeItemSetter](const render::ShapePipeline& shapePipeline, gpu::Batch& batch, render::Args* args) { batch.setResourceTexture(gr::Texture::MaterialAlbedo, DependencyManager::get()->getWhiteTexture()); diff --git a/libraries/render-utils/src/HighlightEffect.cpp b/libraries/render-utils/src/HighlightEffect.cpp index 2d4aee7880..176480e35c 100644 --- a/libraries/render-utils/src/HighlightEffect.cpp +++ b/libraries/render-utils/src/HighlightEffect.cpp @@ -22,6 +22,8 @@ #include "GeometryCache.h" #include "CubeProjectedPolygon.h" +#include "FadeEffect.h" + #include "render-utils/ShaderConstants.h" using namespace render; @@ -37,7 +39,7 @@ namespace gr { #define OUTLINE_STENCIL_MASK 1 -extern void initZPassPipelines(ShapePlumber& plumber, gpu::StatePointer state); +extern void initZPassPipelines(ShapePlumber& plumber, gpu::StatePointer state, const render::ShapePipeline::BatchSetter& batchSetter, const render::ShapePipeline::ItemSetter& itemSetter); HighlightResources::HighlightResources() { } @@ -156,7 +158,6 @@ void DrawHighlightMask::run(const render::RenderContextPointer& renderContext, c auto& highlight = highlightStage->getHighlight(highlightId); RenderArgs* args = renderContext->args; - ShapeKey::Builder defaultKeyBuilder; // Render full screen outputs = args->_viewport; @@ -177,10 +178,6 @@ void DrawHighlightMask::run(const render::RenderContextPointer& renderContext, c gpu::doInBatch("DrawHighlightMask::run", args->_context, [&](gpu::Batch& batch) { args->_batch = &batch; - auto maskPipeline = _shapePlumber->pickPipeline(args, defaultKeyBuilder); - auto maskDeformedPipeline = _shapePlumber->pickPipeline(args, defaultKeyBuilder.withDeformed()); - auto maskDeformedDQPipeline = _shapePlumber->pickPipeline(args, defaultKeyBuilder.withDeformed().withDualQuatSkinned()); - // Setup camera, projection and viewport for all items glm::mat4 projMat; Transform viewMat; @@ -191,38 +188,54 @@ void DrawHighlightMask::run(const render::RenderContextPointer& renderContext, c batch.setProjectionJitter(jitter.x, jitter.y); batch.setViewTransform(viewMat); - std::vector deformedShapeKeys; - std::vector deformedDQShapeKeys; + const std::vector keys = { + ShapeKey::Builder(), ShapeKey::Builder().withFade(), + ShapeKey::Builder().withDeformed(), ShapeKey::Builder().withDeformed().withFade(), + ShapeKey::Builder().withDeformed().withDualQuatSkinned(), ShapeKey::Builder().withDeformed().withDualQuatSkinned().withFade(), + ShapeKey::Builder().withOwnPipeline(), ShapeKey::Builder().withOwnPipeline().withFade() + }; + std::vector> sortedShapeKeys(keys.size()); - // Iterate through all inShapes and render the unskinned - args->_shapePipeline = maskPipeline; - batch.setPipeline(maskPipeline->pipeline); + const int OWN_PIPELINE_INDEX = 6; for (const auto& items : inShapes) { itemBounds.insert(itemBounds.end(), items.second.begin(), items.second.end()); - if (items.first.isDeformed() && items.first.isDualQuatSkinned()) { - deformedDQShapeKeys.push_back(items.first); - } else if (items.first.isDeformed()) { - deformedShapeKeys.push_back(items.first); - } else { - renderItems(renderContext, items.second); + + int index = items.first.hasOwnPipeline() ? OWN_PIPELINE_INDEX : 0; + if (items.first.isDeformed()) { + index += 2; + if (items.first.isDualQuatSkinned()) { + index += 2; + } + } + + if (items.first.isFaded()) { + index += 1; + } + + sortedShapeKeys[index].push_back(items.first); + } + + // Render non-withOwnPipeline things + for (size_t i = 0; i < OWN_PIPELINE_INDEX; i++) { + auto& shapeKeys = sortedShapeKeys[i]; + if (shapeKeys.size() > 0) { + const auto& shapePipeline = _shapePlumber->pickPipeline(args, keys[i]); + args->_shapePipeline = shapePipeline; + for (const auto& key : shapeKeys) { + renderShapes(renderContext, _shapePlumber, inShapes.at(key)); + } } } - // Reiterate to render the skinned - if (deformedShapeKeys.size() > 0) { - args->_shapePipeline = maskDeformedPipeline; - batch.setPipeline(maskDeformedPipeline->pipeline); - for (const auto& key : deformedShapeKeys) { - renderItems(renderContext, inShapes.at(key)); - } - } - - // Reiterate to render the DQ skinned - if (deformedDQShapeKeys.size() > 0) { - args->_shapePipeline = maskDeformedDQPipeline; - batch.setPipeline(maskDeformedDQPipeline->pipeline); - for (const auto& key : deformedDQShapeKeys) { - renderItems(renderContext, inShapes.at(key)); + // Render withOwnPipeline things + for (size_t i = OWN_PIPELINE_INDEX; i < keys.size(); i++) { + auto& shapeKeys = sortedShapeKeys[i]; + if (shapeKeys.size() > 0) { + args->_shapePipeline = nullptr; + for (const auto& key : shapeKeys) { + args->_itemShapeKey = key._flags.to_ulong(); + renderShapes(renderContext, _shapePlumber, inShapes.at(key)); + } } } @@ -502,7 +515,9 @@ void DrawHighlightTask::build(JobModel& task, const render::Varying& inputs, ren state->setDepthTest(true, true, gpu::LESS_EQUAL); state->setColorWriteMask(false, false, false, false); - initZPassPipelines(*shapePlumber, state); + + auto fadeEffect = DependencyManager::get(); + initZPassPipelines(*shapePlumber, state, fadeEffect->getBatchSetter(), fadeEffect->getItemUniformSetter()); } auto sharedParameters = std::make_shared(); diff --git a/libraries/render-utils/src/RenderPipelines.cpp b/libraries/render-utils/src/RenderPipelines.cpp index 4626264756..98596a3d88 100644 --- a/libraries/render-utils/src/RenderPipelines.cpp +++ b/libraries/render-utils/src/RenderPipelines.cpp @@ -40,7 +40,7 @@ namespace gr { void initDeferredPipelines(ShapePlumber& plumber, const render::ShapePipeline::BatchSetter& batchSetter, const render::ShapePipeline::ItemSetter& itemSetter); void initForwardPipelines(ShapePlumber& plumber); -void initZPassPipelines(ShapePlumber& plumber, gpu::StatePointer state); +void initZPassPipelines(ShapePlumber& plumber, gpu::StatePointer state, const render::ShapePipeline::BatchSetter& batchSetter, const render::ShapePipeline::ItemSetter& itemSetter); void addPlumberPipeline(ShapePlumber& plumber, const ShapeKey& key, int programId, @@ -364,37 +364,29 @@ void lightBatchSetter(const ShapePipeline& pipeline, gpu::Batch& batch, RenderAr } } -void initZPassPipelines(ShapePlumber& shapePlumber, gpu::StatePointer state) { +void initZPassPipelines(ShapePlumber& shapePlumber, gpu::StatePointer state, const render::ShapePipeline::BatchSetter& extraBatchSetter, const render::ShapePipeline::ItemSetter& itemSetter) { using namespace shader::render_utils::program; - gpu::ShaderPointer modelProgram = gpu::Shader::createProgram(model_shadow); + shapePlumber.addPipeline( ShapeKey::Filter::Builder().withoutDeformed().withoutFade(), - modelProgram, state); - - gpu::ShaderPointer skinProgram = gpu::Shader::createProgram(deformed_model_shadow); - shapePlumber.addPipeline( - ShapeKey::Filter::Builder().withDeformed().withoutDualQuatSkinned().withoutFade(), - skinProgram, state); - - gpu::ShaderPointer modelFadeProgram = gpu::Shader::createProgram(model_shadow_fade); + gpu::Shader::createProgram(model_shadow), state); shapePlumber.addPipeline( ShapeKey::Filter::Builder().withoutDeformed().withFade(), - modelFadeProgram, state); + gpu::Shader::createProgram(model_shadow_fade), state, extraBatchSetter, itemSetter); - gpu::ShaderPointer skinFadeProgram = gpu::Shader::createProgram(deformed_model_shadow_fade); + shapePlumber.addPipeline( + ShapeKey::Filter::Builder().withDeformed().withoutDualQuatSkinned().withoutFade(), + gpu::Shader::createProgram(deformed_model_shadow), state); shapePlumber.addPipeline( ShapeKey::Filter::Builder().withDeformed().withoutDualQuatSkinned().withFade(), - skinFadeProgram, state); + gpu::Shader::createProgram(deformed_model_shadow_fade), state, extraBatchSetter, itemSetter); - gpu::ShaderPointer skinModelShadowDualQuatProgram = gpu::Shader::createProgram(deformed_model_shadow_dq); shapePlumber.addPipeline( ShapeKey::Filter::Builder().withDeformed().withDualQuatSkinned().withoutFade(), - skinModelShadowDualQuatProgram, state); - - gpu::ShaderPointer skinModelShadowFadeDualQuatProgram = gpu::Shader::createProgram(deformed_model_shadow_fade_dq); + gpu::Shader::createProgram(deformed_model_shadow_dq), state); shapePlumber.addPipeline( ShapeKey::Filter::Builder().withDeformed().withDualQuatSkinned().withFade(), - skinModelShadowFadeDualQuatProgram, state); + gpu::Shader::createProgram(deformed_model_shadow_fade_dq), state, extraBatchSetter, itemSetter); } // FIXME find a better way to setup the default textures diff --git a/libraries/render-utils/src/RenderShadowTask.cpp b/libraries/render-utils/src/RenderShadowTask.cpp index c4fa297965..0b6aebadd7 100644 --- a/libraries/render-utils/src/RenderShadowTask.cpp +++ b/libraries/render-utils/src/RenderShadowTask.cpp @@ -26,6 +26,8 @@ #include "RenderCommonTask.h" +#include "FadeEffect.h" + // These values are used for culling the objects rendered in the shadow map // but are readjusted afterwards #define SHADOW_FRUSTUM_NEAR 1.0f @@ -33,7 +35,7 @@ using namespace render; -extern void initZPassPipelines(ShapePlumber& plumber, gpu::StatePointer state); +extern void initZPassPipelines(ShapePlumber& plumber, gpu::StatePointer state, const render::ShapePipeline::BatchSetter& batchSetter, const render::ShapePipeline::ItemSetter& itemSetter); void RenderShadowTask::configure(const Config& configuration) { DependencyManager::get()->setShadowMapEnabled(configuration.enabled); @@ -49,7 +51,8 @@ void RenderShadowTask::build(JobModel& task, const render::Varying& input, rende state->setCullMode(gpu::State::CULL_BACK); state->setDepthTest(true, true, gpu::LESS_EQUAL); - initZPassPipelines(*shapePlumber, state); + auto fadeEffect = DependencyManager::get(); + initZPassPipelines(*shapePlumber, state, fadeEffect->getBatchSetter(), fadeEffect->getItemUniformSetter()); } // FIXME: calling this here before the zones/lights are drawn during the deferred/forward passes means we're actually using the frames from the previous draw @@ -222,7 +225,6 @@ void RenderShadowMap::run(const render::RenderContextPointer& renderContext, con auto& fbo = cascade.framebuffer; RenderArgs* args = renderContext->args; - ShapeKey::Builder defaultKeyBuilder; auto adjustedShadowFrustum = args->getViewFrustum(); // Adjust the frustum near and far depths based on the rendered items bounding box to have @@ -253,53 +255,56 @@ void RenderShadowMap::run(const render::RenderContextPointer& renderContext, con batch.setProjectionTransform(projMat); batch.setViewTransform(viewMat, false); - auto shadowPipeline = _shapePlumber->pickPipeline(args, defaultKeyBuilder); - auto shadowDeformedPipeline = _shapePlumber->pickPipeline(args, defaultKeyBuilder.withDeformed()); - auto shadowDeformedDQPipeline = _shapePlumber->pickPipeline(args, defaultKeyBuilder.withDeformed().withDualQuatSkinned()); + const std::vector keys = { + ShapeKey::Builder(), ShapeKey::Builder().withFade(), + ShapeKey::Builder().withDeformed(), ShapeKey::Builder().withDeformed().withFade(), + ShapeKey::Builder().withDeformed().withDualQuatSkinned(), ShapeKey::Builder().withDeformed().withDualQuatSkinned().withFade(), + ShapeKey::Builder().withOwnPipeline(), ShapeKey::Builder().withOwnPipeline().withFade() + }; + std::vector> sortedShapeKeys(keys.size()); - std::vector deformedShapeKeys{}; - std::vector deformedDQShapeKeys{}; - std::vector ownPipelineShapeKeys{}; - - // Iterate through all inShapes and render the unskinned - args->_shapePipeline = shadowPipeline; - batch.setPipeline(shadowPipeline->pipeline); - for (auto items : inShapes) { + const int OWN_PIPELINE_INDEX = 6; + for (const auto& items : inShapes) { + int index = items.first.hasOwnPipeline() ? OWN_PIPELINE_INDEX : 0; if (items.first.isDeformed()) { + index += 2; if (items.first.isDualQuatSkinned()) { - deformedDQShapeKeys.push_back(items.first); - } else { - deformedShapeKeys.push_back(items.first); + index += 2; + } + } + + if (items.first.isFaded()) { + index += 1; + } + + sortedShapeKeys[index].push_back(items.first); + } + + // Render non-withOwnPipeline things + for (size_t i = 0; i < OWN_PIPELINE_INDEX; i++) { + auto& shapeKeys = sortedShapeKeys[i]; + if (shapeKeys.size() > 0) { + const auto& shapePipeline = _shapePlumber->pickPipeline(args, keys[i]); + args->_shapePipeline = shapePipeline; + for (const auto& key : shapeKeys) { + renderShapes(renderContext, _shapePlumber, inShapes.at(key)); } - } else if (!items.first.hasOwnPipeline()) { - renderItems(renderContext, items.second); - } else { - ownPipelineShapeKeys.push_back(items.first); } } - // Reiterate to render the skinned - args->_shapePipeline = shadowDeformedPipeline; - batch.setPipeline(shadowDeformedPipeline->pipeline); - for (const auto& key : deformedShapeKeys) { - renderItems(renderContext, inShapes.at(key)); + // Render withOwnPipeline things + for (size_t i = OWN_PIPELINE_INDEX; i < keys.size(); i++) { + auto& shapeKeys = sortedShapeKeys[i]; + if (shapeKeys.size() > 0) { + args->_shapePipeline = nullptr; + for (const auto& key : shapeKeys) { + args->_itemShapeKey = key._flags.to_ulong(); + renderShapes(renderContext, _shapePlumber, inShapes.at(key)); + } + } } - // Reiterate to render the DQ skinned - args->_shapePipeline = shadowDeformedDQPipeline; - batch.setPipeline(shadowDeformedDQPipeline->pipeline); - for (const auto& key : deformedDQShapeKeys) { - renderItems(renderContext, inShapes.at(key)); - } - - // Finally render the items with their own pipeline last to prevent them from breaking the - // render state. This is probably a temporary code as there is probably something better - // to do in the render call of objects that have their own pipeline. args->_shapePipeline = nullptr; - for (const auto& key : ownPipelineShapeKeys) { - args->_itemShapeKey = key._flags.to_ulong(); - renderItems(renderContext, inShapes.at(key)); - } } args->_batch = nullptr; From 6572400d068f67552f7bc83debcc2faaed3b53e7 Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Mon, 22 Oct 2018 15:03:09 -0700 Subject: [PATCH 5/7] fix highlight debug script --- .../utilities/render/debugHighlight.js | 55 +++++++++++++------ 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/scripts/developer/utilities/render/debugHighlight.js b/scripts/developer/utilities/render/debugHighlight.js index 664af836a9..3b171aaaa7 100644 --- a/scripts/developer/utilities/render/debugHighlight.js +++ b/scripts/developer/utilities/render/debugHighlight.js @@ -86,22 +86,23 @@ type: "sphere", dimensions: END_DIMENSIONS, color: COLOR1, - ignoreRayIntersection: true + ignorePickIntersection: true } var end2 = { type: "sphere", dimensions: END_DIMENSIONS, color: COLOR2, - ignoreRayIntersection: true + ignorePickIntersection: true } var laser = Pointers.createPointer(PickType.Ray, { joint: "Mouse", - filter: Picks.PICK_ENTITIES, + filter: Picks.PICK_ENTITIES | Picks.PICK_OVERLAYS | Picks.PICK_AVATARS, renderStates: [{name: "one", end: end1}], defaultRenderStates: [{name: "one", end: end2, distance: 2.0}], enabled: true }); Pointers.setRenderState(laser, "one"); + var hoveredObject = undefined; var HoveringList = "Hovering" var hoveringStyle = { @@ -140,21 +141,41 @@ time = 0 } } - - Entities.hoverEnterEntity.connect(function (id, event) { - // print("hoverEnterEntity"); - if (isSelectionEnabled) Selection.addToSelectedItemsList(HoveringList, "entity", id) - }) - - Entities.hoverOverEntity.connect(function (id, event) { - // print("hoverOverEntity"); - }) - - Entities.hoverLeaveEntity.connect(function (id, event) { - if (isSelectionEnabled) Selection.removeFromSelectedItemsList(HoveringList, "entity", id) - // print("hoverLeaveEntity"); - }) + function getIntersectionTypeString(type) { + if (type === Picks.INTERSECTED_ENTITY) { + return "entity"; + } else if (type === Picks.INTERSECTED_OVERLAY) { + return "overlay"; + } else if (type === Picks.INTERSECTED_AVATAR) { + return "avatar"; + } + } + + function update() { + var result = Pointers.getPrevPickResult(laser); + if (result.intersects) { + // Hovering on something different + if (hoveredObject !== undefined && result.objectID !== hoveredObject.objectID) { + if (isSelectionEnabled) { + Selection.removeFromSelectedItemsList(HoveringList, getIntersectionTypeString(hoveredObject.type), hoveredObject.objectID) + } + } + + // Hovering over something new + if (isSelectionEnabled) { + Selection.addToSelectedItemsList(HoveringList, getIntersectionTypeString(result.type), result.objectID); + hoveredObject = result; + } + } else if (hoveredObject !== undefined) { + // Stopped hovering + if (isSelectionEnabled) { + Selection.removeFromSelectedItemsList(HoveringList, getIntersectionTypeString(hoveredObject.type), hoveredObject.objectID) + hoveredObject = undefined; + } + } + } + Script.update.connect(update); function cleanup() { Pointers.removePointer(laser); From d254db02dcac0bf70817bc31a40574217ae3f07d Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Tue, 23 Oct 2018 11:17:50 -0700 Subject: [PATCH 6/7] small cleanup --- libraries/graphics/src/graphics/Material.slh | 2 +- .../graphics/src/graphics/ShaderConstants.h | 2 -- .../render-utils/src/DeferredBufferWrite.slh | 1 - .../render-utils/src/RenderPipelines.cpp | 25 ------------------- .../render-utils/src/deformed_model_dq.slv | 1 - libraries/render/src/render/ShapePipeline.cpp | 1 - libraries/render/src/render/ShapePipeline.h | 8 ------ 7 files changed, 1 insertion(+), 39 deletions(-) diff --git a/libraries/graphics/src/graphics/Material.slh b/libraries/graphics/src/graphics/Material.slh index 2e71e97e06..412e967180 100644 --- a/libraries/graphics/src/graphics/Material.slh +++ b/libraries/graphics/src/graphics/Material.slh @@ -48,7 +48,7 @@ struct Material { vec4 _keySpare3; }; -layout(binding=GRAPHICS_BUFFER_MATERIAL) uniform materialBuffer { +layout(std140, binding=GRAPHICS_BUFFER_MATERIAL) uniform materialBuffer { Material _mat; TexMapArray _texMapArray; }; diff --git a/libraries/graphics/src/graphics/ShaderConstants.h b/libraries/graphics/src/graphics/ShaderConstants.h index c902185d4f..0aff0a7077 100644 --- a/libraries/graphics/src/graphics/ShaderConstants.h +++ b/libraries/graphics/src/graphics/ShaderConstants.h @@ -16,7 +16,6 @@ #define GRAPHICS_BUFFER_SKINNING 0 #define GRAPHICS_BUFFER_MATERIAL 1 -#define GRAPHICS_BUFFER_TEXMAPARRAY 2 #define GRAPHICS_BUFFER_KEY_LIGHT 4 #define GRAPHICS_BUFFER_LIGHT 5 #define GRAPHICS_BUFFER_AMBIENT_LIGHT 6 @@ -41,7 +40,6 @@ namespace buffer { enum Buffer { Skinning = GRAPHICS_BUFFER_SKINNING, Material = GRAPHICS_BUFFER_MATERIAL, - TexMapArray = GRAPHICS_BUFFER_TEXMAPARRAY, Light = GRAPHICS_BUFFER_LIGHT, KeyLight = GRAPHICS_BUFFER_KEY_LIGHT, AmbientLight = GRAPHICS_BUFFER_AMBIENT_LIGHT, diff --git a/libraries/render-utils/src/DeferredBufferWrite.slh b/libraries/render-utils/src/DeferredBufferWrite.slh index 04a65477b2..9602bc4bf4 100644 --- a/libraries/render-utils/src/DeferredBufferWrite.slh +++ b/libraries/render-utils/src/DeferredBufferWrite.slh @@ -21,7 +21,6 @@ layout(location=3) out vec4 _fragColor3; // emissive // the alpha threshold const float alphaThreshold = 0.5; -// FIXME: is this correct? float evalOpaqueFinalAlpha(float alpha, float mapAlpha) { return mix(alpha, 1.0 - alpha, step(mapAlpha, alphaThreshold)); } diff --git a/libraries/render-utils/src/RenderPipelines.cpp b/libraries/render-utils/src/RenderPipelines.cpp index 98596a3d88..2880c06d1c 100644 --- a/libraries/render-utils/src/RenderPipelines.cpp +++ b/libraries/render-utils/src/RenderPipelines.cpp @@ -201,31 +201,6 @@ void initDeferredPipelines(render::ShapePlumber& plumber, const render::ShapePip addPipeline( Key::Builder().withMaterial().withDeformed().withDualQuatSkinned().withTranslucent().withTangents().withFade(), deformed_model_normal_map_translucent_fade_dq, batchSetter, itemSetter); - - // Depth-only - addPipeline( - Key::Builder().withDepthOnly(), - model_shadow, nullptr, nullptr); - addPipeline( - Key::Builder().withDeformed().withDepthOnly(), - deformed_model_shadow, nullptr, nullptr); - // Same thing but with Fade on - addPipeline( - Key::Builder().withDepthOnly().withFade(), - model_shadow_fade, batchSetter, itemSetter); - addPipeline( - Key::Builder().withDeformed().withDepthOnly().withFade(), - deformed_model_shadow_fade, batchSetter, itemSetter); - - // Now repeat for dual quaternion - // Depth-only - addPipeline( - Key::Builder().withDeformed().withDualQuatSkinned().withDepthOnly(), - deformed_model_shadow_dq, nullptr, nullptr); - // Same thing but with Fade on - addPipeline( - Key::Builder().withDeformed().withDualQuatSkinned().withDepthOnly().withFade(), - deformed_model_shadow_fade_dq, batchSetter, itemSetter); } void initForwardPipelines(ShapePlumber& plumber) { diff --git a/libraries/render-utils/src/deformed_model_dq.slv b/libraries/render-utils/src/deformed_model_dq.slv index c6540c90b1..2165f3b9a4 100644 --- a/libraries/render-utils/src/deformed_model_dq.slv +++ b/libraries/render-utils/src/deformed_model_dq.slv @@ -31,7 +31,6 @@ layout(location=RENDER_UTILS_ATTR_NORMAL_WS) out vec3 _normalWS; layout(location=RENDER_UTILS_ATTR_COLOR) out vec4 _color; void main(void) { - vec4 deformedPosition = vec4(0.0, 0.0, 0.0, 0.0); vec3 deformedNormal = vec3(0.0, 0.0, 0.0); evalMeshDeformer(inPosition, deformedPosition, inNormal.xyz, deformedNormal, diff --git a/libraries/render/src/render/ShapePipeline.cpp b/libraries/render/src/render/ShapePipeline.cpp index 2b2accde37..e7c88b3923 100644 --- a/libraries/render/src/render/ShapePipeline.cpp +++ b/libraries/render/src/render/ShapePipeline.cpp @@ -96,7 +96,6 @@ void ShapePlumber::addPipeline(const Filter& filter, const gpu::ShaderPointer& p locations->lightingModelBufferUnit = program->getUniformBuffers().isValid(render_utils::slot::buffer::LightModel); locations->skinClusterBufferUnit = program->getUniformBuffers().isValid(graphics::slot::buffer::Skinning); locations->materialBufferUnit = program->getUniformBuffers().isValid(graphics::slot::buffer::Material); - locations->texMapArrayBufferUnit = program->getUniformBuffers().isValid(graphics::slot::buffer::TexMapArray); locations->keyLightBufferUnit = program->getUniformBuffers().isValid(graphics::slot::buffer::KeyLight); locations->lightBufferUnit = program->getUniformBuffers().isValid(graphics::slot::buffer::Light); locations->lightAmbientBufferUnit = program->getUniformBuffers().isValid(graphics::slot::buffer::AmbientLight); diff --git a/libraries/render/src/render/ShapePipeline.h b/libraries/render/src/render/ShapePipeline.h index bd6ac6521a..715b467e49 100644 --- a/libraries/render/src/render/ShapePipeline.h +++ b/libraries/render/src/render/ShapePipeline.h @@ -32,7 +32,6 @@ public: UNLIT, DEFORMED, DUAL_QUAT_SKINNED, - DEPTH_ONLY, DEPTH_BIAS, WIREFRAME, NO_CULL_FACE, @@ -80,7 +79,6 @@ public: Builder& withUnlit() { _flags.set(UNLIT); return (*this); } Builder& withDeformed() { _flags.set(DEFORMED); return (*this); } Builder& withDualQuatSkinned() { _flags.set(DUAL_QUAT_SKINNED); return (*this); } - Builder& withDepthOnly() { _flags.set(DEPTH_ONLY); return (*this); } Builder& withDepthBias() { _flags.set(DEPTH_BIAS); return (*this); } Builder& withWireframe() { _flags.set(WIREFRAME); return (*this); } Builder& withoutCullFace() { _flags.set(NO_CULL_FACE); return (*this); } @@ -133,9 +131,6 @@ public: Builder& withDualQuatSkinned() { _flags.set(DUAL_QUAT_SKINNED); _mask.set(DUAL_QUAT_SKINNED); return (*this); } Builder& withoutDualQuatSkinned() { _flags.reset(DUAL_QUAT_SKINNED); _mask.set(DUAL_QUAT_SKINNED); return (*this); } - Builder& withDepthOnly() { _flags.set(DEPTH_ONLY); _mask.set(DEPTH_ONLY); return (*this); } - Builder& withoutDepthOnly() { _flags.reset(DEPTH_ONLY); _mask.set(DEPTH_ONLY); return (*this); } - Builder& withDepthBias() { _flags.set(DEPTH_BIAS); _mask.set(DEPTH_BIAS); return (*this); } Builder& withoutDepthBias() { _flags.reset(DEPTH_BIAS); _mask.set(DEPTH_BIAS); return (*this); } @@ -171,7 +166,6 @@ public: bool isTranslucent() const { return _flags[TRANSLUCENT]; } bool isDeformed() const { return _flags[DEFORMED]; } bool isDualQuatSkinned() const { return _flags[DUAL_QUAT_SKINNED]; } - bool isDepthOnly() const { return _flags[DEPTH_ONLY]; } bool isDepthBiased() const { return _flags[DEPTH_BIAS]; } bool isWireframe() const { return _flags[WIREFRAME]; } bool isCullFace() const { return !_flags[NO_CULL_FACE]; } @@ -211,7 +205,6 @@ inline QDebug operator<<(QDebug debug, const ShapeKey& key) { << "isTranslucent:" << key.isTranslucent() << "isDeformed:" << key.isDeformed() << "isDualQuatSkinned:" << key.isDualQuatSkinned() - << "isDepthOnly:" << key.isDepthOnly() << "isDepthBiased:" << key.isDepthBiased() << "isWireframe:" << key.isWireframe() << "isCullFace:" << key.isCullFace() @@ -239,7 +232,6 @@ public: bool lightingModelBufferUnit{ false }; bool skinClusterBufferUnit{ false }; bool materialBufferUnit{ false }; - bool texMapArrayBufferUnit{ false }; bool keyLightBufferUnit{ false }; bool lightBufferUnit{ false }; bool lightAmbientBufferUnit{ false }; From df1a84881197bba8fe9238c7edb80e06a87817ca Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Mon, 12 Nov 2018 12:58:40 -0800 Subject: [PATCH 7/7] fix fade out --- .../src/avatars-renderer/Avatar.cpp | 20 +++++++++---------- libraries/render/src/render/Scene.cpp | 10 ++++++---- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp index 23f3c36e68..712ff8c1a8 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp @@ -763,8 +763,7 @@ void Avatar::fadeOut(render::ScenePointer scene, KillAvatarReason reason) { if (reason == KillAvatarReason::YourAvatarEnteredTheirBubble) { transitionType = render::Transition::BUBBLE_ISECT_TRESPASSER; - } - else if (reason == KillAvatarReason::TheirAvatarEnteredYourBubble) { + } else if (reason == KillAvatarReason::TheirAvatarEnteredYourBubble) { transitionType = render::Transition::BUBBLE_ISECT_OWNER; } fade(transaction, transitionType); @@ -782,14 +781,15 @@ void Avatar::fade(render::Transaction& transaction, render::Transition::Type typ } void Avatar::updateFadingStatus() { - render::Transaction transaction; - transaction.queryTransitionOnItem(_renderItemID, [this](render::ItemID id, const render::Transition* transition) { - if (!transition || transition->isFinished) { - AbstractViewStateInterface::instance()->getMain3DScene()->resetItemTransition(id); - _isFading = false; - } - }); - AbstractViewStateInterface::instance()->getMain3DScene()->enqueueTransaction(transaction); + if (_isFading) { + render::Transaction transaction; + transaction.queryTransitionOnItem(_renderItemID, [this](render::ItemID id, const render::Transition* transition) { + if (!transition || transition->isFinished) { + _isFading = false; + } + }); + AbstractViewStateInterface::instance()->getMain3DScene()->enqueueTransaction(transaction); + } } void Avatar::removeFromScene(AvatarSharedPointer self, const render::ScenePointer& scene, render::Transaction& transaction) { diff --git a/libraries/render/src/render/Scene.cpp b/libraries/render/src/render/Scene.cpp index 0b4ee2f11a..8d12cfae25 100644 --- a/libraries/render/src/render/Scene.cpp +++ b/libraries/render/src/render/Scene.cpp @@ -391,15 +391,17 @@ void Scene::transitionItems(const Transaction::TransitionAdds& transactions) { // Remove pre-existing transition, if need be if (!TransitionStage::isIndexInvalid(transitionId)) { - transitionStage->removeTransition(transitionId); - transitionId = TransitionStage::INVALID_INDEX; + resetItemTransition(itemId); } + // Add a new one. if (transitionType != Transition::NONE) { transitionId = transitionStage->addTransition(itemId, transitionType, boundId); - } - setItemTransition(itemId, transitionId); + if (!TransitionStage::isIndexInvalid(transitionId)) { + setItemTransition(itemId, transitionId); + } + } } }