BUG: Occlusion Inside Ambient Light

   7119   6   0
User Avatar
Member
941 posts
Joined: July 2005
Offline
I think this is a bug.
(H8.0.488)

Let's see if I didn't screw something up here:

1. As I understand it, in Mantra, an “ambient” light (a light whose contribution is only accessible through the ambient() call) is one which sets L to zero (same as prman – no directionality). And the following shader works as advertised:
light vex_light_testamb(float intensity=1) {
Cl = intensity;
L = 0;
}
when tested with a surface shader like:
surface vex_surf_testamb() {
Cf = ambient();
}
all's good – a flat ambient color.

2. Now, if I wanted to add the option to have occluded ambient (as a light), I should presumably be able to do this:
light vex_light_testamb(float intensity=1; int samples=100) {
float occ=0; vector bent=N;
occlusion(occ,bent,Ps,normalize(N),“samples”,samples,“maxdist”,1e9);
Cl = intensity*(1.0-occ);
L = 0;
}
but it doesn't work (with either of the two occlusion() versions) – it gives a very faint result – as though it wasn't searching far enough, or started at the wrong Ps, or N was in the wrong space… something.
See the “Busted” image below (corrected to gamma=0.01):

3. But if I then change the light so that it has some directionality (L!=0)
light vex_light_testamb(float intensity=1; int samples=100) {
vector Ns=normalize(N);
float occ=0; vector bent=Ns;
occlusion(occ,bent,Ps,Ns,“samples”,samples,“maxdist”,1e9);
Cl = intensity*(1.0-occ);
L = Ns*1e-6; // <– *almost* zero…
}
and the surface shader to react to diffuse, since the light is no longer an ambient light
surface vex_surf_testamb() {
Cf = diffuse(normalize(N));
}
then things render as expected.
Of course, the problem is that now my light is no longer an ambient light
See “OK” image below.

It seems to me that something is clobbering N (or it just doesn't get initialized properly) when the light is set to “ambient mode” (L=0).

Attachments:
ambtest1.jpg (7.9 KB)
ambtest2.jpg (23.5 KB)

Mario Marengo
Senior Developer at Folks VFX [folksvfx.com] in Toronto, Canada.
User Avatar
Member
4344 posts
Joined: July 2005
Offline
On a subdivision Torus…..


light test() {
Cl = normalize(N);
L = 0.0;
}

Attachments:
surf.png (18.3 KB)
light.png (24.3 KB)

if(coffees<2,round(float),float)
User Avatar
Member
4344 posts
Joined: July 2005
Offline

light test() {
Cl = Ps;
L = 0;
}


(Cl = Ps; in the light shader results in an image all black.)

Attachments:
surf.png (13.0 KB)
light.png (5.6 KB)

if(coffees<2,round(float),float)
User Avatar
Member
1002 posts
Joined: July 2005
Offline
It appears that there is a bug when running ambient light shaders that use Ps or N - we'll always initialize Ps to 0 and leave N uninitialized. I'll raise a bug for this.

Out of curiosity, why would you want to use an ambient light for a diffuse effect such as GI?

Andrew
User Avatar
Member
941 posts
Joined: July 2005
Offline
andrewc
Out of curiosity, why would you want to use an ambient light for a diffuse effect such as GI?
Well, I haven't come across this bug before precisely because I normally do this on the surface side (where P and N are well defined). But I'm doing some work with our shading library and thought I'd extend the little lowly ambient light by including occlusion and environment color – seemed logical enough.
But yeah, I don't think Ps and N should suddenly be “undefined” for ambient lights – (they are well defined in the other renderers we support).

Thanks Andrew.
Mario Marengo
Senior Developer at Folks VFX [folksvfx.com] in Toronto, Canada.
User Avatar
Member
4344 posts
Joined: July 2005
Offline
Yum. NaNs.

Light:

light test() {
vector Ps_ndc = toNDC(Ps);
if (Ps_ndc.x < 0.5)
L = Ps;
else
L = 0;

Cl = Ps;
}


Surface:

surface amb() {
Cf = ambient();
}


Sorry…I'll stop picking on ambient() now. :wink:

Attachments:
nan.png (4.1 KB)

if(coffees<2,round(float),float)
User Avatar
Member
4344 posts
Joined: July 2005
Offline
Ah nevermind…

First, as Mario pointed out toNDC() needs Ps to be in object space and second I can't even reproduce the case regardless of the space of Ps.
if(coffees<2,round(float),float)
  • Quick Links