From 4ec94c97879aafef15f7663135745e4ba61e62cf Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Mon, 17 May 2021 00:15:33 +0200 Subject: Extract first public LiterateLB version --- tangle/sampler/velocity_norm.h | 79 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 tangle/sampler/velocity_norm.h (limited to 'tangle/sampler/velocity_norm.h') diff --git a/tangle/sampler/velocity_norm.h b/tangle/sampler/velocity_norm.h new file mode 100644 index 0000000..59ca0a7 --- /dev/null +++ b/tangle/sampler/velocity_norm.h @@ -0,0 +1,79 @@ +#pragma once + +#include "sampler.h" + +#include +#include + +#include +#include +#include + +#include + +template +class VelocityNormS : public Sampler { +private: +Lattice& _lattice; +DeviceBuffer& _mask; +SDF _geometry; + +DeviceBuffer _moments_rho; +DeviceBuffer _moments_u; +DeviceBuffer _u_norm; + +float _scale = 1; +float _lower = 0; +float _upper = 1; + +public: +VelocityNormS(Lattice& lattice, DeviceBuffer& mask, SDF geometry): + Sampler("Velocity norm", lattice.cuboid()), + _lattice(lattice), + _mask(mask), + _geometry(geometry), + _moments_rho(lattice.cuboid().volume), + _moments_u(DESCRIPTOR::d * lattice.cuboid().volume), + _u_norm(lattice.cuboid().volume) +{ } + +void sample() { + _lattice.template inspect(_mask, _moments_rho.device(), _moments_u.device()); + _lattice.template helper(_mask, _moments_u.device(), _sample_surface, _u_norm.device()); +} + +void render(VolumetricRenderConfig& config) { + raymarch<<< + dim3(config.canvas_size.x / 32 + 1, config.canvas_size.y / 32 + 1), + dim3(32, 32) + >>>(config, + _geometry, + [samples=_sample_texture, scale=_scale, lower=_lower, upper=_upper] + __device__ (float3 p) -> float { + float sample = scale * tex3D(samples, p.x, p.y, p.z); + return sample >= lower && sample <= upper ? sample : 0; + }, + [] __device__ (float x) -> float { + return x; + }); +} + +void scale() { + auto max = thrust::max_element(thrust::device_pointer_cast(_u_norm.device()), + thrust::device_pointer_cast(_u_norm.device() + _lattice.cuboid().volume)); + _scale = 1 / max[0]; +} + +void interact() { + ImGui::SliderFloat("Scale", &_scale, 0.01f, 100.f); + ImGui::SameLine(); + if (ImGui::Button("Auto")) { + scale(); + } + ImGui::DragFloatRange2("Bounds", &_lower, &_upper, 0.01f, 0.f, 1.f, "%.2f", "%.2f"); +} + +}; + +template +VelocityNormS(Lattice&, DeviceBuffer&, SDF) -> VelocityNormS; -- cgit v1.2.3