1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
// Copyright 2009 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
#include "QuadLight.h"
#ifndef OSPRAY_TARGET_SYCL
#include "lights/QuadLight_ispc.h"
#else
namespace ispc {
void QuadLight_Transform(const void *self, const void *xfm, void *dyn);
}
#endif
#include "QuadLightShared.h"
#include "common/InstanceShared.h"
namespace ospray {
ispc::Light *QuadLight::createSh(uint32_t, const ispc::Instance *instance) const
{
ispc::QuadLight *sh =
StructSharedCreate<ispc::QuadLight>(getISPCDevice().getDRTDevice());
#ifndef OSPRAY_TARGET_SYCL
sh->super.sample =
reinterpret_cast<ispc::Light_SampleFunc>(ispc::QuadLight_sample_addr());
sh->super.eval =
reinterpret_cast<ispc::Light_EvalFunc>(ispc::QuadLight_eval_addr());
#endif
sh->super.isVisible = visible;
sh->super.instance = instance;
sh->radiance = radiance;
sh->pre.position = position;
sh->pre.edge1 = edge1;
sh->pre.edge2 = edge2;
intensityDistribution.setSh(sh->intensityDistribution);
// Enable dynamic runtime instancing or apply static transformation
if (instance) {
sh->pre.c0 = intensityDistribution.c0;
if (instance->motionBlur) {
#ifndef OSPRAY_TARGET_SYCL
// TODO: QuadLight sample/eval dispatch needs to handle this case now
sh->super.sample = reinterpret_cast<ispc::Light_SampleFunc>(
ispc::QuadLight_sample_instanced_addr());
sh->super.eval = reinterpret_cast<ispc::Light_EvalFunc>(
ispc::QuadLight_eval_instanced_addr());
#endif
} else
ispc::QuadLight_Transform(sh, instance->xfm, &sh->pre);
} else {
const vec3f ndirection = cross(edge2, edge1);
sh->pre.ppdf = rcp(length(ndirection)); // 1/area
sh->pre.nnormal = ndirection * sh->pre.ppdf; // normalize
sh->pre.c90 = normalize(cross(sh->pre.nnormal, intensityDistribution.c0));
sh->pre.c0 = cross(sh->pre.c90, sh->pre.nnormal);
}
return &sh->super;
}
std::string QuadLight::toString() const
{
return "ospray::QuadLight";
}
void QuadLight::commit()
{
Light::commit();
position = getParam<vec3f>("position", vec3f(0.f));
edge1 = getParam<vec3f>("edge1", vec3f(1.f, 0.f, 0.f));
edge2 = getParam<vec3f>("edge2", vec3f(0.f, 1.f, 0.f));
intensityDistribution.c0 = edge2;
intensityDistribution.readParams(*this);
queryIntensityQuantityType(intensityDistribution
? OSP_INTENSITY_QUANTITY_SCALE
: OSP_INTENSITY_QUANTITY_RADIANCE);
processIntensityQuantityType();
}
void QuadLight::processIntensityQuantityType()
{
const float quadArea = length(cross(edge1, edge2));
// converting from the chosen intensity quantity type to radiance
if (intensityDistribution
? intensityQuantity == OSP_INTENSITY_QUANTITY_SCALE
: intensityQuantity == OSP_INTENSITY_QUANTITY_INTENSITY) {
radiance = coloredIntensity / quadArea;
return;
}
if (!intensityDistribution) {
if (intensityQuantity == OSP_INTENSITY_QUANTITY_POWER) {
radiance = coloredIntensity / (M_PI * quadArea);
return;
}
if (intensityQuantity == OSP_INTENSITY_QUANTITY_RADIANCE) {
radiance = coloredIntensity;
return;
}
}
postStatusMsg(OSP_LOG_WARNING)
<< toString() << " unsupported 'intensityQuantity' value";
radiance = vec3f(0.0f);
}
} // namespace ospray
|