From 82029b4cb011df2cb85a1e1bb3813b267879426e Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Mon, 6 Aug 2018 18:34:57 -0700 Subject: [PATCH] fix v1 and transparent procedurals --- .../src/RenderableShapeEntityItem.cpp | 4 +- libraries/render-utils/src/forward_simple.slf | 4 +- .../src/forward_simple_transparent.slf | 93 ------------------- libraries/render-utils/src/simple.slf | 4 +- .../render-utils/src/simple_transparent.slf | 32 ++++--- 5 files changed, 25 insertions(+), 112 deletions(-) delete mode 100644 libraries/render-utils/src/forward_simple_transparent.slf diff --git a/libraries/entities-renderer/src/RenderableShapeEntityItem.cpp b/libraries/entities-renderer/src/RenderableShapeEntityItem.cpp index a1b0eaf9e6..02dc6008a3 100644 --- a/libraries/entities-renderer/src/RenderableShapeEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableShapeEntityItem.cpp @@ -35,9 +35,7 @@ ShapeEntityRenderer::ShapeEntityRenderer(const EntityItemPointer& entity) : Pare _procedural._vertexSource = gpu::Shader::getVertexShaderSource(shader::render_utils::vertex::simple); // FIXME: Setup proper uniform slots and use correct pipelines for forward rendering _procedural._opaquefragmentSource = gpu::Shader::getFragmentShaderSource(shader::render_utils::fragment::simple); - // FIXME: Transparent procedural entities only seem to work if they use the opaque pipelines - //_procedural._transparentfragmentSource = simple_transparent_frag::getSource(); - _procedural._transparentfragmentSource = _procedural._opaquefragmentSource; + _procedural._transparentfragmentSource = gpu::Shader::getFragmentShaderSource(shader::render_utils::fragment::simple_transparent); _procedural._opaqueState->setCullMode(gpu::State::CULL_NONE); _procedural._opaqueState->setDepthTest(true, true, gpu::LESS_EQUAL); PrepareStencil::testMaskDrawShape(*_procedural._opaqueState); diff --git a/libraries/render-utils/src/forward_simple.slf b/libraries/render-utils/src/forward_simple.slf index 2c1be14080..ca3a13c024 100644 --- a/libraries/render-utils/src/forward_simple.slf +++ b/libraries/render-utils/src/forward_simple.slf @@ -51,9 +51,9 @@ void main(void) { #ifdef PROCEDURAL #ifdef PROCEDURAL_V1 - specular = getProceduralColor().rgb; + diffuse = getProceduralColor().rgb; // Procedural Shaders are expected to be Gamma corrected so let's bring back the RGB in linear space for the rest of the pipeline - //specular = pow(specular, vec3(2.2)); + //diffuse = pow(diffuse, vec3(2.2)); emissiveAmount = 1.0; #else emissiveAmount = getProceduralColors(diffuse, specular, shininess); diff --git a/libraries/render-utils/src/forward_simple_transparent.slf b/libraries/render-utils/src/forward_simple_transparent.slf deleted file mode 100644 index f8390d6253..0000000000 --- a/libraries/render-utils/src/forward_simple_transparent.slf +++ /dev/null @@ -1,93 +0,0 @@ -<@include gpu/Config.slh@> -<$VERSION_HEADER$> -// Generated on <$_SCRIBE_DATE$> -// -// forward_simple_transparent.frag -// fragment shader -// -// Created by Andrzej Kapolka on 9/15/14. -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// -<@include DefaultMaterials.slh@> - -<@include ForwardGlobalLight.slh@> -<$declareEvalGlobalLightingAlphaBlended()$> - -// the interpolated normal -layout(location=RENDER_UTILS_ATTR_NORMAL_WS) in vec3 _normalWS; -layout(location=RENDER_UTILS_ATTR_NORMAL_MS) in vec3 _normalMS; -layout(location=RENDER_UTILS_ATTR_COLOR) in vec4 _color; -layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01; -#define _texCoord0 _texCoord01.xy -#define _texCoord1 _texCoord01.zw -layout(location=RENDER_UTILS_ATTR_POSITION_MS) in vec4 _positionMS; -layout(location=RENDER_UTILS_ATTR_POSITION_ES) in vec4 _positionES; - -// For retro-compatibility -#define _normal _normalWS -#define _modelNormal _normalMS -#define _position _positionMS -#define _eyePosition _positionES - -layout(location=0) out vec4 _fragColor0; - -//PROCEDURAL_COMMON_BLOCK - -#line 1001 -//PROCEDURAL_BLOCK - -#line 2030 -void main(void) { - vec3 normal = normalize(_normalWS.xyz); - vec3 diffuse = _color.rgb; - vec3 specular = DEFAULT_SPECULAR; - float shininess = DEFAULT_SHININESS; - float emissiveAmount = 0.0; - -#ifdef PROCEDURAL - -#ifdef PROCEDURAL_V1 - specular = getProceduralColor().rgb; - // Procedural Shaders are expected to be Gamma corrected so let's bring back the RGB in linear space for the rest of the pipeline - //specular = pow(specular, vec3(2.2)); - emissiveAmount = 1.0; -#else - emissiveAmount = getProceduralColors(diffuse, specular, shininess); -#endif - -#endif - - TransformCamera cam = getTransformCamera(); - vec3 fragPosition = _positionES.xyz; - - if (emissiveAmount > 0.0) { - _fragColor0 = vec4(evalGlobalLightingAlphaBlendedWithHaze( - cam._viewInverse, - 1.0, - DEFAULT_OCCLUSION, - fragPosition, - normal, - specular, - DEFAULT_FRESNEL, - DEFAULT_METALLIC, - DEFAULT_EMISSIVE, - DEFAULT_ROUGHNESS, _color.a), - _color.a); - } else { - _fragColor0 = vec4(evalGlobalLightingAlphaBlendedWithHaze( - cam._viewInverse, - 1.0, - DEFAULT_OCCLUSION, - fragPosition, - normal, - diffuse, - DEFAULT_FRESNEL, - DEFAULT_METALLIC, - DEFAULT_EMISSIVE, - DEFAULT_ROUGHNESS, _color.a), - _color.a); - } -} diff --git a/libraries/render-utils/src/simple.slf b/libraries/render-utils/src/simple.slf index 04ffade2fa..a7f5151880 100644 --- a/libraries/render-utils/src/simple.slf +++ b/libraries/render-utils/src/simple.slf @@ -48,9 +48,9 @@ void main(void) { #ifdef PROCEDURAL #ifdef PROCEDURAL_V1 - specular = getProceduralColor().rgb; + diffuse = getProceduralColor().rgb; // Procedural Shaders are expected to be Gamma corrected so let's bring back the RGB in linear space for the rest of the pipeline - //specular = pow(specular, vec3(2.2)); + //diffuse = pow(diffuse, vec3(2.2)); emissiveAmount = 1.0; #else emissiveAmount = getProceduralColors(diffuse, specular, shininess); diff --git a/libraries/render-utils/src/simple_transparent.slf b/libraries/render-utils/src/simple_transparent.slf index f81c06390c..5db54aa770 100644 --- a/libraries/render-utils/src/simple_transparent.slf +++ b/libraries/render-utils/src/simple_transparent.slf @@ -11,8 +11,10 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +<@include DefaultMaterials.slh@> -<@include DeferredBufferWrite.slh@> +<@include DeferredGlobalLight.slh@> +<$declareEvalGlobalLightingAlphaBlendedWithHaze()$> <@include render-utils/ShaderConstants.h@> @@ -26,6 +28,8 @@ layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01; layout(location=RENDER_UTILS_ATTR_POSITION_MS) in vec4 _positionMS; layout(location=RENDER_UTILS_ATTR_POSITION_ES) in vec4 _positionES; +layout(location=0) out vec4 _fragColor0; + // For retro-compatibility #define _normal _normalWS #define _modelNormal _normalMS @@ -48,9 +52,9 @@ void main(void) { #ifdef PROCEDURAL #ifdef PROCEDURAL_V1 - specular = getProceduralColor().rgb; + diffuse = getProceduralColor().rgb; // Procedural Shaders are expected to be Gamma corrected so let's bring back the RGB in linear space for the rest of the pipeline - //specular = pow(specular, vec3(2.2)); + //diffuse = pow(diffuse, vec3(2.2)); emissiveAmount = 1.0; #else emissiveAmount = getProceduralColors(diffuse, specular, shininess); @@ -58,19 +62,23 @@ void main(void) { #endif + TransformCamera cam = getTransformCamera(); + vec3 fragPosition = _positionES.xyz; + if (emissiveAmount > 0.0) { - packDeferredFragmentTranslucent( - normal, - _color.a, - specular, - DEFAULT_FRESNEL, - DEFAULT_ROUGHNESS); + _fragColor0 = vec4(diffuse, _color.a); } else { - packDeferredFragmentTranslucent( + _fragColor0 = vec4(evalGlobalLightingAlphaBlendedWithHaze( + cam._viewInverse, + 1.0, + DEFAULT_OCCLUSION, + fragPosition, normal, - _color.a, diffuse, DEFAULT_FRESNEL, - DEFAULT_ROUGHNESS); + length(specular), + DEFAULT_EMISSIVE, + max(0.0, 1.0 - shininess / 128.0), _color.a), + _color.a); } }