Jump to content

Creating colour with facing ratio


roarke80

Recommended Posts

Hi, sorry if this has been asked before, but I'm a beginner and am not even sure how to begin searching.

I'm trying to select the points on an object that are at a greater angle away from camera. Basically it would be as though I applied a Fresnel in C4D or a facing ratio shader in Arnold, and then deleted away all the black points which leaves me with the outer rim of the object. If I can control it by somehow shining a light on it to determine where the camera is that would be great. Any tips would be greatly appreciated, many thanks!

 

 

Link to comment
Share on other sites

You can compare the angle of the camera direction towards the points against the surface normals with a dot product.

float thresh = chf('angle_threshold');
vector cam_pos = normalize( chv('camera_position') );
vector dir = normalize(@P - cam_pos);
float angle = abs( dot(cam_pos, @N) );
if(angle > thresh) removepoint(0, @ptnum);

 

 

camera_angle_delete.hipnc

  • Like 1
Link to comment
Share on other sites

1 hour ago, stickman said:

Cool stuff, Konstantin!
If you wanted to just make a group of those points, what would that last line be?
 

@group_delPoints = (angle > thresh);

//or alternatively (needed if want to assign the group to points other than the ones currently ran over):

if(angle > thresh)
	setpointgroup(0, "delPoints", @ptnum, 1);

//or again optimized:
setpointgroup(0, "delPoints", @ptnum, angle > thresh);

 

  • Like 2
Link to comment
Share on other sites

With optransform(), cracktransform() you can access a nice object chooser that reads out the camera position for you. I also corrected the code which results in this:

float thresh = chf('threshold');
matrix cam_matrix = optransform(chs("camera"));
vector cam_pos = cracktransform(0, 0, 0, {0,0,0}, cam_matrix);
vector dir = normalize(cam_pos - @P);
float angle = abs( dot(dir, @N) );
setpointgroup(0, "rim", @ptnum, angle > thresh, "set");

camera_angle_delete.hipnc

Edited by konstantin magnus
added example file
  • Like 2
Link to comment
Share on other sites

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...