mirror of
https://github.com/overte-org/overte.git
synced 2025-04-22 17:53:32 +02:00
Added fade on poly line entities
This commit is contained in:
parent
0319a16e24
commit
b652d94a43
5 changed files with 140 additions and 7 deletions
|
@ -22,9 +22,14 @@
|
|||
#include "paintStroke_vert.h"
|
||||
#include "paintStroke_frag.h"
|
||||
|
||||
#include "paintStroke_fade_vert.h"
|
||||
#include "paintStroke_fade_frag.h"
|
||||
|
||||
uint8_t PolyLinePayload::CUSTOM_PIPELINE_NUMBER = 0;
|
||||
|
||||
gpu::PipelinePointer PolyLinePayload::_pipeline;
|
||||
gpu::PipelinePointer PolyLinePayload::_fadePipeline;
|
||||
|
||||
const int32_t PolyLinePayload::PAINTSTROKE_TEXTURE_SLOT;
|
||||
const int32_t PolyLinePayload::PAINTSTROKE_UNIFORM_SLOT;
|
||||
|
||||
|
@ -32,12 +37,16 @@ render::ShapePipelinePointer PolyLinePayload::shapePipelineFactory(const render:
|
|||
if (!_pipeline) {
|
||||
auto VS = gpu::Shader::createVertex(std::string(paintStroke_vert));
|
||||
auto PS = gpu::Shader::createPixel(std::string(paintStroke_frag));
|
||||
auto fadeVS = gpu::Shader::createVertex(std::string(paintStroke_fade_vert));
|
||||
auto fadePS = gpu::Shader::createPixel(std::string(paintStroke_fade_frag));
|
||||
gpu::ShaderPointer program = gpu::Shader::createProgram(VS, PS);
|
||||
gpu::ShaderPointer fadeProgram = gpu::Shader::createProgram(fadeVS, fadePS);
|
||||
|
||||
gpu::Shader::BindingSet slotBindings;
|
||||
slotBindings.insert(gpu::Shader::Binding(std::string("originalTexture"), PAINTSTROKE_TEXTURE_SLOT));
|
||||
slotBindings.insert(gpu::Shader::Binding(std::string("polyLineBuffer"), PAINTSTROKE_UNIFORM_SLOT));
|
||||
gpu::Shader::makeProgram(*program, slotBindings);
|
||||
gpu::Shader::makeProgram(*fadeProgram, slotBindings);
|
||||
|
||||
gpu::StatePointer state = gpu::StatePointer(new gpu::State());
|
||||
state->setDepthTest(true, true, gpu::LESS_EQUAL);
|
||||
|
@ -46,8 +55,14 @@ render::ShapePipelinePointer PolyLinePayload::shapePipelineFactory(const render:
|
|||
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);
|
||||
_pipeline = gpu::Pipeline::create(program, state);
|
||||
_fadePipeline = gpu::Pipeline::create(fadeProgram, state);
|
||||
}
|
||||
|
||||
if (key.isFaded()) {
|
||||
return std::make_shared<render::ShapePipeline>(_fadePipeline, nullptr, nullptr, nullptr);
|
||||
} else {
|
||||
return std::make_shared<render::ShapePipeline>(_pipeline, nullptr, nullptr, nullptr);
|
||||
}
|
||||
return std::make_shared<render::ShapePipeline>(_pipeline, nullptr, nullptr, nullptr);
|
||||
}
|
||||
|
||||
namespace render {
|
||||
|
@ -201,6 +216,24 @@ void RenderablePolyLineEntityItem::update(const quint64& now) {
|
|||
|
||||
}
|
||||
|
||||
bool RenderablePolyLineEntityItem::addToScene(const EntityItemPointer& self,
|
||||
const render::ScenePointer& scene,
|
||||
render::Transaction& transaction) {
|
||||
_myItem = scene->allocateID();
|
||||
|
||||
auto renderData = std::make_shared<PolyLinePayload>(self, _myItem);
|
||||
auto renderPayload = std::make_shared<PolyLinePayload::Payload>(renderData);
|
||||
|
||||
render::Item::Status::Getters statusGetters;
|
||||
makeEntityItemStatusGetters(self, statusGetters);
|
||||
renderPayload->addStatusGetters(statusGetters);
|
||||
|
||||
transaction.resetItem(_myItem, renderPayload);
|
||||
transaction.addTransitionToItem(_myItem, render::Transition::ELEMENT_ENTER_DOMAIN);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void RenderablePolyLineEntityItem::render(RenderArgs* args) {
|
||||
checkFading();
|
||||
|
||||
|
@ -239,11 +272,5 @@ void RenderablePolyLineEntityItem::render(RenderArgs* args) {
|
|||
batch.setInputFormat(_format);
|
||||
batch.setInputBuffer(0, _verticesBuffer, 0, _format->getChannels().at(0)._stride);
|
||||
|
||||
if (_isFading) {
|
||||
batch._glColor4f(1.0f, 1.0f, 1.0f, Interpolate::calculateFadeRatio(_fadeStartTime));
|
||||
} else {
|
||||
batch._glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
}
|
||||
|
||||
batch.draw(gpu::TRIANGLE_STRIP, _numVertices, 0);
|
||||
};
|
||||
|
|
|
@ -33,6 +33,7 @@ public:
|
|||
}
|
||||
}
|
||||
static gpu::PipelinePointer _pipeline;
|
||||
static gpu::PipelinePointer _fadePipeline;
|
||||
|
||||
static const int32_t PAINTSTROKE_TEXTURE_SLOT{ 0 };
|
||||
static const int32_t PAINTSTROKE_UNIFORM_SLOT{ 0 };
|
||||
|
@ -60,6 +61,9 @@ public:
|
|||
virtual void render(RenderArgs* args) override;
|
||||
virtual void update(const quint64& now) override;
|
||||
virtual bool needsToCallUpdate() const override { return true; }
|
||||
virtual bool addToScene(const EntityItemPointer& self,
|
||||
const render::ScenePointer& scene,
|
||||
render::Transaction& transaction) override;
|
||||
|
||||
bool isTransparent() override { return true; }
|
||||
|
||||
|
|
54
libraries/entities-renderer/src/paintStroke_fade.slf
Normal file
54
libraries/entities-renderer/src/paintStroke_fade.slf
Normal file
|
@ -0,0 +1,54 @@
|
|||
<@include gpu/Config.slh@>
|
||||
<$VERSION_HEADER$>
|
||||
// Generated on <$_SCRIBE_DATE$>
|
||||
//
|
||||
// paintStroke_fade.slf
|
||||
// fragment shader
|
||||
//
|
||||
// Created by Olivier Prat on 19/07/17.
|
||||
// Copyright 2017 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@>
|
||||
|
||||
<@include Fade.slh@>
|
||||
<$declareFadeFragment()$>
|
||||
|
||||
// the albedo texture
|
||||
uniform sampler2D originalTexture;
|
||||
|
||||
// the interpolated normal
|
||||
in vec3 interpolatedNormal;
|
||||
in vec2 varTexcoord;
|
||||
in vec4 varColor;
|
||||
in vec4 _worldPosition;
|
||||
|
||||
struct PolyLineUniforms {
|
||||
vec3 color;
|
||||
};
|
||||
|
||||
uniform polyLineBuffer {
|
||||
PolyLineUniforms polyline;
|
||||
};
|
||||
|
||||
void main(void) {
|
||||
vec3 fadeEmissive;
|
||||
FadeObjectParams fadeParams;
|
||||
|
||||
<$fetchFadeObjectParams(fadeParams)$>
|
||||
applyFade(fadeParams, _worldPosition.xyz, fadeEmissive);
|
||||
|
||||
vec4 texel = texture(originalTexture, varTexcoord);
|
||||
int frontCondition = 1 -int(gl_FrontFacing) * 2;
|
||||
vec3 color = varColor.rgb;
|
||||
packDeferredFragmentTranslucentEmissive(
|
||||
interpolatedNormal * frontCondition,
|
||||
texel.a * varColor.a,
|
||||
polyline.color * texel.rgb,
|
||||
vec3(0.01, 0.01, 0.01),
|
||||
10.0,
|
||||
fadeEmissive);
|
||||
}
|
43
libraries/entities-renderer/src/paintStroke_fade.slv
Normal file
43
libraries/entities-renderer/src/paintStroke_fade.slv
Normal file
|
@ -0,0 +1,43 @@
|
|||
<@include gpu/Config.slh@>
|
||||
<$VERSION_HEADER$>
|
||||
// Generated on <$_SCRIBE_DATE$>
|
||||
//
|
||||
// paintStroke_fade.slv
|
||||
// vertex shader
|
||||
//
|
||||
// Created by Olivier Prat on 19/07/17.
|
||||
// Copyright 2017 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 gpu/Inputs.slh@>
|
||||
<@include gpu/Color.slh@>
|
||||
<@include gpu/Transform.slh@>
|
||||
<$declareStandardTransform()$>
|
||||
|
||||
// the interpolated normal
|
||||
out vec3 interpolatedNormal;
|
||||
|
||||
//the diffuse texture
|
||||
out vec2 varTexcoord;
|
||||
|
||||
out vec4 varColor;
|
||||
out vec4 _worldPosition;
|
||||
|
||||
void main(void) {
|
||||
|
||||
varTexcoord = inTexCoord0.st;
|
||||
|
||||
// pass along the diffuse color
|
||||
varColor = colorToLinearRGBA(inColor);
|
||||
|
||||
|
||||
// standard transform
|
||||
TransformCamera cam = getTransformCamera();
|
||||
TransformObject obj = getTransformObject();
|
||||
<$transformModelToClipPos(cam, obj, inPosition, gl_Position)$>
|
||||
<$transformModelToEyeDir(cam, obj, inNormal.xyz, interpolatedNormal)$>
|
||||
<$transformModelToWorldPos(obj, inPosition, _worldPosition)$>
|
||||
}
|
|
@ -77,4 +77,9 @@ void packDeferredFragmentTranslucent(vec3 normal, float alpha, vec3 albedo, vec3
|
|||
|
||||
}
|
||||
|
||||
void packDeferredFragmentTranslucentEmissive(vec3 normal, float alpha, vec3 albedo, vec3 fresnel, float roughness, vec3 emissive) {
|
||||
packDeferredFragmentTranslucent(normal, alpha, albedo, fresnel, roughness);
|
||||
_fragColor3 = vec4(emissive, 1.0);
|
||||
}
|
||||
|
||||
<@endif@>
|
||||
|
|
Loading…
Reference in a new issue