From 1ad61b768328daf4cbae0996a21b3c2a7cfb6194 Mon Sep 17 00:00:00 2001 From: Gabriel Calero Date: Mon, 15 Jan 2018 16:56:48 -0300 Subject: [PATCH] Adding forward pipelines for translucent objects --- .../render-utils/src/ForwardGlobalLight.slh | 39 +++++++++++++++++++ .../render-utils/src/RenderPipelines.cpp | 22 ++++++++++- 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/libraries/render-utils/src/ForwardGlobalLight.slh b/libraries/render-utils/src/ForwardGlobalLight.slh index e86f0c7fe3..812aae0968 100644 --- a/libraries/render-utils/src/ForwardGlobalLight.slh +++ b/libraries/render-utils/src/ForwardGlobalLight.slh @@ -168,6 +168,7 @@ vec3 evalLightmappedColor(mat4 invViewMat, float shadowAttenuation, float obscur +<@include Haze.slh@> <@func declareEvalGlobalLightingAlphaBlended()@> @@ -198,6 +199,44 @@ vec3 evalGlobalLightingAlphaBlended(mat4 invViewMat, float shadowAttenuation, fl return color; } +vec3 evalGlobalLightingAlphaBlendedWithHaze( + mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, + vec3 albedo, vec3 fresnel, float metallic, vec3 emissive, float roughness, float opacity) +{ + <$prepareGlobalLight()$> + + color += emissive * isEmissiveEnabled(); + + // Ambient + vec3 ambientDiffuse; + vec3 ambientSpecular; + evalLightingAmbient(ambientDiffuse, ambientSpecular, lightAmbient, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, obscurance); + color += ambientDiffuse; + color += ambientSpecular / opacity; + + // Directional + vec3 directionalDiffuse; + vec3 directionalSpecular; + evalLightingDirectional(directionalDiffuse, directionalSpecular, lightDirection, lightIrradiance, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, shadowAttenuation); + color += directionalDiffuse; + color += directionalSpecular / opacity; + + // Haze + if ((hazeParams.hazeMode & HAZE_MODE_IS_ACTIVE) == HAZE_MODE_IS_ACTIVE) { + vec4 colorV4 = computeHazeColor( + vec4(color, 1.0), // fragment original color + position, // fragment position in eye coordinates + fragEyeVector, // fragment position in world coordinates + invViewMat[3].y, // eye height in world coordinates + lightDirection // keylight direction vector + ); + + color = colorV4.rgb; + } + + return color; +} + <@endfunc@> diff --git a/libraries/render-utils/src/RenderPipelines.cpp b/libraries/render-utils/src/RenderPipelines.cpp index b6458ea80a..6214b2a59a 100644 --- a/libraries/render-utils/src/RenderPipelines.cpp +++ b/libraries/render-utils/src/RenderPipelines.cpp @@ -64,6 +64,7 @@ #include "forward_model_normal_map_frag.h" #include "forward_model_normal_specular_map_frag.h" #include "forward_model_specular_map_frag.h" +#include "forward_model_translucent_frag.h" #include "model_lightmap_frag.h" #include "model_lightmap_normal_map_frag.h" @@ -451,6 +452,7 @@ void initForwardPipelines(ShapePlumber& plumber, const render::ShapePipeline::Ba auto modelSpecularMapPixel = gpu::Shader::createPixel(std::string(forward_model_specular_map_frag)); auto modelNormalSpecularMapPixel = gpu::Shader::createPixel(std::string(forward_model_normal_specular_map_frag)); auto modelNormalMapFadePixel = gpu::Shader::createPixel(std::string(model_normal_map_fade_frag)); + auto modelTranslucentPixel = gpu::Shader::createPixel(std::string(forward_model_translucent_frag)); using Key = render::ShapeKey; auto addPipeline = std::bind(&addPlumberPipeline, std::ref(plumber), _1, _2, _3, _4, _5); @@ -486,7 +488,25 @@ void initForwardPipelines(ShapePlumber& plumber, const render::ShapePipeline::Ba addPipeline( Key::Builder().withMaterial().withSkinned().withTangents().withFade(), skinModelNormalMapFadeVertex, modelNormalMapFadePixel, batchSetter, itemSetter, nullptr, nullptr); - + // Translucents + addPipeline( + Key::Builder().withMaterial().withTranslucent(), + modelVertex, modelTranslucentPixel, batchSetter, itemSetter, nullptr, nullptr); + addPipeline( + Key::Builder().withMaterial().withTranslucent().withTangents(), + modelNormalMapVertex, modelTranslucentPixel, batchSetter, itemSetter, nullptr, nullptr); + addPipeline( + Key::Builder().withMaterial().withTranslucent().withSpecular(), + modelVertex, modelTranslucentPixel, batchSetter, itemSetter, nullptr, nullptr); + addPipeline( + Key::Builder().withMaterial().withTranslucent().withTangents().withSpecular(), + modelNormalMapVertex, modelTranslucentPixel, batchSetter, itemSetter, nullptr, nullptr); + addPipeline( + Key::Builder().withMaterial().withSkinned().withTranslucent().withTangents(), + skinModelNormalMapVertex, modelTranslucentPixel, batchSetter, itemSetter, nullptr, nullptr); + addPipeline( + Key::Builder().withMaterial().withSkinned().withTranslucent(), + skinModelVertex, modelTranslucentPixel, batchSetter, itemSetter, nullptr, nullptr); } void addPlumberPipeline(ShapePlumber& plumber,