Jump to content

Environment Color Shader


Recommended Posts

Hi,

I would like to write this simple shader which samples color of the environment. The idea is to cast a ray form the surface of the geometry along its normal and sample the color of the geometry it hits.

For that I used VEX raytrace node (example attached). To get blurred environment color I increased "Cone Angle To Sample" and "Area Samples" on raytrace node. And everything works fine until ray hits another surface with the same shader. Then rendering becomes extremely long because for example we have 10 rays on Area Samples, and all of those 10 rays are hitting the surface that require to cast another 10 rays form each point the first 10 hit. So we have 100 rays already, and what if those 100 rays are hitting the surface that need ray trace again so we have 1000 rays... this geometrical progression stretches rendering time to impractical. My idea is to make a shader which would switch Cone Angle and Area Samples to 0 and 1 on the second bounce of the ray trace. So I am stuck on getting info on the ray-trace level in the shader.

The other idea is limit ray bounces in mantra. However I could not find the option for that. The only ray bounce limit I found is in PBR and it is a Reflect Limit. However ray-trace I am using in my shader is not a reflection and also I wish I would not have to render with PBR.

Please share ideas how to solve the problem of ray-trace sampling ray-trace surfaces.

PS in my example SuroundingColor material is doing ray-tracing I have mentioned above. I set it up not to sample itself, so to see the example of geometrical progression I described above put * in the "Object Scope" of the raytrace node of the SurroundingColor material...

Thanks

HDRI_test04.hip

Link to comment
Share on other sites

The Ray Bounce Level vop, will give you the ray level in your shader.

http://www.sidefx.com/docs/houdini10.0/nodes/vop/raybounce

Also, what your trying to do sounds a lot like what the Irraidaince vop does

http://www.sidefx.com/docs/houdini10.0/nodes/vop/irradiance

Mantra allows you to set the ray bounce limit separately for reflections and refractions. You just need to add the Reflect Limit and Refraction Limit parameters. The glass material in the in the Material Palette has these on a properties shop, but you can also add them to your ROP.

Link to comment
Share on other sites

The Ray Bounce Level vop, will give you the ray level in your shader.

http://www.sidefx.com/docs/houdini10.0/nodes/vop/raybounce

Also, what your trying to do sounds a lot like what the Irraidaince vop does

http://www.sidefx.com/docs/houdini10.0/nodes/vop/irradiance

Mantra allows you to set the ray bounce limit separately for reflections and refractions. You just need to add the Reflect Limit and Refraction Limit parameters. The glass material in the in the Material Palette has these on a properties shop, but you can also add them to your ROP.

Hi Dan,

Thank you for your response.

I already tried to use Irraidaince vop. And like you said it does very similar thing however I am missing a an option of the cone angle or anything like that just to specify the area to sample or the amount of blur. Please share if you know how Irraidaince is dealing with sampling another surface with Irraidaince on it. From the test I have made it looks like it just makes the sampled surface as a solid black, but I might be wrong.

Also I already tried to use raybounce vop however it gives values of 0 (another example attached where I replaces blue color channel with raybaunce values). I might be wrong but I think the reason for that is mantra doesn't read it as a BOUNCE because when the raytrace ray hits the surface with raytrace shader it casts NEW set of rays from that surface so raybounce values do not change...

so it would be rally helpful if you could give me any idea of how to get the information of the surface that ray hit which later on could be used to control area samples and cone angle of the raytrace vop.

thanks

HDRI_test05.hip

Link to comment
Share on other sites

I think may be misunderstanding the way raybounce works a bit.

When a ray is fired from the camera to the surface, the shader is run and raybounce will return 0. If that surface traces rays, the shader on the surfaces that the rays hit will run and ray bounce will return 1, and so on.

In file 05 the surfaces that have raybounce writing to blue are only being hit by camera rays, so raybounce is always returning zero.

I edited the file to have the environment and the ground write raybounce to blue, and have the spheres just ray trace, and you can see how the reflections on the spheres have a blue channel, while the sky and ground are just green and red.

You could use the raybounce vop to control an if statement that traces several rays if raybounce is zero, but just one or none if raybounce is greater.

HDRI_test05_danbode.hipnc

Link to comment
Share on other sites

I think may be misunderstanding the way raybounce works a bit.

When a ray is fired from the camera to the surface, the shader is run and raybounce will return 0. If that surface traces rays, the shader on the surfaces that the rays hit will run and ray bounce will return 1, and so on.

In file 05 the surfaces that have raybounce writing to blue are only being hit by camera rays, so raybounce is always returning zero.

I edited the file to have the environment and the ground write raybounce to blue, and have the spheres just ray trace, and you can see how the reflections on the spheres have a blue channel, while the sky and ground are just green and red.

You could use the raybounce vop to control an if statement that traces several rays if raybounce is zero, but just one or none if raybounce is greater.

Thanks a lot for explaining me this :)

just one more question.

Since raybounce VALUES are being generated in the Environment and Ground shaders how do I bring them (those VALUES) to my SuroundingColor shader to control raytrace parameters (Cone Angle and Area Sampling) with the if function that you have mentioned?

Link to comment
Share on other sites

The values of raybounce are generated in any shader that gets hit by a ray. The original problem you were having was that each time your "SuroundingColor" shader was hit by a ray, you would trace 10x more rays. So if you ray trace in an if statement you can trace 10 rays when raybounce is zero for surfaces hit by camera rays and have another if statement that traces just one ray when raybounce is one or greater, for surfaces hit by rays traced from other surfaces.

Link to comment
Share on other sites

The values of raybounce are generated in any shader that gets hit by a ray. The original problem you were having was that each time your "SuroundingColor" shader was hit by a ray, you would trace 10x more rays. So if you ray trace in an if statement you can trace 10 rays when raybounce is zero for surfaces hit by camera rays and have another if statement that traces just one ray when raybounce is one or greater, for surfaces hit by rays traced from other surfaces.

This is my first shader ever :) so I apologize for questions that seams to you a common sense.

That was my original idea to do what you just described. Although I am confused how to bring ray-bounce values in to my SuroundingColor shader. Correct me if I am wrong but as I understand I have to have ray-bounce values in my SuroundingColor shader which I will run through the IF statement and go in to the Cone Angle and Area Samples of the ray-trace vop. In your example ray-bounce values were overwriting blue channel. How do I bring them in without overwriting.

Thanks once again

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