-
Notifications
You must be signed in to change notification settings - Fork 2
How to use Raycast shader node
In this small tutorial, we will create a displacement map for a sphere that turns it into a dodecahedron.
Okay, let's take a sphere and a dodecahedron.
To make the dodecahedron invisible, add a CyclesMesh property and disable all visibility flags except Raycast. This will make the dodecahedron invisible in the render but visible to raycasting.
Assign an emissive shader to the sphere and start creating the shader tree.
Start by adding Geometry and Raycast nodes, and connect Position to Position and Normal to Direction. This pair of nodes will measure the positive shift (along the normal) for displacement.
For the negative direction, create a vector (-1, -1, -1), multiply it by the Normal vector from the Geometry node, and connect the result to Direction on the second Raycast node. Also connect Position to Position. This node will measure the distance along the direction opposite to the normal.
Multiply the outputs IsHit and HitDistance for both Raycast nodes.
Negate the result of the negative Raycast, and combine the obtained values by taking a simple sum.
Finally, add 0.5 to the result. This will shift all negative values into a positive interval. Connect it to the Emission color.
Render.
Unwrap the sphere.
Add a CyclesBake property to the sphere and define an EXR output file.
Bake the map; you should obtain something like this.
Solidify the boundary (using Photoshop, for example).
Okay, now apply this map as a displacement map. Create a copy of the sphere (or a new one, but it should have the same UVs). Assign a simple diffuse material. Add an Image texture, set the mode to Non-Color Data, and connect it to the Displacement node.
Add a subdivision.
Render. It's a sphere.