forward pipelines for primitives

This commit is contained in:
SamGondelman 2018-03-30 16:35:51 -07:00
parent e8a62d2943
commit 0c069574c5
22 changed files with 587 additions and 180 deletions

View file

@ -18,6 +18,18 @@
#include "render-utils/simple_vert.h" #include "render-utils/simple_vert.h"
#include "render-utils/simple_frag.h" #include "render-utils/simple_frag.h"
#include "render-utils/simple_transparent_frag.h"
#include "render-utils/forward_simple_frag.h"
#include "render-utils/forward_simple_transparent_frag.h"
#include <QProcess>
#if defined(USE_GLES)
static bool DISABLE_DEFERRED = true;
#else
static const QString RENDER_FORWARD{ "HIFI_RENDER_FORWARD" };
static bool DISABLE_DEFERRED = QProcessEnvironment::systemEnvironment().contains(RENDER_FORWARD);
#endif
#include "RenderPipelines.h" #include "RenderPipelines.h"
@ -35,13 +47,20 @@ static const float SPHERE_ENTITY_SCALE = 0.5f;
ShapeEntityRenderer::ShapeEntityRenderer(const EntityItemPointer& entity) : Parent(entity) { ShapeEntityRenderer::ShapeEntityRenderer(const EntityItemPointer& entity) : Parent(entity) {
_procedural._vertexSource = simple_vert::getSource(); _procedural._vertexSource = simple_vert::getSource();
_procedural._fragmentSource = simple_frag::getSource(); _procedural._opaquefragmentSource = DISABLE_DEFERRED ? forward_simple_frag::getSource() : simple_frag::getSource();
_procedural._transparentfragmentSource = DISABLE_DEFERRED ? forward_simple_transparent_frag::getSource() : simple_transparent_frag::getSource();
_procedural._opaqueState->setCullMode(gpu::State::CULL_NONE); _procedural._opaqueState->setCullMode(gpu::State::CULL_NONE);
_procedural._opaqueState->setDepthTest(true, true, gpu::LESS_EQUAL); _procedural._opaqueState->setDepthTest(true, true, gpu::LESS_EQUAL);
PrepareStencil::testMaskDrawShape(*_procedural._opaqueState); PrepareStencil::testMaskDrawShape(*_procedural._opaqueState);
_procedural._opaqueState->setBlendFunction(false, _procedural._opaqueState->setBlendFunction(false,
gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA,
gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE); gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE);
_procedural._transparentState->setCullMode(gpu::State::CULL_BACK);
_procedural._transparentState->setDepthTest(true, true, gpu::LESS_EQUAL);
PrepareStencil::testMask(*_procedural._transparentState);
_procedural._transparentState->setBlendFunction(true,
gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA,
gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE);
} }
bool ShapeEntityRenderer::needsRenderUpdate() const { bool ShapeEntityRenderer::needsRenderUpdate() const {
@ -216,9 +235,9 @@ void ShapeEntityRenderer::doRender(RenderArgs* args) {
if (mat) { if (mat) {
outColor = glm::vec4(mat->getAlbedo(), mat->getOpacity()); outColor = glm::vec4(mat->getAlbedo(), mat->getOpacity());
if (_procedural.isReady()) { if (_procedural.isReady()) {
_procedural.prepare(batch, _position, _dimensions, _orientation);
outColor = _procedural.getColor(outColor); outColor = _procedural.getColor(outColor);
outColor.a *= _procedural.isFading() ? Interpolate::calculateFadeRatio(_procedural.getFadeStartTime()) : 1.0f; outColor.a *= _procedural.isFading() ? Interpolate::calculateFadeRatio(_procedural.getFadeStartTime()) : 1.0f;
_procedural.prepare(batch, _position, _dimensions, _orientation, outColor);
proceduralRender = true; proceduralRender = true;
} }
} }
@ -230,9 +249,9 @@ void ShapeEntityRenderer::doRender(RenderArgs* args) {
if (proceduralRender) { if (proceduralRender) {
if (render::ShapeKey(args->_globalShapeKey).isWireframe()) { if (render::ShapeKey(args->_globalShapeKey).isWireframe()) {
geometryCache->renderWireShape(batch, geometryShape, outColor); geometryCache->renderWireShapeColor(batch, geometryShape, outColor);
} else { } else {
geometryCache->renderShape(batch, geometryShape, outColor); geometryCache->renderShapeColor(batch, geometryShape, outColor);
} }
} else if (!useMaterialPipeline()) { } else if (!useMaterialPipeline()) {
// FIXME, support instanced multi-shape rendering using multidraw indirect // FIXME, support instanced multi-shape rendering using multidraw indirect

View file

@ -219,7 +219,29 @@ bool Procedural::isReady() const {
return true; return true;
} }
void Procedural::prepare(gpu::Batch& batch, const glm::vec3& position, const glm::vec3& size, const glm::quat& orientation) { std::string Procedural::replaceProceduralBlock(const std::string& fragmentSource) {
std::string fragmentShaderSource = fragmentSource;
size_t replaceIndex = fragmentShaderSource.find(PROCEDURAL_COMMON_BLOCK);
if (replaceIndex != std::string::npos) {
fragmentShaderSource.replace(replaceIndex, PROCEDURAL_COMMON_BLOCK.size(), ProceduralCommon_frag::getSource());
}
replaceIndex = fragmentShaderSource.find(PROCEDURAL_VERSION);
if (replaceIndex != std::string::npos) {
if (_data.version == 1) {
fragmentShaderSource.replace(replaceIndex, PROCEDURAL_VERSION.size(), "#define PROCEDURAL_V1 1");
} else if (_data.version == 2) {
fragmentShaderSource.replace(replaceIndex, PROCEDURAL_VERSION.size(), "#define PROCEDURAL_V2 1");
}
}
replaceIndex = fragmentShaderSource.find(PROCEDURAL_BLOCK);
if (replaceIndex != std::string::npos) {
fragmentShaderSource.replace(replaceIndex, PROCEDURAL_BLOCK.size(), _shaderSource.toLocal8Bit().data());
}
return fragmentShaderSource;
}
void Procedural::prepare(gpu::Batch& batch, const glm::vec3& position, const glm::vec3& size, const glm::quat& orientation, const glm::vec4& color) {
_entityDimensions = size; _entityDimensions = size;
_entityPosition = position; _entityPosition = position;
_entityOrientation = glm::mat3_cast(orientation); _entityOrientation = glm::mat3_cast(orientation);
@ -242,49 +264,36 @@ void Procedural::prepare(gpu::Batch& batch, const glm::vec3& position, const glm
} }
// Build the fragment shader // Build the fragment shader
std::string fragmentShaderSource = _fragmentSource; std::string opaqueShaderSource = replaceProceduralBlock(_opaquefragmentSource);
size_t replaceIndex = fragmentShaderSource.find(PROCEDURAL_COMMON_BLOCK); std::string transparentShaderSource = replaceProceduralBlock(_transparentfragmentSource);
if (replaceIndex != std::string::npos) {
fragmentShaderSource.replace(replaceIndex, PROCEDURAL_COMMON_BLOCK.size(), ProceduralCommon_frag::getSource());
}
replaceIndex = fragmentShaderSource.find(PROCEDURAL_VERSION);
if (replaceIndex != std::string::npos) {
if (_data.version == 1) {
fragmentShaderSource.replace(replaceIndex, PROCEDURAL_VERSION.size(), "#define PROCEDURAL_V1 1");
} else if (_data.version == 2) {
fragmentShaderSource.replace(replaceIndex, PROCEDURAL_VERSION.size(), "#define PROCEDURAL_V2 1");
}
}
replaceIndex = fragmentShaderSource.find(PROCEDURAL_BLOCK);
if (replaceIndex != std::string::npos) {
fragmentShaderSource.replace(replaceIndex, PROCEDURAL_BLOCK.size(), _shaderSource.toLocal8Bit().data());
}
// Leave this here for debugging // Leave this here for debugging
// qCDebug(procedural) << "FragmentShader:\n" << fragmentShaderSource.c_str(); // qCDebug(procedural) << "FragmentShader:\n" << fragmentShaderSource.c_str();
_fragmentShader = gpu::Shader::createPixel(fragmentShaderSource); _opaqueFragmentShader = gpu::Shader::createPixel(opaqueShaderSource);
_shader = gpu::Shader::createProgram(_vertexShader, _fragmentShader); _opaqueShader = gpu::Shader::createProgram(_vertexShader, _opaqueFragmentShader);
_transparentFragmentShader = gpu::Shader::createPixel(transparentShaderSource);
_transparentShader = gpu::Shader::createProgram(_vertexShader, _transparentFragmentShader);
gpu::Shader::BindingSet slotBindings; gpu::Shader::BindingSet slotBindings;
slotBindings.insert(gpu::Shader::Binding(std::string("iChannel0"), 0)); slotBindings.insert(gpu::Shader::Binding(std::string("iChannel0"), 0));
slotBindings.insert(gpu::Shader::Binding(std::string("iChannel1"), 1)); slotBindings.insert(gpu::Shader::Binding(std::string("iChannel1"), 1));
slotBindings.insert(gpu::Shader::Binding(std::string("iChannel2"), 2)); slotBindings.insert(gpu::Shader::Binding(std::string("iChannel2"), 2));
slotBindings.insert(gpu::Shader::Binding(std::string("iChannel3"), 3)); slotBindings.insert(gpu::Shader::Binding(std::string("iChannel3"), 3));
gpu::Shader::makeProgram(*_shader, slotBindings); gpu::Shader::makeProgram(*_opaqueShader, slotBindings);
gpu::Shader::makeProgram(*_transparentShader, slotBindings);
_opaquePipeline = gpu::Pipeline::create(_shader, _opaqueState); _opaquePipeline = gpu::Pipeline::create(_opaqueShader, _opaqueState);
_transparentPipeline = gpu::Pipeline::create(_shader, _transparentState); _transparentPipeline = gpu::Pipeline::create(_transparentShader, _transparentState);
for (size_t i = 0; i < NUM_STANDARD_UNIFORMS; ++i) { for (size_t i = 0; i < NUM_STANDARD_UNIFORMS; ++i) {
const std::string& name = STANDARD_UNIFORM_NAMES[i]; const std::string& name = STANDARD_UNIFORM_NAMES[i];
_standardUniformSlots[i] = _shader->getUniforms().findLocation(name); _standardUniformSlots[i] = _opaqueShader->getUniforms().findLocation(name);
} }
_start = usecTimestampNow(); _start = usecTimestampNow();
_frameCount = 0; _frameCount = 0;
} }
batch.setPipeline(isFading() ? _transparentPipeline : _opaquePipeline); batch.setPipeline(color.a < 1.0f ? _transparentPipeline : _opaquePipeline);
if (_shaderDirty || _uniformsDirty) { if (_shaderDirty || _uniformsDirty) {
setupUniforms(); setupUniforms();
@ -324,7 +333,7 @@ void Procedural::setupUniforms() {
// Set any userdata specified uniforms // Set any userdata specified uniforms
foreach(QString key, _data.uniforms.keys()) { foreach(QString key, _data.uniforms.keys()) {
std::string uniformName = key.toLocal8Bit().data(); std::string uniformName = key.toLocal8Bit().data();
int32_t slot = _shader->getUniforms().findLocation(uniformName); int32_t slot = _opaqueShader->getUniforms().findLocation(uniformName);
if (gpu::Shader::INVALID_LOCATION == slot) { if (gpu::Shader::INVALID_LOCATION == slot) {
continue; continue;
} }

View file

@ -55,8 +55,8 @@ public:
bool isReady() const; bool isReady() const;
bool isEnabled() const { return _enabled; } bool isEnabled() const { return _enabled; }
void prepare(gpu::Batch& batch, const glm::vec3& position, const glm::vec3& size, const glm::quat& orientation); void prepare(gpu::Batch& batch, const glm::vec3& position, const glm::vec3& size, const glm::quat& orientation, const glm::vec4& color = glm::vec4(1));
const gpu::ShaderPointer& getShader() const { return _shader; } const gpu::ShaderPointer& getOpaqueShader() const { return _opaqueShader; }
glm::vec4 getColor(const glm::vec4& entityColor); glm::vec4 getColor(const glm::vec4& entityColor);
quint64 getFadeStartTime() const { return _fadeStartTime; } quint64 getFadeStartTime() const { return _fadeStartTime; }
@ -65,7 +65,8 @@ public:
void setDoesFade(bool doesFade) { _doesFade = doesFade; } void setDoesFade(bool doesFade) { _doesFade = doesFade; }
std::string _vertexSource; std::string _vertexSource;
std::string _fragmentSource; std::string _opaquefragmentSource;
std::string _transparentfragmentSource;
gpu::StatePointer _opaqueState { std::make_shared<gpu::State>() }; gpu::StatePointer _opaqueState { std::make_shared<gpu::State>() };
gpu::StatePointer _transparentState { std::make_shared<gpu::State>() }; gpu::StatePointer _transparentState { std::make_shared<gpu::State>() };
@ -106,8 +107,10 @@ protected:
gpu::PipelinePointer _opaquePipeline; gpu::PipelinePointer _opaquePipeline;
gpu::PipelinePointer _transparentPipeline; gpu::PipelinePointer _transparentPipeline;
gpu::ShaderPointer _vertexShader; gpu::ShaderPointer _vertexShader;
gpu::ShaderPointer _fragmentShader; gpu::ShaderPointer _opaqueFragmentShader;
gpu::ShaderPointer _shader; gpu::ShaderPointer _transparentFragmentShader;
gpu::ShaderPointer _opaqueShader;
gpu::ShaderPointer _transparentShader;
// Entity metadata // Entity metadata
glm::vec3 _entityDimensions; glm::vec3 _entityDimensions;
@ -119,6 +122,8 @@ private:
void setupUniforms(); void setupUniforms();
void setupChannels(bool shouldCreate); void setupChannels(bool shouldCreate);
std::string replaceProceduralBlock(const std::string& fragmentSource);
mutable quint64 _fadeStartTime { 0 }; mutable quint64 _fadeStartTime { 0 };
mutable bool _hasStartedFade { false }; mutable bool _hasStartedFade { false };
mutable bool _isFading { false }; mutable bool _isFading { false };

View file

@ -20,7 +20,7 @@
ProceduralSkybox::ProceduralSkybox() : graphics::Skybox() { ProceduralSkybox::ProceduralSkybox() : graphics::Skybox() {
_procedural._vertexSource = skybox_vert::getSource(); _procedural._vertexSource = skybox_vert::getSource();
_procedural._fragmentSource = skybox_frag::getSource(); _procedural._opaquefragmentSource = skybox_frag::getSource();
// Adjust the pipeline state for background using the stencil test // Adjust the pipeline state for background using the stencil test
_procedural.setDoesFade(false); _procedural.setDoesFade(false);
// Must match PrepareStencil::STENCIL_BACKGROUND // Must match PrepareStencil::STENCIL_BACKGROUND
@ -61,8 +61,8 @@ void ProceduralSkybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum,
auto& procedural = skybox._procedural; auto& procedural = skybox._procedural;
procedural.prepare(batch, glm::vec3(0), glm::vec3(1), glm::quat()); procedural.prepare(batch, glm::vec3(0), glm::vec3(1), glm::quat());
auto textureSlot = procedural.getShader()->getTextures().findLocation("cubeMap"); auto textureSlot = procedural.getOpaqueShader()->getTextures().findLocation("cubeMap");
auto bufferSlot = procedural.getShader()->getUniformBuffers().findLocation("skyboxBuffer"); auto bufferSlot = procedural.getOpaqueShader()->getUniformBuffers().findLocation("skyboxBuffer");
skybox.prepare(batch, textureSlot, bufferSlot); skybox.prepare(batch, textureSlot, bufferSlot);
batch.draw(gpu::TRIANGLE_STRIP, 4); batch.draw(gpu::TRIANGLE_STRIP, 4);
} }

View file

@ -0,0 +1,23 @@
<!
// DefaultMaterials.slh
// libraries/render-utils/src
//
// Created by Sam Gondelman on 3/22/18
// Copyright 2018 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
!>
<@if not DEFAULT_MATERIAL_SLH@>
<@def DEFAULT_MATERIAL_SLH@>
const float DEFAULT_ROUGHNESS = 0.9;
const float DEFAULT_SHININESS = 10.0;
const float DEFAULT_METALLIC = 0.0;
const vec3 DEFAULT_SPECULAR = vec3(0.1);
const vec3 DEFAULT_EMISSIVE = vec3(0.0);
const float DEFAULT_OCCLUSION = 1.0;
const float DEFAULT_SCATTERING = 0.0;
const vec3 DEFAULT_FRESNEL = DEFAULT_EMISSIVE;
<@endif@>

View file

@ -26,14 +26,7 @@ float evalOpaqueFinalAlpha(float alpha, float mapAlpha) {
return mix(alpha, 1.0 - alpha, step(mapAlpha, alphaThreshold)); return mix(alpha, 1.0 - alpha, step(mapAlpha, alphaThreshold));
} }
const float DEFAULT_ROUGHNESS = 0.9; <@include DefaultMaterials.slh@>
const float DEFAULT_SHININESS = 10.0;
const float DEFAULT_METALLIC = 0.0;
const vec3 DEFAULT_SPECULAR = vec3(0.1);
const vec3 DEFAULT_EMISSIVE = vec3(0.0);
const float DEFAULT_OCCLUSION = 1.0;
const float DEFAULT_SCATTERING = 0.0;
const vec3 DEFAULT_FRESNEL = DEFAULT_EMISSIVE;
void packDeferredFragment(vec3 normal, float alpha, vec3 albedo, float roughness, float metallic, vec3 emissive, float occlusion, float scattering) { void packDeferredFragment(vec3 normal, float alpha, vec3 albedo, float roughness, float metallic, vec3 emissive, float occlusion, float scattering) {
if (alpha != 1.0) { if (alpha != 1.0) {

View file

@ -40,6 +40,7 @@
#include "simple_vert.h" #include "simple_vert.h"
#include "simple_textured_frag.h" #include "simple_textured_frag.h"
#include "simple_transparent_textured_frag.h"
#include "simple_textured_unlit_frag.h" #include "simple_textured_unlit_frag.h"
#include "simple_fade_vert.h" #include "simple_fade_vert.h"
#include "simple_textured_fade_frag.h" #include "simple_textured_fade_frag.h"
@ -49,6 +50,19 @@
#include "glowLine_vert.h" #include "glowLine_vert.h"
#include "glowLine_frag.h" #include "glowLine_frag.h"
#include "forward_simple_textured_frag.h"
#include "forward_simple_textured_transparent_frag.h"
#include "forward_simple_textured_unlit_frag.h"
#include "DeferredLightingEffect.h"
#if defined(USE_GLES)
static bool DISABLE_DEFERRED = true;
#else
static const QString RENDER_FORWARD{ "HIFI_RENDER_FORWARD" };
static bool DISABLE_DEFERRED = QProcessEnvironment::systemEnvironment().contains(RENDER_FORWARD);
#endif
#include "grid_frag.h" #include "grid_frag.h"
//#define WANT_DEBUG //#define WANT_DEBUG
@ -679,6 +693,7 @@ gpu::Stream::FormatPointer& getInstancedSolidFadeStreamFormat() {
QHash<SimpleProgramKey, gpu::PipelinePointer> GeometryCache::_simplePrograms; QHash<SimpleProgramKey, gpu::PipelinePointer> GeometryCache::_simplePrograms;
gpu::ShaderPointer GeometryCache::_simpleShader; gpu::ShaderPointer GeometryCache::_simpleShader;
gpu::ShaderPointer GeometryCache::_transparentShader;
gpu::ShaderPointer GeometryCache::_unlitShader; gpu::ShaderPointer GeometryCache::_unlitShader;
gpu::ShaderPointer GeometryCache::_simpleFadeShader; gpu::ShaderPointer GeometryCache::_simpleFadeShader;
gpu::ShaderPointer GeometryCache::_unlitFadeShader; gpu::ShaderPointer GeometryCache::_unlitFadeShader;
@ -774,8 +789,12 @@ render::ShapePipelinePointer GeometryCache::getShapePipeline(bool textured, bool
bool unlit, bool depthBias) { bool unlit, bool depthBias) {
return std::make_shared<render::ShapePipeline>(getSimplePipeline(textured, transparent, culled, unlit, depthBias, false, true), nullptr, return std::make_shared<render::ShapePipeline>(getSimplePipeline(textured, transparent, culled, unlit, depthBias, false, true), nullptr,
[](const render::ShapePipeline& , gpu::Batch& batch, render::Args*) { [](const render::ShapePipeline& pipeline, gpu::Batch& batch, render::Args* args) {
batch.setResourceTexture(render::ShapePipeline::Slot::MAP::ALBEDO, DependencyManager::get<TextureCache>()->getWhiteTexture()); batch.setResourceTexture(render::ShapePipeline::Slot::MAP::ALBEDO, DependencyManager::get<TextureCache>()->getWhiteTexture());
DependencyManager::get<DeferredLightingEffect>()->setupKeyLightBatch(args, batch,
pipeline.pipeline->getProgram()->getUniformBuffers().findLocation("keyLightBuffer"),
pipeline.pipeline->getProgram()->getUniformBuffers().findLocation("lightAmbientBuffer"),
pipeline.pipeline->getProgram()->getUniformBuffers().findLocation("skyboxMap"));
} }
); );
} }
@ -826,6 +845,20 @@ void GeometryCache::renderWireShape(gpu::Batch& batch, Shape shape, const glm::v
_shapes[shape].drawWire(batch); _shapes[shape].drawWire(batch);
} }
void GeometryCache::renderShapeColor(gpu::Batch& batch, Shape shape, const glm::vec4& color) {
batch.setInputFormat(getInstancedSolidStreamFormat());
// Color must be set after input format
batch._glColor4f(color.r, color.g, color.b, color.a);
_shapes[shape].draw(batch);
}
void GeometryCache::renderWireShapeColor(gpu::Batch& batch, Shape shape, const glm::vec4& color) {
batch.setInputFormat(getInstancedSolidStreamFormat());
// Color must be set after input format
batch._glColor4f(color.r, color.g, color.b, color.a);
_shapes[shape].drawWire(batch);
}
void setupBatchInstance(gpu::Batch& batch, gpu::BufferPointer colorBuffer) { void setupBatchInstance(gpu::Batch& batch, gpu::BufferPointer colorBuffer) {
gpu::BufferView colorView(colorBuffer, COLOR_ELEMENT); gpu::BufferView colorView(colorBuffer, COLOR_ELEMENT);
batch.setInputBuffer(gpu::Stream::COLOR, colorView); batch.setInputBuffer(gpu::Stream::COLOR, colorView);
@ -2231,29 +2264,40 @@ gpu::PipelinePointer GeometryCache::getSimplePipeline(bool textured, bool transp
static std::once_flag once; static std::once_flag once;
std::call_once(once, [&]() { std::call_once(once, [&]() {
auto VS = simple_vert::getShader(); auto VS = simple_vert::getShader();
auto PS = simple_textured_frag::getShader(); auto PS = DISABLE_DEFERRED ? forward_simple_textured_frag::getShader() : simple_textured_frag::getShader();
auto PSUnlit = simple_textured_unlit_frag::getShader(); auto PSTransparent = DISABLE_DEFERRED ? forward_simple_textured_transparent_frag::getShader() : simple_transparent_textured_frag::getShader();
auto PSUnlit = DISABLE_DEFERRED ? forward_simple_textured_unlit_frag::getShader() : simple_textured_unlit_frag::getShader();
_simpleShader = gpu::Shader::createProgram(VS, PS); _simpleShader = gpu::Shader::createProgram(VS, PS);
_transparentShader = gpu::Shader::createProgram(VS, PSTransparent);
_unlitShader = gpu::Shader::createProgram(VS, PSUnlit); _unlitShader = gpu::Shader::createProgram(VS, PSUnlit);
gpu::Shader::BindingSet slotBindings; gpu::Shader::BindingSet slotBindings;
slotBindings.insert(gpu::Shader::Binding(std::string("originalTexture"), render::ShapePipeline::Slot::MAP::ALBEDO)); slotBindings.insert(gpu::Shader::Binding(std::string("originalTexture"), render::ShapePipeline::Slot::MAP::ALBEDO));
slotBindings.insert(gpu::Shader::Binding(std::string("lightingModelBuffer"), render::ShapePipeline::Slot::LIGHTING_MODEL));
slotBindings.insert(gpu::Shader::Binding(std::string("keyLightBuffer"), render::ShapePipeline::Slot::KEY_LIGHT));
slotBindings.insert(gpu::Shader::Binding(std::string("lightAmbientBuffer"), render::ShapePipeline::Slot::LIGHT_AMBIENT_BUFFER));
slotBindings.insert(gpu::Shader::Binding(std::string("skyboxMap"), render::ShapePipeline::Slot::MAP::LIGHT_AMBIENT));
gpu::Shader::makeProgram(*_simpleShader, slotBindings); gpu::Shader::makeProgram(*_simpleShader, slotBindings);
gpu::Shader::makeProgram(*_transparentShader, slotBindings);
gpu::Shader::makeProgram(*_unlitShader, slotBindings); gpu::Shader::makeProgram(*_unlitShader, slotBindings);
}); });
} else { } else {
static std::once_flag once; static std::once_flag once;
std::call_once(once, [&]() { std::call_once(once, [&]() {
auto VS = simple_fade_vert::getShader(); auto VS = simple_fade_vert::getShader();
auto PS = simple_textured_fade_frag::getShader(); auto PS = DISABLE_DEFERRED ? forward_simple_textured_frag::getShader() : simple_textured_fade_frag::getShader();
auto PSUnlit = simple_textured_unlit_fade_frag::getShader(); auto PSUnlit = DISABLE_DEFERRED ? forward_simple_textured_unlit_frag::getShader() : simple_textured_unlit_fade_frag::getShader();
_simpleFadeShader = gpu::Shader::createProgram(VS, PS); _simpleFadeShader = gpu::Shader::createProgram(VS, PS);
_unlitFadeShader = gpu::Shader::createProgram(VS, PSUnlit); _unlitFadeShader = gpu::Shader::createProgram(VS, PSUnlit);
gpu::Shader::BindingSet slotBindings; gpu::Shader::BindingSet slotBindings;
slotBindings.insert(gpu::Shader::Binding(std::string("originalTexture"), render::ShapePipeline::Slot::MAP::ALBEDO)); slotBindings.insert(gpu::Shader::Binding(std::string("originalTexture"), render::ShapePipeline::Slot::MAP::ALBEDO));
slotBindings.insert(gpu::Shader::Binding(std::string("lightingModelBuffer"), render::ShapePipeline::Slot::LIGHTING_MODEL));
slotBindings.insert(gpu::Shader::Binding(std::string("keyLightBuffer"), render::ShapePipeline::Slot::KEY_LIGHT));
slotBindings.insert(gpu::Shader::Binding(std::string("lightAmbientBuffer"), render::ShapePipeline::Slot::LIGHT_AMBIENT_BUFFER));
slotBindings.insert(gpu::Shader::Binding(std::string("skyboxMap"), render::ShapePipeline::Slot::MAP::LIGHT_AMBIENT));
slotBindings.insert(gpu::Shader::Binding(std::string("fadeMaskMap"), render::ShapePipeline::Slot::MAP::FADE_MASK)); slotBindings.insert(gpu::Shader::Binding(std::string("fadeMaskMap"), render::ShapePipeline::Slot::MAP::FADE_MASK));
gpu::Shader::makeProgram(*_simpleFadeShader, slotBindings); gpu::Shader::makeProgram(*_simpleFadeShader, slotBindings);
gpu::Shader::makeProgram(*_unlitFadeShader, slotBindings); gpu::Shader::makeProgram(*_unlitFadeShader, slotBindings);
@ -2282,7 +2326,8 @@ gpu::PipelinePointer GeometryCache::getSimplePipeline(bool textured, bool transp
PrepareStencil::testMaskDrawShapeNoAA(*state); PrepareStencil::testMaskDrawShapeNoAA(*state);
} }
gpu::ShaderPointer program = (config.isUnlit()) ? (config.isFading() ? _unlitFadeShader : _unlitShader) : (config.isFading() ? _simpleFadeShader : _simpleShader); gpu::ShaderPointer program = (config.isUnlit()) ? (config.isFading() ? _unlitFadeShader : _unlitShader) :
(config.isFading() ? _simpleFadeShader : (config.isTransparent() ? _transparentShader : _simpleShader));
gpu::PipelinePointer pipeline = gpu::Pipeline::create(program, state); gpu::PipelinePointer pipeline = gpu::Pipeline::create(program, state);
_simplePrograms.insert(config, pipeline); _simplePrograms.insert(config, pipeline);
return pipeline; return pipeline;

View file

@ -253,6 +253,8 @@ public:
void renderWireShape(gpu::Batch& batch, Shape shape); void renderWireShape(gpu::Batch& batch, Shape shape);
void renderShape(gpu::Batch& batch, Shape shape, const glm::vec4& color); void renderShape(gpu::Batch& batch, Shape shape, const glm::vec4& color);
void renderWireShape(gpu::Batch& batch, Shape shape, const glm::vec4& color); void renderWireShape(gpu::Batch& batch, Shape shape, const glm::vec4& color);
void renderShapeColor(gpu::Batch& batch, Shape shape, const glm::vec4& color);
void renderWireShapeColor(gpu::Batch& batch, Shape shape, const glm::vec4& color);
size_t getShapeTriangleCount(Shape shape); size_t getShapeTriangleCount(Shape shape);
void renderCube(gpu::Batch& batch); void renderCube(gpu::Batch& batch);
@ -471,6 +473,7 @@ private:
QHash<int, GridBuffer> _registeredGridBuffers; QHash<int, GridBuffer> _registeredGridBuffers;
static gpu::ShaderPointer _simpleShader; static gpu::ShaderPointer _simpleShader;
static gpu::ShaderPointer _transparentShader;
static gpu::ShaderPointer _unlitShader; static gpu::ShaderPointer _unlitShader;
static gpu::ShaderPointer _simpleFadeShader; static gpu::ShaderPointer _simpleFadeShader;
static gpu::ShaderPointer _unlitFadeShader; static gpu::ShaderPointer _unlitFadeShader;
@ -478,8 +481,6 @@ private:
static render::ShapePipelinePointer _simpleTransparentPipeline; static render::ShapePipelinePointer _simpleTransparentPipeline;
static render::ShapePipelinePointer _simpleOpaqueFadePipeline; static render::ShapePipelinePointer _simpleOpaqueFadePipeline;
static render::ShapePipelinePointer _simpleTransparentFadePipeline; static render::ShapePipelinePointer _simpleTransparentFadePipeline;
static render::ShapePipelinePointer _simpleOpaqueOverlayPipeline;
static render::ShapePipelinePointer _simpleTransparentOverlayPipeline;
static render::ShapePipelinePointer _simpleWirePipeline; static render::ShapePipelinePointer _simpleWirePipeline;
gpu::PipelinePointer _glowLinePipeline; gpu::PipelinePointer _glowLinePipeline;

View file

@ -111,15 +111,11 @@ void evalLightingAmbient(out vec3 diffuse, out vec3 specular, LightAmbient ambie
} }
<@endif@> <@endif@>
if (!(isObscuranceEnabled() > 0.0)) { obscurance = mix(1.0, obscurance, isObscuranceEnabled());
obscurance = 1.0;
}
float lightEnergy = obscurance * getLightAmbientIntensity(ambient); float lightEnergy = obscurance * getLightAmbientIntensity(ambient);
if (isAlbedoEnabled() > 0.0) { diffuse *= mix(vec3(1), albedo, isAlbedoEnabled());
diffuse *= albedo;
}
lightEnergy *= isAmbientEnabled(); lightEnergy *= isAmbientEnabled();
diffuse *= lightEnergy * isDiffuseEnabled(); diffuse *= lightEnergy * isDiffuseEnabled();

View file

@ -13,11 +13,19 @@
<@func declareLightingModel()@> <@func declareLightingModel()@>
#ifndef PRECISIONQ
#ifdef GL_ES
#define PRECISIONQ highp
#else
#define PRECISIONQ
#endif
#endif
struct LightingModel { struct LightingModel {
vec4 _UnlitEmissiveLightmapBackground; PRECISIONQ vec4 _UnlitEmissiveLightmapBackground;
vec4 _ScatteringDiffuseSpecularAlbedo; PRECISIONQ vec4 _ScatteringDiffuseSpecularAlbedo;
vec4 _AmbientDirectionalPointSpot; PRECISIONQ vec4 _AmbientDirectionalPointSpot;
vec4 _ShowContourObscuranceWireframe; PRECISIONQ vec4 _ShowContourObscuranceWireframe;
}; };
uniform lightingModelBuffer{ uniform lightingModelBuffer{
@ -256,9 +264,7 @@ void evalFragShading(out vec3 diffuse, out vec3 specular,
float metallic, vec3 fresnel, SurfaceData surface, vec3 albedo) { float metallic, vec3 fresnel, SurfaceData surface, vec3 albedo) {
vec4 shading = evalPBRShading(metallic, fresnel, surface); vec4 shading = evalPBRShading(metallic, fresnel, surface);
diffuse = vec3(shading.w); diffuse = vec3(shading.w);
if (isAlbedoEnabled() > 0.0) { diffuse *= mix(vec3(1.0), albedo, isAlbedoEnabled());
diffuse *= albedo;
}
specular = shading.xyz; specular = shading.xyz;
} }

View file

@ -1,10 +1,8 @@
// glsl / C++ compatible source as interface for Shadows // glsl / C++ compatible source as interface for Shadows
#ifdef __cplusplus #ifdef __cplusplus
# define MAT4 glm::mat4 # define MAT4 glm::mat4
# define VEC3 glm::vec3
#else #else
# define MAT4 mat4 # define MAT4 mat4
# define VEC3 vec3
#endif #endif
#define SHADOW_CASCADE_MAX_COUNT 4 #define SHADOW_CASCADE_MAX_COUNT 4

View file

@ -0,0 +1,85 @@
<@include gpu/Config.slh@>
<$VERSION_HEADER$>
// Generated on <$_SCRIBE_DATE$>
//
// forward_simple.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@>
<$declareEvalSkyboxGlobalColor()$>
<@include gpu/Transform.slh@>
<$declareStandardCameraTransform()$>
// the interpolated normal
in vec3 _normal;
in vec3 _modelNormal;
in vec4 _color;
in vec2 _texCoord0;
in vec4 _eyePosition;
layout(location = 0) out vec4 _fragColor0;
//PROCEDURAL_COMMON_BLOCK
#line 1001
//PROCEDURAL_BLOCK
#line 2030
void main(void) {
vec3 normal = normalize(_normal.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 = _eyePosition.xyz;
if (emissiveAmount > 0.0) {
_fragColor0 = vec4(evalSkyboxGlobalColor(
cam._viewInverse,
1.0,
DEFAULT_OCCLUSION,
fragPosition,
normal,
diffuse,
specular,
DEFAULT_METALLIC,
max(0.0, 1.0 - shininess / 128.0)),
1.0);
} else {
_fragColor0 = vec4(evalSkyboxGlobalColor(
cam._viewInverse,
1.0,
DEFAULT_OCCLUSION,
fragPosition,
normal,
diffuse,
DEFAULT_FRESNEL,
length(specular),
max(0.0, 1.0 - shininess / 128.0)),
1.0);
}
}

View file

@ -0,0 +1,51 @@
<@include gpu/Config.slh@>
<$VERSION_HEADER$>
// Generated on <$_SCRIBE_DATE$>
//
// forward_simple_textured.slf
// fragment shader
//
// Created by Clément Brisset on 5/29/15.
// 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@>
<$declareEvalSkyboxGlobalColor()$>
<@include gpu/Transform.slh@>
<$declareStandardCameraTransform()$>
// the albedo texture
uniform sampler2D originalTexture;
// the interpolated normal
in vec3 _normal;
in vec4 _color;
in vec2 _texCoord0;
in vec4 _eyePosition;
layout(location = 0) out vec4 _fragColor0;
void main(void) {
vec4 texel = texture(originalTexture, _texCoord0);
float colorAlpha = _color.a * texel.a;
TransformCamera cam = getTransformCamera();
vec3 fragPosition = _eyePosition.xyz;
_fragColor0 = vec4(evalSkyboxGlobalColor(
cam._viewInverse,
1.0,
DEFAULT_OCCLUSION,
fragPosition,
normalize(_normal),
_color.rgb * texel.rgb,
DEFAULT_FRESNEL,
DEFAULT_METALLIC,
DEFAULT_ROUGHNESS),
1.0);
}

View file

@ -0,0 +1,52 @@
<@include gpu/Config.slh@>
<$VERSION_HEADER$>
// Generated on <$_SCRIBE_DATE$>
//
// forward_simple_textured_transparent.slf
// fragment shader
//
// Created by Clément Brisset on 5/29/15.
// 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()$>
<@include gpu/Transform.slh@>
<$declareStandardCameraTransform()$>
// the albedo texture
uniform sampler2D originalTexture;
// the interpolated normal
in vec3 _normal;
in vec4 _color;
in vec2 _texCoord0;
in vec4 _eyePosition;
layout(location = 0) out vec4 _fragColor0;
void main(void) {
vec4 texel = texture(originalTexture, _texCoord0);
float colorAlpha = _color.a * texel.a;
TransformCamera cam = getTransformCamera();
vec3 fragPosition = _eyePosition.xyz;
_fragColor0 = vec4(evalGlobalLightingAlphaBlendedWithHaze(
cam._viewInverse,
1.0,
DEFAULT_OCCLUSION,
fragPosition,
normalize(_normal),
_color.rgb * texel.rgb,
DEFAULT_FRESNEL,
DEFAULT_METALLIC,
DEFAULT_EMISSIVE,
DEFAULT_ROUGHNESS, colorAlpha),
colorAlpha);
}

View file

@ -0,0 +1,35 @@
<@include gpu/Config.slh@>
<$VERSION_HEADER$>
// Generated on <$_SCRIBE_DATE$>
//
// simple_textured_unlit.frag
// fragment shader
//
// Created by Clément Brisset on 5/29/15.
// 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 LightingModel.slh@>
<@include gpu/Color.slh@>
layout(location = 0) out vec4 _fragColor0;
// the albedo texture
uniform sampler2D originalTexture;
in vec4 _color;
in vec2 _texCoord0;
void main(void) {
vec4 texel = texture(originalTexture, _texCoord0.st);
float colorAlpha = _color.a;
if (_color.a <= 0.0) {
texel = color_sRGBAToLinear(texel);
colorAlpha = -_color.a;
}
_fragColor0 = vec4(_color.rgb * texel.rgb * isUnlitEnabled(), colorAlpha * texel.a);
}

View file

@ -0,0 +1,87 @@
<@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()$>
<@include gpu/Transform.slh@>
<$declareStandardCameraTransform()$>
// the interpolated normal
in vec3 _normal;
in vec3 _modelNormal;
in vec4 _color;
in vec2 _texCoord0;
in vec4 _eyePosition;
layout(location = 0) out vec4 _fragColor0;
//PROCEDURAL_COMMON_BLOCK
#line 1001
//PROCEDURAL_BLOCK
#line 2030
void main(void) {
vec3 normal = normalize(_normal.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 = _eyePosition.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);
}
}

View file

@ -13,7 +13,6 @@
// //
<@include DeferredBufferWrite.slh@> <@include DeferredBufferWrite.slh@>
<@include graphics/Material.slh@>
// the interpolated normal // the interpolated normal
in vec3 _normal; in vec3 _normal;
@ -29,7 +28,6 @@ in vec4 _position;
#line 2030 #line 2030
void main(void) { void main(void) {
Material material = getMaterial();
vec3 normal = normalize(_normal.xyz); vec3 normal = normalize(_normal.xyz);
vec3 diffuse = _color.rgb; vec3 diffuse = _color.rgb;
vec3 specular = DEFAULT_SPECULAR; vec3 specular = DEFAULT_SPECULAR;
@ -49,24 +47,6 @@ void main(void) {
#endif #endif
const float ALPHA_THRESHOLD = 0.999;
if (_color.a < ALPHA_THRESHOLD) {
if (emissiveAmount > 0.0) {
packDeferredFragmentTranslucent(
normal,
_color.a,
specular,
DEFAULT_FRESNEL,
DEFAULT_ROUGHNESS);
} else {
packDeferredFragmentTranslucent(
normal,
_color.a,
diffuse,
DEFAULT_FRESNEL,
DEFAULT_ROUGHNESS);
}
} else {
if (emissiveAmount > 0.0) { if (emissiveAmount > 0.0) {
packDeferredFragmentLightmap( packDeferredFragmentLightmap(
normal, normal,
@ -88,4 +68,3 @@ void main(void) {
DEFAULT_SCATTERING); DEFAULT_SCATTERING);
} }
} }
}

View file

@ -23,6 +23,7 @@ out vec3 _modelNormal;
out vec4 _color; out vec4 _color;
out vec2 _texCoord0; out vec2 _texCoord0;
out vec4 _position; out vec4 _position;
out vec4 _eyePosition;
void main(void) { void main(void) {
_color = color_sRGBAToLinear(inColor); _color = color_sRGBAToLinear(inColor);
@ -33,6 +34,6 @@ void main(void) {
// standard transform // standard transform
TransformCamera cam = getTransformCamera(); TransformCamera cam = getTransformCamera();
TransformObject obj = getTransformObject(); TransformObject obj = getTransformObject();
<$transformModelToClipPos(cam, obj, inPosition, gl_Position)$> <$transformModelToEyeAndClipPos(cam, obj, inPosition, _eyePosition, gl_Position)$>
<$transformModelToWorldDir(cam, obj, inNormal.xyz, _normal)$> <$transformModelToWorldDir(cam, obj, inNormal.xyz, _normal)$>
} }

View file

@ -26,6 +26,7 @@ out vec3 _modelNormal;
out vec4 _color; out vec4 _color;
out vec2 _texCoord0; out vec2 _texCoord0;
out vec4 _position; out vec4 _position;
out vec4 _eyePosition;
out vec4 _worldPosition; out vec4 _worldPosition;
void main(void) { void main(void) {
@ -37,7 +38,7 @@ void main(void) {
// standard transform // standard transform
TransformCamera cam = getTransformCamera(); TransformCamera cam = getTransformCamera();
TransformObject obj = getTransformObject(); TransformObject obj = getTransformObject();
<$transformModelToClipPos(cam, obj, inPosition, gl_Position)$> <$transformModelToEyeAndClipPos(cam, obj, inPosition, _eyePosition, gl_Position)$>
<$transformModelToWorldPos(obj, inPosition, _worldPosition)$> <$transformModelToWorldPos(obj, inPosition, _worldPosition)$>
<$transformModelToWorldDir(cam, obj, inNormal.xyz, _normal)$> <$transformModelToWorldDir(cam, obj, inNormal.xyz, _normal)$>
<$passThroughFadeObjectParams()$> <$passThroughFadeObjectParams()$>

View file

@ -12,9 +12,7 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
<@include gpu/Color.slh@>
<@include DeferredBufferWrite.slh@> <@include DeferredBufferWrite.slh@>
<@include graphics/Material.slh@>
// the albedo texture // the albedo texture
uniform sampler2D originalTexture; uniform sampler2D originalTexture;
@ -26,21 +24,7 @@ in vec2 _texCoord0;
void main(void) { void main(void) {
vec4 texel = texture(originalTexture, _texCoord0); vec4 texel = texture(originalTexture, _texCoord0);
float colorAlpha = _color.a;
if (_color.a <= 0.0) {
texel = color_sRGBAToLinear(texel);
colorAlpha = -_color.a;
}
const float ALPHA_THRESHOLD = 0.999;
if (colorAlpha * texel.a < ALPHA_THRESHOLD) {
packDeferredFragmentTranslucent(
normalize(_normal),
colorAlpha * texel.a,
_color.rgb * texel.rgb,
DEFAULT_FRESNEL,
DEFAULT_ROUGHNESS);
} else {
packDeferredFragment( packDeferredFragment(
normalize(_normal), normalize(_normal),
1.0, 1.0,
@ -51,4 +35,3 @@ void main(void) {
DEFAULT_OCCLUSION, DEFAULT_OCCLUSION,
DEFAULT_SCATTERING); DEFAULT_SCATTERING);
} }
}

View file

@ -0,0 +1,65 @@
<@include gpu/Config.slh@>
<$VERSION_HEADER$>
// Generated on <$_SCRIBE_DATE$>
//
// 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 DeferredBufferWrite.slh@>
// the interpolated normal
in vec3 _normal;
in vec3 _modelNormal;
in vec4 _color;
in vec2 _texCoord0;
in vec4 _position;
//PROCEDURAL_COMMON_BLOCK
#line 1001
//PROCEDURAL_BLOCK
#line 2030
void main(void) {
vec3 normal = normalize(_normal.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
if (emissiveAmount > 0.0) {
packDeferredFragmentTranslucent(
normal,
_color.a,
specular,
DEFAULT_FRESNEL,
DEFAULT_ROUGHNESS);
} else {
packDeferredFragmentTranslucent(
normal,
_color.a,
diffuse,
DEFAULT_FRESNEL,
DEFAULT_ROUGHNESS);
}
}

View file

@ -12,51 +12,24 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
<@include gpu/Color.slh@>
<@include DeferredBufferWrite.slh@> <@include DeferredBufferWrite.slh@>
<@include DeferredGlobalLight.slh@>
<$declareEvalGlobalLightingAlphaBlendedWithHaze()$>
<@include gpu/Transform.slh@>
<$declareStandardCameraTransform()$>
// the albedo texture // the albedo texture
uniform sampler2D originalTexture; uniform sampler2D originalTexture;
// the interpolated normal // the interpolated normal
in vec4 _position;
in vec3 _normal; in vec3 _normal;
in vec4 _color; in vec4 _color;
in vec2 _texCoord0; in vec2 _texCoord0;
void main(void) { void main(void) {
vec4 texel = texture(originalTexture, _texCoord0.st); vec4 texel = texture(originalTexture, _texCoord0);
float opacity = _color.a; float colorAlpha = _color.a * texel.a;
if (_color.a <= 0.0) {
texel = color_sRGBAToLinear(texel);
opacity = -_color.a;
}
opacity *= texel.a;
vec3 albedo = _color.rgb * texel.rgb;
vec3 fragPosition = _position.xyz; packDeferredFragmentTranslucent(
vec3 fragNormal = normalize(_normal); normalize(_normal),
colorAlpha,
TransformCamera cam = getTransformCamera(); _color.rgb * texel.rgb,
_fragColor0 = vec4(evalGlobalLightingAlphaBlendedWithHaze(
cam._viewInverse,
1.0,
1.0,
fragPosition,
fragNormal,
albedo,
DEFAULT_FRESNEL, DEFAULT_FRESNEL,
0.0, DEFAULT_ROUGHNESS);
vec3(0.0f),
DEFAULT_ROUGHNESS,
opacity),
opacity);
} }