blue_riviera Posted June 23, 2009 Share Posted June 23, 2009 Hi, 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? thx imre Quote Link to comment Share on other sites More sharing options...
Alanw Posted June 23, 2009 Share Posted June 23, 2009 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. -Alan exponential_fade.tar.gz Quote Link to comment Share on other sites More sharing options...
blue_riviera Posted June 23, 2009 Author Share Posted June 23, 2009 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. -Alan 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! imre Quote Link to comment Share on other sites More sharing options...
Alanw Posted June 23, 2009 Share Posted June 23, 2009 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; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.