Jump to content

retrieving attributes from objects within refractions


Recommended Posts

I hope the title is clear enough, essentially what I am trying to do is create a custom image plane that will output an rgb matte for objects being refracted by another object. (in my case objects inside a glass sphere)

lets say i give an object inside the glass sphere a vector attribute of green {0,1,0} is it possible to output an image plane that displays that attribute through the refraction of the outer sphere?

I've been searching for a while all over google and OD but have yet to find exactly what I'm after.. I feel like Trace() is about the closest thing I could find, but not sure how that would work for what I'm trying to accomplish..

Perhaps my approach is wrong as well, if anyone knows hows to accomplish something like this, I'm all ears.

Ideally I'd like to accomplish this with image planes if possible and avoid having to create separate takes and what not..

 

Thanks!,

-C

Link to comment
Share on other sites

@StepbyStepVFX, thanks for the reply... you are correct in that I can do something like this (e.g. create another mantra ROP and associate a 'take' with it, and apply constants etc..) I was more curious if there was a 'smarter' way to do this. Something to the effect of using a ray to capture the attribute and drawing it on a ROP image plane without having to change any render settings or material assignments!

-C

 

Link to comment
Share on other sites

Your `trace()` instinct is about right, but personally I'd use `gather()`.

You need to provide `gather()` with a position P and a direction T. The Fresnel VOP can get you T based on N, I (the camera ray) and an IOR (called eta here). Then tell `gather()` to sample the value of the exported AOV attribute (multimatte RGB or whatever) you want to be refracting in this shader:

vector temp = 0;
vector hit;
gather($P,$T,”bias”,0.01,”samples”,1,”name_of_aov_attribute”,hit) {
    temp += hit;
}
$out = temp;

then you can bind that output to any export you like. i'm only doing one sample here, but if you needed smoother samples you could increase that number, then divide `temp` by the number of samples after your gather loop is done.

i used an Inline VOP for that code, but it'd probably work in a snippet if you changed from $ style variables to snippet syntax.

Edited by toadstorm
Link to comment
Share on other sites

@toadstorm I really appreciate this response as well.. this was definitely more in line with what I was thinking.. I can picture conceptually of what I would need to do to retrieve that data, but finding the correct functions and what not become a little daunting..

So, I attempted you use your code in a test scene.. but I'm unsure if I'm putting it in the proper place / feeding it the correct data..

If I were to go the inline VOP route. I would put that in the mat context, yeah? then I would use your code and plug in the outputs of a fresnel to get T. I'm a little confused about what position I'd feed it.. I think in general my understanding of setting something like this up in the mat context confuses me..  i.e. in an attribute vop (on geo for instance) the position's source is already implied by the pipe that is plugged into the node..

I hate asking this.. but i feel like I'm more of a visual learner.. is there anyway you could throw together a quick scene that has this laid out.. or perhaps just elaborate a little more on the inputs and output on the inline VOP?

Cheers,

-C

Link to comment
Share on other sites

here you go!

The teapot is exporting a "matte" AOV, which is a solid red color. This is handled inside the teapot's shader.

To get the glass sphere to refract this AOV, we include the code I posted above in an Inline VOP in the sphere's shader. It uses gather() to look for this same export from other objects in the scene, then writes back to that same "matte" AOV.

refract_aov.hip

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