Mantra Light Shaders

   12588   29   2
User Avatar
Member
250 posts
Joined: 3月 2013
Offline
Hey All,

There are no resources for making light shaders anywhere, either as code or in a VOP.
I'd like to make an area light that has directionality control, similar to Vray and 3Delight.
So rays are not just cast in an increasing hemisphere from the center of the area light.
This can pull those rays more parallel, a very handy feature.
I've checked the math, it's entirely possible, but there seems to be nothing other than the actual
vfl files to go off from existing lights.

Does anyone has some knowledge they'd like to share?



Cheers

Lewie
I'm not lying, I'm writing fiction with my mouth.
User Avatar
Member
1390 posts
Joined: 7月 2005
Offline
Checkout ASAD Light/Shadow SHOPS as they are comprehensive source of information on how to write custom light shaders.
User Avatar
Member
8045 posts
Joined: 9月 2011
Offline
I made a light shader with directionality before, but it's useless as the sampler has no idea about the light shader's bias. The more you increase directionality the noisier the image gets, until you get a black image with one or two hot pixels. If anyone knows how to teach the sampler about your light shader's importance distribution, it would make it far more viable.
User Avatar
Member
250 posts
Joined: 3月 2013
Offline
Geez, that's pretty lame. It's a super useful light type, and I'm a little frustrated at that.
Thanks for the info and heads up. I shall plow along and see what results I get.


Cheers
I'm not lying, I'm writing fiction with my mouth.
User Avatar
Member
22 posts
Joined: 3月 2014
Offline
hi, are there any news about this topic ?? I found this thread while searching for exactly this light behavior in houdini.

cheers
https://vimeo.com/jon3de [vimeo.com]
User Avatar
Member
55 posts
Joined: 4月 2019
Offline
I'm actually curious about this too. It would be great to see how the spread/directionality implementation is like.
VFX Supervisor | CG Artist

http://yasinhasanian.com/ [yasinhasanian.com]
User Avatar
Member
8045 posts
Joined: 9月 2011
Offline
Karma lights now include ‘focus’ or directionality controls. Sample distribution is still naive AFAIK though, so you can't make a laser, or even remotely approach laser-focus.
User Avatar
Member
55 posts
Joined: 4月 2019
Offline
jsmack
Karma lights now include ‘focus’ or directionality controls. Sample distribution is still naive AFAIK though, so you can't make a laser, or even remotely approach laser-focus.
That's a bummer. Regardless of the noise issue, how would one implement its light material for Mantra?
Edited by YasinH - 2020年8月14日 20:38:13
VFX Supervisor | CG Artist

http://yasinhasanian.com/ [yasinhasanian.com]
User Avatar
Member
8045 posts
Joined: 9月 2011
Offline
YasinH
jsmack
Karma lights now include ‘focus’ or directionality controls. Sample distribution is still naive AFAIK though, so you can't make a laser, or even remotely approach laser-focus.
That's a bummer. Regardless of the noise issue, how would one implement its light material for Mantra?

I don't know the math for the pdf of ‘directionality’ used by vray and the like, but the pdf for ggx is a nice gaussian distribution. And there's built in functions for getting the weight in a direction with a given focus exponent, as well as the integral over the pdf so you can normalize the power over the hemisphere. That's all I did when I added it lazily.
User Avatar
Member
55 posts
Joined: 4月 2019
Offline
jsmack
YasinH
jsmack
Karma lights now include ‘focus’ or directionality controls. Sample distribution is still naive AFAIK though, so you can't make a laser, or even remotely approach laser-focus.
That's a bummer. Regardless of the noise issue, how would one implement its light material for Mantra?

I don't know the math for the pdf of ‘directionality’ used by vray and the like, but the pdf for ggx is a nice gaussian distribution. And there's built in functions for getting the weight in a direction with a given focus exponent, as well as the integral over the pdf so you can normalize the power over the hemisphere. That's all I did when I added it lazily.
Thanks for the explanation. I'm quite new to the VEX part of light materials. The built-in function you are referring to is sample_hemisphereand create_pdf?
VFX Supervisor | CG Artist

http://yasinhasanian.com/ [yasinhasanian.com]
User Avatar
Member
55 posts
Joined: 4月 2019
Offline
Also, would you recommend using VEX code(similar to Asad light) or just VOP nodes for the light material?
VFX Supervisor | CG Artist

http://yasinhasanian.com/ [yasinhasanian.com]
User Avatar
Member
8045 posts
Joined: 9月 2011
Offline
YasinH
The built-in function you are referring to is sample_hemisphereand create_pdf?

I think everything I needed was from the evalbsdf function. Sample functions are only needed for discreet samples (ray tracing). Since light shaders are continuous function, we only care about power scale in a given direction which is what the ‘eval’ argument of the evalbsdf function is. It may to be scaled by the pdf though, which is another argument of the same function.

YasinH
Also, would you recommend using VEX code(similar to Asad light) or just VOP nodes for the light material?

This is down to preference.
User Avatar
Member
55 posts
Joined: 4月 2019
Offline
jsmack
YasinH
The built-in function you are referring to is sample_hemisphereand create_pdf?

I think everything I needed was from the evalbsdf function. Sample functions are only needed for discreet samples (ray tracing). Since light shaders are continuous function, we only care about power scale in a given direction which is what the ‘eval’ argument of the evalbsdf function is. It may to be scaled by the pdf though, which is another argument of the same function.

