feat: add particle visual runtime controls
Some checks failed
validate-scripts / validate-scripts (push) Has been cancelled
Some checks failed
validate-scripts / validate-scripts (push) Has been cancelled
This commit is contained in:
@@ -58,16 +58,33 @@ struct ParticleSettings {
|
||||
bool usesFormalSource;
|
||||
float timeMix;
|
||||
uint32_t particleCount;
|
||||
float lineWidth;
|
||||
float particleLength;
|
||||
float particleOpacity;
|
||||
float trailOpacity;
|
||||
float trailFade;
|
||||
bool speedColorEnabled;
|
||||
};
|
||||
|
||||
ParticleSettings particleSettings(const Immutable<style::Layer::Impl>& value) {
|
||||
if (value->getTypeInfo() == style::RasterParticleLayer::Impl::staticTypeInfo()) {
|
||||
const auto& layer = static_cast<const style::RasterParticleLayer::Impl&>(*value);
|
||||
return {layer.active, layer.maskMode, 0, true, layer.timeMix, layer.particleCount};
|
||||
return {layer.active,
|
||||
layer.maskMode,
|
||||
0,
|
||||
true,
|
||||
layer.timeMix,
|
||||
layer.particleCount,
|
||||
layer.lineWidth,
|
||||
layer.particleLength,
|
||||
layer.particleOpacity,
|
||||
layer.trailOpacity,
|
||||
layer.trailFade,
|
||||
layer.speedColorEnabled};
|
||||
}
|
||||
assert(value->getTypeInfo() == style::ParticleValidationLayer::Impl::staticTypeInfo());
|
||||
const auto& layer = static_cast<const style::ParticleValidationLayer::Impl&>(*value);
|
||||
return {layer.active, layer.maskMode, layer.fixtureMode, false, 0.0f, 256};
|
||||
return {layer.active, layer.maskMode, layer.fixtureMode, false, 0.0f, 256, 2.0f, 0.018f, 1.0f, 1.0f, 0.965f, false};
|
||||
}
|
||||
|
||||
enum class ValidationPass : uint8_t {
|
||||
@@ -190,6 +207,12 @@ public:
|
||||
uint64_t resetCount = 0;
|
||||
float timeMix = 0.0f;
|
||||
uint32_t particleCount = 0;
|
||||
float lineWidth = 2.0f;
|
||||
float particleLength = 0.018f;
|
||||
float particleOpacity = 1.0f;
|
||||
float trailOpacity = 1.0f;
|
||||
float trailFade = 0.92f;
|
||||
bool speedColorEnabled = true;
|
||||
uint8_t fixtureMode = 255;
|
||||
uint8_t loggedMaskMode = 255;
|
||||
Size trailSize{};
|
||||
@@ -265,22 +288,29 @@ constexpr uint32_t MaxParticleVerticesPerSegment = std::numeric_limits<uint16_t>
|
||||
|
||||
void rebuildParticleDrawResources(const std::shared_ptr<ParticleGpuResources>& resources) {
|
||||
auto vertices = std::make_shared<gfx::VertexVector<HeatmapTextureLayoutVertex>>();
|
||||
vertices->reserve(resources->particleCount);
|
||||
// Each State texel is represented by a two-vertex line. Its endpoints are
|
||||
// static texel indices; State position, interpolated Field velocity and
|
||||
// orientation remain GPU-owned in the vertex shader.
|
||||
vertices->reserve(resources->particleCount * 2);
|
||||
for (uint32_t particleIndex = 0; particleIndex < resources->particleCount; ++particleIndex) {
|
||||
const auto x = static_cast<int16_t>(particleIndex % resources->stateSize.width);
|
||||
const auto y = static_cast<int16_t>(particleIndex / resources->stateSize.width);
|
||||
vertices->emplace_back(HeatmapBucket::textureVertex({x, y}));
|
||||
// a_pos.x packs state X and endpoint (0=start, 1=end). State grids
|
||||
// are at most 1024 wide, so the encoded value remains a signed short.
|
||||
vertices->emplace_back(HeatmapBucket::textureVertex({static_cast<int16_t>(x * 2), y}));
|
||||
vertices->emplace_back(HeatmapBucket::textureVertex({static_cast<int16_t>(x * 2 + 1), y}));
|
||||
}
|
||||
|
||||
auto indices = std::make_shared<gfx::IndexVectorBase>();
|
||||
indices->reserve(std::min(resources->particleCount, MaxParticleVerticesPerSegment));
|
||||
for (uint32_t index = 0; index < std::min(resources->particleCount, MaxParticleVerticesPerSegment); ++index) {
|
||||
indices->reserve(MaxParticleVerticesPerSegment);
|
||||
for (uint32_t index = 0; index < MaxParticleVerticesPerSegment; ++index) {
|
||||
indices->extend(1, static_cast<uint16_t>(index));
|
||||
}
|
||||
|
||||
SegmentVector segments;
|
||||
for (uint32_t offset = 0; offset < resources->particleCount; offset += MaxParticleVerticesPerSegment) {
|
||||
const auto count = std::min(resources->particleCount - offset, MaxParticleVerticesPerSegment);
|
||||
const auto vertexCount = resources->particleCount * 2;
|
||||
for (uint32_t offset = 0; offset < vertexCount; offset += MaxParticleVerticesPerSegment) {
|
||||
const auto count = std::min(vertexCount - offset, MaxParticleVerticesPerSegment);
|
||||
segments.emplace_back(offset, 0, count, count);
|
||||
}
|
||||
resources->particleVertices = std::move(vertices);
|
||||
@@ -337,17 +367,20 @@ public:
|
||||
|
||||
const float frame = simulationStep;
|
||||
const float markerX = resources->timeMix;
|
||||
const float markerY = 0.5f + 0.32f * std::cos(frame * 0.053f);
|
||||
// RenderTarget clear is opaque black. State initialization must therefore
|
||||
// be an explicit lifecycle signal, never inferred from sampled alpha.
|
||||
const bool seedState = pass == ValidationPass::State && !resources->stateSeeded;
|
||||
const shaders::ParticleGpuValidationUBO ubo = {
|
||||
.pass = {static_cast<float>(pass), frame, maskMode == 0 ? 0.0f : 1.0f, static_cast<float>(maskMode)},
|
||||
.marker = {markerX, markerY, 0.035f, 0.965f},
|
||||
.marker = {markerX, resources->speedColorEnabled ? 1.0f : 0.0f, 0.035f, 0.965f},
|
||||
.mask = {static_cast<float>(resources->stateSize.width),
|
||||
static_cast<float>(resources->stateSize.height),
|
||||
resources->formalDisplay ? 1.0f : 0.0f,
|
||||
seedState ? 1.0f : 0.0f},
|
||||
.visual = {resources->particleOpacity,
|
||||
resources->particleLength,
|
||||
resources->trailOpacity,
|
||||
resources->formalDisplay ? resources->trailFade : 0.965f},
|
||||
.matrix = util::cast<float>(parameters.matrixForTile({worldWrap, {0, 0, 0}})),
|
||||
};
|
||||
drawable.mutableUniformBuffers().createOrUpdate(shaders::idParticleGpuValidationUBO, &ubo, parameters.context);
|
||||
@@ -590,7 +623,7 @@ bool buildParticlePoints(gfx::Context& context,
|
||||
builder->setCullFaceMode(gfx::CullFaceMode::disabled());
|
||||
builder->setVertexAttributes(std::move(attributes));
|
||||
builder->setRawVertices({}, resources->particleVertices->elements(), gfx::AttributeDataType::Short2);
|
||||
builder->setSegments(gfx::Points(3.0f),
|
||||
builder->setSegments(gfx::Lines(resources->lineWidth),
|
||||
resources->particleIndices,
|
||||
resources->particleSegments.data(),
|
||||
resources->particleSegments.size());
|
||||
@@ -627,7 +660,13 @@ RenderRasterParticleLayer::RenderRasterParticleLayer(Immutable<style::Layer::Imp
|
||||
settings.maskMode,
|
||||
settings.fixtureMode,
|
||||
settings.timeMix,
|
||||
settings.particleCount);
|
||||
settings.particleCount,
|
||||
settings.lineWidth,
|
||||
settings.particleLength,
|
||||
settings.particleOpacity,
|
||||
settings.trailOpacity,
|
||||
settings.trailFade,
|
||||
settings.speedColorEnabled);
|
||||
}()) {
|
||||
renderLayerInstanceId = ++nextRenderLayerInstanceId;
|
||||
formalSource = baseImpl->getTypeInfo() == style::RasterParticleLayer::Impl::staticTypeInfo();
|
||||
@@ -653,8 +692,18 @@ void RenderRasterParticleLayer::evaluate(const PropertyEvaluationParameters&) {
|
||||
"ParticleGPU: event=LAYER_CHANGED layerId=" + getID() +
|
||||
" renderLayerInstanceId=" + std::to_string(renderLayerInstanceId));
|
||||
const auto settings = particleSettings(baseImpl);
|
||||
auto properties = makeMutable<style::ParticleRenderLayerProperties>(
|
||||
baseImpl, settings.active, settings.maskMode, settings.fixtureMode, settings.timeMix, settings.particleCount);
|
||||
auto properties = makeMutable<style::ParticleRenderLayerProperties>(baseImpl,
|
||||
settings.active,
|
||||
settings.maskMode,
|
||||
settings.fixtureMode,
|
||||
settings.timeMix,
|
||||
settings.particleCount,
|
||||
settings.lineWidth,
|
||||
settings.particleLength,
|
||||
settings.particleOpacity,
|
||||
settings.trailOpacity,
|
||||
settings.trailFade,
|
||||
settings.speedColorEnabled);
|
||||
passes = RenderPass::Translucent;
|
||||
properties->renderPasses = mbgl::underlying_type(passes);
|
||||
evaluatedProperties = std::move(properties);
|
||||
@@ -664,7 +713,11 @@ void RenderRasterParticleLayer::evaluate(const PropertyEvaluationParameters&) {
|
||||
" maskMode=" + std::to_string(settings.maskMode) + " id=" + getID() + " fixture=" +
|
||||
(formalSource && sourceField ? sourceField->fixtureID : fixtureID(settings.fixtureMode)) +
|
||||
" layerIndex=" + std::to_string(getLayerIndex()) + " timeMix=" + std::to_string(settings.timeMix) +
|
||||
" particleCount=" + std::to_string(settings.particleCount) + " stage=40-03");
|
||||
" particleCount=" + std::to_string(settings.particleCount) + " lineWidth=" +
|
||||
std::to_string(settings.lineWidth) + " streakLength=" + std::to_string(settings.particleLength) +
|
||||
" particleOpacity=" + std::to_string(settings.particleOpacity) + " trailOpacity=" +
|
||||
std::to_string(settings.trailOpacity) + " trailFade=" + std::to_string(settings.trailFade) +
|
||||
" speedColor=" + (settings.speedColorEnabled ? "true" : "false") + " stage=40-05");
|
||||
}
|
||||
|
||||
bool RenderRasterParticleLayer::needsRepaint() const {
|
||||
@@ -687,7 +740,7 @@ void RenderRasterParticleLayer::layerRemoved(UniqueChangeRequestVec& changes) {
|
||||
std::to_string(gpuResources->particleCount) +
|
||||
" resourceGeneration=" + std::to_string(gpuResources->generation));
|
||||
Log::Info(Event::Render,
|
||||
"ParticleGPU: event=PARTICLE_DRAW_RESOURCES_RELEASE reason=LAYER_REMOVED trailDrawCount=" +
|
||||
"ParticleGPU: event=PARTICLE_DRAW_RESOURCES_RELEASE reason=LAYER_REMOVED streakVertexCount=" +
|
||||
std::to_string(gpuResources->particleVertices ? gpuResources->particleVertices->elements() : 0) +
|
||||
" fullParticleDraw=true resourceGeneration=" + std::to_string(gpuResources->generation));
|
||||
removeTargets(gpuResources->registeredTargets, changes);
|
||||
@@ -704,7 +757,7 @@ void RenderRasterParticleLayer::markContextDestroyed() {
|
||||
std::to_string(gpuResources->particleCount) +
|
||||
" resourceGeneration=" + std::to_string(gpuResources->generation));
|
||||
Log::Info(Event::Render,
|
||||
"ParticleGPU: event=PARTICLE_DRAW_RESOURCES_RELEASE reason=CONTEXT_DESTROYED trailDrawCount=" +
|
||||
"ParticleGPU: event=PARTICLE_DRAW_RESOURCES_RELEASE reason=CONTEXT_DESTROYED streakVertexCount=" +
|
||||
std::to_string(gpuResources->particleVertices ? gpuResources->particleVertices->elements() : 0) +
|
||||
" fullParticleDraw=true resourceGeneration=" + std::to_string(gpuResources->generation));
|
||||
Log::Info(
|
||||
@@ -852,8 +905,8 @@ void RenderRasterParticleLayer::update(gfx::ShaderRegistry& shaders,
|
||||
"ParticleGPU: event=PARTICLE_DRAW_RESOURCES_CREATE effectiveParticleCount=" +
|
||||
std::to_string(resources->particleCount) + " stateGrid=" +
|
||||
std::to_string(resources->stateSize.width) + "x" + std::to_string(resources->stateSize.height) +
|
||||
" trailDrawCount=" + std::to_string(resources->particleVertices->elements()) +
|
||||
" particleIndexCount=" + std::to_string(resources->particleVertices->elements()) +
|
||||
" particleDrawCount=" + std::to_string(resources->particleCount) +
|
||||
" streakVertexCount=" + std::to_string(resources->particleVertices->elements()) +
|
||||
" fullParticleDraw=true resourceGeneration=" + std::to_string(resources->generation));
|
||||
Log::Info(
|
||||
Event::Render,
|
||||
@@ -913,7 +966,7 @@ void RenderRasterParticleLayer::update(gfx::ShaderRegistry& shaders,
|
||||
std::to_string(previousSize.height) +
|
||||
" resourceGeneration=" + std::to_string(resources->generation));
|
||||
Log::Info(Event::Render,
|
||||
"ParticleGPU: event=PARTICLE_DRAW_RESOURCES_RELEASE reason=PARTICLE_COUNT_CHANGE trailDrawCount=" +
|
||||
"ParticleGPU: event=PARTICLE_DRAW_RESOURCES_RELEASE reason=PARTICLE_COUNT_CHANGE streakVertexCount=" +
|
||||
std::to_string(resources->particleVertices ? resources->particleVertices->elements() : 0) +
|
||||
" fullParticleDraw=true resourceGeneration=" + std::to_string(resources->generation));
|
||||
removeTargets(resources->stateTargets, changes);
|
||||
@@ -932,8 +985,8 @@ void RenderRasterParticleLayer::update(gfx::ShaderRegistry& shaders,
|
||||
"ParticleGPU: event=PARTICLE_DRAW_RESOURCES_REBUILD effectiveParticleCount=" +
|
||||
std::to_string(resources->particleCount) + " stateGrid=" +
|
||||
std::to_string(resources->stateSize.width) + "x" + std::to_string(resources->stateSize.height) +
|
||||
" trailDrawCount=" + std::to_string(resources->particleVertices->elements()) +
|
||||
" particleIndexCount=" + std::to_string(resources->particleVertices->elements()) +
|
||||
" particleDrawCount=" + std::to_string(resources->particleCount) +
|
||||
" streakVertexCount=" + std::to_string(resources->particleVertices->elements()) +
|
||||
" fullParticleDraw=true resourceGeneration=" + std::to_string(resources->generation));
|
||||
}
|
||||
|
||||
@@ -1054,6 +1107,31 @@ void RenderRasterParticleLayer::update(gfx::ShaderRegistry& shaders,
|
||||
" resetCount=" + std::to_string(resources->resetCount));
|
||||
}
|
||||
|
||||
const bool visualChanged = resources->lineWidth != properties.lineWidth ||
|
||||
resources->particleLength != properties.particleLength ||
|
||||
resources->particleOpacity != properties.particleOpacity ||
|
||||
resources->trailOpacity != properties.trailOpacity ||
|
||||
resources->trailFade != properties.trailFade ||
|
||||
resources->speedColorEnabled != properties.speedColorEnabled;
|
||||
if (visualChanged) {
|
||||
resources->lineWidth = properties.lineWidth;
|
||||
resources->particleLength = properties.particleLength;
|
||||
resources->particleOpacity = properties.particleOpacity;
|
||||
resources->trailOpacity = properties.trailOpacity;
|
||||
resources->trailFade = properties.trailFade;
|
||||
resources->speedColorEnabled = properties.speedColorEnabled;
|
||||
Log::Info(Event::Render,
|
||||
"ParticleGPU: event=VISUAL_PROPERTY_APPLIED lineWidth=" + std::to_string(resources->lineWidth) +
|
||||
" streakLength=" + std::to_string(resources->particleLength) +
|
||||
" particleOpacity=" + std::to_string(resources->particleOpacity) + " trailOpacity=" +
|
||||
std::to_string(resources->trailOpacity) + " trailFade=" + std::to_string(resources->trailFade) +
|
||||
" speedColor=" + (resources->speedColorEnabled ? "true" : "false") +
|
||||
" renderLayerInstanceId=" + std::to_string(resources->renderLayerInstanceId) +
|
||||
" resourceGeneration=" + std::to_string(resources->generation) +
|
||||
" fieldUploadCount=" + std::to_string(resources->fieldUploadCount) +
|
||||
" resetCount=" + std::to_string(resources->resetCount));
|
||||
}
|
||||
|
||||
if (!resources->lifecycleModeKnown || resources->lifecycleActive != active) {
|
||||
Log::Info(Event::Render,
|
||||
"ParticleRender: lifecycle transition=" + std::string(active ? "ACTIVE" : "STATIC") +
|
||||
|
||||
Reference in New Issue
Block a user