How to extract goal of a spotlight by VEX?

   1407   2   1
User Avatar
Member
2 posts
Joined: Feb. 2017
Offline
Hi !

I have an object and a light. I want to create an attribute on the points of my object that are directly illuminated by my light. 1 when the point is illuminated, 0 when it's not. For now I have this :

4@m = optransform('/obj/hlight1');

vector lightDirection = set(0, 0, 1) * 4@m;

float result = dot(- lightDirection, @N);
result = fit(result, 0.99, 1, 0, 1);

@Cd = set(result, result, result);

The problem is that I get a value on my result even when the goal of my spotlight isn't in the direction of my object. In fact, it only takes care of my light's center. I want it to take care of my light direction but I can't find where to get the goal or target parameters (tx,ty,tz). Can you help me guys ?

I join the scene attached.

Attachments:
LightDirection.hipnc (120.9 KB)

User Avatar
Member
7762 posts
Joined: Sept. 2011
Offline
The lighting equation is a little different than that. You need to take into account the light's position as well as it's direction. Check out my scene file.

key:
pos = surface position
nn = surface normal
lpos = light position
lz = light z axis
ldir = direction from surface to light

Attachments:
lighting_in_vex.zip (77.1 KB)

User Avatar
Member
2 posts
Joined: Feb. 2017
Offline
Thanks a lot!!! I didn't think about cone functionality! But I have a question, why do you do coneangle*0.5? Thanks again!
  • Quick Links