31 const Size particleCnt = cached.r.size();
39 cached.flags.resize(particleCnt);
44 for (
Size i = 0; i < particleCnt; ++i) {
45 cached.flags[i] = idxs[i];
46 if (reduce[i] == 0._f) {
54 cached.materialIDs.resize(particleCnt);
55 cached.materialIDs.fill(0);
56 const bool loadTextures = cached.textures.empty();
64 cached.materialIDs[i] = matId;
68 if (loadTextures && !texturePath.empty()) {
69 if (textureMap.
contains(texturePath)) {
70 cached.textures[matId] = textureMap[texturePath];
74 textureMap.
insert(texturePath, texture);
75 cached.textures[matId] = texture;
80 cached.v.resize(particleCnt);
88 cached.v[i] = m[i] / rho;
92 for (
Size i = 0; i < particleCnt; ++i) {
98 cached.colors.resize(particleCnt);
99 for (
Size i = 0; i < particleCnt; ++i) {
100 cached.colors[i] = colorizer.
evalColor(i);
101 if (cached.doEmission) {
108 for (
Size i = 0; i < particleCnt; ++i) {
112 bvh.
build(std::move(spheres));
119 march.previousIdx =
Size(-1);
120 data.data = std::move(march);
127 return !cached.r.empty();
134 MarchData& march(data.data);
136 return this->getSurfaceColor(march, params, march.previousIdx, hit.value(), ray.direction());
144 if (index != data.previousIdx) {
146 finder->
findAll(index, kernel.
radius() * cached.r[index][
H], neighs);
147 data.previousIdx = index;
152 const Size flag1 = cached.flags[index];
153 const Size flag2 = cached.flags[n.index];
155 data.neighs.push(n.index);
164 const Float surfaceLevel,
165 const bool occlusion)
const {
166 data.intersections.clear();
168 std::sort(data.intersections.begin(), data.intersections.end());
174 sc.t_min = intersect.
t;
175 sc.surfaceLevel = surfaceLevel;
186 const IntersectContext& context,
187 bool occlusion)
const {
188 if (fixed.renderSpheres) {
189 data.previousIdx = context.index;
190 return context.ray.origin() + context.ray.direction() * context.t_min;
193 this->getNeighbourList(data, context.index);
195 const Size i = context.index;
196 const Ray& ray = context.ray;
203 const Float limit = 2._f * cached.r[i][
H];
205 Float eps = 0.5_f * cached.r[i][
H];
209 Float travelled = eps;
210 while (travelled < limit && eps > 0.2_f * cached.r[i][
H]) {
211 phi = this->evalField(data.neighs, v2) - context.surfaceLevel;
217 v2 = 0.5_f * (v1 + v2);
229 if (travelled >= limit) {
237 Rgba RayMarcher::getSurfaceColor(MarchData& data,
241 const Vector& dir)
const {
243 if (!cached.textures.empty() && !cached.uvws.empty()) {
244 Size textureIdx = cached.materialIDs[index];
246 if (textureIdx >= cached.textures.size()) {
249 if (cached.textures[textureIdx]) {
250 const Vector uvw = this->evalUvws(data.neighs, hit);
251 diffuse = cached.textures[textureIdx]->eval(uvw);
256 const Rgba colorizerValue =
257 fixed.renderSpheres ? cached.colors[index] : this->evalColor(data.neighs, hit);
260 if (cached.doEmission) {
263 diffuse = diffuse * colorizerValue;
267 const Vector n = fixed.renderSpheres ? cached.r[index] - hit : this->evalGradient(data.neighs, hit);
270 const Float cosPhi =
dot(n_norm, fixed.dirToSun);
271 if (cosPhi <= 0._f) {
278 Ray rayToSun(hit - 1.e-3_f * fixed.dirToSun, -fixed.dirToSun);
279 if (this->intersect(data, rayToSun, params.
surface.
level,
true)) {
286 const Float f = fixed.brdf->transport(n_norm, -dir, fixed.dirToSun);
295 for (
Size index : neighs) {
296 const Vector& pos2 = cached.r[index];
298 const Float w = kernel.
value(pos1 - pos2, pos2[
H]);
299 value += cached.v[index] * w;
306 for (
Size index : neighs) {
307 const Vector& pos2 = cached.r[index];
308 const Vector grad = kernel.
grad(pos1 - pos2, pos2[
H]);
309 value += cached.v[index] * grad;
317 float weightSum = 0.f;
318 for (
Size index : neighs) {
319 const Vector& pos2 = cached.r[index];
321 const float w = float(kernel.
value(pos1 - pos2, pos2[
H]) * cached.v[index]);
322 color += cached.colors[index] * w;
326 return color / weightSum;
334 Float weightSum = 0._f;
336 for (
Size index : neighs) {
337 const Vector& pos2 = cached.r[index];
341 seamFlag |= cached.uvws[index][
X] <
SEAM_WIDTH ? 0x01 : 0;
342 seamFlag |= cached.uvws[index][
X] > 1._f -
SEAM_WIDTH ? 0x02 : 0;
344 if (seamFlag & 0x03) {
348 for (
Size index : neighs) {
349 const Vector& pos2 = cached.r[index];
352 Vector uvw = cached.uvws[index];
354 uvw[
X] -= (uvw[
X] > 0.5_f) ? 1._f : 0._f;
364 return uvws / weightSum;
INLINE bool almostEqual(const AffineMatrix &m1, const AffineMatrix &m2, const Float eps=EPS)
#define SPH_ASSERT(x,...)
Wrapper of wxBitmap, will be possibly replaced by custom implementation.
Defines projection transforming 3D particles onto 2D screen.
Object converting quantity values of particles into colors.
Key-value associative container implemented as a sorted array.
uint32_t Size
Integral type used to index arrays (by default).
double Float
Precision used withing the code. Use Float instead of float or double where precision is important.
INLINE Float weight(const Vector &r1, const Vector &r2)
constexpr INLINE Float sphereVolume(const Float radius)
Computes a volume of a sphere given its radius.
constexpr Float PI
Mathematical constants.
#define NAMESPACE_SPH_END
const NothingType NOTHING
Helper iterators allowing to save values to containers.
BackInserter< TContainer > backInserter(TContainer &c)
Tool to measure time spent in functions and profile the code.
#define MEASURE_SCOPE(name)
@ FLAG
ID of original body, used to implement discontinuities between bodies in SPH.
@ POSITION
Positions (velocities, accelerations) of particles, always a vector quantity,.
@ DENSITY
Density, always a scalar quantity.
@ MASS
Paricles masses, always a scalar quantity.
@ STRESS_REDUCING
Total stress reduction factor due to damage and yielding. Is always scalar.
@ UVW
Texture mapping coordinates,.
constexpr Size BLEND_ALL_FLAG
constexpr Float SEAM_WIDTH
StaticArray< T0 &, sizeof...(TArgs)+1 > tie(T0 &t0, TArgs &... rest)
Creates a static array from a list of l-value references.
INLINE Float getSqrLength(const Vector &v)
BasicVector< Float > Vector
INLINE float dot(const BasicVector< float > &v1, const BasicVector< float > &v2)
Make sure the vector is trivially constructible and destructible, needed for fast initialization of a...
INLINE Vector getNormalized(const Vector &v)
INLINE bool empty() const
void reserve(const TCounter newMaxSize)
Allocates enough memory to store the given number of elements.
StorageType & emplaceBack(TArgs &&... args)
Constructs a new element at the end of the array in place, using the provided arguments.
Trait for finding intersections with a sphere.
void build(Array< TBvhObject > &&objects)
Contructs the BVH from given set of objects.
Size getAllIntersections(const Ray &ray, TOutIter iter) const
Returns all intersections of the ray.
Cubic spline (M4) kernel.
Container of key-value pairs.
INLINE bool contains(const TKey &key) const
Returns true if the map contains element of given key.
INLINE TValue & insert(const TKey &key, const TValue &value)
Adds a new element into the map or sets new value of element with the same key.
INLINE TValue get(const GuiSettingsId id) const
void build(IScheduler &scheduler, ArrayView< const Vector > points)
Constructs the struct with an array of vectors.
virtual Size findAll(const Size index, const Float radius, Array< NeighbourRecord > &neighbours) const =0
Finds all neighbours within given radius from the point given by index.
Interface defining a camera or view, used by a renderer.
Interface for objects assigning colors to particles.
virtual Rgba evalColor(const Size idx) const =0
Returns the color of idx-th particle.
virtual Optional< float > evalScalar(const Size UNUSED(idx)) const
Returns the scalar representation of the colorized quantity for idx-th particle.
Base class for renderers based on raytracing.
Rgba getEnviroColor(const CameraRay &ray) const
ThreadLocal< ThreadData > threadData
SharedPtr< IScheduler > scheduler
std::atomic_bool shouldContinue
INLINE Float value(const Vector &r, const Float h) const noexcept
INLINE Vector grad(const Vector &r, const Float h) const noexcept
INLINE Float radius() const noexcept
Non-owning wrapper of a material and particles with this material.
INLINE IndexSequence sequence()
Returns iterable index sequence.
Wrapper of type value of which may or may not be present.
INLINE Type & value()
Returns the reference to the stored value.
Object representing a path on a filesystem.
Array< Vector > uvws
Mapping coordinates. May be empty.
virtual void initialize(const Storage &storage, const IColorizer &colorizer, const ICamera &camera) override
Prepares the objects for rendering and updates its data.
RayMarcher(SharedPtr< IScheduler > scheduler, const GuiSettings &settings)
virtual bool isInitialized() const override
Checks if the renderer has been initialized.
const Vector & direction() const
const Vector & origin() const
static const Settings & getDefaults()
\brief Returns a reference to object containing default values of all settings.
Container storing all quantities used within the simulations.
Size getMaterialCnt() const
Return the number of materials in the storage.
auto getValues(const QuantityId first, const QuantityId second, const TArgs... others)
Retrieves an array of quantities from the key.
MaterialView getMaterial(const Size matIdx) const
Returns an object containing a reference to given material.
bool has(const QuantityId key) const
Checks if the storage contains quantity with given key.
Array< TValue > & getValue(const QuantityId key)
Retrieves a quantity values from the storage, given its key and value type.
@ DENSITY
Density at zero pressure.
@ SURFACE_SUN_POSITION
Direction to the sun used for shading.
AutoPtr< IBrdf > getBrdf(const GuiSettings &settings)
AutoPtr< ISymmetricFinder > getFinder(const RunSettings &settings)
Size userData
Generic user data, can be used to store additional information to the primitives.
Ray given by origin and target point.
Holds intormation about intersection.
Float t
Distance of the hit in units of ray.direction().
const BvhPrimitive * object
Object hit by the ray, or nullptr if nothing has been hit.
Holds information about a neighbour particles.
Parameters of the rendered image.
float sunLight
Intensity of the sunlight.
float level
Value of the iso-surface defining the rendered surface.
struct RenderParams::@35 surface
Parameters of rendered surface.
float emission
Emission multiplier.
float ambientLight
Intensity of the ambient light, illuminating every point unconditionally.