core: add scalar vector field snapshots
This commit is contained in:
@@ -155,18 +155,18 @@ std::shared_ptr<PremultipliedImage> makeVelocityFieldImage(const particle::Parti
|
||||
float scale = 1.0f;
|
||||
for (size_t index = 0; index < field.valid.size(); ++index) {
|
||||
if (!field.valid[index]) continue;
|
||||
scale = std::max(scale, std::abs(field.velocity[index * 2]));
|
||||
scale = std::max(scale, std::abs(field.velocity[index * 2 + 1]));
|
||||
scale = std::max(scale, std::abs(field.vector[index * 2]));
|
||||
scale = std::max(scale, std::abs(field.vector[index * 2 + 1]));
|
||||
}
|
||||
auto image = std::make_shared<PremultipliedImage>(Size{field.width, field.height});
|
||||
for (uint32_t y = 0; y < field.height; ++y) {
|
||||
for (uint32_t x = 0; x < field.width; ++x) {
|
||||
const auto cell = (static_cast<size_t>(y) * field.width + x) * 2;
|
||||
const auto pixel = (static_cast<size_t>(y) * field.width + x) * PremultipliedImage::channels;
|
||||
image->data[pixel + 0] = static_cast<uint8_t>(std::clamp(field.velocity[cell] / scale * 0.5f + 0.5f, 0.0f, 1.0f) *
|
||||
image->data[pixel + 0] = static_cast<uint8_t>(std::clamp(field.vector[cell] / scale * 0.5f + 0.5f, 0.0f, 1.0f) *
|
||||
255.0f);
|
||||
image->data[pixel + 1] = static_cast<uint8_t>(
|
||||
std::clamp(field.velocity[cell + 1] / scale * 0.5f + 0.5f, 0.0f, 1.0f) * 255.0f);
|
||||
std::clamp(field.vector[cell + 1] / scale * 0.5f + 0.5f, 0.0f, 1.0f) * 255.0f);
|
||||
image->data[pixel + 2] = 0;
|
||||
image->data[pixel + 3] = field.valid[y * field.width + x] ? 255 : 0;
|
||||
}
|
||||
@@ -178,8 +178,8 @@ float fieldVelocityScale(const particle::ParticleFieldSnapshot& field) {
|
||||
float scale = 1.0f;
|
||||
for (size_t index = 0; index < field.valid.size(); ++index) {
|
||||
if (!field.valid[index]) continue;
|
||||
scale = std::max(scale, std::abs(field.velocity[index * 2]));
|
||||
scale = std::max(scale, std::abs(field.velocity[index * 2 + 1]));
|
||||
scale = std::max(scale, std::abs(field.vector[index * 2]));
|
||||
scale = std::max(scale, std::abs(field.vector[index * 2 + 1]));
|
||||
}
|
||||
return scale;
|
||||
}
|
||||
@@ -506,8 +506,8 @@ public:
|
||||
const auto latitude = resources->field.north +
|
||||
(resources->field.south - resources->field.north) *
|
||||
(static_cast<float>(row) / std::max(1u, resources->field.height - 1));
|
||||
const auto u = resources->field.velocity[cell * 2];
|
||||
const auto v = resources->field.velocity[cell * 2 + 1];
|
||||
const auto u = resources->field.vector[cell * 2];
|
||||
const auto v = resources->field.vector[cell * 2 + 1];
|
||||
const auto cosLatitude = std::max(0.01f, std::cos(static_cast<float>(latitude * M_PI / 180.0)));
|
||||
const auto dx = u * simulationStep / EarthCircumferenceMeters;
|
||||
const auto dy = -v * simulationStep / (EarthCircumferenceMeters * cosLatitude);
|
||||
@@ -1077,6 +1077,12 @@ void RenderRasterParticleLayer::update(gfx::ShaderRegistry& shaders,
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Scalar-only is a valid V3 Core snapshot, but this velocity-only
|
||||
// renderer stays fail-closed until the V3-03 texture contract exists.
|
||||
if (formalSource && (!sourceField->hasVector() || !sourceNextField->hasVector())) {
|
||||
if (layerGroup) static_cast<LayerGroup&>(*layerGroup).clearDrawables();
|
||||
return;
|
||||
}
|
||||
if (!layerGroup || !isLayerRenderable()) return;
|
||||
|
||||
const auto& properties = static_cast<const style::ParticleRenderLayerProperties&>(*evaluatedProperties);
|
||||
@@ -1228,7 +1234,7 @@ void RenderRasterParticleLayer::update(gfx::ShaderRegistry& shaders,
|
||||
Log::Info(Event::Render,
|
||||
"ParticleField: field validated id=" + resources->field.fieldID +
|
||||
" noData=" + std::to_string(resources->field.noData) +
|
||||
" velocityCount=" + std::to_string(resources->field.velocity.size()));
|
||||
" vectorCount=" + std::to_string(resources->field.vector.size()));
|
||||
Log::Info(Event::Render,
|
||||
"ParticleField: created id=" + resources->field.fieldID +
|
||||
" generation=" + std::to_string(resources->fieldGeneration));
|
||||
|
||||
Reference in New Issue
Block a user