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); }