From 0f24c18de538d58601a083b71b727963786f8591 Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Wed, 26 Sep 2018 14:44:19 -0700 Subject: [PATCH] slightly fix forward pipelines --- .../graphics/src/graphics/MaterialTextures.slh | 10 ---------- libraries/render-utils/src/RenderPipelines.cpp | 4 +++- libraries/render-utils/src/forward_model.slf | 15 +++++++++------ .../src/forward_model_normal_map.slf | 18 +++++++++++------- .../src/forward_model_translucent.slf | 15 ++++++++++----- .../render-utils/src/forward_model_unlit.slf | 11 +++-------- 6 files changed, 36 insertions(+), 37 deletions(-) diff --git a/libraries/graphics/src/graphics/MaterialTextures.slh b/libraries/graphics/src/graphics/MaterialTextures.slh index 106453877c..a01eb5dcd0 100644 --- a/libraries/graphics/src/graphics/MaterialTextures.slh +++ b/libraries/graphics/src/graphics/MaterialTextures.slh @@ -226,16 +226,6 @@ vec3 fetchLightmapMap(vec2 uv) { } <@endfunc@> -<@func evalMaterialNormal(fetchedNormal, interpolatedNormal, interpolatedTangent, normal)@> -{ - vec3 normalizedNormal = normalize(<$interpolatedNormal$>.xyz); - vec3 normalizedTangent = normalize(<$interpolatedTangent$>.xyz); - vec3 normalizedBitangent = cross(normalizedNormal, normalizedTangent); - vec3 localNormal = <$fetchedNormal$>; - <$normal$> = vec3(normalizedBitangent * localNormal.x + normalizedNormal * localNormal.y + normalizedTangent * localNormal.z); -} -<@endfunc@> - <@func evalMaterialNormalLOD(fragPosES, fetchedNormal, interpolatedNormal, interpolatedTangent, normal)@> { vec3 normalizedNormal = normalize(<$interpolatedNormal$>.xyz); diff --git a/libraries/render-utils/src/RenderPipelines.cpp b/libraries/render-utils/src/RenderPipelines.cpp index 704b1d7663..84f0835651 100644 --- a/libraries/render-utils/src/RenderPipelines.cpp +++ b/libraries/render-utils/src/RenderPipelines.cpp @@ -254,7 +254,7 @@ void initForwardPipelines(ShapePlumber& plumber) { // Opaques addPipeline(Key::Builder().withMaterial(), forward_model); addPipeline(Key::Builder().withMaterial().withUnlit(), forward_model_unlit); - addPipeline(Key::Builder().withMaterial().withTangents(), forward_model_translucent); + addPipeline(Key::Builder().withMaterial().withTangents(), forward_model_normal_map); // Skinned Opaques addPipeline(Key::Builder().withMaterial().withSkinned(), forward_skin_model); @@ -272,6 +272,8 @@ void initForwardPipelines(ShapePlumber& plumber) { addPipeline(Key::Builder().withMaterial().withSkinned().withTranslucent().withDualQuatSkinned(), forward_skin_translucent_dq); addPipeline(Key::Builder().withMaterial().withSkinned().withTranslucent().withTangents().withDualQuatSkinned(), forward_skin_translucent_normal_map_dq); + // FIXME: incorrent pipelines for normal mapped + translucent models + forceLightBatchSetter = false; } diff --git a/libraries/render-utils/src/forward_model.slf b/libraries/render-utils/src/forward_model.slf index f77ab358f2..daccd9c6d6 100644 --- a/libraries/render-utils/src/forward_model.slf +++ b/libraries/render-utils/src/forward_model.slf @@ -1,10 +1,8 @@ <@include gpu/Config.slh@> <$VERSION_HEADER$> +// <$_SCRIBE_FILENAME$> // Generated on <$_SCRIBE_DATE$> // -// forward_model.frag -// fragment shader -// // Created by Sam Gateau on 2/15/2016. // Copyright 2014 High Fidelity, Inc. // @@ -12,15 +10,16 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -<@include gpu/Transform.slh@> +<@include DefaultMaterials.slh@> <@include graphics/Material.slh@> <@include graphics/MaterialTextures.slh@> <@include render-utils/ShaderConstants.h@> + <@include ForwardGlobalLight.slh@> <$declareEvalSkyboxGlobalColor()$> - +<@include gpu/Transform.slh@> <$declareStandardCameraTransform()$> <$declareMaterialTextures(ALBEDO, ROUGHNESS, _SCRIBE_NULL, METALLIC, EMISSIVE, OCCLUSION)$> @@ -56,8 +55,12 @@ void main(void) { float metallic = getMaterialMetallic(mat); <$evalMaterialMetallic(metallicTex, metallic, matKey, metallic)$>; + vec3 fresnel = getFresnelF0(metallic, albedo); + float occlusion = DEFAULT_OCCLUSION; + <$evalMaterialOcclusion(occlusionTex, matKey, occlusion)$>; + vec3 fragPosition = _positionES.xyz; vec3 fragNormal = normalize(_normalWS); @@ -66,7 +69,7 @@ void main(void) { vec4 color = vec4(evalSkyboxGlobalColor( cam._viewInverse, 1.0, - occlusionTex, + occlusion, fragPosition, fragNormal, albedo, diff --git a/libraries/render-utils/src/forward_model_normal_map.slf b/libraries/render-utils/src/forward_model_normal_map.slf index 73fae33fb0..33e375c495 100644 --- a/libraries/render-utils/src/forward_model_normal_map.slf +++ b/libraries/render-utils/src/forward_model_normal_map.slf @@ -1,10 +1,8 @@ <@include gpu/Config.slh@> <$VERSION_HEADER$> +// <$_SCRIBE_FILENAME$> // Generated on <$_SCRIBE_DATE$> // -// forward_model_normal_map.frag -// fragment shader -// // Created by Sam Gateau on 2/15/2016. // Copyright 2014 High Fidelity, Inc. // @@ -12,13 +10,16 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -<@include gpu/Transform.slh@> +<@include DefaultMaterials.slh@> <@include graphics/Material.slh@> <@include graphics/MaterialTextures.slh@> <@include render-utils/ShaderConstants.h@> + <@include ForwardGlobalLight.slh@> <$declareEvalSkyboxGlobalColor()$> + +<@include gpu/Transform.slh@> <$declareStandardCameraTransform()$> <$declareMaterialTextures(ALBEDO, ROUGHNESS, NORMAL, METALLIC, EMISSIVE, OCCLUSION)$> @@ -55,18 +56,22 @@ void main(void) { float metallic = getMaterialMetallic(mat); <$evalMaterialMetallic(metallicTex, metallic, matKey, metallic)$>; + vec3 fresnel = getFresnelF0(metallic, albedo); + float occlusion = DEFAULT_OCCLUSION; + <$evalMaterialOcclusion(occlusionTex, matKey, occlusion)$>; + vec3 fragPosition = _positionES.xyz; vec3 fragNormal; - <$evalMaterialNormal(normalTex, _normalWS, _tangentWS, fragNormal)$> + <$evalMaterialNormalLOD(fragPosition, normalTex, _normalWS, _tangentWS, fragNormal)$> TransformCamera cam = getTransformCamera(); vec4 color = vec4(evalSkyboxGlobalColor( cam._viewInverse, 1.0, - occlusionTex, + occlusion, fragPosition, fragNormal, albedo, @@ -74,7 +79,6 @@ void main(void) { metallic, roughness), opacity); - color.rgb += emissive * isEmissiveEnabled(); _fragColor0 = color; diff --git a/libraries/render-utils/src/forward_model_translucent.slf b/libraries/render-utils/src/forward_model_translucent.slf index 5fb2c7c1a7..080ed7eea3 100644 --- a/libraries/render-utils/src/forward_model_translucent.slf +++ b/libraries/render-utils/src/forward_model_translucent.slf @@ -1,10 +1,8 @@ <@include gpu/Config.slh@> <$VERSION_HEADER$> +// <$_SCRIBE_FILENAME$> // Generated on <$_SCRIBE_DATE$> // -// forward_model_translucent.frag -// fragment shader -// // Created by Sam Gateau on 2/15/2016. // Copyright 2014 High Fidelity, Inc. // @@ -12,13 +10,16 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -<@include gpu/Transform.slh@> +<@include DefaultMaterials.slh@> <@include graphics/Material.slh@> <@include graphics/MaterialTextures.slh@> <@include render-utils/ShaderConstants.h@> + <@include ForwardGlobalLight.slh@> <$declareEvalGlobalLightingAlphaBlended()$> + +<@include gpu/Transform.slh@> <$declareStandardCameraTransform()$> <$declareMaterialTextures(ALBEDO, ROUGHNESS, _SCRIBE_NULL, METALLIC, EMISSIVE, OCCLUSION)$> @@ -51,8 +52,12 @@ void main(void) { float metallic = getMaterialMetallic(mat); <$evalMaterialMetallic(metallicTex, metallic, matKey, metallic)$>; + vec3 fresnel = getFresnelF0(metallic, albedo); + float occlusion = DEFAULT_OCCLUSION; + <$evalMaterialOcclusion(occlusionTex, matKey, occlusion)$>; + vec3 emissive = getMaterialEmissive(mat); <$evalMaterialEmissive(emissiveTex, emissive, matKey, emissive)$>; @@ -64,7 +69,7 @@ void main(void) { _fragColor0 = vec4(evalGlobalLightingAlphaBlendedWithHaze( cam._viewInverse, 1.0, - occlusionTex, + occlusion, fragPosition, fragNormal, albedo, diff --git a/libraries/render-utils/src/forward_model_unlit.slf b/libraries/render-utils/src/forward_model_unlit.slf index 19b40d884c..ccd264f0bf 100644 --- a/libraries/render-utils/src/forward_model_unlit.slf +++ b/libraries/render-utils/src/forward_model_unlit.slf @@ -1,10 +1,8 @@ <@include gpu/Config.slh@> <$VERSION_HEADER$> +// <$_SCRIBE_FILENAME$> // Generated on <$_SCRIBE_DATE$> // -// forward_model_unlit.frag -// fragment shader -// // Created by Sam Gateau on 5/5/2016. // Copyright 2016 High Fidelity, Inc. // @@ -12,11 +10,12 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -<@include LightingModel.slh@> <@include graphics/Material.slh@> <@include graphics/MaterialTextures.slh@> <@include render-utils/ShaderConstants.h@> +<@include LightingModel.slh@> + <$declareMaterialTextures(ALBEDO)$> layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01; @@ -27,7 +26,6 @@ layout(location=RENDER_UTILS_ATTR_COLOR) in vec4 _color; layout(location=0) out vec4 _fragColor0; void main(void) { - Material mat = getMaterial(); BITFIELD matKey = getMaterialKey(mat); <$fetchMaterialTexturesCoord0(matKey, _texCoord0, albedoTex)$> @@ -40,8 +38,5 @@ void main(void) { <$evalMaterialAlbedo(albedoTex, albedo, matKey, albedo)$>; albedo *= _color.rgb; - if (opacity != 1.0) { - discard; - } _fragColor0 = vec4(albedo * isUnlitEnabled(), 1.0); }