Jump to content

reflection distance-falloff


Recommended Posts


I'd like to implement distance-based falloff in my ray-traced reflections in mantra. What it means is to basically fade the reflection component to black based on the length of the reflection ray.

I'm coming from a mental ray shader writing background -- in mental ray you can access all details of a 'child' ray after you traced it (so you can just take the length of the child reflection ray, and use it to fade your resulting reflection component).

I've found the mechanism to pass information between shaders when doing ray-tracing calls (as Mario mentioned, all things described in the gather() function's help also apply to all other ray-trace functions).

For instance when tracing a reflection ray, it is easy to query the ray length in the shader _of the hit surface_. However I'd need that information in my shader (that calls the reflection tracing). In mental ray this is something pretty straightforward. Is this possible in mantra?



Link to comment
Share on other sites

The only way I know to achieve this is by using an exponential falloff in gather() from the reflective surface itself. Maybe you're confusing me, but this is providing "ray length" in the surface that's shooting rays. I honestly don't know any other way to do it.

attached a HIP.


thanks for the tip... meanwhile i found what i was after and it was (approximately) the following (i'm not in front of houdini right now) -- something like this:

float ray_length=0.0;
reflectlight( (...) , "ray:length", ray_length);

this returned the length of the reflection ray in ray_length.

i'll check your hip file as soon as i can though... thanks!


Link to comment
Share on other sites

Thats how you would grab the ray length with reflectlight(), but the same thing can be achieved with gather().

My example uses VOPS, but it's essentially doing this.

vector rt = 0, hitc = 0;
float nhits = 0, raylength = 0;

vector reflection_color = 0;

gather(P, R, 0, 1, "Cf", hitc, "ray:length", raylength)
	float fade = fadescale*exp(-fadeexp*raylength);
	hitc *= fade;

	rt += hitc;
	nhits += 1;

rt /= nhits;

reflection_color = Kr*rt;

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.

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