|
Post by ascotti on Feb 5, 2019 22:39:06 GMT
I think the extra chapter on area lights is my favorite now, it's probably the best explanation of the topic I have seen so far... kudos to Jamis again! Anyway I kinda suck at setting up scenes so I found this function quite handy. You pass the function a source and target point in world space, and it will orient the area light so that it is centered at the source point and facing directly the specified target point. I'll try to write it in pseudo code. function orient_area_light(light, source, target) n = normalize(target - source) // Desired direction of the area light normal
// Compute tangent and bitangent vectors a = vector(0, 1, 0) t = normalize( cross_product(a, n) )
b = cross_product( t, n ) // Replace the uvec and vvec vectors, but preserve their length light.uvec = t * length(light.uvec) light.vvec = b * length(light.vvec)
// Set the corner so that the source position falls in the center light.pos = source - (light.uvec * 0.5) - (light.vvec * 0.5) }
Here's a test image!
|
|
|
Post by Jamis on Feb 6, 2019 0:25:51 GMT
Awesome! That's super handy. I think I'll borrow that myself. Thanks ascotti!
|
|
fs
New Member
Posts: 28
|
Post by fs on Feb 6, 2019 0:49:54 GMT
Like the test image
|
|
|
Post by ascotti on Feb 6, 2019 19:33:30 GMT
Thanks! :-)
Edit: I've fixed a small error in the light.pos assignment, it's better now.
|
|