Commit a4d077c4 authored by OlegI94's avatar OlegI94

Last day commit

parent 62462a81
......@@ -33,6 +33,7 @@ struct Actor::InternalsType
vtkm::cont::DynamicCellSet Cells;
vtkm::cont::CoordinateSystem Coordinates;
vtkm::cont::Field ScalarField;
vtkm::cont::Field NormalField;
vtkm::cont::ColorTable ColorTable;
vtkm::Range ScalarRange;
......@@ -59,6 +60,21 @@ struct Actor::InternalsType
, Coordinates(coordinates)
, ScalarField(scalarField)
, ColorTable(colorTable)
{
// NormalField.Allocate(0);
}
VTKM_CONT
InternalsType(const vtkm::cont::DynamicCellSet& cells,
const vtkm::cont::CoordinateSystem& coordinates,
const vtkm::cont::Field& scalarField,
const vtkm::cont::Field& normalField,
const vtkm::cont::ColorTable& colorTable = vtkm::cont::ColorTable::Preset::DEFAULT)
: Cells(cells)
, Coordinates(coordinates)
, ScalarField(scalarField)
, NormalField(normalField)
, ColorTable(colorTable)
{
}
};
......@@ -71,6 +87,16 @@ Actor::Actor(const vtkm::cont::DynamicCellSet& cells,
this->Init(coordinates, scalarField);
}
Actor::Actor(const vtkm::cont::DynamicCellSet& cells,
const vtkm::cont::CoordinateSystem& coordinates,
const vtkm::cont::Field& scalarField,
const vtkm::cont::Field& normalField)
: Internals(new InternalsType(cells, coordinates, scalarField, normalField))
{
VTKM_ASSERT(normalField.GetData().GetNumberOfComponents() == 3);
this->Init(coordinates, scalarField);
}
Actor::Actor(const vtkm::cont::DynamicCellSet& cells,
const vtkm::cont::CoordinateSystem& coordinates,
const vtkm::cont::Field& scalarField,
......@@ -108,6 +134,7 @@ void Actor::Render(vtkm::rendering::Mapper& mapper,
mapper.RenderCells(this->Internals->Cells,
this->Internals->Coordinates,
this->Internals->ScalarField,
this->Internals->NormalField,
this->Internals->ColorTable,
camera,
this->Internals->ScalarRange,
......@@ -124,6 +151,7 @@ void Actor::RenderUpdate(vtkm::rendering::Mapper& mapper,
mapper.AddRenderCells(this->Internals->Cells,
this->Internals->Coordinates,
this->Internals->ScalarField,
this->Internals->NormalField,
this->Internals->ColorTable,
camera,
this->Internals->ScalarRange,
......
......@@ -39,6 +39,11 @@ public:
Actor(const vtkm::cont::DynamicCellSet& cells,
const vtkm::cont::CoordinateSystem& coordinates,
const vtkm::cont::Field& scalarField);
Actor(const vtkm::cont::DynamicCellSet& cells,
const vtkm::cont::CoordinateSystem& coordinates,
const vtkm::cont::Field& scalarField,
const vtkm::cont::Field& normalField);
Actor(const vtkm::cont::DynamicCellSet& cells,
const vtkm::cont::CoordinateSystem& coordinates,
......
......@@ -62,20 +62,16 @@ template<typename T, typename BackgroundImagePortalType>
VTKM_EXEC_CONT inline Spectrum getBackgroundFromImage(const Vec<T, 3>& dir, const BackgroundImagePortalType &bgImage, const Vec<UInt32, 2>& res)
{ //assume dir is normalized
using vec3 = Vec<Float32, 3>;
vec3 d = dir;
vec3 d = Normal(dir);
Float32 r = Float32(acos(d[2]) / (Sqrt(d[0]*d[0]+d[1]*d[1]) * Pi<T>()));
Vec<Float32, 2> imgCoords = Vec<Float32, 2>(d[0]*r, d[1]*r);
Vec<Float32, 2> imgCoordsNormalized = 0.5*(imgCoords + Vec<Float32, 2>(1));
// imgCoordsNormalized[1] = 1 - imgCoordsNormalized[1];
// imgCoordsNormalized = clamp(imgCoordsNormalized, Vec<Float32, 2>(0), Vec<Float32, 2>(1));
imgCoordsNormalized[1] = 1-imgCoordsNormalized[1];
// vec2i imgDim = res;
// vec2i imgCoord = min(texCoord,0.99999) * imgDim;
Vec<Float32, 2> imgCoordf((imgCoordsNormalized[0] * Float32(res[0]-1)), (imgCoordsNormalized[1] * Float32(res[1]-1)));
Vec<UInt32, 2> imgCoord((UInt32)imgCoordf[0], (UInt32)imgCoordf[1]);
imgCoordf = Vec<Float32, 2>(imgCoordf[0] - Float32(imgCoord[0]), imgCoordf[1] - Float32(imgCoord[1]));
// uint fCoord = min(size_t(imgCoord.x + imgCoord.y * imgDim.x), image.size()-1);
Id fCoord = Min(Max(Id(imgCoord[0] + imgCoord[1] * res[0]), Id(0)), bgImage.GetNumberOfValues()-1);
Spectrum ll = bgImage[fCoord];
......@@ -88,11 +84,7 @@ VTKM_EXEC_CONT inline Spectrum getBackgroundFromImage(const Vec<T, 3>& dir, cons
Spectrum b = Lerp(l, u, imgCoordf[1]);
// b = Max(b, Spectrum(0.001f));
// return bgImage[fCoord];
return b;
// return bgImage[0];
}
template<typename T, typename BackgroundImagePortalType>
......
......@@ -44,6 +44,7 @@ public:
virtual void RenderCells(const vtkm::cont::DynamicCellSet& cellset,
const vtkm::cont::CoordinateSystem& coords,
const vtkm::cont::Field& scalarField,
const vtkm::cont::Field& normalField,
const vtkm::cont::ColorTable& colorTable,
const vtkm::rendering::Camera& camera,
const vtkm::Range& scalarRange,
......@@ -52,11 +53,12 @@ public:
virtual void AddRenderCells(const vtkm::cont::DynamicCellSet& vtkmNotUsed(cellset),
const vtkm::cont::CoordinateSystem& vtkmNotUsed(coords),
const vtkm::cont::Field& vtkmNotUsed(scalarField),
const vtkm::cont::Field& vtkmNotUsed(normalField),
const vtkm::cont::ColorTable& vtkmNotUsed(colorTable),
const vtkm::rendering::Camera& vtkmNotUsed(camera),
const vtkm::Range& vtkmNotUsed(scalarRange),
const vtkm::rendering::Scene& vtkmNotUsed(scene)) {};
virtual void RenderStoredCells(const vtkm::rendering::Camera& vtkmNotUsed(camera)) {};
virtual void SetActiveColorTable(const vtkm::cont::ColorTable& ct);
......
......@@ -74,6 +74,7 @@ VTKM_CONT
void MapperConnectivity::RenderCells(const vtkm::cont::DynamicCellSet& cellset,
const vtkm::cont::CoordinateSystem& coords,
const vtkm::cont::Field& scalarField,
const vtkm::cont::Field& vtkmNotUsed(normalField),
const vtkm::cont::ColorTable& vtkmNotUsed(colorTable),
const vtkm::rendering::Camera& camera,
const vtkm::Range& vtkmNotUsed(scalarRange),
......
......@@ -43,6 +43,7 @@ public:
virtual void RenderCells(const vtkm::cont::DynamicCellSet& cellset,
const vtkm::cont::CoordinateSystem& coords,
const vtkm::cont::Field& scalarField,
const vtkm::cont::Field& normalField,
const vtkm::cont::ColorTable&, //colorTable
const vtkm::rendering::Camera& camera,
const vtkm::Range& scalarRange,
......
......@@ -449,6 +449,7 @@ MapperGL::~MapperGL()
void MapperGL::RenderCells(const vtkm::cont::DynamicCellSet& cellset,
const vtkm::cont::CoordinateSystem& coords,
const vtkm::cont::Field& scalarField,
const vtkm::cont::Field& vtkmNotUsed(normalField),
const vtkm::cont::ColorTable& colorTable,
const vtkm::rendering::Camera& camera,
const vtkm::Range& scalarRange,
......
......@@ -47,18 +47,11 @@ struct MapperPathTracer::InternalsType
vtkm::rendering::raytracing::PathTracer Tracer;
vtkm::rendering::raytracing::Camera RayCamera;
vtkm::rendering::raytracing::Ray<vtkm::Float32> Rays;
vtkm::UInt32 numRends = 500;
vtkm::UInt32 numRends = 50;
vtkm::UInt32 maxDepth = 12;
vtkm::UInt32 curRends = 0;
// vtkm::UInt32 num_rends = 10000;
// vtkm::UInt32 num_rends = 100000;
// vtkm::UInt32 num_rends = 2500;
// vtkm::UInt32 num_rends = 500;
// vtkm::UInt32 num_rends = 10;
// vtkm::UInt32 num_rends = 2;
// vtkm::UInt32 num_rends = 1;
// vtkm::cont::ArrayHandle<vtkm::Float32>
bool isVolume = false;
// Id3 volRendSize = Id3(0,0,0);
bool CompositeBackground;
VTKM_CONT
InternalsType()
......@@ -96,6 +89,7 @@ UInt32 MapperPathTracer::GetNumRends()
void MapperPathTracer::SetMaxDepth(const vtkm::UInt32 &val)
{
this->Internals->maxDepth = val;
this->Internals->Tracer.SetMaxDepth(this->Internals->maxDepth);
}
UInt32 MapperPathTracer::GetMaxDepth()
......@@ -136,12 +130,13 @@ vtkm::rendering::Canvas* MapperPathTracer::GetCanvas() const
void MapperPathTracer::RenderCells(const vtkm::cont::DynamicCellSet& cellset,
const vtkm::cont::CoordinateSystem& coords,
const vtkm::cont::Field& scalarField,
const vtkm::cont::Field& normalField,
const vtkm::cont::ColorTable& colorTable,
const vtkm::rendering::Camera& camera,
const vtkm::Range& scalarRange,
const vtkm::rendering::Scene& scene)
{
AddRenderCells(cellset, coords, scalarField, colorTable, camera, scalarRange, scene);
AddRenderCells(cellset, coords, scalarField, normalField, colorTable, camera, scalarRange, scene);
RenderStoredCells(camera);
this->Internals->Canvas->ToneMapCanvas(this->Internals->curRends + this->Internals->numRends);
......@@ -150,12 +145,13 @@ void MapperPathTracer::RenderCells(const vtkm::cont::DynamicCellSet& cellset,
}
void MapperPathTracer::AddRenderCells(const vtkm::cont::DynamicCellSet& cellset,
const vtkm::cont::CoordinateSystem& coords,
const vtkm::cont::Field& scalarField,
const vtkm::cont::ColorTable& vtkmNotUsed(colorTable),
const vtkm::rendering::Camera& vtkmNotUsed(camera),
const vtkm::Range& scalarRange,
const vtkm::rendering::Scene& scene)
const vtkm::cont::CoordinateSystem& coords,
const vtkm::cont::Field& scalarField,
const vtkm::cont::Field& normalField,
const vtkm::cont::ColorTable& vtkmNotUsed(colorTable),
const vtkm::rendering::Camera& vtkmNotUsed(camera),
const vtkm::Range& scalarRange,
const vtkm::rendering::Scene& scene)
{
raytracing::Logger* logger = raytracing::Logger::GetInstance();
logger->OpenLogEntry("mapper_path_tracer");
......@@ -175,6 +171,8 @@ void MapperPathTracer::AddRenderCells(const vtkm::cont::DynamicCellSet& cellset,
{
raytracing::TriangleIntersector* triIntersector = new raytracing::TriangleIntersector();
triIntersector->SetData(coords, triExtractor.GetTriangles());
triIntersector->SetNormals(normalField.GetData());
this->Internals->Tracer.AddShapeIntersector(triIntersector);
savedShapeBounds.Include(triIntersector->GetShapeBounds());
}
......@@ -213,7 +211,6 @@ void MapperPathTracer::AddRenderCells(const vtkm::cont::DynamicCellSet& cellset,
// scene.SetMaterialsFromColorMap(this->ColorMap, 10);
this->Internals->Tracer.SetColorMap(this->ColorMap);
this->Internals->Tracer.SetMaxDepth(this->Internals->maxDepth);
vtkm::Float64 time = timer.GetElapsedTime();
logger->AddLogData("add_shapes", time);
......
......@@ -44,6 +44,7 @@ public:
void RenderCells(const vtkm::cont::DynamicCellSet& cellset,
const vtkm::cont::CoordinateSystem& coords,
const vtkm::cont::Field& scalarField,
const vtkm::cont::Field& normalField,
const vtkm::cont::ColorTable& colorTable,
const vtkm::rendering::Camera& camera,
const vtkm::Range& scalarRange,
......@@ -52,12 +53,13 @@ public:
void AddRenderCells(const vtkm::cont::DynamicCellSet& cellset,
const vtkm::cont::CoordinateSystem& coords,
const vtkm::cont::Field& scalarField,
const vtkm::cont::Field& normalField,
const vtkm::cont::ColorTable& colorTable,
const vtkm::rendering::Camera& camera,
const vtkm::Range& scalarRange,
const vtkm::rendering::Scene& scene) override;
void RenderStoredCells(const vtkm::rendering::Camera& camera) override;
void RenderStoredCells(const vtkm::rendering::Camera& camera);
void ToneMap();
......
......@@ -123,6 +123,7 @@ void MapperPoint::UseVariableRadius(bool useVariableRadius)
void MapperPoint::RenderCells(const vtkm::cont::DynamicCellSet& cellset,
const vtkm::cont::CoordinateSystem& coords,
const vtkm::cont::Field& scalarField,
const vtkm::cont::Field& vtkmNotUsed(normalField),
const vtkm::cont::ColorTable& vtkmNotUsed(colorTable),
const vtkm::rendering::Camera& camera,
const vtkm::Range& scalarRange,
......
......@@ -78,6 +78,7 @@ public:
void RenderCells(const vtkm::cont::DynamicCellSet& cellset,
const vtkm::cont::CoordinateSystem& coords,
const vtkm::cont::Field& scalarField,
const vtkm::cont::Field& normalField,
const vtkm::cont::ColorTable& colorTable,
const vtkm::rendering::Camera& camera,
const vtkm::Range& scalarRange,
......
......@@ -86,6 +86,7 @@ vtkm::rendering::Canvas* MapperRayTracer::GetCanvas() const
void MapperRayTracer::RenderCells(const vtkm::cont::DynamicCellSet& cellset,
const vtkm::cont::CoordinateSystem& coords,
const vtkm::cont::Field& scalarField,
const vtkm::cont::Field& vtkmNotUsed(normalField),
const vtkm::cont::ColorTable& vtkmNotUsed(colorTable),
const vtkm::rendering::Camera& camera,
const vtkm::Range& scalarRange,
......
......@@ -44,6 +44,7 @@ public:
void RenderCells(const vtkm::cont::DynamicCellSet& cellset,
const vtkm::cont::CoordinateSystem& coords,
const vtkm::cont::Field& scalarField,
const vtkm::cont::Field& normalField,
const vtkm::cont::ColorTable& colorTable,
const vtkm::rendering::Camera& camera,
const vtkm::Range& scalarRange,
......
......@@ -89,6 +89,7 @@ vtkm::rendering::Canvas* MapperVolume::GetCanvas() const
void MapperVolume::RenderCells(const vtkm::cont::DynamicCellSet& cellset,
const vtkm::cont::CoordinateSystem& coords,
const vtkm::cont::Field& scalarField,
const vtkm::cont::Field& vtkmNotUsed(normalField),
const vtkm::cont::ColorTable& vtkmNotUsed(colorTable),
const vtkm::rendering::Camera& camera,
const vtkm::Range& scalarRange,
......
......@@ -42,6 +42,7 @@ public:
virtual void RenderCells(const vtkm::cont::DynamicCellSet& cellset,
const vtkm::cont::CoordinateSystem& coords,
const vtkm::cont::Field& scalarField,
const vtkm::cont::Field& normalField,
const vtkm::cont::ColorTable&, //colorTable
const vtkm::rendering::Camera& camera,
const vtkm::Range& scalarRange,
......
......@@ -314,6 +314,7 @@ void MapperWireframer::EndScene()
void MapperWireframer::RenderCells(const vtkm::cont::DynamicCellSet& inCellSet,
const vtkm::cont::CoordinateSystem& coords,
const vtkm::cont::Field& inScalarField,
const vtkm::cont::Field& normalField,
const vtkm::cont::ColorTable& colorTable,
const vtkm::rendering::Camera& camera,
const vtkm::Range& scalarRange,
......@@ -413,7 +414,7 @@ void MapperWireframer::RenderCells(const vtkm::cont::DynamicCellSet& inCellSet,
MapperRayTracer raytracer;
raytracer.SetCanvas(&canvas);
raytracer.SetActiveColorTable(colorTable);
raytracer.RenderCells(cellSet, actualCoords, actualField, colorTable, camera, scalarRange, scene);
raytracer.RenderCells(cellSet, actualCoords, actualField, normalField, colorTable, camera, scalarRange, scene);
renderer.SetSolidDepthBuffer(canvas.GetDepthBuffer());
}
else
......
......@@ -58,6 +58,7 @@ public:
virtual void RenderCells(const vtkm::cont::DynamicCellSet& cellset,
const vtkm::cont::CoordinateSystem& coords,
const vtkm::cont::Field& scalarField,
const vtkm::cont::Field& normalField,
const vtkm::cont::ColorTable& colorTable,
const vtkm::rendering::Camera& camera,
const vtkm::Range& scalarRange,
......
......@@ -56,9 +56,9 @@ VTKM_EXEC_CONT inline Float32 getInvBlinnScaledAngle(Float32 theta, Float32 r)
template<typename T>
VTKM_EXEC_CONT inline Float32 getGeometricTerm(Vec<T, 3> wi, Vec<T, 3> wo, Vec<T, 3> wh)
{ //all in terms of normal facing up
Float32 nDotWh = Abs(Cos(Float32(wh[2])));
Float32 nDotWo = Abs(Cos(Float32(wo[2])));
Float32 nDotWi = Abs(Cos(Float32(wi[2])));
Float32 nDotWh = Abs(Cos(Float32(wh[1])));
Float32 nDotWo = Abs(Cos(Float32(wo[1])));
Float32 nDotWi = Abs(Cos(Float32(wi[1])));
Float32 WoDotWh = Abs(Float32(Dot(wo, wh)));
return Min(1.f, Min((2.f * nDotWh * nDotWo / WoDotWh),
(2.f * nDotWh * nDotWi / WoDotWh)));
......@@ -106,11 +106,12 @@ VTKM_EXEC_CONT inline Spectrum getColorDiffuseSpecular(Vec<T, 3> inDir, Vec<T, 3
auto vec4ToVec3 = [](vec4 in)->vec3{vec3 ret; ret[0] = in[0]; ret[1] = in[1]; ret[2] = in[2]; return ret;};
Spectrum addCol = Spectrum(0.f);
vec3 wn = normal;
vec3 wi = inDir;
vec3 wo = outDir;
vec3 wn = Normal(normal);
vec3 wi = Normal(inDir);
vec3 wo = Normal(outDir);
vec3 wh;// = Normal(wi + wo);
// Float32 dotProduct = Max(0,Dot(wn,wo));
// vec4 diffuse = m.Diffuse;
......@@ -121,19 +122,20 @@ VTKM_EXEC_CONT inline Spectrum getColorDiffuseSpecular(Vec<T, 3> inDir, Vec<T, 3
if (dot(wn, wo) <= 0.f) {return addCol;}
{ //
vec3 rotAxis;
vec3 rotAxis = vec3(0,0,1);
// Float32 _len = 1.f;
T angle = T(0.f);
if (wn[2] < -0.99f) {wi = -wi; wo = -wo;}
else if (wn[2] < 0.99f)
if (wn[1] < -0.99f) {wi = -wi; wo = -wo;}
else if (wn[1] < 0.99f)
{
angle = acos(Dot(wn, vec3(0,0,1)));
rotAxis = Cross(wn, vec3(0,0,1));
angle = acos(Dot(wn, vec3(0,1,0)));
rotAxis = Cross(wn, vec3(0,1,0));
}
if (abs(angle) > 0.f)
{
vtkm::Matrix<T, 4, 4> rMat = rotationMatrix(rotAxis, angle);
vtkm::Matrix<T, 4, 4> rMat = rotationMatrix(rotAxis, -angle);
vec4 wi4, wo4;
wi4 = vec3ToVec4(wi);
wo4 = vec3ToVec4(wo);
......@@ -144,6 +146,7 @@ VTKM_EXEC_CONT inline Spectrum getColorDiffuseSpecular(Vec<T, 3> inDir, Vec<T, 3
wi = vec4ToVec3(wi4);
wo = vec4ToVec3(wo4);
}
// return SpectrumFromRGB((wi));
}
wh = Normal(wi + wo);
......@@ -153,8 +156,8 @@ VTKM_EXEC_CONT inline Spectrum getColorDiffuseSpecular(Vec<T, 3> inDir, Vec<T, 3
Float32 D = 1.f;
// Float32 D = getBlinnDistribution(wh, r); //Distribution term
Float32 dotI = abs(cos(Float32(wi[2])));
Float32 dotO = abs(cos(Float32(wo[2])));
Float32 dotI = abs(cos(Float32(wi[1])));
Float32 dotO = abs(cos(Float32(wo[1])));
Float32 refr = D * G * F / (4.f * dotI * dotO);
refr = Min(Max(refr, 0.f), 1.f);
......
......@@ -491,9 +491,15 @@ public:
{
vtkm::Vec<vtkm::UInt32, 4> randState;
randState[0] = vtkm::random::xorshift::getRand32(RayCount*1) + 1;
randState[1] = vtkm::random::xorshift::getRand32(RayCount*2) + 1;
randState[2] = vtkm::random::xorshift::getRand32(RayCount*3) + 1;
randState[3] = vtkm::random::xorshift::getRand32(RayCount*4) + 1;
randState[1] = vtkm::random::xorshift::getRand32(RayCount*2) + 2;
randState[2] = vtkm::random::xorshift::getRand32(RayCount*3) + 3;
randState[3] = vtkm::random::xorshift::getRand32(RayCount*4) + 4;
vtkm::random::xorshift::getRandF(randState);
vtkm::random::xorshift::getRandF(randState);
vtkm::random::xorshift::getRandF(randState);
vtkm::random::xorshift::getRandF(randState);
vtkm::Vec<Precision, 3> ray_dir(rayDirX, rayDirY, rayDirZ);
int i = vtkm::Int32(idx) % SubsetWidth;
int j = vtkm::Int32(idx) / SubsetWidth;
......@@ -506,7 +512,7 @@ public:
Precision _randU = vtkm::random::xorshift::getRandF(randState);
Precision _randV = vtkm::random::xorshift::getRandF(randState);
if (RayCount == 0) {_randU = 0; _randV = 0;}
if (RayCount < 2) {_randU = 0.5f; _randV = 0.5f;}
// if (idx == 15427)
// {
......@@ -517,8 +523,8 @@ public:
// DBGVAR(ray_dir);
// }
ray_dir = nlook + delta_x * ((2.f * (Precision(i) + (0.5 - _randU)) - Precision(w)) / 2.0f) +
delta_y * ((2.f * (Precision(j) + (0.5 - _randV)) - Precision(h)) / 2.0f);
ray_dir = nlook + delta_x * ((2.f * (Precision(i) + (1.f - _randU)) - Precision(w)) / 2.0f) +
delta_y * ((2.f * (Precision(j) + (_randV)) - Precision(h)) / 2.0f);
// if (idx == 15427)
// {
......
......@@ -300,6 +300,15 @@ VTKM_EXEC vtkm::Vec<T, 4> getBPhong(vtkm::Vec<T, 4> diffuse, vtkm::Vec<T, 4> spe
return retColor;
}
#define DBG_R spectrumAcc[0] += 1;
#define DBG_G spectrumAcc[1] += 1;
#define DBG_B spectrumAcc[2] += 1;
#define DBG_Rx(x) spectrumAcc[0] += x;
#define DBG_Gx(x) spectrumAcc[1] += x;
#define DBG_Bx(x) spectrumAcc[2] += x;
#define DBG_Cx(x) spectrumAcc += Vec<Float32,3>(x);
#define DBG_Vx(x) spectrumAcc += Vec<Float32,3>(x[0], x[2], x[1]);
class ShadeRay
{
public:
......@@ -356,16 +365,19 @@ public:
{
using vec3 = vtkm::Vec<Precision, 3>;
Precision iDist = Magnitude(intersection - origin);
vec3 viewDir = Normal(direction);
auto onReturn = [&](vec3 dir)
{
minDistance = 0;
GetInfinity(maxDistance);
hitIdx = -2;
direction = dir;
origin = intersection + (1e-3f * direction);
origin = intersection + (1e-3f * dir);
// origin = intersection;
};
vec3 viewDir = Normal(direction);
//{ Set the random state
vtkm::Vec<vtkm::UInt32, 4> randState;
......@@ -406,15 +418,13 @@ public:
return;
}
//}
//{ Test incidence and set ray values
vec3 norm = normal;
vec3 origNorm = norm;
bool incident = (Dot(viewDir, norm) < 0);
Precision iDist = Magnitude(intersection - origin);
Float32 val1 = lastVals[0]; //last val
Float32 val2 = Float32(scalar);
// Float32 val2 = Float32(0.5);
......@@ -545,6 +555,7 @@ public:
if (Magnitude(rfDir) <= 0.01f) {alpha = 1.f; /* spectrumAcc = spectrumAcc + SpectrumFromRGB(1,0,0); */}
//}
//{ Handle reflection or refraction
if ((alpha == 0.f) || ((alpha < 1.f) && (rand > alpha) && !(MagnitudeSquared(rfDir) <= 0.1)))
{
......@@ -556,8 +567,14 @@ public:
}
else
{
// DBG_Vx(Abs(viewDir));
// DBG_Vx(Abs(origNorm));
Spectrum reflectCol = getColor(viewDir, rDir, origNorm, mat2);
// DBG_Vx(Abs(RGBFromSpectrum(reflectCol)));
// reflectCol = SpectrumFromRGB(.5,.5,.5);
spectrumMult = spectrumMult * reflectCol;
// rDir = vec3(1,0,0);
onReturn(rDir);
}
//}
......
......@@ -591,6 +591,49 @@ public:
}
}; //class CalculateNormals
template <typename Precision>
class LerpNormals : public vtkm::worklet::WorkletMapField
{
public:
VTKM_CONT
LerpNormals() {}
typedef void ControlSignature(FieldIn<>,
FieldIn<>,
FieldIn<>,
FieldInOut<>,
FieldInOut<>,
FieldInOut<>,
WholeArrayIn<>,
WholeArrayIn<>);
typedef void ExecutionSignature(_1, _2, _3, _4, _5, _6, _7, _8);
template <typename NormalPortalType, typename IndicesPortalType>
VTKM_EXEC void operator()(const vtkm::Id& hitIndex,
const Precision& u,
const Precision& v,
Precision& normalX,
Precision& normalY,
Precision& normalZ,
const NormalPortalType& normals,
const IndicesPortalType& indicesPortal) const
{
if (hitIndex < 0)
return;
vtkm::Vec<Id, 4> indices = indicesPortal.Get(hitIndex);
Precision n = 1.f - u - v;
vtkm::Vec<Precision, 3> aNormal = vtkm::Vec<Precision, 3>(normals.Get(indices[1]));
vtkm::Vec<Precision, 3> bNormal = vtkm::Vec<Precision, 3>(normals.Get(indices[2]));
vtkm::Vec<Precision, 3> cNormal = vtkm::Vec<Precision, 3>(normals.Get(indices[3]));
vtkm::Vec<Precision, 3> normal = aNormal * n + bNormal * u + cNormal * v;
vtkm::Normalize(normal);
normalX = normal[0];
normalY = normal[1];
normalZ = normal[2];
}
}; //class LerpNormals
template <typename Precision>
class LerpScalar : public vtkm::worklet::WorkletMapField
{
......@@ -690,7 +733,8 @@ public:
vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Id, 4>> triangles,
vtkm::cont::CoordinateSystem coordsHandle,
const vtkm::cont::Field* scalarField,
const vtkm::Range& scalarRange)
const vtkm::Range& scalarRange,
vtkm::cont::ArrayHandle<vtkm::Vec<Precision, 3>> normals)
{
bool isSupportedField =
(scalarField->GetAssociation() == vtkm::cont::Field::Association::POINTS ||
......@@ -700,9 +744,16 @@ public:
bool isAssocPoints = scalarField->GetAssociation() == vtkm::cont::Field::Association::POINTS;
// Find the triangle normal
vtkm::worklet::AutoDispatcherMapField<CalculateNormals>(CalculateNormals())
.Invoke(
rays.HitIdx, rays.Dir, rays.NormalX, rays.NormalY, rays.NormalZ, coordsHandle, triangles);
if (normals.GetNumberOfValues() == 0)
{
vtkm::worklet::AutoDispatcherMapField<CalculateNormals>(CalculateNormals())
.Invoke(rays.HitIdx, rays.Dir, rays.NormalX, rays.NormalY, rays.NormalZ, coordsHandle, triangles);
}
else
{
vtkm::worklet::AutoDispatcherMapField<LerpNormals<Precision>>(LerpNormals<Precision>())
.Invoke(rays.HitIdx, rays.U, rays.V, rays.NormalX, rays.NormalY, rays.NormalZ, normals, triangles);
}
// Calculate scalar value at intersection point
if (isAssocPoints)
......@@ -793,15 +844,28 @@ class TriangleIntersector : public ShapeIntersector
{
protected:
vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Id, 4>> Triangles;
vtkm::cont::DynamicArrayHandle Normals;
bool UseWaterTight;
public:
TriangleIntersector()
: UseWaterTight(false)
: Normals(),
UseWaterTight(false)
{
}
void SetUseWaterTight(bool useIt) { UseWaterTight = useIt; }
template <typename Precision>
void SetNormals(const vtkm::cont::ArrayHandle<vtkm::Vec<Precision,3>> normals)
{
Normals = normals;
}
void SetNormals(const vtkm::cont::DynamicArrayHandle normals)
{
Normals = normals;
}
void SetData(const vtkm::cont::CoordinateSystem& coords,
vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Id, 4>> triangles)
......@@ -924,7 +988,19 @@ public:
{
ShapeIntersector::IntersectionPoint(rays);
detail::TriangleIntersectionData intData;
intData.Run(rays, this->Triangles, this->CoordsHandle, scalarField, scalarRange);
vtkm::cont::ArrayHandle<vtkm::Vec<Precision,3>> normals;
if (Normals.IsSameType(normals))
{
Normals.CopyTo(normals);
}
else
{
normals.Allocate(0);
}
intData.Run(rays, this->Triangles, this->CoordsHandle, scalarField, scalarRange, normals);
}
vtkm::Id GetNumberOfShapes() const override { return Triangles.GetNumberOfValues(); }
......
......@@ -261,12 +261,14 @@ void MultiMapperRender(const vtkm::cont::DataSet& ds1,
const vtkm::cont::Field field2 = ds2.GetField(fieldNm);
vtkm::Range range2;
field2.GetRange(&range2);
const vtkm::cont::Field fieldUnused;
mapper1.RenderCells(
ds1.GetCellSet(), ds1.GetCoordinateSystem(), field1, colorTable1, camera, range1, scene);
ds1.GetCellSet(), ds1.GetCoordinateSystem(), field1, fieldUnused, colorTable1, camera, range1, scene);
mapper2.RenderCells(
ds2.GetCellSet(), ds2.GetCoordinateSystem(), field2, colorTable2, camera, range2, scene);
ds2.GetCellSet(), ds2.GetCoordinateSystem(), field2, fieldUnused, colorTable2, camera, range2, scene);
canvas.SaveAs(outputFile);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment