PeriDyno 1.0.0
Loading...
Searching...
No Matches
ApplyBumpMap2TriangleSet.cu
Go to the documentation of this file.
1#include "ApplyBumpMap2TriangleSet.h"
2
3#include "Math/Lerp.h"
4
5namespace dyno
6{
7 IMPLEMENT_TCLASS(ApplyBumpMap2TriangleSet, TDataType)
8
9 template<typename TDataType>
10 ApplyBumpMap2TriangleSet<TDataType>::ApplyBumpMap2TriangleSet()
11 : TopologyMapping()
12 {
13 }
14
15 template<typename Real, typename Coord3D>
16 __global__ void ABMTS_UpdateVertices(
17 DArray<Coord3D> vertices,
18 DArray2D<Coord3D> bumpMap,
19 Coord3D origin,
20 Real h)
21 {
22 int tId = threadIdx.x + (blockIdx.x * blockDim.x);
23 if (tId >= vertices.size()) return;
24
25 Coord3D xyz = vertices[tId];
26
27 Real x = (xyz.x - origin.x) / h;
28 Real z = (xyz.z - origin.z) / h;
29
30 Coord3D disp = bilinear(bumpMap, x, z);
31
32 vertices[tId] = xyz + disp;
33 }
34
35 template<typename TDataType>
36 bool ApplyBumpMap2TriangleSet<TDataType>::apply()
37 {
38 if (this->outTriangleSet()->isEmpty()) {
39 this->outTriangleSet()->allocate();
40 }
41
42 auto inTs = this->inTriangleSet()->constDataPtr();
43 auto outTs = this->outTriangleSet()->getDataPtr();
44
45 auto topo = this->inHeightField()->constDataPtr();
46 auto& disp = topo->getDisplacement();
47 Coord3D origin = topo->getOrigin();
48 Real h = topo->getGridSpacing();
49
50 outTs->copyFrom(*inTs);
51
52 auto& vertices = outTs->getPoints();
53
54 cuExecute(vertices.size(),
55 ABMTS_UpdateVertices,
56 vertices,
57 disp,
58 origin,
59 h);
60
61 outTs->update();
62
63 return true;
64 }
65
66 DEFINE_CLASS(ApplyBumpMap2TriangleSet);
67}