1#include "ApplyBumpMap2TriangleSet.h"
7 IMPLEMENT_TCLASS(ApplyBumpMap2TriangleSet, TDataType)
9 template<typename TDataType>
10 ApplyBumpMap2TriangleSet<TDataType>::ApplyBumpMap2TriangleSet()
15 template<typename Real, typename Coord3D>
16 __global__ void ABMTS_UpdateVertices(
17 DArray<Coord3D> vertices,
18 DArray2D<Coord3D> bumpMap,
22 int tId = threadIdx.x + (blockIdx.x * blockDim.x);
23 if (tId >= vertices.size()) return;
25 Coord3D xyz = vertices[tId];
27 Real x = (xyz.x - origin.x) / h;
28 Real z = (xyz.z - origin.z) / h;
30 Coord3D disp = bilinear(bumpMap, x, z);
32 vertices[tId] = xyz + disp;
35 template<typename TDataType>
36 bool ApplyBumpMap2TriangleSet<TDataType>::apply()
38 if (this->outTriangleSet()->isEmpty()) {
39 this->outTriangleSet()->allocate();
42 auto inTs = this->inTriangleSet()->constDataPtr();
43 auto outTs = this->outTriangleSet()->getDataPtr();
45 auto topo = this->inHeightField()->constDataPtr();
46 auto& disp = topo->getDisplacement();
47 Coord3D origin = topo->getOrigin();
48 Real h = topo->getGridSpacing();
50 outTs->copyFrom(*inTs);
52 auto& vertices = outTs->getPoints();
54 cuExecute(vertices.size(),
66 DEFINE_CLASS(ApplyBumpMap2TriangleSet);