mirror of
https://github.com/lubosz/overte.git
synced 2025-04-09 06:04:42 +02:00
Preparing to introducte TransitionStage
This commit is contained in:
parent
69a7ec42fd
commit
5ab093dc38
5 changed files with 101 additions and 360 deletions
|
@ -829,10 +829,10 @@ void RenderablePolyVoxEntityItem::render(RenderArgs* args) {
|
|||
}
|
||||
|
||||
// Apply fade effect
|
||||
if (args->_enableFade) {
|
||||
/* if (args->_enableFade) {
|
||||
FadeRenderJob::bindPerBatch(batch, render::ShapePipeline::Slot::MAP::FADE_MASK, render::ShapePipeline::Slot::BUFFER::FADE_PARAMETERS);
|
||||
FadeRenderJob::bindPerItem(batch, pipeline.get(), glm::vec3(0, 0, 0), _fadeStartTime);
|
||||
}
|
||||
}*/
|
||||
|
||||
int voxelVolumeSizeLocation = pipeline->getProgram()->getUniforms().findLocation("voxelVolumeSize");
|
||||
batch._glUniform3f(voxelVolumeSizeLocation, voxelVolumeSize.x, voxelVolumeSize.y, voxelVolumeSize.z);
|
||||
|
|
|
@ -21,103 +21,6 @@ inline float valueToParameterPow(float value, const double minValue, const doubl
|
|||
return (float)(log(double(value) / minValue) / log(maxOverMinValue));
|
||||
}
|
||||
|
||||
void FadeSwitchJob::configure(const Config& config) {
|
||||
_parameters->_isEditEnabled = config.editFade;
|
||||
}
|
||||
|
||||
void FadeSwitchJob::run(const render::RenderContextPointer& renderContext, const Input& input, Output& output) {
|
||||
auto& normalOutputs = output.edit0().edit0();
|
||||
auto& fadeOutputs = output.edit1();
|
||||
|
||||
// Only shapes are affected by fade at this time.
|
||||
normalOutputs[RenderFetchCullSortTask::LIGHT].edit<render::ItemBounds>() = input.get0()[RenderFetchCullSortTask::LIGHT].get<render::ItemBounds>();
|
||||
normalOutputs[RenderFetchCullSortTask::META].edit<render::ItemBounds>() = input.get0()[RenderFetchCullSortTask::META].get<render::ItemBounds>();
|
||||
normalOutputs[RenderFetchCullSortTask::OVERLAY_OPAQUE_SHAPE].edit<render::ItemBounds>() = input.get0()[RenderFetchCullSortTask::OVERLAY_OPAQUE_SHAPE].get<render::ItemBounds>();
|
||||
normalOutputs[RenderFetchCullSortTask::OVERLAY_TRANSPARENT_SHAPE].edit<render::ItemBounds>() = input.get0()[RenderFetchCullSortTask::OVERLAY_TRANSPARENT_SHAPE].get<render::ItemBounds>();
|
||||
normalOutputs[RenderFetchCullSortTask::BACKGROUND].edit<render::ItemBounds>() = input.get0()[RenderFetchCullSortTask::BACKGROUND].get<render::ItemBounds>();
|
||||
output.edit0().edit1() = input.get1();
|
||||
|
||||
// Find the nearest item that intersects the view direction
|
||||
const render::Item* editedItem = nullptr;
|
||||
if (_parameters->_isEditEnabled) {
|
||||
float nearestOpaqueDistance = std::numeric_limits<float>::max();
|
||||
float nearestTransparentDistance = std::numeric_limits<float>::max();
|
||||
const render::Item* nearestItem;
|
||||
|
||||
editedItem = findNearestItem(renderContext, input.get0()[RenderFetchCullSortTask::OPAQUE_SHAPE], nearestOpaqueDistance);
|
||||
nearestItem = findNearestItem(renderContext, input.get0()[RenderFetchCullSortTask::TRANSPARENT_SHAPE], nearestTransparentDistance);
|
||||
if (nearestTransparentDistance < nearestOpaqueDistance) {
|
||||
editedItem = nearestItem;
|
||||
}
|
||||
|
||||
if (editedItem) {
|
||||
output.edit2() = editedItem->getBound();
|
||||
}
|
||||
}
|
||||
|
||||
// Now, distribute items that need to be faded accross both outputs
|
||||
distribute(renderContext, input.get0()[RenderFetchCullSortTask::OPAQUE_SHAPE], normalOutputs[RenderFetchCullSortTask::OPAQUE_SHAPE], fadeOutputs[OPAQUE_SHAPE], editedItem);
|
||||
distribute(renderContext, input.get0()[RenderFetchCullSortTask::TRANSPARENT_SHAPE], normalOutputs[RenderFetchCullSortTask::TRANSPARENT_SHAPE], fadeOutputs[TRANSPARENT_SHAPE], editedItem);
|
||||
}
|
||||
|
||||
const render::Item* FadeSwitchJob::findNearestItem(const render::RenderContextPointer& renderContext, const render::Varying& input, float& minIsectDistance) const {
|
||||
const glm::vec3 rayOrigin = renderContext->args->getViewFrustum().getPosition();
|
||||
const glm::vec3 rayDirection = renderContext->args->getViewFrustum().getDirection();
|
||||
const auto& inputItems = input.get<render::ItemBounds>();
|
||||
auto& scene = renderContext->_scene;
|
||||
BoxFace face;
|
||||
glm::vec3 normal;
|
||||
float isectDistance;
|
||||
const render::Item* nearestItem = nullptr;
|
||||
const float minDistance = 2.f;
|
||||
|
||||
for (const auto& itemBound : inputItems) {
|
||||
if (!itemBound.bound.contains(rayOrigin) && itemBound.bound.findRayIntersection(rayOrigin, rayDirection, isectDistance, face, normal)) {
|
||||
if (isectDistance>minDistance && isectDistance < minIsectDistance) {
|
||||
auto& item = scene->getItem(itemBound.id);
|
||||
|
||||
if (item.getKey().isShape() && !item.getKey().isMeta()) {
|
||||
nearestItem = &item;
|
||||
minIsectDistance = isectDistance;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nearestItem;
|
||||
}
|
||||
|
||||
void FadeSwitchJob::distribute(const render::RenderContextPointer& renderContext, const render::Varying& input,
|
||||
render::Varying& normalOutput, render::Varying& fadeOutput, const render::Item* editedItem) const {
|
||||
auto& scene = renderContext->_scene;
|
||||
assert(_parameters);
|
||||
const auto& inputItems = input.get<render::ItemBounds>();
|
||||
|
||||
// Clear previous values
|
||||
normalOutput.edit<render::ItemBounds>().clear();
|
||||
fadeOutput.edit<render::ItemBounds>().clear();
|
||||
|
||||
for (const auto& itemBound : inputItems) {
|
||||
auto& item = scene->getItem(itemBound.id);
|
||||
|
||||
// if (!item.mustFade() && &item!=editedItem) {
|
||||
// No need to fade
|
||||
normalOutput.edit<render::ItemBounds>().emplace_back(itemBound);
|
||||
/* }
|
||||
else {
|
||||
fadeOutput.edit<render::ItemBounds>().emplace_back(itemBound);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
FadeCommonParameters::FadeCommonParameters()
|
||||
{
|
||||
_durations[FadeJobConfig::ELEMENT_ENTER_LEAVE_DOMAIN] = 0.f;
|
||||
_durations[FadeJobConfig::BUBBLE_ISECT_OWNER] = 0.f;
|
||||
_durations[FadeJobConfig::BUBBLE_ISECT_TRESPASSER] = 0.f;
|
||||
_durations[FadeJobConfig::USER_ENTER_LEAVE_DOMAIN] = 0.f;
|
||||
_durations[FadeJobConfig::AVATAR_CHANGE] = 0.f;
|
||||
}
|
||||
|
||||
FadeJobConfig::FadeJobConfig()
|
||||
{
|
||||
events[FadeJobConfig::ELEMENT_ENTER_LEAVE_DOMAIN].noiseSize = glm::vec3{ 0.75f, 0.75f, 0.75f };
|
||||
|
@ -556,137 +459,54 @@ void FadeJobConfig::load() {
|
|||
}
|
||||
}
|
||||
|
||||
FadeConfigureJob::FadeConfigureJob(FadeCommonParameters::Pointer commonParams) :
|
||||
_parameters{ commonParams }
|
||||
FadeJob::FadeJob()
|
||||
{
|
||||
auto texturePath = PathUtils::resourcesPath() + "images/fadeMask.png";
|
||||
_fadeMaskMap = DependencyManager::get<TextureCache>()->getImageTexture(texturePath, image::TextureUsage::STRICT_TEXTURE);
|
||||
}
|
||||
|
||||
void FadeConfigureJob::configure(const Config& config) {
|
||||
assert(_parameters);
|
||||
_parameters->_editedCategory = config.editedCategory;
|
||||
_parameters->_isManualThresholdEnabled = config.manualFade;
|
||||
_parameters->_manualThreshold = config.manualThreshold;
|
||||
void FadeJob::configure(const Config& config) {
|
||||
auto& configurations = _configurations.edit();
|
||||
|
||||
for (auto i = 0; i < FadeJobConfig::EVENT_CATEGORY_COUNT; i++) {
|
||||
auto& configuration = _configurations[i];
|
||||
auto& eventParameters = configurations.parameters[i];
|
||||
const auto& eventConfig = config.events[i];
|
||||
|
||||
_parameters->_durations[i] = eventConfig._duration;
|
||||
configuration._baseInvSizeAndLevel.x = 1.f / eventConfig.baseSize.x;
|
||||
configuration._baseInvSizeAndLevel.y = 1.f / eventConfig.baseSize.y;
|
||||
configuration._baseInvSizeAndLevel.z = 1.f / eventConfig.baseSize.z;
|
||||
configuration._baseInvSizeAndLevel.w = eventConfig.baseLevel;
|
||||
configuration._noiseInvSizeAndLevel.x = 1.f / eventConfig.noiseSize.x;
|
||||
configuration._noiseInvSizeAndLevel.y = 1.f / eventConfig.noiseSize.y;
|
||||
configuration._noiseInvSizeAndLevel.z = 1.f / eventConfig.noiseSize.z;
|
||||
configuration._noiseInvSizeAndLevel.w = eventConfig.noiseLevel;
|
||||
configuration._isInverted = eventConfig._isInverted & 1;
|
||||
configuration._edgeWidthInvWidth.x = eventConfig.edgeWidth;
|
||||
configuration._edgeWidthInvWidth.y = 1.f / configuration._edgeWidthInvWidth.x;
|
||||
configuration._innerEdgeColor = eventConfig.edgeInnerColor;
|
||||
configuration._outerEdgeColor = eventConfig.edgeOuterColor;
|
||||
_parameters->_thresholdScale[i] = 1.f + (configuration._edgeWidthInvWidth.x + std::max(0.f, (eventConfig.noiseLevel + eventConfig.baseLevel)*0.5f-0.5f));
|
||||
_parameters->_noiseSpeed[i] = eventConfig.noiseSpeed;
|
||||
_parameters->_timing[i] = (FadeJobConfig::Timing) eventConfig.timing;
|
||||
eventParameters._baseLevel = eventConfig.baseLevel;
|
||||
eventParameters._noiseInvSizeAndLevel.x = 1.f / eventConfig.noiseSize.x;
|
||||
eventParameters._noiseInvSizeAndLevel.y = 1.f / eventConfig.noiseSize.y;
|
||||
eventParameters._noiseInvSizeAndLevel.z = 1.f / eventConfig.noiseSize.z;
|
||||
eventParameters._noiseInvSizeAndLevel.w = eventConfig.noiseLevel;
|
||||
eventParameters._isInverted = eventConfig._isInverted & 1;
|
||||
eventParameters._edgeWidthInvWidth.x = eventConfig.edgeWidth;
|
||||
eventParameters._edgeWidthInvWidth.y = 1.f / eventParameters._edgeWidthInvWidth.x;
|
||||
eventParameters._innerEdgeColor = eventConfig.edgeInnerColor;
|
||||
eventParameters._outerEdgeColor = eventConfig.edgeOuterColor;
|
||||
_thresholdScale[i] = 1.f + (eventParameters._edgeWidthInvWidth.x + std::max(0.f, (eventConfig.noiseLevel + eventConfig.baseLevel)*0.5f - 0.5f));
|
||||
}
|
||||
_isBufferDirty = true;
|
||||
}
|
||||
|
||||
void FadeConfigureJob::run(const render::RenderContextPointer& renderContext, const Input& input, Output& output) {
|
||||
if (_isBufferDirty || _parameters->_isEditEnabled) {
|
||||
auto& configurations = output.edit1().edit();
|
||||
std::copy(_configurations, _configurations + FadeJobConfig::EVENT_CATEGORY_COUNT, configurations.parameters);
|
||||
if (_parameters->_editedCategory == FadeJobConfig::USER_ENTER_LEAVE_DOMAIN) {
|
||||
configurations.parameters[FadeJobConfig::USER_ENTER_LEAVE_DOMAIN]._baseInvSizeAndLevel.y = 1.0f / input.getDimensions().y;
|
||||
const FadeJob* FadeJob::_currentInstance{ nullptr };
|
||||
gpu::TexturePointer FadeJob::_currentFadeMaskMap;
|
||||
const gpu::BufferView* FadeJob::_currentFadeBuffer{ nullptr };
|
||||
|
||||
void FadeJob::run(const render::RenderContextPointer& renderContext, const Input& input) {
|
||||
const Config* jobConfig = static_cast<const Config*>(renderContext->jobConfig.get());
|
||||
auto scene = renderContext->args->_scene;
|
||||
|
||||
// And now update fade effect on all visible items
|
||||
for (auto i = 0; i < RenderFetchCullSortTask::NUM_BUCKETS; i++) {
|
||||
auto& bucket = input[i].get<render::ItemBounds>();
|
||||
|
||||
for (const auto& itemBound : bucket) {
|
||||
auto& item = scene->getItem(itemBound.id);
|
||||
|
||||
//updateFadeOnItem(item);
|
||||
}
|
||||
_isBufferDirty = false;
|
||||
}
|
||||
output.edit0() = _fadeMaskMap;
|
||||
}
|
||||
|
||||
const FadeRenderJob* FadeRenderJob::_currentInstance{ nullptr };
|
||||
gpu::TexturePointer FadeRenderJob::_currentFadeMaskMap;
|
||||
const gpu::BufferView* FadeRenderJob::_currentFadeBuffer{ nullptr };
|
||||
|
||||
void FadeRenderJob::run(const render::RenderContextPointer& renderContext, const Input& inputs) {
|
||||
assert(renderContext->args);
|
||||
assert(renderContext->args->hasViewFrustum());
|
||||
|
||||
const auto& inItems = inputs.get0();
|
||||
|
||||
if (!inItems.empty()) {
|
||||
const auto& lightingModel = inputs.get1();
|
||||
const auto& configuration = inputs.get2();
|
||||
const auto& fadeMaskMap = configuration.get0();
|
||||
const auto& fadeParamBuffer = configuration.get1();
|
||||
|
||||
RenderArgs* args = renderContext->args;
|
||||
render::ShapeKey::Builder defaultKeyBuilder;
|
||||
|
||||
defaultKeyBuilder.withFade();
|
||||
defaultKeyBuilder.withoutCullFace();
|
||||
|
||||
gpu::doInBatch(args->_context, [&](gpu::Batch& batch) {
|
||||
args->_batch = &batch;
|
||||
|
||||
// Very, very ugly hack to keep track of the current fade render job
|
||||
_currentInstance = this;
|
||||
_currentFadeMaskMap = fadeMaskMap;
|
||||
_currentFadeBuffer = &fadeParamBuffer;
|
||||
|
||||
// Update interactive edit effect
|
||||
if (_parameters->_isEditEnabled) {
|
||||
updateFadeEdit(renderContext, inItems.front());
|
||||
}
|
||||
else {
|
||||
_editPreviousTime = 0;
|
||||
}
|
||||
|
||||
// Setup camera, projection and viewport for all items
|
||||
batch.setViewportTransform(args->_viewport);
|
||||
batch.setStateScissorRect(args->_viewport);
|
||||
|
||||
glm::mat4 projMat;
|
||||
Transform viewMat;
|
||||
args->getViewFrustum().evalProjectionMatrix(projMat);
|
||||
args->getViewFrustum().evalViewTransform(viewMat);
|
||||
|
||||
batch.setProjectionTransform(projMat);
|
||||
batch.setViewTransform(viewMat);
|
||||
|
||||
// Setup lighting model for all items;
|
||||
batch.setUniformBuffer(render::ShapePipeline::Slot::LIGHTING_MODEL, lightingModel->getParametersBuffer());
|
||||
|
||||
// From the lighting model define a global shapKey ORED with individiual keys
|
||||
render::ShapeKey::Builder keyBuilder = defaultKeyBuilder;
|
||||
if (lightingModel->isWireframeEnabled()) {
|
||||
keyBuilder.withWireframe();
|
||||
}
|
||||
|
||||
// Prepare fade effect
|
||||
bindPerBatch(batch, fadeMaskMap, render::ShapePipeline::Slot::MAP::FADE_MASK, &fadeParamBuffer, render::ShapePipeline::Slot::BUFFER::FADE_PARAMETERS);
|
||||
|
||||
render::ShapeKey globalKey = keyBuilder.build();
|
||||
args->_globalShapeKey = globalKey._flags.to_ulong();
|
||||
args->_enableFade = true;
|
||||
|
||||
renderShapes(renderContext, _shapePlumber, inItems, -1, globalKey);
|
||||
|
||||
args->_enableFade = false;
|
||||
args->_batch = nullptr;
|
||||
args->_globalShapeKey = 0;
|
||||
|
||||
// Very, very ugly hack to keep track of the current fade render job
|
||||
_currentInstance = nullptr;
|
||||
_currentFadeMaskMap.reset();
|
||||
_currentFadeBuffer = nullptr;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
float FadeRenderJob::computeElementEnterThreshold(double time, const double period, FadeJobConfig::Timing timing) const {
|
||||
float FadeJob::computeElementEnterThreshold(double time, const double period, FadeJobConfig::Timing timing) const {
|
||||
assert(period > 0.0);
|
||||
float fadeAlpha = 1.0f;
|
||||
const double INV_FADE_PERIOD = 1.0 / period;
|
||||
|
@ -712,16 +532,17 @@ float FadeRenderJob::computeElementEnterThreshold(double time, const double peri
|
|||
return fadeAlpha;
|
||||
}
|
||||
|
||||
float FadeRenderJob::computeFadePercent(quint64 startTime) {
|
||||
float FadeJob::computeFadePercent(quint64 startTime) {
|
||||
const double time = (double)(int64_t(usecTimestampNow()) - int64_t(startTime)) / (double)(USECS_PER_SECOND);
|
||||
assert(_currentInstance);
|
||||
/* assert(_currentInstance);
|
||||
return _currentInstance->computeElementEnterThreshold(time,
|
||||
_currentInstance->_parameters->_durations[FadeJobConfig::ELEMENT_ENTER_LEAVE_DOMAIN],
|
||||
_currentInstance->_parameters->_timing[FadeJobConfig::ELEMENT_ENTER_LEAVE_DOMAIN]);
|
||||
_currentInstance->_parameters->_timing[FadeJobConfig::ELEMENT_ENTER_LEAVE_DOMAIN]);*/
|
||||
return (float)time;
|
||||
}
|
||||
|
||||
void FadeRenderJob::updateFadeEdit(const render::RenderContextPointer& renderContext, const render::ItemBound& itemBounds) {
|
||||
if (_editPreviousTime == 0) {
|
||||
void FadeJob::updateFadeEdit(const render::RenderContextPointer& renderContext, const render::ItemBound& itemBounds) {
|
||||
/* if (_editPreviousTime == 0) {
|
||||
_editPreviousTime = usecTimestampNow();
|
||||
_editTime = 0.0;
|
||||
}
|
||||
|
@ -804,32 +625,32 @@ void FadeRenderJob::updateFadeEdit(const render::RenderContextPointer& renderCon
|
|||
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
void FadeRenderJob::bindPerBatch(gpu::Batch& batch, int fadeMaskMapLocation, int fadeBufferLocation) {
|
||||
void FadeJob::bindPerBatch(gpu::Batch& batch, int fadeMaskMapLocation, int fadeBufferLocation) {
|
||||
assert(_currentFadeMaskMap);
|
||||
assert(_currentFadeBuffer!=nullptr);
|
||||
bindPerBatch(batch, _currentFadeMaskMap, fadeMaskMapLocation, _currentFadeBuffer, fadeBufferLocation);
|
||||
}
|
||||
|
||||
void FadeRenderJob::bindPerBatch(gpu::Batch& batch, gpu::TexturePointer texture, int fadeMaskMapLocation, const gpu::BufferView* buffer, int fadeBufferLocation) {
|
||||
void FadeJob::bindPerBatch(gpu::Batch& batch, gpu::TexturePointer texture, int fadeMaskMapLocation, const gpu::BufferView* buffer, int fadeBufferLocation) {
|
||||
batch.setResourceTexture(fadeMaskMapLocation, texture);
|
||||
batch.setUniformBuffer(fadeBufferLocation, *buffer);
|
||||
}
|
||||
|
||||
void FadeRenderJob::bindPerBatch(gpu::Batch& batch, gpu::TexturePointer texture, const gpu::BufferView* buffer, const gpu::PipelinePointer& pipeline) {
|
||||
void FadeJob::bindPerBatch(gpu::Batch& batch, gpu::TexturePointer texture, const gpu::BufferView* buffer, const gpu::PipelinePointer& pipeline) {
|
||||
auto program = pipeline->getProgram();
|
||||
auto maskMapLocation = program->getTextures().findLocation("fadeMaskMap");
|
||||
auto bufferLocation = program->getUniformBuffers().findLocation("fadeParametersBuffer");
|
||||
bindPerBatch(batch, texture, maskMapLocation, buffer, bufferLocation);
|
||||
}
|
||||
|
||||
bool FadeRenderJob::bindPerItem(gpu::Batch& batch, RenderArgs* args, glm::vec3 offset, quint64 startTime) {
|
||||
bool FadeJob::bindPerItem(gpu::Batch& batch, RenderArgs* args, glm::vec3 offset, quint64 startTime) {
|
||||
return bindPerItem(batch, args->_pipeline->pipeline.get(), offset, startTime);
|
||||
}
|
||||
|
||||
bool FadeRenderJob::bindPerItem(gpu::Batch& batch, const gpu::Pipeline* pipeline, glm::vec3 offset, quint64 startTime) {
|
||||
bool FadeJob::bindPerItem(gpu::Batch& batch, const gpu::Pipeline* pipeline, glm::vec3 offset, quint64 startTime) {
|
||||
auto& uniforms = pipeline->getProgram()->getUniforms();
|
||||
auto fadeNoiseOffsetLocation = uniforms.findLocation("fadeNoiseOffset");
|
||||
auto fadeBaseOffsetLocation = uniforms.findLocation("fadeBaseOffset");
|
||||
|
@ -845,7 +666,7 @@ bool FadeRenderJob::bindPerItem(gpu::Batch& batch, const gpu::Pipeline* pipeline
|
|||
threshold = 1.f-computeFadePercent(startTime);
|
||||
|
||||
// Manage interactive edition override
|
||||
assert(_currentInstance);
|
||||
/* assert(_currentInstance);
|
||||
if (_currentInstance->_parameters->_isEditEnabled) {
|
||||
eventCategory = _currentInstance->_parameters->_editedCategory;
|
||||
threshold = _currentInstance->_editThreshold;
|
||||
|
@ -859,7 +680,7 @@ bool FadeRenderJob::bindPerItem(gpu::Batch& batch, const gpu::Pipeline* pipeline
|
|||
if (eventCategory != FadeJobConfig::BUBBLE_ISECT_OWNER) {
|
||||
threshold = (threshold - 0.5f)*_currentInstance->_parameters->_thresholdScale[eventCategory] + 0.5f;
|
||||
}
|
||||
|
||||
*/
|
||||
batch._glUniform1i(fadeCategoryLocation, eventCategory);
|
||||
batch._glUniform1f(fadeThresholdLocation, threshold);
|
||||
// This is really temporary
|
||||
|
@ -871,3 +692,29 @@ bool FadeRenderJob::bindPerItem(gpu::Batch& batch, const gpu::Pipeline* pipeline
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const render::Item* FadeJob::findNearestItem(const render::RenderContextPointer& renderContext, const render::Varying& input, float& minIsectDistance) const {
|
||||
const glm::vec3 rayOrigin = renderContext->args->getViewFrustum().getPosition();
|
||||
const glm::vec3 rayDirection = renderContext->args->getViewFrustum().getDirection();
|
||||
const auto& inputItems = input.get<render::ItemBounds>();
|
||||
auto& scene = renderContext->_scene;
|
||||
BoxFace face;
|
||||
glm::vec3 normal;
|
||||
float isectDistance;
|
||||
const render::Item* nearestItem = nullptr;
|
||||
const float minDistance = 2.f;
|
||||
|
||||
for (const auto& itemBound : inputItems) {
|
||||
if (!itemBound.bound.contains(rayOrigin) && itemBound.bound.findRayIntersection(rayOrigin, rayDirection, isectDistance, face, normal)) {
|
||||
if (isectDistance>minDistance && isectDistance < minIsectDistance) {
|
||||
auto& item = scene->getItem(itemBound.id);
|
||||
|
||||
if (item.getKey().isShape() && !item.getKey().isMeta()) {
|
||||
nearestItem = &item;
|
||||
minIsectDistance = isectDistance;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nearestItem;
|
||||
}
|
||||
|
|
|
@ -15,21 +15,6 @@
|
|||
#include <render/ShapePipeline.h>
|
||||
#include <render/RenderFetchCullSortTask.h>
|
||||
|
||||
#include "LightingModel.h"
|
||||
|
||||
class FadeSwitchJobConfig : public render::Job::Config {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool editFade MEMBER editFade NOTIFY dirty)
|
||||
|
||||
public:
|
||||
|
||||
bool editFade{ false };
|
||||
|
||||
signals:
|
||||
void dirty();
|
||||
|
||||
};
|
||||
|
||||
class FadeJobConfig : public render::Job::Config {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int editedCategory MEMBER editedCategory WRITE setEditedCategory NOTIFY dirtyCategory)
|
||||
|
@ -58,6 +43,8 @@ class FadeJobConfig : public render::Job::Config {
|
|||
Q_PROPERTY(float noiseSpeedX READ getNoiseSpeedX WRITE setNoiseSpeedX NOTIFY dirty)
|
||||
Q_PROPERTY(float noiseSpeedY READ getNoiseSpeedY WRITE setNoiseSpeedY NOTIFY dirty)
|
||||
Q_PROPERTY(float noiseSpeedZ READ getNoiseSpeedZ WRITE setNoiseSpeedZ NOTIFY dirty)
|
||||
Q_PROPERTY(float threshold MEMBER threshold NOTIFY dirty)
|
||||
Q_PROPERTY(bool editFade MEMBER editFade NOTIFY dirty)
|
||||
|
||||
public:
|
||||
|
||||
|
@ -153,10 +140,6 @@ public:
|
|||
|
||||
void setTiming(int value);
|
||||
int getTiming() const { return events[editedCategory].timing; }
|
||||
|
||||
bool manualFade{ false };
|
||||
float manualThreshold{ 0.f };
|
||||
int editedCategory{ ELEMENT_ENTER_LEAVE_DOMAIN };
|
||||
|
||||
struct Event {
|
||||
glm::vec4 edgeInnerColor;
|
||||
|
@ -173,6 +156,11 @@ public:
|
|||
};
|
||||
|
||||
Event events[EVENT_CATEGORY_COUNT];
|
||||
float threshold{ 0.f };
|
||||
float manualThreshold{ 0.f };
|
||||
int editedCategory{ ELEMENT_ENTER_LEAVE_DOMAIN };
|
||||
bool editFade{ false };
|
||||
bool manualFade{ false };
|
||||
|
||||
Q_INVOKABLE void save() const;
|
||||
Q_INVOKABLE void load();
|
||||
|
@ -180,67 +168,20 @@ public:
|
|||
static QString eventNames[EVENT_CATEGORY_COUNT];
|
||||
|
||||
signals:
|
||||
|
||||
void dirty();
|
||||
void dirtyCategory();
|
||||
|
||||
};
|
||||
|
||||
struct FadeCommonParameters
|
||||
{
|
||||
using Pointer = std::shared_ptr<FadeCommonParameters>;
|
||||
|
||||
FadeCommonParameters();
|
||||
|
||||
bool _isEditEnabled{ false };
|
||||
bool _isManualThresholdEnabled{ false };
|
||||
float _manualThreshold{ 0.f };
|
||||
float _thresholdScale[FadeJobConfig::EVENT_CATEGORY_COUNT];
|
||||
int _editedCategory{ FadeJobConfig::ELEMENT_ENTER_LEAVE_DOMAIN };
|
||||
float _durations[FadeJobConfig::EVENT_CATEGORY_COUNT];
|
||||
glm::vec3 _noiseSpeed[FadeJobConfig::EVENT_CATEGORY_COUNT];
|
||||
FadeJobConfig::Timing _timing[FadeJobConfig::EVENT_CATEGORY_COUNT];
|
||||
};
|
||||
|
||||
class FadeSwitchJob {
|
||||
public:
|
||||
|
||||
enum FadeBuckets {
|
||||
OPAQUE_SHAPE = 0,
|
||||
TRANSPARENT_SHAPE,
|
||||
|
||||
NUM_BUCKETS
|
||||
};
|
||||
|
||||
using FadeOutput = render::VaryingArray<render::ItemBounds, FadeBuckets::NUM_BUCKETS>;
|
||||
|
||||
using Input = RenderFetchCullSortTask::Output;
|
||||
using Output = render::VaryingSet3 < RenderFetchCullSortTask::Output, FadeOutput, render::Item::Bound > ;
|
||||
using Config = FadeSwitchJobConfig;
|
||||
using JobModel = render::Job::ModelIO<FadeSwitchJob, Input, Output, Config>;
|
||||
|
||||
FadeSwitchJob(FadeCommonParameters::Pointer commonParams) : _parameters{ commonParams } {}
|
||||
|
||||
void configure(const Config& config);
|
||||
void run(const render::RenderContextPointer& renderContext, const Input& input, Output& output);
|
||||
|
||||
private:
|
||||
|
||||
FadeCommonParameters::Pointer _parameters;
|
||||
|
||||
void distribute(const render::RenderContextPointer& renderContext, const render::Varying& input,
|
||||
render::Varying& normalOutput, render::Varying& fadeOutput, const render::Item* editedItem = nullptr) const;
|
||||
const render::Item* findNearestItem(const render::RenderContextPointer& renderContext, const render::Varying& input, float& minIsectDistance) const;
|
||||
};
|
||||
|
||||
struct FadeParameters
|
||||
{
|
||||
glm::vec4 _baseInvSizeAndLevel;
|
||||
glm::vec4 _noiseInvSizeAndLevel;
|
||||
glm::vec4 _innerEdgeColor;
|
||||
glm::vec4 _outerEdgeColor;
|
||||
glm::vec2 _edgeWidthInvWidth;
|
||||
glm::float32 _baseLevel;
|
||||
glm::int32 _isInverted;
|
||||
glm::float32 _padding;
|
||||
};
|
||||
|
||||
struct FadeConfiguration
|
||||
|
@ -248,56 +189,17 @@ struct FadeConfiguration
|
|||
FadeParameters parameters[FadeJobConfig::EVENT_CATEGORY_COUNT];
|
||||
};
|
||||
|
||||
class FadeConfigureJob {
|
||||
class FadeJob {
|
||||
|
||||
public:
|
||||
|
||||
using UniformBuffer = gpu::StructBuffer<FadeConfiguration>;
|
||||
using Input = render::Item::Bound ;
|
||||
using Output = render::VaryingSet2<gpu::TexturePointer, UniformBuffer>;
|
||||
using Config = FadeJobConfig;
|
||||
using JobModel = render::Job::ModelIO<FadeConfigureJob, Input, Output, Config>;
|
||||
using Input = RenderFetchCullSortTask::BucketList;
|
||||
using JobModel = render::Job::ModelI<FadeJob, Input, Config>;
|
||||
|
||||
FadeConfigureJob(FadeCommonParameters::Pointer commonParams);
|
||||
|
||||
const gpu::TexturePointer getFadeMaskMap() const { return _fadeMaskMap; }
|
||||
FadeJob();
|
||||
|
||||
void configure(const Config& config);
|
||||
void run(const render::RenderContextPointer& renderContext, const Input& input, Output& output);
|
||||
|
||||
private:
|
||||
|
||||
FadeCommonParameters::Pointer _parameters;
|
||||
bool _isBufferDirty{ true };
|
||||
gpu::TexturePointer _fadeMaskMap;
|
||||
FadeParameters _configurations[FadeJobConfig::EVENT_CATEGORY_COUNT];
|
||||
};
|
||||
|
||||
|
||||
class FadeRenderJobConfig : public render::Job::Config {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(float threshold MEMBER threshold NOTIFY dirty)
|
||||
|
||||
public:
|
||||
|
||||
float threshold{ 0.f };
|
||||
|
||||
signals:
|
||||
void dirty();
|
||||
|
||||
};
|
||||
|
||||
class FadeRenderJob {
|
||||
|
||||
public:
|
||||
|
||||
using Config = FadeRenderJobConfig;
|
||||
using Input = render::VaryingSet3<render::ItemBounds, LightingModelPointer, FadeConfigureJob::Output>;
|
||||
using JobModel = render::Job::ModelI<FadeRenderJob, Input, Config>;
|
||||
|
||||
FadeRenderJob(FadeCommonParameters::Pointer commonParams, render::ShapePlumberPointer shapePlumber) : _shapePlumber{ shapePlumber }, _parameters{ commonParams } {}
|
||||
|
||||
void configure(const Config& config) {}
|
||||
void run(const render::RenderContextPointer& renderContext, const Input& inputs);
|
||||
|
||||
static void bindPerBatch(gpu::Batch& batch, int fadeMaskMapLocation, int fadeBufferLocation);
|
||||
|
@ -311,15 +213,17 @@ public:
|
|||
|
||||
private:
|
||||
|
||||
static const FadeRenderJob* _currentInstance;
|
||||
static const FadeJob* _currentInstance;
|
||||
static gpu::TexturePointer _currentFadeMaskMap;
|
||||
static const gpu::BufferView* _currentFadeBuffer;
|
||||
|
||||
render::ShapePlumberPointer _shapePlumber;
|
||||
FadeCommonParameters::Pointer _parameters;
|
||||
gpu::StructBuffer<FadeConfiguration> _configurations;
|
||||
gpu::TexturePointer _fadeMaskMap;
|
||||
float _thresholdScale[FadeJobConfig::EVENT_CATEGORY_COUNT];
|
||||
|
||||
float computeElementEnterThreshold(double time, const double period, FadeJobConfig::Timing timing) const;
|
||||
|
||||
|
||||
// Everything needed for interactive edition
|
||||
uint64_t _editPreviousTime{ 0 };
|
||||
double _editTime{ 0.0 };
|
||||
|
@ -328,6 +232,7 @@ private:
|
|||
glm::vec3 _editBaseOffset{ 0.f, 0.f, 0.f };
|
||||
|
||||
void updateFadeEdit(const render::RenderContextPointer& renderContext, const render::ItemBound& itemBounds);
|
||||
const render::Item* findNearestItem(const render::RenderContextPointer& renderContext, const render::Varying& input, float& minIsectDistance) const;
|
||||
};
|
||||
|
||||
#endif // hifi_FadeEffect_h
|
||||
|
|
|
@ -53,14 +53,9 @@ void RenderDeferredTask::configure(const Config& config)
|
|||
}
|
||||
|
||||
void RenderDeferredTask::build(JobModel& task, const render::Varying& input, render::Varying& output) {
|
||||
auto commonFadeParameters = std::make_shared<FadeCommonParameters>();
|
||||
const auto fadeSwitchOutputs = task.addJob<FadeSwitchJob>("FadeSwitch", input, commonFadeParameters).get<FadeSwitchJob::Output>();
|
||||
|
||||
const auto& items = fadeSwitchOutputs.get0();
|
||||
const auto& fadeItems = fadeSwitchOutputs.get1();
|
||||
const auto& fadeEditedItem = fadeSwitchOutputs[2];
|
||||
|
||||
const auto fadeConfigureOutputs = task.addJob<FadeConfigureJob>("FadeConfigure", fadeEditedItem, commonFadeParameters).get<FadeConfigureJob::Output>();
|
||||
const auto& items = input.get<Input>();
|
||||
|
||||
// task.addJob<FadeJob>("Fade", fadeEditedItem, commonFadeParameters).get<FadeConfigureJob::Output>();
|
||||
|
||||
// Prepare the ShapePipelines
|
||||
ShapePlumberPointer shapePlumber = std::make_shared<ShapePlumber>();
|
||||
|
@ -101,11 +96,6 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren
|
|||
const auto opaqueInputs = DrawStateSortDeferred::Inputs(opaques, lightingModel).asVarying();
|
||||
task.addJob<DrawStateSortDeferred>("DrawOpaqueDeferred", opaqueInputs, shapePlumber);
|
||||
|
||||
const auto fadeOpaques = fadeItems[FadeSwitchJob::OPAQUE_SHAPE];
|
||||
const auto fadeOpaqueInputs = FadeRenderJob::Input(fadeOpaques, lightingModel, fadeConfigureOutputs).asVarying();
|
||||
task.addJob<FadeRenderJob>("DrawFadeOpaque", fadeOpaqueInputs, commonFadeParameters, shapePlumber);
|
||||
|
||||
|
||||
task.addJob<EndGPURangeTimer>("OpaqueRangeTimer", opaqueRangeTimer);
|
||||
|
||||
|
||||
|
@ -159,10 +149,6 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren
|
|||
const auto transparentsInputs = DrawDeferred::Inputs(transparents, lightingModel).asVarying();
|
||||
task.addJob<DrawDeferred>("DrawTransparentDeferred", transparentsInputs, shapePlumber);
|
||||
|
||||
const auto fadeTransparents = fadeItems[FadeSwitchJob::TRANSPARENT_SHAPE];
|
||||
const auto fadeTransparentInputs = FadeRenderJob::Input(fadeTransparents, lightingModel, fadeConfigureOutputs).asVarying();
|
||||
task.addJob<FadeRenderJob>("DrawFadeTransparent", fadeTransparentInputs, commonFadeParameters, shapePlumber);
|
||||
|
||||
// LIght Cluster Grid Debuging job
|
||||
{
|
||||
const auto debugLightClustersInputs = DebugLightClusters::Inputs(deferredFrameTransform, deferredFramebuffer, lightingModel, linearDepthTarget, lightClusters).asVarying();
|
||||
|
@ -176,7 +162,6 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren
|
|||
task.addJob<ToneMappingDeferred>("ToneMapping", toneMappingInputs);
|
||||
|
||||
{ // DEbug the bounds of the rendered items, still look at the zbuffer
|
||||
task.addJob<DrawBounds>("DrawFadedOpaqueBounds", fadeOpaques);
|
||||
task.addJob<DrawBounds>("DrawMetaBounds", metas);
|
||||
task.addJob<DrawBounds>("DrawOpaqueBounds", opaques);
|
||||
task.addJob<DrawBounds>("DrawTransparentBounds", transparents);
|
||||
|
|
|
@ -314,12 +314,16 @@ public:
|
|||
class FadeState {
|
||||
public:
|
||||
|
||||
enum {
|
||||
INACTIVE = (uint8_t)-1
|
||||
};
|
||||
|
||||
uint8_t eventType{ INACTIVE };
|
||||
uint64_t startTime{ 0 };
|
||||
glm::vec3 noiseOffset{ 0.f, 0.f, 0.f };
|
||||
glm::vec3 baseOffset{ 0.f, 0.f, 0.f };
|
||||
glm::vec3 baseSize{ 1.f, 1.f, 1.f };
|
||||
float threshold{ 0.f };
|
||||
uint8_t eventType{ (uint8_t)-1 };
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue