Skip to content

Commit

Permalink
Fixed background material in advanced renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
favreau committed Sep 6, 2023
1 parent 1dd4c23 commit 931dfd9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ inline vec3f pathTracingContribution(const uniform PathTracingRenderer* uniform
// if ray misses scene (no hit occurs), return background colour
if (localray.geomID < 0)
{
localray.t = inf;
const vec3f bgcol =
make_vec3f(skyboxMapping((Renderer*)self, localray, self->super.super.bgMaterial)) * skypower;
accucolor = accucolor + mask * bgcol;
Expand Down Expand Up @@ -168,7 +167,6 @@ inline vec3f PathTracingRenderer_shadeRay(const uniform PathTracingRenderer* uni
if (ray.geomID < 0)
{
// No intersection. Return skybox color
ray.t = inf;
color = self->super.showBackground
? make_vec3f(skyboxMapping((Renderer*)self, ray, self->super.super.bgMaterial)) *
skypower_zerobounce
Expand Down
2 changes: 1 addition & 1 deletion platform/engines/ospray/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void toOSPRayProperties(const PropertyMap& object, OSPObject ospObject)
osphelper::set(ospObject, prop->name.c_str(), prop->get<int32_t>());
break;
case Property::Type::Bool:
osphelper::set(ospObject, prop->name.c_str(), prop->get<bool>());
osphelper::set(ospObject, prop->name.c_str(), static_cast<int32_t>(prop->get<bool>()));
break;
case Property::Type::String:
osphelper::set(ospObject, prop->name.c_str(), prop->get<std::string>());
Expand Down
17 changes: 10 additions & 7 deletions platform/engines/ospray/ispc/render/utils/SkyBox.ispc
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,18 @@ vec4f skyboxMapping(const uniform Renderer* uniform renderer, const varying Ray&
const uniform AdvancedMaterial* uniform bgMaterial)
{
varying vec4f result = make_vec4f(bgMaterial->Kd);

const varying float radius = 1e6;
if (!valid(bgMaterial->map_Kd))
return result;

Ray infiniteRay = ray;

const varying float radius = 1e6;
infiniteRay.t = inf;

// solve the equation sphere-ray to find the intersections
const varying float a = 2.f * dot(ray.dir, ray.dir);
const varying float b = 2.f * dot(ray.org, ray.dir);
const varying float c = dot(ray.org, ray.org) - radius * radius;
const varying float a = 2.f * dot(infiniteRay.dir, infiniteRay.dir);
const varying float b = 2.f * dot(infiniteRay.org, infiniteRay.dir);
const varying float c = dot(infiniteRay.org, infiniteRay.org) - radius * radius;
const varying float d = b * b - 2.f * a * c;

if (d <= 0.f || a == 0.f)
Expand All @@ -58,10 +61,10 @@ vec4f skyboxMapping(const uniform Renderer* uniform renderer, const varying Ray&
else
t = (t1 < t2) ? t1 : t2;

if (t < epsilon || t > ray.t)
if (t < epsilon || t > infiniteRay.t)
return result; // Too close to intersection

const varying vec3f intersection = normalize(ray.org + t * ray.dir);
const varying vec3f intersection = normalize(infiniteRay.org + t * infiniteRay.dir);

// Only st needs to be set to sample from Texture2D
varying DifferentialGeometry dg;
Expand Down

0 comments on commit 931dfd9

Please sign in to comment.