Area light parallel to the camera view

84 views Asked by At

I'm trying to render an image, and I know the coordinates of the camera, and the lookat object. I want to create an area light (plane) behind the camera, but parallel to the camera view.

I guess I should use the right and up vectors of the camera. But I don't know how to do that. Let me show you some code samples:

TooN::Vector<3> eye = TooN::makeVector(camera_pos[0],camera_pos[1],camera_pos[2]);
TooN::Vector<3> lookat = TooN::makeVector(lookat_pos[0],lookat_pos[1],lookat_pos[2]);
TooN::Vector<3> look_dir = eye - lookat;
TooN::normalize(look_dir);
TooN::Vector<3> up_vec = TooN::makeVector(0.0f,1.0f,0.0f);
TooN::Vector<3> right = up_vec ^ look_dir;
//TooN::normalize(right); // I am not sure if I should use normalize here.
TooN::Vector<3> newup = look_dir ^ right;
TooN::normalize(newup); // I am not sure if I should use normalize here.
// ^ denotes cross product

Then I copied some code from github to generate area light:

optix::float3 v1     = optix::make_float3( 0.0f, 0.0f, -0.5f);
optix::float3 v2     = optix::make_float3( 0.5f, 0.0f, 0.0f);
createParallelogram(light.position,light.v1,light.v2);

Using above v1 and v2, I can only create area light on the ceiling.

Here is the createParallelogram function:

optix::GeometryInstance AreaLight::createParallelogram(const optix::float3& anchor,
const optix::float3& offset1, const optix::float3& offset2) {

optix::float3 normal = optix::normalize( optix::cross( offset1, offset2 ) );
float d = optix::dot( normal, anchor );
optix::float4 plane = optix::make_float4( normal, d );

optix::float3 v1 = offset1 / optix::dot( offset1, offset1 );
optix::float3 v2 = offset2 / optix::dot( offset2, offset2 );

parallelogram["plane"]->setFloat( plane );
parallelogram["anchor"]->setFloat( anchor );
parallelogram["v1"]->setFloat( v1 );
parallelogram["v2"]->setFloat( v2 );

return;

I want to know how to set v1 and v2 so that the plan can be parallel to camera view to illuminate the objects (lookat direction). Thank you in advance!!

Update1:

According to what @Blindman67 has said, I tried to set createParallelogram((eye - look_dir)* .1, right * 2.0, newup * 0.5) then I found the picture is very dark, I changed it to createParallelogram( -(eye - look_dir)* .1, right * 2.0, newup * 0.5), now I the area light is facing the object [figure 1], and it's brighter. However, when I set createParallelogram((eye - look_dir)* .7, right * 2.0, newup * 0.5), I can see the area light (rectangle) in rendered image. I don't want to see this shape. Do you know how should I control the size or position of this light? Thank you!

figure 1

0

There are 0 answers