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
|
// Copyright 2009-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
#include "light.h"
#include "../math/sampling.h"
#include "../math/linearspace.h"
namespace embree {
struct AmbientLight
{
Light super; //!< inherited light fields
Vec3fa radiance; //!< RGB color and intensity of light
};
// Implementation
//////////////////////////////////////////////////////////////////////////////
// XXX importance sampling is only done into the positive hemisphere
// ==> poor support for translucent materials
SYCL_EXTERNAL Light_SampleRes AmbientLight_sample(const Light* super,
const DifferentialGeometry& dg,
const Vec2f& s)
{
AmbientLight* self = (AmbientLight*)super;
Light_SampleRes res;
const Vec3fa localDir = cosineSampleHemisphere(s);
res.dir = frame(dg.Ns) * localDir;
res.pdf = cosineSampleHemispherePDF(localDir);
res.dist = inf;
res.weight = self->radiance * rcp(res.pdf);
return res;
}
SYCL_EXTERNAL Light_EvalRes AmbientLight_eval(const Light* super,
const DifferentialGeometry& dg,
const Vec3fa& dir)
{
AmbientLight* self = (AmbientLight*)super;
Light_EvalRes res;
res.value = self->radiance;
res.dist = inf;
res.pdf = cosineSampleHemispherePDF(max(dot(dg.Ns, dir), 0.f));
return res;
}
void AmbientLight_Constructor(AmbientLight* self,
const Vec3fa& radiance)
{
Light_Constructor(&self->super);
self->radiance = radiance;
//self->super.sample = GET_FUNCTION_POINTER(AmbientLight_sample);
//self->super.eval = GET_FUNCTION_POINTER(AmbientLight_eval);
self->super.type = LIGHT_AMBIENT;
}
// Exports (called from C++)
//////////////////////////////////////////////////////////////////////////////
//! Create an ispc-side AmbientLight object
extern "C" void *AmbientLight_create()
{
AmbientLight* self = (AmbientLight*) alignedUSMMalloc(sizeof(AmbientLight),16);
AmbientLight_Constructor(self, Vec3fa(1.f));
return self;
}
//! Set the parameters of an ispc-side AmbientLight object
extern "C" void AmbientLight_set(void* super,
const Vec3fa& radiance)
{
AmbientLight* self = (AmbientLight*)super;
self->radiance = radiance;
}
} // namespace embree
|