Jump to content

How to extract goal of a spotlight in vex


ouyang

Recommended Posts

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.

LightDirection.hipnc

Link to comment
Share on other sites

Your code does basic point lighting with lambert. You need to add cone functionality. Check example $HH/vex/Light/asad_light.vfl for different light parameters.

Basic spot light support:

// Point wrangle.

string lobj = "/obj/hlight1";

vector l = ptransform(lobj, "space:current", {0, 0, 0}) - @P;
vector lz = vtransform(lobj, "space:current", {0, 0, 1});

float coneangle = ch(lobj + "/coneangle");
float conedelta = ch(lobj + "/conedelta");
float rolloff = ch(lobj + "/coneroll");

float angle = cos(radians(coneangle/2));
float delta = cos(radians(coneangle/2 + conedelta));

float cone = smooth(min(angle, delta), max(angle, delta),
                    dot(lz, normalize(l)), rolloff);
float lambert = clamp(dot(@N, normalize(l)), 0, 1);

@Cd = cone * lambert;

sop_spotlight.gif.a0fb95ce550dc0771c3799e9af7f2a80.gif

Use integer casting to output hard mask:

@Cd = length(@Cd) > 0;

sop_spotlight.hipnc

Edited by f1480187
  • Like 4
Link to comment
Share on other sites

  • 4 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...