Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Matt Larsen
VTK-m
Commits
342092f6
Commit
342092f6
authored
Feb 01, 2016
by
Matt Larsen
Browse files
path tracer mostly working
parent
54158d7e
Changes
12
Hide whitespace changes
Inline
Side-by-side
examples/raytesting/CMakeLists.txt
View file @
342092f6
...
...
@@ -31,7 +31,7 @@ add_executable(testray_SERIAL testray.cxx)
if
(
VTKm_Cuda_FOUND
)
vtkm_disable_troublesome_thrust_warnings
()
#
cuda_add_executable(testray_CUDA testray.cu)
cuda_add_executable
(
testray_CUDA testray.cu
)
# cuda_add_executable(testraster_CUDA testraster.cu)
# cuda_add_executable(testvolume_CUDA testvolume.cu)
target_link_libraries
(
testray_CUDA
)
...
...
@@ -39,10 +39,10 @@ endif()
if
(
VTKm_ENABLE_TBB
)
add_executable
(
testray_TBB testrayTBB.cxx
)
add_executable
(
testraster_TBB testrasterTBB.cxx
)
add_executable
(
testvolume_TBB testvolumeTBB.cxx
)
#
add_executable(testraster_TBB testrasterTBB.cxx)
#
add_executable(testvolume_TBB testvolumeTBB.cxx)
# target_include_directories(testray_TBB )
target_link_libraries
(
testray_TBB
PRIVATE
${
TBB_LIBRARIES
}
)
target_link_libraries
(
testray_TBB
)
# target_link_libraries(testraster_TBB PRIVATE ${TBB_LIBRARIES})
# target_link_libraries(testvolume_TBB PRIVATE ${TBB_LIBRARIES})
endif
()
...
...
vtkm/cont/tbb/internal/DeviceAdapterAlgorithmTBB.h
View file @
342092f6
...
...
@@ -399,7 +399,7 @@ private:
}
};
/*
template<>
class DeviceAdapterDepthBufferImplementation<vtkm::cont::DeviceAdapterTagTBB>
{
...
...
@@ -450,7 +450,7 @@ private:
}
}
};
};
*/
}
}
// namespace vtkm::cont
...
...
vtkm/io/reader/VTKPolyDataReader.h
View file @
342092f6
...
...
@@ -146,7 +146,7 @@ private:
vtkm
::
io
::
internal
::
FixupCellSet
(
connectivity
,
numIndices
,
shapes
,
permutation
);
this
->
SetCellsPermutation
(
permutation
);
if
(
vtkm
::
io
::
internal
::
IsSingleShape
(
shapes
))
if
(
vtkm
::
io
::
internal
::
IsSingleShape
(
shapes
)
&&
false
)
{
vtkm
::
cont
::
CellSetSingleType
<>
cs
;
switch
(
shapes
.
GetPortalConstControl
().
Get
(
0
))
...
...
vtkm/rendering/SceneRendererRayTracer.h
View file @
342092f6
...
...
@@ -34,8 +34,8 @@ class SceneRendererRayTracer : public SceneRenderer
{
protected:
vtkm
::
cont
::
ArrayHandle
<
vtkm
::
Vec
<
vtkm
::
Float32
,
4
>
>
ColorMap
;
vtkm
::
rendering
::
raytracing
::
RayTracer
<
DeviceAdapter
>
Tracer
;
//
vtkm::rendering::raytracing::PathTracer<DeviceAdapter> Tracer;
//
vtkm::rendering::raytracing::RayTracer<DeviceAdapter> Tracer;
vtkm
::
rendering
::
raytracing
::
PathTracer
<
DeviceAdapter
>
Tracer
;
public:
VTKM_CONT_EXPORT
SceneRendererRayTracer
()
...
...
@@ -71,4 +71,4 @@ public:
}
};
}}
//namespace vtkm::rendering
#endif //vtk_m_rendering_SceneRendererRayTracer_h
\ No newline at end of file
#endif //vtk_m_rendering_SceneRendererRayTracer_h
vtkm/rendering/raytracing/BoundingVolumeHierarchy.h
View file @
342092f6
...
...
@@ -162,7 +162,7 @@ public:
const
PointPortalType
&
points
)
const
{
// cast to Float32
std
::
cout
<<
"Here"
<<
std
::
endl
;
//
std::cout<<"Here"<<std::endl;
vtkm
::
Vec
<
vtkm
::
Float32
,
3
>
point
;
point
=
static_cast
<
vtkm
::
Vec
<
vtkm
::
Float32
,
3
>
>
(
points
.
Get
(
indices
[
1
]));
xmin
=
point
[
0
];
...
...
vtkm/rendering/raytracing/Camera.h
View file @
342092f6
...
...
@@ -23,6 +23,7 @@
#include
<vtkm/cont/ArrayHandle.h>
#include
<vtkm/cont/ErrorControlBadValue.h>
#include
<vtkm/rendering/View.h>
#include
<vtkm/rendering/raytracing/Sampler.h>
#include
<vtkm/rendering/raytracing/Ray.h>
#include
<vtkm/rendering/raytracing/Worklets.h>
#include
<vtkm/worklet/DispatcherMapField.h>
...
...
@@ -106,6 +107,90 @@ public:
}
};
// class perspective ray gen
class
PerspectiveRayGenJitter
:
public
vtkm
::
worklet
::
WorkletMapField
{
public:
vtkm
::
Int32
w
;
vtkm
::
Int32
h
;
vtkm
::
Vec
<
vtkm
::
Float32
,
3
>
nlook
;
// normalized look
vtkm
::
Vec
<
vtkm
::
Float32
,
3
>
delta_x
;
vtkm
::
Vec
<
vtkm
::
Float32
,
3
>
delta_y
;
vtkm
::
Int32
CurrentSample
;
VTKM_CONT_EXPORT
PerspectiveRayGenJitter
(
vtkm
::
Int32
width
,
vtkm
::
Int32
height
,
vtkm
::
Float32
fovX
,
vtkm
::
Float32
fovY
,
vtkm
::
Vec
<
vtkm
::
Float32
,
3
>
look
,
vtkm
::
Vec
<
vtkm
::
Float32
,
3
>
up
,
vtkm
::
Float32
_zoom
,
vtkm
::
Int32
currentSample
)
:
w
(
width
),
h
(
height
)
{
vtkm
::
Float32
thx
=
tanf
(
(
fovX
*
3.1415926
f
/
180.
f
)
*
.5
f
);
vtkm
::
Float32
thy
=
tanf
(
(
fovY
*
3.1415926
f
/
180.
f
)
*
.5
f
);
std
::
cout
<<
"Tan fovx "
<<
thx
<<
std
::
endl
;
vtkm
::
Vec
<
vtkm
::
Float32
,
3
>
ru
=
vtkm
::
Cross
(
up
,
look
);
vtkm
::
Normalize
(
ru
);
vtkm
::
Vec
<
vtkm
::
Float32
,
3
>
rv
=
vtkm
::
Cross
(
ru
,
look
);
vtkm
::
Normalize
(
rv
);
delta_x
=
ru
*
(
2
*
thx
/
(
float
)
w
);
delta_y
=
rv
*
(
2
*
thy
/
(
float
)
h
);
if
(
_zoom
>
0
)
{
delta_x
[
0
]
=
delta_x
[
0
]
/
_zoom
;
delta_x
[
1
]
=
delta_x
[
1
]
/
_zoom
;
delta_x
[
2
]
=
delta_x
[
2
]
/
_zoom
;
delta_y
[
0
]
=
delta_y
[
0
]
/
_zoom
;
delta_y
[
1
]
=
delta_y
[
1
]
/
_zoom
;
delta_y
[
2
]
=
delta_y
[
2
]
/
_zoom
;
}
nlook
=
look
;
vtkm
::
Normalize
(
nlook
);
std
::
cout
<<
"Up/look/right "
<<
ru
<<
nlook
<<
rv
<<
std
::
endl
;
CurrentSample
=
currentSample
;
}
typedef
void
ControlSignature
(
FieldOut
<>
,
FieldOut
<>
,
FieldOut
<>
,
FieldIn
<>
);
typedef
void
ExecutionSignature
(
WorkIndex
,
_1
,
_2
,
_3
,
_4
);
VTKM_EXEC_EXPORT
void
operator
()(
vtkm
::
Id
idx
,
vtkm
::
Float32
&
rayDirX
,
vtkm
::
Float32
&
rayDirY
,
vtkm
::
Float32
&
rayDirZ
,
const
vtkm
::
Int32
&
seed
)
const
{
vtkm
::
Vec
<
vtkm
::
Float32
,
2
>
xy
;
Halton2D
<
3
>
(
CurrentSample
+
seed
,
xy
);
xy
[
0
]
-=
.5
f
;
xy
[
1
]
-=
.5
f
;
vtkm
::
Vec
<
vtkm
::
Float32
,
3
>
ray_dir
(
rayDirX
,
rayDirY
,
rayDirZ
);
vtkm
::
Float32
i
=
vtkm
::
Int32
(
idx
)
%
w
;
vtkm
::
Float32
j
=
vtkm
::
Int32
(
idx
)
/
w
;
i
+=
xy
[
0
];
j
+=
xy
[
1
];
ray_dir
=
nlook
+
delta_x
*
((
2.
f
*
i
-
vtkm
::
Float32
(
w
))
/
2.0
f
)
+
delta_y
*
((
2.
f
*
j
-
vtkm
::
Float32
(
h
))
/
2.0
f
);
vtkm
::
Normalize
(
ray_dir
);
rayDirX
=
ray_dir
[
0
];
rayDirY
=
ray_dir
[
1
];
rayDirZ
=
ray_dir
[
2
];
}
};
// class perspective ray gen jitter
private:
vtkm
::
Int32
Height
;
vtkm
::
Int32
Width
;
...
...
@@ -330,8 +415,53 @@ public:
vtkm
::
worklet
::
DispatcherMapField
<
MemSet
<
vtkm
::
Float32
>
>
(
MemSet
<
vtkm
::
Float32
>
(
1e12
f
)
)
.
Invoke
(
rays
.
Distance
);
//Reset the Rays Hit Index to -2
vtkm
::
worklet
::
DispatcherMapField
<
MemSet
<
vtkm
::
Id
>
>
(
MemSet
<
vtkm
::
Id
>
(
-
2
)
)
//Reset the Rays Hit Index to 0
vtkm
::
worklet
::
DispatcherMapField
<
MemSet
<
vtkm
::
Id
>
>
(
MemSet
<
vtkm
::
Id
>
(
0
)
)
.
Invoke
(
rays
.
HitIdx
);
}
//create rays
VTKM_CONT_EXPORT
void
CreateRaysJitter
(
Ray
&
rays
,
vtkm
::
Int32
currentSample
,
vtkm
::
cont
::
ArrayHandle
<
vtkm
::
Int32
>
&
seeds
)
{
if
(
IsResDirty
)
rays
.
resize
(
Height
*
Width
);
IsResDirty
=
false
;
//Set the origin of the ray back to the camera position
vtkm
::
worklet
::
DispatcherMapField
<
MemSet
<
vtkm
::
Float32
>
>
(
MemSet
<
vtkm
::
Float32
>
(
Position
[
0
]
)
)
.
Invoke
(
rays
.
OriginX
);
vtkm
::
worklet
::
DispatcherMapField
<
MemSet
<
vtkm
::
Float32
>
>
(
MemSet
<
vtkm
::
Float32
>
(
Position
[
1
]
)
)
.
Invoke
(
rays
.
OriginY
);
vtkm
::
worklet
::
DispatcherMapField
<
MemSet
<
vtkm
::
Float32
>
>
(
MemSet
<
vtkm
::
Float32
>
(
Position
[
2
]
)
)
.
Invoke
(
rays
.
OriginZ
);
//Reset the camera look vector
Look
=
LookAt
-
Position
;
vtkm
::
Normalize
(
Look
);
std
::
cout
<<
"******Loook "
<<
Look
<<
std
::
endl
;
std
::
cout
<<
"******Pos "
<<
Position
<<
std
::
endl
;
//Create the ray direction
vtkm
::
worklet
::
DispatcherMapField
<
PerspectiveRayGenJitter
>
(
PerspectiveRayGenJitter
(
Width
,
Height
,
FovX
,
FovY
,
Look
,
Up
,
Zoom
,
currentSample
)
)
.
Invoke
(
rays
.
DirX
,
rays
.
DirY
,
rays
.
DirZ
,
seeds
);
//X Y Z
vtkm
::
worklet
::
DispatcherMapField
<
MemSet
<
vtkm
::
Float32
>
>
(
MemSet
<
vtkm
::
Float32
>
(
1e12
f
)
)
.
Invoke
(
rays
.
Distance
);
//Reset the Rays Hit Index to 0
vtkm
::
worklet
::
DispatcherMapField
<
MemSet
<
vtkm
::
Id
>
>
(
MemSet
<
vtkm
::
Id
>
(
0
)
)
.
Invoke
(
rays
.
HitIdx
);
}
//create rays
...
...
vtkm/rendering/raytracing/PathTracer.h
View file @
342092f6
...
...
@@ -105,6 +105,54 @@ static void WriteColorBuffer(vtkm::rendering::raytracing::ColorBuffer4f &rgba,
}
};
//Class pathwriter
class
ColorMultiply
:
public
vtkm
::
worklet
::
WorkletMapField
{
public:
VTKM_CONT_EXPORT
ColorMultiply
()
{
}
typedef
void
ControlSignature
(
FieldIn
<>
,
FieldInOut
<>
,
FieldIn
<>
);
typedef
void
ExecutionSignature
(
_1
,
_2
,
_3
);
VTKM_EXEC_EXPORT
void
operator
()(
vtkm
::
Vec
<
vtkm
::
Float32
,
4
>
&
color1
,
vtkm
::
Vec
<
vtkm
::
Float32
,
4
>
&
color2
,
const
vtkm
::
Id
&
hitIndex
)
const
{
if
(
hitIndex
<
0
)
return
;
color2
=
color1
*
color2
;
}
};
//class ColorMultiply
class
WeightedAccum
:
public
vtkm
::
worklet
::
WorkletMapField
{
private:
vtkm
::
Int32
NumberOfSamples
;
public:
VTKM_CONT_EXPORT
WeightedAccum
(
const
vtkm
::
Int32
&
numberOfSamples
)
:
NumberOfSamples
(
numberOfSamples
)
{
}
typedef
void
ControlSignature
(
FieldIn
<>
,
FieldInOut
<>
);
typedef
void
ExecutionSignature
(
_1
,
_2
);
VTKM_EXEC_EXPORT
void
operator
()(
vtkm
::
Vec
<
vtkm
::
Float32
,
4
>
&
color1
,
vtkm
::
Vec
<
vtkm
::
Float32
,
4
>
&
color2
)
const
{
vtkm
::
Vec
<
vtkm
::
Float32
,
4
>
total
=
color2
*
NumberOfSamples
+
color1
;
color2
[
0
]
=
total
[
0
]
/
(
vtkm
::
Float32
(
NumberOfSamples
)
+
1.
f
);
color2
[
1
]
=
total
[
1
]
/
(
vtkm
::
Float32
(
NumberOfSamples
)
+
1.
f
);
color2
[
2
]
=
total
[
2
]
/
(
vtkm
::
Float32
(
NumberOfSamples
)
+
1.
f
);
color2
[
3
]
=
total
[
3
]
/
(
vtkm
::
Float32
(
NumberOfSamples
)
+
1.
f
);
}
};
//class ColorMultiply
class
PreethanBackground
:
public
vtkm
::
worklet
::
WorkletMapField
{
...
...
@@ -123,7 +171,7 @@ private:
vtkm
::
Float32
N
=
2.545E25
;
// air molecular density
vtkm
::
Float32
n
=
1.0003
f
;
//refractive index of air
return
(
8.
f
*
vtkm
::
Pow
(
vtkm
::
Pi
(),
3.
f
)
*
vtkm
::
Pow
(
vtkm
::
Pow
(
n
,
2.0
f
)
-
1.
f
,
2.
f
)
*
(
6.
f
+
3.
f
*
ad
))
/
(
3.
f
*
N
*
vtkm
::
Pow
(
waveLength
,
4.
f
)
*
(
6.
f
-
7.
f
*
ad
));
return
(
8.
f
*
vtkm
::
Pow
(
vtkm
::
Float32
(
vtkm
::
Pi
()
)
,
3.
f
)
*
vtkm
::
Pow
(
vtkm
::
Pow
(
n
,
2.0
f
)
-
1.
f
,
2.
f
)
*
(
6.
f
+
3.
f
*
ad
))
/
(
3.
f
*
N
*
vtkm
::
Pow
(
waveLength
,
4.
f
)
*
(
6.
f
-
7.
f
*
ad
));
}
VTKM_EXEC_CONT_EXPORT
...
...
@@ -132,7 +180,7 @@ private:
vtkm
::
Float32
t
)
const
{
vtkm
::
Float32
c
=
(
0.2
f
*
t
)
*
10E-18
;
return
0.434
f
*
c
*
vtkm
::
Pi
()
*
vtkm
::
Pow
((
2.
f
*
vtkm
::
Pi
())
/
waveLength
,
2.
f
)
*
k
;
return
0.434
f
*
c
*
vtkm
::
Float32
(
vtkm
::
Pi
()
)
*
vtkm
::
Pow
((
2.
f
*
vtkm
::
Float32
(
vtkm
::
Pi
())
)
/
waveLength
,
2.
f
)
*
k
;
}
public:
...
...
@@ -145,7 +193,7 @@ public:
up
[
0
]
=
0.
f
;
up
[
1
]
=
1.
f
;
up
[
2
]
=
0.
f
;
SunIntensity
=
1000.
f
*
vtkm
::
Max
(
0.
f
,
1.
f
-
vtkm
::
Exp
(
-
((
vtkm
::
Pi
()
/
2.
f
-
vtkm
::
ACos
(
vtkm
::
dot
(
SunDirection
,
up
)))
/
.5
f
)));
SunIntensity
=
1000.
f
*
vtkm
::
Max
(
0.
f
,
1.
f
-
vtkm
::
Exp
(
-
((
vtkm
::
Float32
(
vtkm
::
Pi
()
)
/
2.
f
-
vtkm
::
ACos
(
vtkm
::
dot
(
SunDirection
,
up
)))
/
.5
f
)));
//Earth scattering coeffs, all these can vary
float
reileigh
=
1.
f
;
float
mie
=
0.0553
f
;
...
...
@@ -159,7 +207,7 @@ public:
SunAngularCos
=
0.99995667694644844
f
;
// cos(0.5f);
}
typedef
void
ControlSignature
(
FieldInOut
<>
,
FieldOut
<>
,
Field
In
Out
<>
,
FieldIn
<>
);
typedef
void
ExecutionSignature
(
_1
,
_2
,
...
...
@@ -169,12 +217,13 @@ public:
vtkm
::
Vec
<
vtkm
::
Float32
,
4
>
&
color
,
const
vtkm
::
Vec
<
vtkm
::
Float32
,
3
>
&
rayDir
)
const
{
if
(
hitIndex
!=
-
1
)
if
(
hitIndex
!=
-
2
)
{
color
[
0
]
=
0.
f
;
color
[
1
]
=
0.
f
;
color
[
2
]
=
0.
f
;
color
[
3
]
=
0.
f
;
// color[0] = 1.f;
// color[1] = 1.f;
// color[2] = 1.f;
// color[3] = 1.f;
return
;
}
color
[
3
]
=
1.
f
;
...
...
@@ -183,10 +232,10 @@ public:
up
[
0
]
=
0.
f
;
up
[
1
]
=
1.
f
;
up
[
2
]
=
0.
f
;
vtkm
::
Float32
fPi
=
vtkm
::
Float32
(
vtkm
::
Pi
());
vtkm
::
Float32
skyAngle
=
vtkm
::
ACos
(
vtkm
::
Max
(
0.
f
,
vtkm
::
dot
(
rayDir
,
up
)));
//this could be the camera up
vtkm
::
Float32
sR
=
8.4E3
/
(
vtkm
::
Cos
(
skyAngle
)
+
0.15
f
*
vtkm
::
Pow
(
93.885
f
-
((
skyAngle
*
180.0
f
)
/
vtkm
::
Pi
()
),
-
1.253
f
));
vtkm
::
Float32
sM
=
1.25E3
/
(
vtkm
::
Cos
(
skyAngle
)
+
0.15
f
*
vtkm
::
Pow
(
93.885
f
-
((
skyAngle
*
180.0
f
)
/
vtkm
::
Pi
()
),
-
1.253
f
));
vtkm
::
Float32
sR
=
8.4E3
/
(
vtkm
::
Cos
(
skyAngle
)
+
0.15
f
*
vtkm
::
Pow
(
93.885
f
-
((
skyAngle
*
180.0
f
)
/
fPi
),
-
1.253
f
));
vtkm
::
Float32
sM
=
1.25E3
/
(
vtkm
::
Cos
(
skyAngle
)
+
0.15
f
*
vtkm
::
Pow
(
93.885
f
-
((
skyAngle
*
180.0
f
)
/
fPi
),
-
1.253
f
));
//cout<<"skyeAngle "<<skyAngle<<" "<<sR<<" "<<sM<<endl;
vtkm
::
Vec
<
vtkm
::
Float32
,
3
>
fex
;
for
(
int
i
=
0
;
i
<
3
;
++
i
)
...
...
@@ -197,14 +246,14 @@ public:
vtkm
::
Float32
cosTheta
=
vtkm
::
dot
(
rayDir
,
SunDirection
);
vtkm
::
Float32
rPhase
=
(
3.0
f
/
4.0
f
)
*
(
1.0
f
+
vtkm
::
Pow
(
cosTheta
,
2.
f
));
vtkm
::
Vec
<
vtkm
::
Float32
,
3
>
angleBetaR
=
BetaR
*
rPhase
;
vtkm
::
Float32
mPhase
=
(
1.0
f
/
(
4.0
f
*
vtkm
::
Pi
()
))
*
((
1.0
f
-
vtkm
::
Pow
(
MieG
,
2.
f
))
/
vtkm
::
Pow
(
1.0
f
-
2.0
f
*
MieG
*
cosTheta
+
vtkm
::
Pow
(
MieG
,
2.
f
),
1.5
f
));
vtkm
::
Float32
mPhase
=
(
1.0
f
/
(
4.0
f
*
fPi
))
*
((
1.0
f
-
vtkm
::
Pow
(
MieG
,
2.
f
))
/
vtkm
::
Pow
(
1.0
f
-
2.0
f
*
MieG
*
cosTheta
+
vtkm
::
Pow
(
MieG
,
2.
f
),
1.5
f
));
vtkm
::
Vec
<
vtkm
::
Float32
,
3
>
angleBetaM
=
BetaM
*
mPhase
;
vtkm
::
Vec
<
vtkm
::
Float32
,
3
>
lIn
;
vtkm
::
Float32
t
=
vtkm
::
Abs
(
SunDirection
[
1
]);
fex
[
0
]
=
lerp
(
fex
[
0
],
1.
f
-
fex
[
0
],
t
);
fex
[
1
]
=
lerp
(
fex
[
1
],
1.
f
-
fex
[
1
],
t
);
fex
[
2
]
=
lerp
(
fex
[
2
],
1.
f
-
fex
[
2
],
t
);
//std::cout<<fex<<" ";
for
(
int
i
=
0
;
i
<
3
;
++
i
)
{
lIn
[
i
]
=
SunIntensity
*
((
angleBetaR
[
i
]
+
angleBetaM
[
i
])
/
(
BetaR
[
i
]
+
BetaM
[
i
]))
*
fex
[
i
];
...
...
@@ -214,9 +263,10 @@ public:
if
(
cosTheta
>
SunAngularCos
)
pColor
=
pColor
+
SunIntensity
*
fex
;
pColor
=
pColor
+
lIn
;
pColor
=
pColor
*
.01
f
;
color
[
0
]
=
pColor
[
0
];
color
[
1
]
=
pColor
[
1
];
color
[
2
]
=
pColor
[
2
];
color
[
0
]
=
vtkm
::
Min
(
1.
f
,
color
[
0
]
*
pColor
[
0
]);
color
[
1
]
=
vtkm
::
Min
(
1.
f
,
color
[
1
]
*
pColor
[
1
]);
color
[
2
]
=
vtkm
::
Min
(
1.
f
,
color
[
2
]
*
pColor
[
2
]);
//std::cout<<color<< " pColor "<<pColor<<" ";
hitIndex
=
-
1
;
}
};
//class Preetham
...
...
@@ -343,63 +393,95 @@ public:
vtkm
::
Vec
<
vtkm
::
Float32
,
3
>
sunDirection
;
sunDirection
[
0
]
=
0.
f
;
sunDirection
[
1
]
=
1
.
f
;
sunDirection
[
1
]
=
1
;
sunDirection
[
2
]
=
0.
f
;
vtkm
::
Normalize
(
sunDirection
);
//std::cout<<"Sun direction "<<sunDirection<<std::endl;
//Clear the framebuffer
RGBA
.
Allocate
(
camera
.
GetWidth
()
*
camera
.
GetHeight
());
SurfaceColorBuffer
.
Allocate
(
camera
.
GetWidth
()
*
camera
.
GetHeight
());
CurrentColorBuffer
.
Allocate
(
camera
.
GetWidth
()
*
camera
.
GetHeight
());
vtkm
::
Vec
<
vtkm
::
Float32
,
4
>
clearColor
;
clearColor
[
0
]
=
1.
f
;
clearColor
[
1
]
=
1.
f
;
clearColor
[
2
]
=
1.
f
;
clearColor
[
3
]
=
1.
f
;
vtkm
::
Vec
<
vtkm
::
Float32
,
4
>
black
;
black
[
0
]
=
0.
f
;
black
[
1
]
=
0.
f
;
black
[
2
]
=
0.
f
;
black
[
3
]
=
0.
f
;
vtkm
::
worklet
::
DispatcherMapField
<
MemSet
<
vtkm
::
Vec
<
vtkm
::
Float32
,
4
>
>
>
(
MemSet
<
vtkm
::
Vec
<
vtkm
::
Float32
,
4
>
>
(
clearColor
)
)
.
Invoke
(
RGBA
);
TriangleIntersector
<
DeviceAdapter
>
intersector
;
vtkm
::
worklet
::
DispatcherMapField
<
MemSet
<
vtkm
::
Vec
<
vtkm
::
Float32
,
4
>
>
>
(
MemSet
<
vtkm
::
Vec
<
vtkm
::
Float32
,
4
>
>
(
black
)
)
.
Invoke
(
RGBA
);
for
(
int
i
=
0
;
i
<
1
;
i
++
)
TriangleIntersector
<
DeviceAdapter
>
intersector
;
const
int
maxDepth
=
5
;
const
int
numSamples
=
500
;
for
(
int
sample
=
0
;
sample
<
numSamples
;
++
sample
)
{
//Get the vertices array Handle for whatever type it is
std
::
cout
<<
"Intersection()
\n
"
;
Rays
.
PrintSummary
();
intersector
.
run
(
Rays
,
Bvh
,
CoordsHandle
);
//Get the scalar bounds so we can normalize on the fly
//vtkm::Float64 scalarBounds[2];
//ScalarField.GetBounds(scalarBounds, VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
Reflector
<
DeviceAdapter
>
reflector
;
reflector
.
run
(
Rays
,
Bvh
,
CoordsHandle
,
ScalarField
);
std
::
cout
<<
"Intersection Point()
\n
"
;
vtkm
::
worklet
::
DispatcherMapField
<
IntersectionPoint
>
(
IntersectionPoint
()
)
.
Invoke
(
Rays
.
HitIdx
,
Rays
.
Distance
,
Rays
.
Dir
,
Rays
.
Origin
,
Rays
.
IntersectionX
,
Rays
.
IntersectionY
,
Rays
.
IntersectionZ
);
std
::
cout
<<
"Surface Color
\n
"
;
vtkm
::
rendering
::
raytracing
::
SurfaceColor
<
DeviceAdapter
>
surfaceColor
;
surfaceColor
.
GetColorOnly
(
Rays
,
ColorMap
,
SurfaceColorBuffer
);
std
::
cout
<<
"Hemi
\n
"
;
vtkm
::
worklet
::
DispatcherMapField
<
Hemisphere
>
(
Hemisphere
(
i
)
)
.
Invoke
(
Rays
.
HitIdx
,
Seeds
,
Rays
.
Normal
,
Rays
.
DirX
,
Rays
.
DirY
,
Rays
.
DirZ
);
std
::
cout
<<
"Preetham
\n
"
;
vtkm
::
worklet
::
DispatcherMapField
<
PreethanBackground
>
(
PreethanBackground
(
sunDirection
)
)
.
Invoke
(
Rays
.
HitIdx
,
CurrentColorBuffer
,
Rays
.
Dir
);
}
// samples
vtkm
::
worklet
::
DispatcherMapField
<
MemSet
<
vtkm
::
Vec
<
vtkm
::
Float32
,
4
>
>
>
(
MemSet
<
vtkm
::
Vec
<
vtkm
::
Float32
,
4
>
>
(
clearColor
)
)
.
Invoke
(
CurrentColorBuffer
);
camera
.
CreateRaysJitter
(
Rays
,
sample
,
Seeds
);
for
(
int
depth
=
0
;
depth
<
maxDepth
;
depth
++
)
{
vtkm
::
worklet
::
DispatcherMapField
<
MemSet
<
vtkm
::
Vec
<
vtkm
::
Float32
,
4
>
>
>
(
MemSet
<
vtkm
::
Vec
<
vtkm
::
Float32
,
4
>
>
(
clearColor
)
)
.
Invoke
(
SurfaceColorBuffer
);
std
::
cout
<<
"Intersection()
\n
"
;
//Rays.PrintSummary();
intersector
.
run
(
Rays
,
Bvh
,
CoordsHandle
);
Reflector
<
DeviceAdapter
>
reflector
;
reflector
.
run
(
Rays
,
Bvh
,
CoordsHandle
,
ScalarField
);
std
::
cout
<<
"Intersection Point()
\n
"
;
vtkm
::
worklet
::
DispatcherMapField
<
IntersectionPoint
>
(
IntersectionPoint
()
)
.
Invoke
(
Rays
.
HitIdx
,
Rays
.
Distance
,
Rays
.
Dir
,
Rays
.
Origin
,
Rays
.
IntersectionX
,
Rays
.
IntersectionY
,
Rays
.
IntersectionZ
);
std
::
cout
<<
"Surface Color
\n
"
;
vtkm
::
rendering
::
raytracing
::
SurfaceColor
<
DeviceAdapter
>
surfaceColor
;
surfaceColor
.
GetColorOnly
(
Rays
,
ColorMap
,
SurfaceColorBuffer
);
vtkm
::
worklet
::
DispatcherMapField
<
ColorMultiply
>
(
ColorMultiply
()
)
.
Invoke
(
SurfaceColorBuffer
,
CurrentColorBuffer
,
Rays
.
HitIdx
);
std
::
cout
<<
"Preetham
\n
"
;
vtkm
::
worklet
::
DispatcherMapField
<
PreethanBackground
>
(
PreethanBackground
(
sunDirection
)
)
.
Invoke
(
Rays
.
HitIdx
,
CurrentColorBuffer
,
Rays
.
Dir
);
std
::
cout
<<
"Hemi
\n
"
;
vtkm
::
worklet
::
DispatcherMapField
<
Hemisphere
>
(
Hemisphere
(
sample
*
maxDepth
+
depth
)
)
.
Invoke
(
Rays
.
HitIdx
,
Seeds
,
Rays
.
Normal
,
Rays
.
DirX
,
Rays
.
DirY
,
Rays
.
DirZ
);
Rays
.
SwapIntersections
();
}
// Depth
vtkm
::
worklet
::
DispatcherMapField
<
WeightedAccum
>
(
WeightedAccum
(
sample
)
)
.
Invoke
(
CurrentColorBuffer
,
RGBA
);
}
//PathWriter::WriteDepthBuffer(Rays, camera.GetWidth(), camera.GetHeight());
PathWriter
::
WriteColorBuffer
(
SurfaceColorBuffer
,
camera
.
GetWidth
(),
camera
.
GetHeight
());
//std::cout<<"reg "<<std::acos(.5)<<" "<<vtkm::ACos(.5)<<std::endl;
PathWriter
::
WriteColorBuffer
(
RGBA
,
camera
.
GetWidth
(),
camera
.
GetHeight
());
}
};
//class RayTracer
}}}
// namespace vtkm::rendering::raytracing
...
...
vtkm/rendering/raytracing/Ray.h
View file @
342092f6
...
...
@@ -178,6 +178,39 @@ public:
Scalar
.
Allocate
(
NumRays
);
}
VTKM_CONT_EXPORT
void
SwapIntersections
()
{
vtkm
::
cont
::
ArrayHandle
<
vtkm
::
Float32
>
temp
;
temp
=
OriginX
;
OriginX
=
IntersectionX
;
IntersectionX
=
temp
;
temp
=
OriginY
;
OriginY
=
IntersectionY
;
IntersectionY
=
temp
;
temp
=
OriginZ
;
OriginZ
=
IntersectionZ
;
IntersectionZ
=
temp
;
vtkm
::
IdComponent
inComp
[
3
];
inComp
[
0
]
=
0
;
inComp
[
1
]
=
1
;
inComp
[
2
]
=
2
;
Origin
=
vtkm
::
cont
::
make_ArrayHandleCompositeVector
(
OriginX
,
inComp
[
0
],
OriginY
,
inComp
[
1
],
OriginZ
,
inComp
[
2
]);
Intersection
=
vtkm
::
cont
::
make_ArrayHandleCompositeVector
(
IntersectionX
,
inComp
[
0
],
IntersectionY
,
inComp
[
1
],
IntersectionZ
,
inComp
[
2
]);
}
VTKM_CONT_EXPORT
void
PrintSummary
()
{
...
...
vtkm/rendering/raytracing/RayTracer.h
View file @
342092f6
...
...
@@ -125,9 +125,9 @@ public:
{
if
(
hitIndex
<
0
)
return
;
intersectionX
=
rayOrigin
[
0
]
+
rayDir
[
0
]
*
distance
;
intersectionY
=
rayOrigin
[
1
]
+
rayDir
[
1
]
*
distance
;
intersectionZ
=
rayOrigin
[
2
]
+
rayDir
[
2
]
*
distance
;
intersectionX
=
rayOrigin
[
0
]
+
rayDir
[
0
]
*
(
distance
-
0.00001
)
;
intersectionY
=
rayOrigin
[
1
]
+
rayDir
[
1
]
*
(
distance
-
0.00001
)
;
intersectionZ
=
rayOrigin
[
2
]
+
rayDir
[
2
]
*
(
distance
-
0.00001
)
;
}
};
//class IntersectionPoint
...
...
@@ -427,7 +427,7 @@ public:
}
};
//class PhongShader
class
ColorOnly
:
public
vtkm
::
worklet
::
WorkletMapField