YasinH
Also, would you recommend using VEX code(similar to Asad light) or just VOP nodes for the light material?

This is down to preference.
This is super helpful! Thank you. Something I'm trying to figure out eval_bsdf requires a bsdf as its first argument, while a light shader doesn't inherently have a bsdf, does it? Or should I build a custom bsdf in the light shader?
VFX Supervisor | CG Artist

http://yasinhasanian.com/ [yasinhasanian.com]
User Avatar
Member
8045 posts
Joined: 9月 2011
Offline
YasinH
jsmack
YasinH
The built-in function you are referring to is sample_hemisphereand create_pdf?

I think everything I needed was from the evalbsdf function. Sample functions are only needed for discreet samples (ray tracing). Since light shaders are continuous function, we only care about power scale in a given direction which is what the ‘eval’ argument of the evalbsdf function is. It may to be scaled by the pdf though, which is another argument of the same function.

YasinH
Also, would you recommend using VEX code(similar to Asad light) or just VOP nodes for the light material?

This is down to preference.
This is super helpful! Thank you. Something I'm trying to figure out eval_bsdf requires a bsdf as its first argument, while a light shader doesn't inherently have a bsdf, does it? Or should I build a custom bsdf in the light shader?

Yeah, light shaders don't have their own bsdf normally. I'm abusing the ‘bsdf’ a generic function to get the mapping from angle to power. If you're using 18+ the ggx function can be used to create a ggx bsdf. Otherwise in pre-18 you'll have to use a cvex bsdf function.
User Avatar
Member
55 posts
Joined: 4月 2019
Offline
jsmack
YasinH
jsmack
YasinH
The built-in function you are referring to is sample_hemisphereand create_pdf?

I think everything I needed was from the evalbsdf function. Sample functions are only needed for discreet samples (ray tracing). Since light shaders are continuous function, we only care about power scale in a given direction which is what the ‘eval’ argument of the evalbsdf function is. It may to be scaled by the pdf though, which is another argument of the same function.

YasinH
Also, would you recommend using VEX code(similar to Asad light) or just VOP nodes for the light material?

This is down to preference.
This is super helpful! Thank you. Something I'm trying to figure out eval_bsdf requires a bsdf as its first argument, while a light shader doesn't inherently have a bsdf, does it? Or should I build a custom bsdf in the light shader?

Yeah, light shaders don't have their own bsdf normally. I'm abusing the ‘bsdf’ a generic function to get the mapping from angle to power. If you're using 18+ the ggx function can be used to create a ggx bsdf. Otherwise in pre-18 you'll have to use a cvex bsdf function.
Interesting. Here's part of what I have so far. But not getting anything meaningful out of it… I'm sure I'm missing couple things here

vector b;
bsdf f = cvex_bsdf("diffuse_eval", "diffuse_sample", "label", "diffuse", "N", N);
b = eval_bsdf(f, -I, normalize(L), pow(cos(radians(90)), 3), bouncemask("all"));
L = normalize(b);

I'm just using “diffuse_eval” and “diffuse_sample” from here [www.sidefx.com].
VFX Supervisor | CG Artist

http://yasinhasanian.com/ [yasinhasanian.com]
User Avatar
Member
55 posts
Joined: 4月 2019
Offline
Also, if the idea is to make a custom cvex shader and then modify it in eval_bsdf, wouldn't it be easier to make it like so in the shader itself from the beginning unless there are easier ways to build that custom cvex shader?
Edited by YasinH - 2020年8月18日 03:27:45
VFX Supervisor | CG Artist

http://yasinhasanian.com/ [yasinhasanian.com]
User Avatar
Member
55 posts
Joined: 4月 2019
Offline
Another question! (Sorry for the spam…)
I'm now trying to use the ggx bsdf for simplicity sake, but still not having much luck. That makes me wonder if I'm using the eval_bsdf output correctly. By altering the pdf in eval_bsdf coming from ggx, shouldn't it have some effect after multiplying to L? All I'm getting are mainly changes in light intensity, not its focus…
VFX Supervisor | CG Artist

http://yasinhasanian.com/ [yasinhasanian.com]
User Avatar
Member
8045 posts
Joined: 9月 2011
Offline
I tried to mock this up, and I couldn't get it to work anymore either. I remember this being simple. The eval_bsdf function is outputting the same value for all L for me as well.
User Avatar
Member
55 posts
Joined: 4月 2019
Offline
Ah, no wonder why I couldn't get it to work! I'm wondering if we can change the light cosine distribution power somehow. I believe that's how it works in Arnold and Renderman.
VFX Supervisor | CG Artist

http://yasinhasanian.com/ [yasinhasanian.com]
User Avatar
Member
8045 posts
Joined: 9月 2011
Offline
singhharry12
I think everything I needed was from the evalbsdf function. Sample functions are only needed for discreet samples (ray tracing). Since light shaders are continuous function, we only care about power scale in a given direction which is what the ‘eval’ argument of the evalbsdf function is. It may to be scaled by the pdf though, which is another argument of the same function.

This was my theory, and I remember getting it to work before, but for some reason the light output seems uniform in all directions even when passing ‘L’ and ‘Lz’ to the eval bsdf function. I must be doing something wrong.
  • Quick Links