# Illuminance Loop Question

## Recommended Posts

In sig02.course16.pdf page 57 we read:

"the illuminance loop corresponding to the built-in diffuse() function.

```normal Nf = normalize(faceforward(N, I));
illuminance (P, Nf, PI/2) {
Ci += Cl * (Nf . normalize(L));
}```

Which is a very easy stuff.

I wrote in vex :

```#include &lt;math.h&gt;

surface
k_pharr_mattefalloff( vector mycolor = 0.2)

{
vector Nf = normalize(frontface(N,I));
illuminance(P,Nf,PI/2)
Cf = mycolor + Cl * dot(Nf,normalize(L));
}```

Which works but leaves the unlit areas (PI/2 to PI I guess) constant white!

Does illuminance loops differ between vex and rsl?

What to do to correct it not using built-in functions ofcourse?

I have similar problems with other examples from the paper (listings 3.2, 3.4, 3.7...)

I hope this is not one of my stupid errors.

##### Share on other sites

I know next to nothing about shading but some odd things occur to me in your code:

- Do you need braces around your illuminance loop contents?

- I don't see you accumulating the light colours. Do you mean to set Cf to mycolor outside the illuminance loop and then accumulate the the lighting results within?

##### Share on other sites

In help illuminance loop looks like

` illuminance(){}`

, so in the shader it should look like

```surface mysurface()
{
illuminance(){
}
}```

but it works exactly as my example.

About the colour: In rman example there is "Cf +=" because it adds calculated Cf to default surface color (from rib?). AFAIK for light color there is "Cl" in illuminance loops in both rsl and vex.

What I'm trying to do with "Cf = mycol + Cl*(blah)" is exactly to take some colour (instead of default surface) and add light colour multiplied by dot(Nf,L).

Please explain me if this is wrong.

There has to be an error because the result is as I wrote.

##### Share on other sites

Goal of illuminance is:

loop through ALL lights and GATHER illumination...

```#include &lt;math.h&gt;

surface
k_pharr_mattefalloff( vector mycolor = 0.2)

{
vector Nf = normalize(frontface(N,I));

//set global illumination = 0
vector lcol = 0;

//loop through all lights
illuminance(P,Nf,PI/2){
//add illumination of current light to global illumination
lcol += Cl * dot(Nf,normalize(L));
}

Cf = lcol * mycolor;
}```

EDIT

illuminance(P,Nf,PI/2)

Cf = mycolor + Cl * dot(Nf,normalize(L));

}

This means:

Skip all lights except last, get illumination of last light and ???ADD??? some color.

##### Share on other sites

Ouch

Now, where should I send a beer ?

##### Share on other sites

Help me please. In my simple example neither frontface VOP nor frontface() VEX function work with illuminance loop. Maybe it's some bug with my version of houdini...

fronFace_problem.hipc.hip

Edited by thx1138

## Create an account

Register a new account