From 39a785297919ba58400ef97ba9870a3c216e77a4 Mon Sep 17 00:00:00 2001 From: samcake Date: Fri, 19 Feb 2016 18:43:07 -0800 Subject: [PATCH] MOving forward with PBR rendering, cleaning up the lighting shaders and the packi/unpack deferredBuffer shaders --- .../utilities/tools/render/framebuffer.qml | 16 ++++++- libraries/entities-renderer/src/polyvox.slf | 5 +- libraries/gpu/src/gpu/GLBackendShader.cpp | 5 +- .../src/model-networking/ModelCache.cpp | 13 +++++- libraries/model/src/model/Material.cpp | 2 +- libraries/model/src/model/Material.h | 39 ++++++++-------- .../render-utils/src/DebugDeferredBuffer.cpp | 46 ++++++++++++++++--- .../render-utils/src/DebugDeferredBuffer.h | 11 +++-- libraries/render-utils/src/DeferredBuffer.slh | 45 +++++++++++++----- .../render-utils/src/DeferredBufferWrite.slh | 17 ++++--- .../render-utils/src/DeferredGlobalLight.slh | 12 ++--- .../render-utils/src/DeferredLighting.slh | 16 ++++--- .../render-utils/src/MeshPartPayload.cpp | 16 ++++++- .../src/directional_ambient_light.slf | 3 +- .../src/directional_ambient_light_shadow.slf | 3 +- .../render-utils/src/directional_light.slf | 3 +- .../src/directional_light_shadow.slf | 3 +- .../src/directional_skybox_light.slf | 3 +- .../src/directional_skybox_light_shadow.slf | 3 +- libraries/render-utils/src/model.slf | 5 +- libraries/render-utils/src/model_emissive.slf | 3 +- libraries/render-utils/src/model_lightmap.slf | 3 +- .../src/model_lightmap_normal_map.slf | 3 +- .../model_lightmap_normal_specular_map.slf | 3 +- .../src/model_lightmap_specular_map.slf | 3 +- .../render-utils/src/model_normal_map.slf | 5 +- .../src/model_normal_specular_map.slf | 6 ++- .../render-utils/src/model_specular_map.slf | 6 ++- .../render-utils/src/model_translucent.slf | 6 ++- libraries/render-utils/src/overlay3D.slf | 10 ++-- .../src/overlay3D_translucent.slf | 10 ++-- libraries/render-utils/src/point_light.slf | 2 +- libraries/render-utils/src/sdf_text3D.slf | 20 ++++++-- libraries/render-utils/src/simple.slf | 4 +- .../render-utils/src/simple_textured.slf | 4 +- .../src/simple_textured_emisive.slf | 4 +- libraries/render-utils/src/spot_light.slf | 2 +- tests/gpu-test/src/unlit.slf | 2 +- 38 files changed, 248 insertions(+), 114 deletions(-) diff --git a/examples/utilities/tools/render/framebuffer.qml b/examples/utilities/tools/render/framebuffer.qml index 734c62ad19..20b8b384d8 100644 --- a/examples/utilities/tools/render/framebuffer.qml +++ b/examples/utilities/tools/render/framebuffer.qml @@ -26,8 +26,20 @@ Column { ExclusiveGroup { id: bufferGroup } Repeater { model: [ - "Off", "Diffuse", "Metallic", "Roughness", "Normal", "Depth", - "Lighting", "Shadow", "Pyramid Depth", "Ambient Occlusion", "Custom Shader" + "Off", + "Depth", + "Diffuse", + "Normal", + "Roughness", + "Metallic", + "Fresnel", + "Emissive", + "Lightmap", + "Lighting", + "Shadow", + "Pyramid Depth", + "Ambient Occlusion", + "Custom Shader" ] RadioButton { text: qsTr(modelData) diff --git a/libraries/entities-renderer/src/polyvox.slf b/libraries/entities-renderer/src/polyvox.slf index 2bdecbf9fe..38d9494a61 100644 --- a/libraries/entities-renderer/src/polyvox.slf +++ b/libraries/entities-renderer/src/polyvox.slf @@ -28,9 +28,6 @@ void main(void) { vec3 worldNormal = cross(dFdy(_worldPosition.xyz), dFdx(_worldPosition.xyz)); worldNormal = normalize(worldNormal); - vec3 specular = DEFAULT_SPECULAR; - float shininess = DEFAULT_SHININESS; - float inPositionX = (_worldPosition.x - 0.5) / voxelVolumeSize.x; float inPositionY = (_worldPosition.y - 0.5) / voxelVolumeSize.y; float inPositionZ = (_worldPosition.z - 0.5) / voxelVolumeSize.z; @@ -44,5 +41,5 @@ void main(void) { vec3 yzDiffuseScaled = yzDiffuse.rgb * abs(worldNormal.x); vec4 diffuse = vec4(xyDiffuseScaled + xzDiffuseScaled + yzDiffuseScaled, 1.0); - packDeferredFragment(_normal, 1.0, vec3(diffuse), specular, shininess); + packDeferredFragment(_normal, 1.0, vec3(diffuse), DEFAULT_ROUGHNESS, DEFAULT_METALLIC, DEFAULT_SPECULAR); } diff --git a/libraries/gpu/src/gpu/GLBackendShader.cpp b/libraries/gpu/src/gpu/GLBackendShader.cpp index 35ad7dbbd8..c27c5dd97d 100755 --- a/libraries/gpu/src/gpu/GLBackendShader.cpp +++ b/libraries/gpu/src/gpu/GLBackendShader.cpp @@ -162,8 +162,6 @@ GLBackend::GLShader* compileShader(const Shader& shader) { char* temp = new char[infoLength] ; glGetShaderInfoLog(glshader, infoLength, NULL, temp); - qCWarning(gpulogging) << "GLShader::compileShader - failed to compile the gl shader object:"; - qCWarning(gpulogging) << temp; /* filestream.open("debugshader.glsl.info.txt"); @@ -173,7 +171,10 @@ GLBackend::GLShader* compileShader(const Shader& shader) { } */ + qCWarning(gpulogging) << "GLShader::compileShader - failed to compile the gl shader object:"; qCWarning(gpulogging) << srcstr; + qCWarning(gpulogging) << "GLShader::compileShader - errors:"; + qCWarning(gpulogging) << temp; delete[] temp; glDeleteShader(glshader); diff --git a/libraries/model-networking/src/model-networking/ModelCache.cpp b/libraries/model-networking/src/model-networking/ModelCache.cpp index 3de21e5b0e..63cc113f5a 100644 --- a/libraries/model-networking/src/model-networking/ModelCache.cpp +++ b/libraries/model-networking/src/model-networking/ModelCache.cpp @@ -177,7 +177,7 @@ void NetworkGeometry::setTextureWithNameToURL(const QString& name, const QUrl& u auto glossMap = model::TextureMapPointer(new model::TextureMap()); glossMap->setTextureSource(material->specularTexture->_textureSource); - networkMaterial->setTextureMap(model::MaterialKey::GLOSS_MAP, glossMap); + networkMaterial->setTextureMap(model::MaterialKey::ROUGHNESS_MAP, glossMap); } else if (material->emissiveTextureName == name) { material->emissiveTexture = textureCache->getTexture(url); @@ -350,6 +350,15 @@ static NetworkMaterial* buildNetworkMaterial(const FBXMaterial& material, const material._material->setTextureMap(model::MaterialKey::METALLIC_MAP, specularMap); } + if (!material.metallicTexture.filename.isEmpty()) { + networkMaterial->specularTexture = textureCache->getTexture(textureBaseUrl.resolved(QUrl(material.metallicTexture.filename)), SPECULAR_TEXTURE, material.metallicTexture.content); + networkMaterial->specularTextureName = material.metallicTexture.name; + + auto metallicMap = model::TextureMapPointer(new model::TextureMap()); + metallicMap->setTextureSource(networkMaterial->specularTexture->_textureSource); + + material._material->setTextureMap(model::MaterialKey::METALLIC_MAP, metallicMap); + } if (!material.roughnessTexture.filename.isEmpty()) { networkMaterial->roughnessTexture = textureCache->getTexture(textureBaseUrl.resolved(QUrl(material.roughnessTexture.filename)), ROUGHNESS_TEXTURE, material.roughnessTexture.content); networkMaterial->roughnessTextureName = material.roughnessTexture.name; @@ -357,7 +366,7 @@ static NetworkMaterial* buildNetworkMaterial(const FBXMaterial& material, const auto roughnessMap = model::TextureMapPointer(new model::TextureMap()); roughnessMap->setTextureSource(networkMaterial->roughnessTexture->_textureSource); - material._material->setTextureMap(model::MaterialKey::GLOSS_MAP, roughnessMap); + material._material->setTextureMap(model::MaterialKey::ROUGHNESS_MAP, roughnessMap); } if (!material.emissiveTexture.filename.isEmpty()) { networkMaterial->emissiveTexture = textureCache->getTexture(textureBaseUrl.resolved(QUrl(material.emissiveTexture.filename)), EMISSIVE_TEXTURE, material.emissiveTexture.content); diff --git a/libraries/model/src/model/Material.cpp b/libraries/model/src/model/Material.cpp index 2d2bb38b62..770b110ad9 100755 --- a/libraries/model/src/model/Material.cpp +++ b/libraries/model/src/model/Material.cpp @@ -61,7 +61,7 @@ void Material::setAlbedo(const Color& albedo, bool isSRGB) { void Material::setRoughness(float roughness) { roughness = std::min(1.0f, std::max(roughness, 0.0f)); - _key.setGloss((roughness < 1.0f)); + _key.setGlossy((roughness < 1.0f)); _schemaBuffer.edit()._roughness = roughness; } diff --git a/libraries/model/src/model/Material.h b/libraries/model/src/model/Material.h index 88a8e27611..df58f60eb1 100755 --- a/libraries/model/src/model/Material.h +++ b/libraries/model/src/model/Material.h @@ -30,13 +30,13 @@ public: EMISSIVE_VAL_BIT = 0, ALBEDO_VAL_BIT, METALLIC_VAL_BIT, - GLOSS_VAL_BIT, + GLOSSY_VAL_BIT, TRANSPARENT_VAL_BIT, EMISSIVE_MAP_BIT, ALBEDO_MAP_BIT, METALLIC_MAP_BIT, - GLOSS_MAP_BIT, + ROUGHNESS_MAP_BIT, TRANSPARENT_MAP_BIT, NORMAL_MAP_BIT, LIGHTMAP_MAP_BIT, @@ -49,7 +49,7 @@ public: EMISSIVE_MAP = 0, ALBEDO_MAP, METALLIC_MAP, - GLOSS_MAP, + ROUGHNESS_MAP, TRANSPARENT_MAP, NORMAL_MAP, LIGHTMAP_MAP, @@ -73,13 +73,13 @@ public: Builder& withEmissive() { _flags.set(EMISSIVE_VAL_BIT); return (*this); } Builder& withAlbedo() { _flags.set(ALBEDO_VAL_BIT); return (*this); } Builder& withMetallic() { _flags.set(METALLIC_VAL_BIT); return (*this); } - Builder& withGloss() { _flags.set(GLOSS_VAL_BIT); return (*this); } + Builder& withGlossy() { _flags.set(GLOSSY_VAL_BIT); return (*this); } Builder& withTransparent() { _flags.set(TRANSPARENT_VAL_BIT); return (*this); } Builder& withEmissiveMap() { _flags.set(EMISSIVE_MAP_BIT); return (*this); } Builder& withAlbedoMap() { _flags.set(ALBEDO_MAP_BIT); return (*this); } Builder& withMetallicMap() { _flags.set(METALLIC_MAP_BIT); return (*this); } - Builder& withGlossMap() { _flags.set(GLOSS_MAP_BIT); return (*this); } + Builder& withRoughnessMap() { _flags.set(ROUGHNESS_MAP_BIT); return (*this); } Builder& withTransparentMap() { _flags.set(TRANSPARENT_MAP_BIT); return (*this); } Builder& withNormalMap() { _flags.set(NORMAL_MAP_BIT); return (*this); } @@ -107,11 +107,12 @@ public: void setMetallicMap(bool value) { _flags.set(METALLIC_MAP_BIT, value); } bool isMetallicMap() const { return _flags[METALLIC_MAP_BIT]; } - void setGloss(bool value) { _flags.set(GLOSS_VAL_BIT, value); } - bool isGloss() const { return _flags[GLOSS_VAL_BIT]; } + void setGlossy(bool value) { _flags.set(GLOSSY_VAL_BIT, value); } + bool isGlossy() const { return _flags[GLOSSY_VAL_BIT]; } + bool isRough() const { return !_flags[GLOSSY_VAL_BIT]; } - void setGlossMap(bool value) { _flags.set(GLOSS_MAP_BIT, value); } - bool isGlossMap() const { return _flags[GLOSS_MAP_BIT]; } + void setRoughnessMap(bool value) { _flags.set(ROUGHNESS_MAP_BIT, value); } + bool isRoughnessMap() const { return _flags[ROUGHNESS_MAP_BIT]; } void setTransparent(bool value) { _flags.set(TRANSPARENT_VAL_BIT, value); } bool isTransparent() const { return _flags[TRANSPARENT_VAL_BIT]; } @@ -166,11 +167,11 @@ public: Builder& withoutMetallicMap() { _value.reset(MaterialKey::METALLIC_MAP_BIT); _mask.set(MaterialKey::METALLIC_MAP_BIT); return (*this); } Builder& withMetallicMap() { _value.set(MaterialKey::METALLIC_MAP_BIT); _mask.set(MaterialKey::METALLIC_MAP_BIT); return (*this); } - Builder& withoutGloss() { _value.reset(MaterialKey::GLOSS_VAL_BIT); _mask.set(MaterialKey::GLOSS_VAL_BIT); return (*this); } - Builder& withGloss() { _value.set(MaterialKey::GLOSS_VAL_BIT); _mask.set(MaterialKey::GLOSS_VAL_BIT); return (*this); } + Builder& withoutGlossy() { _value.reset(MaterialKey::GLOSSY_VAL_BIT); _mask.set(MaterialKey::GLOSSY_VAL_BIT); return (*this); } + Builder& withGlossy() { _value.set(MaterialKey::GLOSSY_VAL_BIT); _mask.set(MaterialKey::GLOSSY_VAL_BIT); return (*this); } - Builder& withoutGlossMap() { _value.reset(MaterialKey::GLOSS_MAP_BIT); _mask.set(MaterialKey::GLOSS_MAP_BIT); return (*this); } - Builder& withGlossMap() { _value.set(MaterialKey::GLOSS_MAP_BIT); _mask.set(MaterialKey::GLOSS_MAP_BIT); return (*this); } + Builder& withoutRoughnessMap() { _value.reset(MaterialKey::ROUGHNESS_MAP_BIT); _mask.set(MaterialKey::ROUGHNESS_MAP_BIT); return (*this); } + Builder& withRoughnessMap() { _value.set(MaterialKey::ROUGHNESS_MAP_BIT); _mask.set(MaterialKey::ROUGHNESS_MAP_BIT); return (*this); } Builder& withoutTransparent() { _value.reset(MaterialKey::TRANSPARENT_VAL_BIT); _mask.set(MaterialKey::TRANSPARENT_VAL_BIT); return (*this); } Builder& withTransparent() { _value.set(MaterialKey::TRANSPARENT_VAL_BIT); _mask.set(MaterialKey::TRANSPARENT_VAL_BIT); return (*this); } @@ -241,14 +242,14 @@ public: // Schema to access the attribute values of the material class Schema { public: - glm::vec3 _emissive{ 0.0f }; - float _opacity{ 1.f }; + glm::vec3 _emissive{ 0.0f }; // No Emissive + float _opacity{ 1.f }; // Opacity = 1 => Not Transparent - glm::vec3 _albedo{ 0.5f }; - float _roughness{ 0.9f }; + glm::vec3 _albedo{ 0.5f }; // Grey albedo => isAlbedo + float _roughness{ 1.0f }; // Roughness = 1 => Not Glossy - glm::vec3 _fresnel{ 0.03f }; - float _metallic{ 0.0f }; + glm::vec3 _fresnel{ 0.03f }; // Fresnel value for a default non metallic + float _metallic{ 0.0f }; // Not Metallic glm::vec4 _spare0{ 0.0f }; diff --git a/libraries/render-utils/src/DebugDeferredBuffer.cpp b/libraries/render-utils/src/DebugDeferredBuffer.cpp index 0be3ce422d..1126023f41 100644 --- a/libraries/render-utils/src/DebugDeferredBuffer.cpp +++ b/libraries/render-utils/src/DebugDeferredBuffer.cpp @@ -54,25 +54,51 @@ enum Slot { static const std::string DEFAULT_ALBEDO_SHADER { "vec4 getFragmentColor() {" - " return vec4(pow(texture(albedoMap, uv).xyz, vec3(1.0 / 2.2)), 1.0);" + " DeferredFragment frag = unpackDeferredFragmentNoPosition(uv);" + " return vec4(pow(frag.diffuse, vec3(1.0 / 2.2)), 1.0);" " }" }; -static const std::string DEFAULT_SPECULAR_SHADER { +static const std::string DEFAULT_FRESNEL_SHADER{ "vec4 getFragmentColor() {" - " return vec4(texture(specularMap, uv).xyz, 1.0);" + " DeferredFragment frag = unpackDeferredFragmentNoPosition(uv);" + " return vec4(pow(frag.specular, vec3(1.0 / 2.2)), 1.0);" + " }" +}; + +static const std::string DEFAULT_METALLIC_SHADER { + "vec4 getFragmentColor() {" + " DeferredFragment frag = unpackDeferredFragmentNoPosition(uv);" + " return vec4(vec3(frag.metallic), 1.0);" " }" }; static const std::string DEFAULT_ROUGHNESS_SHADER { "vec4 getFragmentColor() {" - " return vec4(vec3(texture(specularMap, uv).a), 1.0);" + " DeferredFragment frag = unpackDeferredFragmentNoPosition(uv);" + " return vec4(vec3(frag.roughness), 1.0);" " }" }; static const std::string DEFAULT_NORMAL_SHADER { "vec4 getFragmentColor() {" - " return vec4(normalize(texture(normalMap, uv).xyz * 2.0 - vec3(1.0)), 1.0);" + " DeferredFragment frag = unpackDeferredFragmentNoPosition(uv);" + " return vec4(normalize(frag.normal), 1.0);" " }" }; + +static const std::string DEFAULT_EMISSIVE_SHADER{ + "vec4 getFragmentColor() {" + " DeferredFragment frag = unpackDeferredFragmentNoPosition(uv);" + " return (frag.mode != LIGHT_MAPPED ? vec4(pow(frag.emissive, vec3(1.0 / 2.2)), 1.0) : vec4(vec3(0.0), 1.0));" + " }" +}; + +static const std::string DEFAULT_LIGHTMAP_SHADER{ + "vec4 getFragmentColor() {" + " DeferredFragment frag = unpackDeferredFragmentNoPosition(uv);" + " return (frag.mode == LIGHT_MAPPED ? vec4(frag.emissive, 1.0) : vec4(vec3(0.0), 1.0));" + " }" +}; + static const std::string DEFAULT_DEPTH_SHADER { "vec4 getFragmentColor() {" " return vec4(vec3(texture(depthMap, uv).x), 1.0);" @@ -146,14 +172,20 @@ std::string DebugDeferredBuffer::getShaderSourceCode(Mode mode, std::string cust switch (mode) { case AlbedoMode: return DEFAULT_ALBEDO_SHADER; - case SpecularMode: - return DEFAULT_SPECULAR_SHADER; + case FresnelMode: + return DEFAULT_FRESNEL_SHADER; + case MetallicMode: + return DEFAULT_METALLIC_SHADER; case RoughnessMode: return DEFAULT_ROUGHNESS_SHADER; case NormalMode: return DEFAULT_NORMAL_SHADER; case DepthMode: return DEFAULT_DEPTH_SHADER; + case EmissiveMode: + return DEFAULT_EMISSIVE_SHADER; + case LightmapMode: + return DEFAULT_LIGHTMAP_SHADER; case LightingMode: return DEFAULT_LIGHTING_SHADER; case ShadowMode: diff --git a/libraries/render-utils/src/DebugDeferredBuffer.h b/libraries/render-utils/src/DebugDeferredBuffer.h index 221de9a68e..0d72eeec8a 100644 --- a/libraries/render-utils/src/DebugDeferredBuffer.h +++ b/libraries/render-utils/src/DebugDeferredBuffer.h @@ -47,11 +47,14 @@ protected: enum Mode : uint8_t { // Use Mode suffix to avoid collisions - AlbedoMode = 0, - SpecularMode, - RoughnessMode, + DepthMode = 0, + AlbedoMode, NormalMode, - DepthMode, + RoughnessMode, + MetallicMode, + FresnelMode, + EmissiveMode, + LightmapMode, LightingMode, ShadowMode, PyramidDepthMode, diff --git a/libraries/render-utils/src/DeferredBuffer.slh b/libraries/render-utils/src/DeferredBuffer.slh index 339b85ec1a..49cabee727 100755 --- a/libraries/render-utils/src/DeferredBuffer.slh +++ b/libraries/render-utils/src/DeferredBuffer.slh @@ -64,52 +64,73 @@ vec4 evalEyePositionFromZ(DeferredTransform deferredTransform, float depthVal, v } struct DeferredFragment { - float depthVal; vec4 normalVal; vec4 diffuseVal; vec4 specularVal; vec4 position; vec3 normal; + float metallic; vec3 diffuse; float obscurance; vec3 specular; - float gloss; + float roughness; + vec3 emissive; int mode; + float depthVal; }; const int LIGHT_MAPPED = 1; -DeferredFragment unpackDeferredFragment(DeferredTransform deferredTransform, vec2 texcoord) { - DeferredFragment frag; - frag.depthVal = texture(depthMap, texcoord).r; - frag.normalVal = texture(normalMap, texcoord); - frag.diffuseVal = texture(albedoMap, texcoord); - frag.specularVal = texture(specularMap, texcoord); - frag.obscurance = texture(obscuranceMap, texcoord).x; - +vec4 unpackDeferredPosition(DeferredTransform deferredTransform, float depthValue, vec2 texcoord) { if (getStereoMode(deferredTransform)) { if (texcoord.x > 0.5) { texcoord.x -= 0.5; } texcoord.x *= 2.0; } - frag.position = evalEyePositionFromZ(deferredTransform, frag.depthVal, texcoord); + return evalEyePositionFromZ(deferredTransform, depthValue, texcoord); +} + +DeferredFragment unpackDeferredFragmentNoPosition(vec2 texcoord) { + + DeferredFragment frag; + frag.depthVal = -1; + frag.normalVal = texture(normalMap, texcoord); + frag.diffuseVal = texture(albedoMap, texcoord); + frag.specularVal = texture(specularMap, texcoord); + frag.obscurance = texture(obscuranceMap, texcoord).x; // Unpack the normal from the map frag.normal = normalize(frag.normalVal.xyz * 2.0 - vec3(1.0)); frag.mode = 0; + frag.emissive = vec3(0.0); if ((frag.normalVal.a >= 0.45) && (frag.normalVal.a <= 0.55)) { frag.mode = LIGHT_MAPPED; + frag.emissive = frag.specularVal.xyz; } frag.diffuse = frag.diffuseVal.xyz; frag.specular = frag.specularVal.xyz; - frag.gloss = (frag.specularVal.w * 125)*(frag.specularVal.w * 125); + frag.metallic = length(frag.specularVal); + frag.roughness = frag.specularVal.w; + return frag; +} + +DeferredFragment unpackDeferredFragment(DeferredTransform deferredTransform, vec2 texcoord) { + + float depthValue = texture(depthMap, texcoord).r; + + DeferredFragment frag = unpackDeferredFragmentNoPosition(texcoord); + + frag.depthVal = depthValue; + frag.position = unpackDeferredPosition(deferredTransform, frag.depthVal, texcoord); return frag; } + + <@endif@> diff --git a/libraries/render-utils/src/DeferredBufferWrite.slh b/libraries/render-utils/src/DeferredBufferWrite.slh index a54ab4cb3a..d7244cbcad 100755 --- a/libraries/render-utils/src/DeferredBufferWrite.slh +++ b/libraries/render-utils/src/DeferredBufferWrite.slh @@ -40,37 +40,40 @@ float evalOpaqueFinalAlpha(float alpha, float mapAlpha) { return mix(alpha, 1.0 - alpha, step(mapAlpha, alphaThreshold)); } -const vec3 DEFAULT_SPECULAR = vec3(0.1); +const float DEFAULT_ROUGHNESS = 0.9; const float DEFAULT_SHININESS = 10; +const float DEFAULT_METALLIC = 0; +const vec3 DEFAULT_SPECULAR = vec3(0.1); -void packDeferredFragment(vec3 normal, float alpha, vec3 albedo, vec3 fresnel, float shininess) { + +void packDeferredFragment(vec3 normal, float alpha, vec3 albedo, float roughness, float metallic, vec3 fresnel) { if (alpha != 1.0) { discard; } _fragColor0 = vec4(albedo.rgb, 1.0); // Opaque _fragColor1 = vec4(bestFitNormal(normal), 1.0); - _fragColor2 = vec4(fresnel, shininess); + _fragColor2 = vec4(fresnel, roughness); } -void packDeferredFragmentLightmap(vec3 normal, float alpha, vec3 albedo, vec3 fresnel, float shininess, vec3 emissive) { +void packDeferredFragmentLightmap(vec3 normal, float alpha, vec3 albedo, float roughness, float metallic, vec3 fresnel, vec3 emissive) { if (alpha != 1.0) { discard; } _fragColor0 = vec4(albedo.rgb, 0.5); _fragColor1 = vec4(bestFitNormal(normal), 0.5); - _fragColor2 = vec4(emissive, shininess); + _fragColor2 = vec4(emissive, roughness); } -void packDeferredFragmentTranslucent(vec3 normal, float alpha, vec3 albedo, vec3 fresnel, float shininess) { +void packDeferredFragmentTranslucent(vec3 normal, float alpha, vec3 albedo, vec3 fresnel, float roughness) { if (alpha <= 0.0) { discard; } _fragColor0 = vec4(albedo.rgb, alpha); // _fragColor1 = vec4(normal, 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0); - // _fragColor2 = vec4(fresnel, shininess); + // _fragColor2 = vec4(fresnel, roughness); } <@endif@> diff --git a/libraries/render-utils/src/DeferredGlobalLight.slh b/libraries/render-utils/src/DeferredGlobalLight.slh index aad06c9305..de4eb746ef 100755 --- a/libraries/render-utils/src/DeferredGlobalLight.slh +++ b/libraries/render-utils/src/DeferredGlobalLight.slh @@ -30,7 +30,7 @@ vec4 evalSkyboxLight(vec3 direction, float lod) { <@include model/Light.slh@> <@func declareEvalAmbientGlobalColor()@> -vec3 evalAmbientGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, vec3 fresnel, float gloss) { +vec3 evalAmbientGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, float metallic, vec3 fresnel, float roughness) { // Need the light now Light light = getLight(); @@ -41,7 +41,7 @@ vec3 evalAmbientGlobalColor(mat4 invViewMat, float shadowAttenuation, float obsc vec3 color = albedo * getLightColor(light) * obscurance * getLightAmbientIntensity(light); - vec4 shading = evalFragShading(fragNormal, -getLightDirection(light), fragEyeDir, fresnel, gloss); + vec4 shading = evalFragShading(fragNormal, -getLightDirection(light), fragEyeDir, metallic, fresnel, roughness); color += vec3(albedo * shading.w + shading.rgb) * min(shadowAttenuation, obscurance) * getLightColor(light) * getLightIntensity(light); @@ -52,7 +52,7 @@ vec3 evalAmbientGlobalColor(mat4 invViewMat, float shadowAttenuation, float obsc <@func declareEvalAmbientSphereGlobalColor()@> -vec3 evalAmbientSphereGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, vec3 fresnel, float gloss) { +vec3 evalAmbientSphereGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, float metallic, vec3 fresnel, float roughness) { // Need the light now Light light = getLight(); @@ -64,7 +64,7 @@ vec3 evalAmbientSphereGlobalColor(mat4 invViewMat, float shadowAttenuation, floa vec3 color = albedo * evalSphericalLight(getLightAmbientSphere(light), ambientNormal).xyz * obscurance * getLightAmbientIntensity(light); - vec4 shading = evalFragShading(fragNormal, -getLightDirection(light), fragEyeDir, fresnel, gloss); + vec4 shading = evalFragShading(fragNormal, -getLightDirection(light), fragEyeDir, metallic, fresnel, roughness); color += vec3(albedo * shading.w + shading.rgb) * min(shadowAttenuation, obscurance) * getLightColor(light) * getLightIntensity(light); @@ -76,7 +76,7 @@ vec3 evalAmbientSphereGlobalColor(mat4 invViewMat, float shadowAttenuation, floa <$declareSkyboxMap()$> -vec3 evalSkyboxGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, vec3 fresnel, float gloss) { +vec3 evalSkyboxGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, float metallic, vec3 fresnel, float roughness) { // Need the light now Light light = getLight(); @@ -87,7 +87,7 @@ vec3 evalSkyboxGlobalColor(mat4 invViewMat, float shadowAttenuation, float obscu vec3 color = albedo * evalSphericalLight(getLightAmbientSphere(light), fragNormal).xyz * obscurance * getLightAmbientIntensity(light); - vec4 shading = evalFragShading(fragNormal, -getLightDirection(light), fragEyeDir, fresnel, gloss); + vec4 shading = evalFragShading(fragNormal, -getLightDirection(light), fragEyeDir, metallic, fresnel, roughness); color += vec3(albedo * shading.w + shading.rgb) * min(shadowAttenuation, obscurance) * getLightColor(light) * getLightIntensity(light); diff --git a/libraries/render-utils/src/DeferredLighting.slh b/libraries/render-utils/src/DeferredLighting.slh index 01403a8180..032a273d6b 100755 --- a/libraries/render-utils/src/DeferredLighting.slh +++ b/libraries/render-utils/src/DeferredLighting.slh @@ -14,15 +14,17 @@ <@func declareEvalPBRShading()@> // Frag Shading returns the diffuse amount as W and the specular rgb as xyz -vec4 evalPBRShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, vec3 specular, float gloss) { +vec4 evalPBRShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, float metallic, vec3 specular, float roughness) { // Diffuse Lighting float diffuseDot = dot(fragNormal, fragLightDir); float facingLight = step(0.0, diffuseDot); float diffuse = diffuseDot * facingLight; - // Specular Lighting depends on the half vector and the gloss + // Specular Lighting depends on the half vector and the roughness vec3 halfDir = normalize(fragEyeDir + fragLightDir); + float gloss = (1.0 - roughness) * 128.0; + gloss *= gloss; float specularPower = pow(max(0.0, dot(halfDir, fragNormal)), gloss); specularPower *= (gloss * 0.125 + 0.25); @@ -38,15 +40,17 @@ vec4 evalPBRShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, vec3 sp <@func declareEvalBlinnRShading()@> -vec4 evalBlinnShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, vec3 specular, float gloss) { +vec4 evalBlinnShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, vec3 specular, float roughness) { // Diffuse Lighting float diffuseDot = dot(fragNormal, fragLightDir); float facingLight = step(0.0, diffuseDot); float diffuse = diffuseDot * facingLight; - // Specular Lighting depends on the half vector and the gloss + // Specular Lighting depends on the half vector and the roughness vec3 halfDir = normalize(fragEyeDir + fragLightDir); + float gloss = (1.0 - roughness) * 128.0; + glos *= gloss; float specularPower = pow(facingLight * max(0.0, dot(halfDir, fragNormal)), gloss); vec3 reflect = specularPower * specular * diffuse; @@ -59,8 +63,8 @@ vec4 evalBlinnShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, vec3 <$declareEvalPBRShading()$> // Return xyz the specular/reflection component and w the diffuse component -vec4 evalFragShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, vec3 specular, float gloss) { - return evalPBRShading(fragNormal, fragLightDir, fragEyeDir, specular, gloss); +vec4 evalFragShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, float metallic, vec3 specular, float roughness) { + return evalPBRShading(fragNormal, fragLightDir, fragEyeDir, metallic, specular, roughness); } <@endif@> diff --git a/libraries/render-utils/src/MeshPartPayload.cpp b/libraries/render-utils/src/MeshPartPayload.cpp index 9c6c8522fd..e15603cca5 100644 --- a/libraries/render-utils/src/MeshPartPayload.cpp +++ b/libraries/render-utils/src/MeshPartPayload.cpp @@ -106,7 +106,7 @@ ShapeKey MeshPartPayload::getShapeKey() const { if (drawMaterialKey.isNormalMap()) { builder.withTangents(); } - if (drawMaterialKey.isGlossMap()) { + if (drawMaterialKey.isMetallicMap()) { builder.withSpecular(); } if (drawMaterialKey.isLightmapMap()) { @@ -175,6 +175,20 @@ void MeshPartPayload::bindMaterial(gpu::Batch& batch, const ShapePipeline::Locat batch.setResourceTexture(ShapePipeline::Slot::NORMAL_MAP, nullptr); } + // Roughness map + /* if (materialKey.isRoughnessMap()) { + auto roughnessMap = textureMaps[model::MaterialKey::ROUGHNESS_MAP]; + if (roughnessMap && roughnessMap->isDefined()) { + batch.setResourceTexture(ShapePipeline::Slot::ROUGHNESS_MAP, roughnessMap->getTextureView()); + + // texcoord are assumed to be the same has albedo + } else { + batch.setResourceTexture(ShapePipeline::Slot::ROUGHNESS_MAP, textureCache->getBlackTexture()); + } + } else { + batch.setResourceTexture(ShapePipeline::Slot::ROUGHNESS_MAP, nullptr); + }*/ + // Metallic map if (materialKey.isMetallicMap()) { auto specularMap = textureMaps[model::MaterialKey::METALLIC_MAP]; diff --git a/libraries/render-utils/src/directional_ambient_light.slf b/libraries/render-utils/src/directional_ambient_light.slf index 3d1b9db46c..57f9c7e791 100755 --- a/libraries/render-utils/src/directional_ambient_light.slf +++ b/libraries/render-utils/src/directional_ambient_light.slf @@ -44,8 +44,9 @@ void main(void) { frag.position.xyz, frag.normal, frag.diffuse, + frag.metallic, frag.specular, - frag.gloss); + frag.roughness); _fragColor = vec4(color, frag.normalVal.a); } } diff --git a/libraries/render-utils/src/directional_ambient_light_shadow.slf b/libraries/render-utils/src/directional_ambient_light_shadow.slf index ffe0e21851..a4d897044b 100644 --- a/libraries/render-utils/src/directional_ambient_light_shadow.slf +++ b/libraries/render-utils/src/directional_ambient_light_shadow.slf @@ -46,8 +46,9 @@ void main(void) { frag.position.xyz, frag.normal, frag.diffuse, + frag.metallic, frag.specular, - frag.gloss); + frag.roughness); _fragColor = vec4(color, frag.normalVal.a); } } diff --git a/libraries/render-utils/src/directional_light.slf b/libraries/render-utils/src/directional_light.slf index e07c57a905..eed3b94c91 100644 --- a/libraries/render-utils/src/directional_light.slf +++ b/libraries/render-utils/src/directional_light.slf @@ -45,8 +45,9 @@ void main(void) { frag.position.xyz, frag.normal, frag.diffuse, + frag.metallic, frag.specular, - frag.gloss); + frag.roughness); _fragColor = vec4(color, frag.normalVal.a); } } diff --git a/libraries/render-utils/src/directional_light_shadow.slf b/libraries/render-utils/src/directional_light_shadow.slf index 4aa041b847..494046bcb3 100644 --- a/libraries/render-utils/src/directional_light_shadow.slf +++ b/libraries/render-utils/src/directional_light_shadow.slf @@ -47,8 +47,9 @@ void main(void) { frag.position.xyz, frag.normal, frag.diffuse, + frag.metallic, frag.specular, - frag.gloss); + frag.roughness); _fragColor = vec4(color, frag.normalVal.a); } } diff --git a/libraries/render-utils/src/directional_skybox_light.slf b/libraries/render-utils/src/directional_skybox_light.slf index 78fdc4e234..605d1de963 100755 --- a/libraries/render-utils/src/directional_skybox_light.slf +++ b/libraries/render-utils/src/directional_skybox_light.slf @@ -45,8 +45,9 @@ void main(void) { frag.position.xyz, frag.normal, frag.diffuse, + frag.metallic, frag.specular, - frag.gloss); + frag.roughness); _fragColor = vec4(color, frag.normalVal.a); } diff --git a/libraries/render-utils/src/directional_skybox_light_shadow.slf b/libraries/render-utils/src/directional_skybox_light_shadow.slf index bbce15be68..75a48caacf 100644 --- a/libraries/render-utils/src/directional_skybox_light_shadow.slf +++ b/libraries/render-utils/src/directional_skybox_light_shadow.slf @@ -47,8 +47,9 @@ void main(void) { frag.position.xyz, frag.normal, frag.diffuse, + frag.metallic, frag.specular, - frag.gloss); + frag.roughness); _fragColor = vec4(color, frag.normalVal.a); } diff --git a/libraries/render-utils/src/model.slf b/libraries/render-utils/src/model.slf index 63f82a4f03..d09ae500ec 100755 --- a/libraries/render-utils/src/model.slf +++ b/libraries/render-utils/src/model.slf @@ -34,6 +34,7 @@ void main(void) { normalize(_normal.xyz), evalOpaqueFinalAlpha(getMaterialOpacity(mat), albedo.a), getMaterialAlbedo(mat) * albedo.rgb * _color, - getMaterialFresnel(mat), - getMaterialShininess(mat)); + getMaterialRoughness(mat), + getMaterialMetallic(mat), + getMaterialFresnel(mat)); } diff --git a/libraries/render-utils/src/model_emissive.slf b/libraries/render-utils/src/model_emissive.slf index b1b968f259..471e613eb4 100644 --- a/libraries/render-utils/src/model_emissive.slf +++ b/libraries/render-utils/src/model_emissive.slf @@ -32,7 +32,8 @@ void main(void) { normalize(_normal), texel.a, vec3(1.0), + getMaterialRoughness(mat), + getMaterialMetallic(mat), getMaterialFresnel(mat), - getMaterialShininess(mat), fragColor); } diff --git a/libraries/render-utils/src/model_lightmap.slf b/libraries/render-utils/src/model_lightmap.slf index 9287bcf821..a896f5b915 100755 --- a/libraries/render-utils/src/model_lightmap.slf +++ b/libraries/render-utils/src/model_lightmap.slf @@ -39,7 +39,8 @@ void main(void) { normalize(_normal), evalOpaqueFinalAlpha(getMaterialOpacity(mat), albedo.a), getMaterialAlbedo(mat) * albedo.rgb * _color, + getMaterialRoughness(mat), + getMaterialMetallic(mat), getMaterialFresnel(mat), - getMaterialShininess(mat), (vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb)); } diff --git a/libraries/render-utils/src/model_lightmap_normal_map.slf b/libraries/render-utils/src/model_lightmap_normal_map.slf index 496f3883ea..6431dfb069 100755 --- a/libraries/render-utils/src/model_lightmap_normal_map.slf +++ b/libraries/render-utils/src/model_lightmap_normal_map.slf @@ -52,7 +52,8 @@ void main(void) { normalize(viewNormal.xyz), evalOpaqueFinalAlpha(getMaterialOpacity(mat), albedo.a), getMaterialAlbedo(mat) * albedo.rgb * _color, + getMaterialRoughness(mat), + getMaterialMetallic(mat), getMaterialFresnel(mat), - getMaterialShininess(mat), (vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb)); } diff --git a/libraries/render-utils/src/model_lightmap_normal_specular_map.slf b/libraries/render-utils/src/model_lightmap_normal_specular_map.slf index bce14fbe94..66aacbb7f6 100755 --- a/libraries/render-utils/src/model_lightmap_normal_specular_map.slf +++ b/libraries/render-utils/src/model_lightmap_normal_specular_map.slf @@ -56,7 +56,8 @@ void main(void) { normalize(viewNormal.xyz), evalOpaqueFinalAlpha(getMaterialOpacity(mat), albedo.a), getMaterialAlbedo(mat) * albedo.rgb * _color, + getMaterialRoughness(mat), + getMaterialMetallic(mat), specular, // no use of getMaterialFresnel(mat) - getMaterialShininess(mat), (vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb)); } diff --git a/libraries/render-utils/src/model_lightmap_specular_map.slf b/libraries/render-utils/src/model_lightmap_specular_map.slf index e7ff753d16..84fb47f73f 100755 --- a/libraries/render-utils/src/model_lightmap_specular_map.slf +++ b/libraries/render-utils/src/model_lightmap_specular_map.slf @@ -44,7 +44,8 @@ void main(void) { normalize(_normal), evalOpaqueFinalAlpha(getMaterialOpacity(mat), albedo.a), getMaterialAlbedo(mat) * albedo.rgb * _color, + getMaterialRoughness(mat), + getMaterialMetallic(mat), specular, // no use of getMaterialFresnel(mat) - getMaterialShininess(mat), (vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb)); } diff --git a/libraries/render-utils/src/model_normal_map.slf b/libraries/render-utils/src/model_normal_map.slf index 58b1b7378e..204cfaec3f 100755 --- a/libraries/render-utils/src/model_normal_map.slf +++ b/libraries/render-utils/src/model_normal_map.slf @@ -45,6 +45,7 @@ void main(void) { normalize(viewNormal.xyz), evalOpaqueFinalAlpha(getMaterialOpacity(mat), albedo.a), getMaterialAlbedo(mat) * albedo.rgb * _color, - getMaterialFresnel(mat), - getMaterialShininess(mat)); + getMaterialRoughness(mat), + getMaterialMetallic(mat), + getMaterialFresnel(mat)); } diff --git a/libraries/render-utils/src/model_normal_specular_map.slf b/libraries/render-utils/src/model_normal_specular_map.slf index 0926ffa79a..ef39460ddd 100755 --- a/libraries/render-utils/src/model_normal_specular_map.slf +++ b/libraries/render-utils/src/model_normal_specular_map.slf @@ -50,6 +50,8 @@ void main(void) { normalize(viewNormal.xyz), evalOpaqueFinalAlpha(getMaterialOpacity(mat), albedo.a), getMaterialAlbedo(mat) * albedo.rgb * _color, - specular, //getMaterialFresnel(mat), - getMaterialShininess(mat)); + getMaterialRoughness(mat), + getMaterialMetallic(mat), + specular //getMaterialFresnel(mat) + ); } diff --git a/libraries/render-utils/src/model_specular_map.slf b/libraries/render-utils/src/model_specular_map.slf index 5ad0cada15..54d6a8a33f 100755 --- a/libraries/render-utils/src/model_specular_map.slf +++ b/libraries/render-utils/src/model_specular_map.slf @@ -39,6 +39,8 @@ void main(void) { normalize(_normal), evalOpaqueFinalAlpha(getMaterialOpacity(mat), albedo.a), getMaterialAlbedo(mat) * albedo.rgb * _color, - specular, //getMaterialFresnel(mat), - getMaterialShininess(mat)); + getMaterialRoughness(mat), + getMaterialMetallic(mat), + specular //getMaterialFresnel(mat) + ); } diff --git a/libraries/render-utils/src/model_translucent.slf b/libraries/render-utils/src/model_translucent.slf index 6cd3839191..3efa523434 100755 --- a/libraries/render-utils/src/model_translucent.slf +++ b/libraries/render-utils/src/model_translucent.slf @@ -37,8 +37,9 @@ void main(void) { vec3 fragPosition = _position.xyz; vec3 fragNormal = normalize(_normal); vec3 fragAlbedo = getMaterialAlbedo(mat) * albedo.rgb * _color; + float fragMetallic = getMaterialMetallic(mat); vec3 fragFresnel = getMaterialFresnel(mat); - float fragGloss = getMaterialShininess(mat) / 128; + float fragRoughness = getMaterialRoughness(mat); float fragOpacity = getMaterialOpacity(mat) * albedo.a * _alpha; TransformCamera cam = getTransformCamera(); @@ -50,7 +51,8 @@ void main(void) { fragPosition, fragNormal, fragAlbedo, + fragMetallic, fragFresnel, - fragGloss), + fragRoughness), fragOpacity); } diff --git a/libraries/render-utils/src/overlay3D.slf b/libraries/render-utils/src/overlay3D.slf index 8de7a23898..38199a7a82 100644 --- a/libraries/render-utils/src/overlay3D.slf +++ b/libraries/render-utils/src/overlay3D.slf @@ -17,7 +17,7 @@ <@include gpu/Transform.slh@> <$declareStandardCameraTransform()$> -vec4 evalGlobalColor(float shadowAttenuation, vec3 position, vec3 normal, vec3 albedo, vec3 specular, float gloss, float opacity) { +vec4 evalGlobalColor(float shadowAttenuation, vec3 position, vec3 normal, vec3 albedo, float metallic, vec3 specular, float roughness, float opacity) { // Need the light now Light light = getLight(); @@ -30,7 +30,7 @@ vec4 evalGlobalColor(float shadowAttenuation, vec3 position, vec3 normal, vec3 a vec3 color = opacity * albedo * getLightColor(light) * getLightAmbientIntensity(light); - vec4 shading = evalFragShading(fragNormal, -getLightDirection(light), fragEyeDir, specular, gloss); + vec4 shading = evalFragShading(fragNormal, -getLightDirection(light), fragEyeDir, metallic, specular, roughness); color += vec3(albedo * shading.w * opacity + shading.rgb) * shadowAttenuation * getLightColor(light) * getLightIntensity(light); @@ -53,8 +53,9 @@ void main(void) { vec3 fragPosition = _position.xyz; vec3 fragNormal = normalize(_normal); vec3 fragAlbedo = albedo.rgb * _color; + float fragMetallic = 0.0; vec3 fragSpecular = vec3(0.1); - float fragGloss = 10.0 / 128.0; + float fragRoughness = 0.9; float fragOpacity = albedo.a; if (fragOpacity <= 0.1) { @@ -65,8 +66,9 @@ void main(void) { fragPosition, fragNormal, fragAlbedo, + fragMetallic, fragSpecular, - fragGloss, + fragRoughness, fragOpacity); // Apply standard tone mapping diff --git a/libraries/render-utils/src/overlay3D_translucent.slf b/libraries/render-utils/src/overlay3D_translucent.slf index 8e6dbb9eff..f8c18abf20 100644 --- a/libraries/render-utils/src/overlay3D_translucent.slf +++ b/libraries/render-utils/src/overlay3D_translucent.slf @@ -18,7 +18,7 @@ <@include gpu/Transform.slh@> <$declareStandardCameraTransform()$> -vec4 evalGlobalColor(float shadowAttenuation, vec3 position, vec3 normal, vec3 albedo, vec3 specular, float gloss, float opacity) { +vec4 evalGlobalColor(float shadowAttenuation, vec3 position, vec3 normal, vec3 albedo, float metallic, vec3 specular, float roughness, float opacity) { // Need the light now Light light = getLight(); @@ -31,7 +31,7 @@ vec4 evalGlobalColor(float shadowAttenuation, vec3 position, vec3 normal, vec3 a vec3 color = opacity * albedo * getLightColor(light) * getLightAmbientIntensity(light); - vec4 shading = evalFragShading(fragNormal, -getLightDirection(light), fragEyeDir, specular, gloss); + vec4 shading = evalFragShading(fragNormal, -getLightDirection(light), fragEyeDir, metallic, specular, roughness); color += vec3(albedo * shading.w * opacity + shading.rgb) * shadowAttenuation * getLightColor(light) * getLightIntensity(light); @@ -54,16 +54,18 @@ void main(void) { vec3 fragPosition = _position.xyz; vec3 fragNormal = normalize(_normal); vec3 fragAlbedo = albedo.rgb * _color; + float fragMetallic = 0.0; vec3 fragSpecular = vec3(0.1); - float fragGloss = 10.0 / 128.0; + float fragRoughness = 0.9; float fragOpacity = albedo.a * _alpha; vec4 color = evalGlobalColor(1.0, fragPosition, fragNormal, fragAlbedo, + fragMetallic, fragSpecular, - fragGloss, + fragRoughness, fragOpacity); // Apply standard tone mapping diff --git a/libraries/render-utils/src/point_light.slf b/libraries/render-utils/src/point_light.slf index fcfb0b336e..298b3751b7 100644 --- a/libraries/render-utils/src/point_light.slf +++ b/libraries/render-utils/src/point_light.slf @@ -60,7 +60,7 @@ void main(void) { vec3 fragNormal = vec3(invViewMat * vec4(frag.normal, 0.0)); vec4 fragEyeVector = invViewMat * vec4(-frag.position.xyz, 0.0); vec3 fragEyeDir = normalize(fragEyeVector.xyz); - vec4 shading = evalFragShading(fragNormal, fragLightDir, fragEyeDir, frag.specular, frag.gloss); + vec4 shading = evalFragShading(fragNormal, fragLightDir, fragEyeDir, frag.metallic, frag.specular, frag.roughness); // Eval attenuation float radialAttenuation = evalLightAttenuation(light, fragLightDistance); diff --git a/libraries/render-utils/src/sdf_text3D.slf b/libraries/render-utils/src/sdf_text3D.slf index 69fec0042b..faa4d02bfa 100644 --- a/libraries/render-utils/src/sdf_text3D.slf +++ b/libraries/render-utils/src/sdf_text3D.slf @@ -10,6 +10,8 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +<@include DeferredBufferWrite.slh@> + uniform sampler2D Font; uniform bool Outline; uniform vec4 Color; @@ -17,12 +19,11 @@ uniform vec4 Color; // the interpolated normal in vec3 _normal; in vec2 _texCoord0; - +/* layout(location = 0) out vec4 _fragColor0; layout(location = 1) out vec4 _fragColor1; layout(location = 2) out vec4 _fragColor2; - -const float DEFAULT_SHININESS = 10; +*/ const float gamma = 2.2; const float smoothing = 256.0; @@ -53,7 +54,16 @@ void main() { } // final color - _fragColor0 = vec4(Color.rgb, Color.a * a); + /* _fragColor0 = vec4(Color.rgb, Color.a * a); _fragColor1 = vec4(normalize(_normal.xyz), 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 0.5); - _fragColor2 = vec4(Color.rgb, DEFAULT_SHININESS / 128.0); + _fragColor2 = vec4(Color.rgb, 10 / 128.0); + */ + packDeferredFragmentLightmap( + normalize(_normal), + Color.a * a, + Color.rgb, + DEFAULT_ROUGHNESS, + DEFAULT_METALLIC, + DEFAULT_SPECULAR, + Color.rgb); } \ No newline at end of file diff --git a/libraries/render-utils/src/simple.slf b/libraries/render-utils/src/simple.slf index b24e4f92ff..4b5cdfb5ce 100644 --- a/libraries/render-utils/src/simple.slf +++ b/libraries/render-utils/src/simple.slf @@ -51,9 +51,9 @@ void main(void) { if (emissiveAmount > 0.0) { packDeferredFragmentLightmap( - normal, 1.0, diffuse, specular, shininess, specular); + normal, 1.0, diffuse, max(0, 1.0 - shininess / 128.0), DEFAULT_METALLIC, specular, specular); } else { packDeferredFragment( - normal, 1.0, diffuse, specular, shininess); + normal, 1.0, diffuse, max(0, 1.0 - shininess / 128.0), DEFAULT_METALLIC, specular); } } diff --git a/libraries/render-utils/src/simple_textured.slf b/libraries/render-utils/src/simple_textured.slf index 6c99343a28..b2bc15dbad 100644 --- a/libraries/render-utils/src/simple_textured.slf +++ b/libraries/render-utils/src/simple_textured.slf @@ -31,5 +31,7 @@ void main(void) { normalize(_normal.xyz), texel.a, _color.rgb * texel.rgb, - DEFAULT_SPECULAR, DEFAULT_SHININESS); + DEFAULT_ROUGHNESS, + DEFAULT_METALLIC, + DEFAULT_SPECULAR); } \ No newline at end of file diff --git a/libraries/render-utils/src/simple_textured_emisive.slf b/libraries/render-utils/src/simple_textured_emisive.slf index 2119af17fb..92bdee8d02 100644 --- a/libraries/render-utils/src/simple_textured_emisive.slf +++ b/libraries/render-utils/src/simple_textured_emisive.slf @@ -29,6 +29,8 @@ void main(void) { normalize(_normal), texel.a, _color.rgb, - DEFAULT_SPECULAR, DEFAULT_SHININESS, + DEFAULT_ROUGHNESS, + DEFAULT_METALLIC, + DEFAULT_SPECULAR, texel.rgb); } \ No newline at end of file diff --git a/libraries/render-utils/src/spot_light.slf b/libraries/render-utils/src/spot_light.slf index 8170929636..a4077c0edb 100644 --- a/libraries/render-utils/src/spot_light.slf +++ b/libraries/render-utils/src/spot_light.slf @@ -66,7 +66,7 @@ void main(void) { vec3 fragNormal = vec3(invViewMat * vec4(frag.normal, 0.0)); vec4 fragEyeVector = invViewMat * vec4(-frag.position.xyz, 0.0); vec3 fragEyeDir = normalize(fragEyeVector.xyz); - vec4 shading = evalFragShading(fragNormal, fragLightDir, fragEyeDir, frag.specular, frag.gloss); + vec4 shading = evalFragShading(fragNormal, fragLightDir, fragEyeDir, frag.metallic, frag.specular, frag.roughness); // Eval attenuation float radialAttenuation = evalLightAttenuation(light, fragLightDistance); diff --git a/tests/gpu-test/src/unlit.slf b/tests/gpu-test/src/unlit.slf index 77d28aa7e9..d070662495 100644 --- a/tests/gpu-test/src/unlit.slf +++ b/tests/gpu-test/src/unlit.slf @@ -24,5 +24,5 @@ void main(void) { normalize(_normal.xyz), 1.0, _color.rgb, - DEFAULT_SPECULAR, DEFAULT_SHININESS); + DEFAULT_ROUGHNESS, DEFAULT_METALLIC, DEFAULT_SPECULAR); }