SPH
RayTracer.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "gui/Settings.h"
4 #include "gui/objects/Color.h"
5 #include "gui/renderers/Brdf.h"
7 #include "objects/finders/Bvh.h"
8 #include "sph/kernel/Kernel.h"
9 
11 
12 class FrameBuffer;
13 class IBrdf;
14 class IColorMap;
15 
16 class RayMarcher : public IRaytracer {
17 private:
19  Bvh<BvhSphere> bvh;
20 
22  AutoPtr<IBasicFinder> finder;
23 
24  LutKernel<3> kernel;
25 
29  struct {
30 
33 
36 
38  bool shadows = true;
39 
41  bool renderSpheres = true;
42 
43  } fixed;
44 
45  struct MarchData {
47  Array<Size> neighs;
48 
50  Array<IntersectionInfo> intersections;
51 
53  Size previousIdx;
54 
55  MarchData() = default;
56  MarchData(MarchData&& other) = default;
57  MarchData(const MarchData& other)
58  : neighs(other.neighs.clone())
59  , intersections(other.intersections.clone())
60  , previousIdx(other.previousIdx) {
61  // needed to be used in Any, but never should be actually called
62  SPH_ASSERT(false);
63  }
64  };
65 
66  struct {
69 
72 
75 
78 
81 
84 
88 
90  bool doEmission;
91 
92  } cached;
93 
94 public:
96 
97  ~RayMarcher() override;
98 
99  virtual void initialize(const Storage& storage,
100  const IColorizer& colorizer,
101  const ICamera& camera) override;
102 
103  virtual bool isInitialized() const override;
104 
105 private:
106  virtual Rgba shade(const RenderParams& params,
107  const CameraRay& cameraRay,
108  ThreadData& data) const override;
109 
114  ArrayView<const Size> getNeighbourList(MarchData& data, const Size index) const;
115 
119  Optional<Vector> intersect(MarchData& data,
120  const Ray& ray,
121  const Float surfaceLevel,
122  const bool occlusion) const;
123 
124  struct IntersectContext {
126  Size index;
127 
129  Ray ray;
130 
132  Float t_min;
133 
135  Float surfaceLevel;
136  };
137 
141  Optional<Vector> getSurfaceHit(MarchData& data,
142  const IntersectContext& context,
143  const bool occlusion) const;
144 
146  Rgba getSurfaceColor(MarchData& data,
147  const RenderParams& params,
148  const Size index,
149  const Vector& hit,
150  const Vector& dir) const;
151 
152  Float evalField(ArrayView<const Size> neighs, const Vector& pos) const;
153 
154  Vector evalGradient(ArrayView<const Size> neighs, const Vector& pos) const;
155 
156  Rgba evalColor(ArrayView<const Size> neighs, const Vector& pos1) const;
157 
158  Vector evalUvws(ArrayView<const Size> neighs, const Vector& pos1) const;
159 };
160 
#define SPH_ASSERT(x,...)
Definition: Assert.h:94
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
uint32_t Size
Integral type used to index arrays (by default).
Definition: Globals.h:16
double Float
Precision used withing the code. Use Float instead of float or double where precision is important.
Definition: Globals.h:13
Interface for renderers.
SPH kernels.
#define NAMESPACE_SPH_END
Definition: Object.h:12
Definition: Brdf.h:7
Interface defining a camera or view, used by a renderer.
Definition: Camera.h:62
Interface for objects assigning colors to particles.
Definition: Colorizer.h:34
Base class for renderers based on raytracing.
Definition: IRenderer.h:196
SharedPtr< IScheduler > scheduler
Definition: IRenderer.h:198
Wrapper of type value of which may or may not be present.
Definition: Optional.h:23
Array< Size > materialIDs
Material ID for each particle.
Definition: RayTracer.h:83
Array< Size > flags
Particle indices.
Definition: RayTracer.h:80
bool doEmission
If true, the colors are used for emission, otherwise for diffuse reflectance.
Definition: RayTracer.h:90
Array< Vector > r
Particle positions.
Definition: RayTracer.h:68
Array< Vector > uvws
Mapping coordinates. May be empty.
Definition: RayTracer.h:74
Array< Float > v
Particle volume (=mass/density)
Definition: RayTracer.h:77
virtual void initialize(const Storage &storage, const IColorizer &colorizer, const ICamera &camera) override
Prepares the objects for rendering and updates its data.
Definition: RayTracer.cpp:26
RayMarcher(SharedPtr< IScheduler > scheduler, const GuiSettings &settings)
Definition: RayTracer.cpp:13
virtual bool isInitialized() const override
Checks if the renderer has been initialized.
Definition: RayTracer.cpp:126
Array< SharedPtr< Texture > > textures
Definition: RayTracer.h:87
Vector dirToSun
Direction to sun; sun is assumed to be a point light source.
Definition: RayTracer.h:32
bool renderSpheres
Render surface of spheres instead of an isosurface.
Definition: RayTracer.h:41
AutoPtr< IBrdf > brdf
BRDF used to get the surface reflectance.
Definition: RayTracer.h:35
bool shadows
Cast shadows.
Definition: RayTracer.h:38
~RayMarcher() override
Array< Rgba > colors
Particle colors.
Definition: RayTracer.h:71
Definition: Bvh.h:10
Definition: Color.h:8
Container storing all quantities used within the simulations.
Definition: Storage.h:230
Ray given by origin and target point.
Definition: Camera.h:56
Parameters of the rendered image.
Definition: IRenderer.h:60