Commit 1bc9c1d6 authored by Carson Brownlee's avatar Carson Brownlee Committed by Carson Brownlee
Browse files

updating ospray backend to be compatible with ospray 2.0.1

parent c77d9f6b
......@@ -118,8 +118,6 @@ namespace RTW
{
OSPData data = ospNewData1D(static_cast<OSPDataType>(dataType), numElements);
OSPData shared = ospNewSharedData1D(source, static_cast<OSPDataType>(dataType), numElements);
std::cout << "newCopyData1D data dataType numElements source " << data << " " <<
dataType << " " << numElements << " " << source << std::endl;
ospCopyData1D(shared, data, 0);
ospCommit(data);
ospRelease(shared);
......
......@@ -443,7 +443,6 @@ OSPGeometricModel RenderAsTriangles(OSPData vertices, std::vector<unsigned int>&
{
if (backend == nullptr)
return OSPGeometry();
std::cout << "renderastriangles\n";
OSPGeometry ospMesh = ospNewGeometry("mesh");
OSPGeometricModel ospGeoModel = ospNewGeometricModel(ospMesh);
ospRelease(ospMesh);
......@@ -662,7 +661,7 @@ OSPMaterial MakeActorMaterial(vtkOSPRayRendererNode* orn, OSPRenderer oRenderer,
OSPMaterial oMaterial;
if (property->GetInterpolation() == VTK_PBR)
{
oMaterial = vtkOSPRayMaterialHelpers::NewMaterial(orn, oRenderer, "Principled");
oMaterial = vtkOSPRayMaterialHelpers::NewMaterial(orn, oRenderer, "principled");
ospSetVec3f(oMaterial, "baseColor", diffusef[0], diffusef[1], diffusef[2]);
ospSetFloat(oMaterial, "metallic", static_cast<float>(property->GetMetallic()));
......@@ -734,7 +733,6 @@ vtkOSPRayPolyDataMapperNode::~vtkOSPRayPolyDataMapperNode()
{
delete this->GeometryCache;
delete this->InstanceCache;
// ClearGeometricModels();
}
//----------------------------------------------------------------------------
......@@ -1236,11 +1234,9 @@ void vtkOSPRayPolyDataMapperNode::Render(bool prepass)
(this->UseInstanceCache && this->InstanceCache->Contains(tstep)) ||
(this->UseGeometryCache && this->GeometryCache->Contains(tstep))))
{
std::cout << "REUSE" << endl;
this->RenderGeometricModels();
return;
}
std::cout << "DRAW" << endl;
this->RenderTime = inTime;
this->ClearGeometricModels();
......@@ -1350,33 +1346,19 @@ void vtkOSPRayPolyDataMapperNode::RenderGeometricModels()
orn->Instances.emplace_back(instance);
this->Instances.emplace_back(instance);
// ospRelease(data);
// ospRelease(group);
ospRelease(data);
ospRelease(group);
}
}
//----------------------------------------------------------------------------
void vtkOSPRayPolyDataMapperNode::ClearGeometricModels()
{
std::cout << "vtkpdm: clearGeometricModels\n";
vtkOSPRayRendererNode* orn =
static_cast<vtkOSPRayRendererNode*>(this->GetFirstAncestorOfType("vtkOSPRayRendererNode"));
RTW::Backend* backend = orn->GetBackend();
// We can't delete if we may reuse.
if (vtkOSPRayRendererNode::GetTimeCacheSize(orn->GetRenderer()) == 0)
{
for (auto g : this->GeometricModels)
{
// ospRelease(g);
// std::cout << "vtkpdm: releasing geometricmodel\n";
}
for (auto i : this->Instances)
{
ospRelease(i);
}
}
this->GeometricModels.clear();
this->Instances.clear();
}
......@@ -292,7 +292,7 @@ public:
return retval;
}
bool SetupPathTraceBackground(RTW::Backend* backend)
bool SetupPathTraceBackground(RTW::Backend* backend, OSPRenderer renderer)
{
vtkRenderer* ren = vtkRenderer::SafeDownCast(this->Owner->GetRenderable());
if (std::string(this->Owner->GetRendererType(ren)).find(std::string("pathtracer")) ==
......@@ -301,7 +301,7 @@ public:
return true;
}
bool reuseable = this->CanReuseBG();
if (!reuseable || !this->BGLight)
if (!reuseable)
{
double* bg1 = ren->GetBackground();
unsigned char* ochars;
......@@ -355,10 +355,7 @@ public:
}
else
{
ochars = new unsigned char[3];
ochars[0] = bg1[0] * 255;
ochars[1] = bg1[1] * 255;
ochars[2] = bg1[2] * 255;
return true;
}
OSPTexture t2d = vtkOSPRayMaterialHelpers::NewTexture2D(
......@@ -367,7 +364,6 @@ public:
OSPLight ospLight = ospNewLight("hdri");
ospSetObject(ospLight, "map", t2d);
ospRelease(t2d);
double* up = vtkOSPRayRendererNode::GetNorthPole(ren);
if (up)
......@@ -388,10 +384,12 @@ public:
ospSetVec3f(ospLight, "direction", 0.0f, 1.0f, 0.0f); // todo: configurable
}
ospCommit(ospLight); // todo: make sure osp frees its side
delete[] ochars;
this->BGLight = ospLight;
this->Owner->AddLight(this->BGLight);
delete[] ochars;
ospRelease(t2d);
}
// this->Owner->AddLight(this->BGLight);
// TODO: hdri light tex is broken in ospray 2.0
return reuseable;
}
......@@ -981,6 +979,12 @@ static std::vector<int32_t> indexTest = { 0, 1, 2, 1, 2, 3 };
//----------------------------------------------------------------------------
void vtkOSPRayRendererNode::Traverse(int operation)
{
vtkRenderer* ren = vtkRenderer::SafeDownCast(this->GetRenderable());
if (!ren)
{
return;
}
// do not override other passes
if (operation != render)
{
......@@ -1044,14 +1048,9 @@ void vtkOSPRayRendererNode::Traverse(int operation)
this->Lights.push_back(ospAmbient);
}
bool bgreused = this->Internal->SetupPathTraceBackground(backend);
// ospRelease(this->OLightArray);
// this->OLightArray = ospNewData(this->Lights.size(), OSP_OBJECT,
// (this->Lights.size()?&this->Lights[0]:nullptr), 0);
// ospSetData(oRenderer, "lights", this->OLightArray);
bool bgreused = this->Internal->SetupPathTraceBackground(backend, oRenderer);
// actors
// OSPWorld oWorld = nullptr;
it->InitTraversal();
// since we have to spatially sort everything
// let's see if we can avoid that in the common case when
......@@ -1080,8 +1079,10 @@ void vtkOSPRayRendererNode::Traverse(int operation)
bool enable_cache = true; // turn off to force rebuilds for debugging
if (!this->OWorld || !enable_cache || (recent > this->RenderTime) || (numAct != this->NumActors))
{
this->VolumetricModels.clear();
this->GeometricModels.clear();
for (auto i : this->Instances)
{
ospRelease(i);
}
this->Instances.clear();
this->NumActors = numAct;
// ospRelease((OSPWorld)this->OWorld);
......@@ -1106,7 +1107,6 @@ void vtkOSPRayRendererNode::Traverse(int operation)
if (!this->OWorld)
;
{
std::cout << "new world\n";
this->OWorld = ospNewWorld();
ospCommit(this->OWorld);
}
......@@ -1191,7 +1191,7 @@ void vtkOSPRayRendererNode::Render(bool prepass)
ospSetFloat(this->ORenderer, "maxContribution", this->GetMaxContribution(ren));
ospSetFloat(this->ORenderer, "minContribution", this->GetMinContribution(ren));
// ospSetFloat(this->ORenderer, "maxDepth", this->GetMaxDepth(ren));
ospSetFloat(this->ORenderer, "maxPathLength", this->GetMaxDepth(ren));
ospSetFloat(this->ORenderer, "rouletteDepth", this->GetRouletteDepth(ren));
ospSetFloat(this->ORenderer, "varianceThreshold", this->GetVarianceThreshold(ren));
ospCommit(this->ORenderer);
......@@ -1233,63 +1233,22 @@ void vtkOSPRayRendererNode::Render(bool prepass)
}
ospSetInt(oRenderer, "aoSamples", this->GetAmbientSamples(ren));
ospSetInt(oRenderer, "spp", this->GetSamplesPerPixel(ren));
ospSetInt(oRenderer, "pixelSamples", this->GetSamplesPerPixel(ren));
this->CompositeOnGL = (this->GetCompositeOnGL(ren) != 0);
double* bg = ren->GetBackground();
ospSetVec4f(oRenderer, "bgColor", bg[0], bg[1], bg[2], ren->GetBackgroundAlpha());
ospSetVec4f(oRenderer, "backgroundColor", bg[0], bg[1], bg[2], ren->GetBackgroundAlpha());
}
else
{
OSPWorld oWorld = this->OWorld;
// put the model into a group (collection of models)
if (this->VolumetricModels.size() || this->GeometricModels.size())
if (this->Instances.size() && this->Lights.size())
{
std::cout << "vtkrenderer populating world\n";
// static OSPGroup group = ospNewGroup();
// put the group into an instance (give the group a world transform)
// static OSPInstance instance = ospNewInstance(group);
if (this->VolumetricModels.size())
{
// static bool once = false;
// if (!once)
// {
// once = true;
// auto data = ospNewSharedData1D(
// this->VolumetricModels.data(), OSP_VOLUMETRIC_MODEL, this->VolumetricModels.size());
// ospCommit(data);
// ospSetObject(group, "volume", data);
// ospRelease(data);
// }
}
if (this->GeometricModels.size())
{
// static bool once = false;
// if (!once)
// {
// once = true;
// ospSetBool(group, "compactMode", true);
// auto data = ospNewCopyData1D(
// this->GeometricModels.size(), OSP_GEOMETRIC_MODEL, this->GeometricModels.data());
// ospCommit(data);
// ospSetObject(group, "geometry", data);
// ospRelease(data);
// ospCommit(group);
// ospCommit(instance);
// // this->Instances.emplace_back(instance);
// }
}
// ospCommit(group);
// ospRelease(group);
if (this->Lights.size())
{
auto data = ospNewSharedData1D(this->Lights.data(), OSP_LIGHT, this->Lights.size());
ospCommit(data);
ospSetObject(oWorld, "light", data);
ospRelease(data);
}
auto data = ospNewSharedData1D(this->Lights.data(), OSP_LIGHT, this->Lights.size());
ospCommit(data);
ospSetObject(oWorld, "light", data);
ospRelease(data);
}
auto instanceData =
......@@ -1518,11 +1477,11 @@ void vtkOSPRayRendererNode::Render(bool prepass)
zNear, zFar, (osp::vec3f&)cameraDir, (osp::vec3f&)cameraUp, this->GetZBuffer(),
this->ODepthBuffer.data(), viewportWidth, viewportHeight, this->Internal->Backend);
ospSetObject(oRenderer, "maxDepthTexture", glDepthTex);
ospSetObject(oRenderer, "map_maxDepth", glDepthTex);
}
else
{
ospSetObject(oRenderer, "maxDepthTexture", 0);
ospSetObject(oRenderer, "map_maxDepth", 0);
}
// Enable VisRTX denoiser
......
......@@ -371,6 +371,7 @@ protected:
bool ComputeDepth;
bool Accumulate;
bool CompositeOnGL;
bool UseBackplate{ true }; // use bgcolor for pathtracer or use bgcolor light
std::vector<float> ODepthBuffer;
int AccumulateCount;
int ActorCount;
......
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