|
Houdini Blobby Shader
|
Surface Color Test
Using
ray tracing to define nearby surfaces, we can use the distance
to nearby objects to affect the color of the surface being
shaded. In the VEX shading language I used the rayhittest()
function.
Basic function
float rayhittest(vector P, vectorD, pHit, nHit, float
bias)
This function returns the distance from the surface position
P to the object in direction D. The length of direction
D will determine how far the rayhittest function checks for
objects and returns a negative number if no hits occur. The
position and normal of the hit surface are pHit and nHit.
Added function options
scope: You can limit what objects in your scene affect the
shaded surface by specifying which objects in the scene will
be used to calculate the distance.
Get VEX Code
I wrote this surface shader in order to determine if it was
possible for nearby surfaces to affect the displacement of the
surface being shaded. After doing some research, I discovered
that the VEX ray tracing function rayhittest() does not work
in displacement shading. None of the raytracing functions
of VEX operate in the VEX displacement shader. This is
because the displacement shader is run to figure out where point
P is. In order to raytrace an object you have to already know
this information, therefore it will not work by this method.
|
Houdini
VEX Code
surface RTDepth05(
int alongN = 0; // ON: trace along -N; OFF: trace along I
float dmax = 8; // max length of intersection test
float rbias = 0.005; // ray bias to avoid self-intersections
string oname = "";
)
{
vector n = normalize(N);
vector i = normalize(I);
vector D = alongN ? normalize(frontface(n,i)) : n;
vector hitpoint;
vector hitnormal;
float dhit = rayhittest(P, D * dmax, hitpoint, hitnormal, rbias, "scope", oname);
float angle = dot(n, normalize(hitnormal));
vector red = set(1, 0, 0);
vector yellow = set(1, 1, 0);
Cf = lerp(yellow, red, lerp(angle);
}
|
|