
The "IsIntersector" is set in script to be 1 or 0 depending on whether the cube we are refering to is used to intersect or is an intersectee.

If one returns 0 we use the last multiply node to make sure the final output will be 0.įinally, we get to the last part of the shader. Each compare with range returns 1 if the point in object space is within the extents for each axis. (I encourage you to learn how to write shaders). Unfortunately, Amplify shader has no good way to check if a vector lies within two vectors. This leads to the next section where the extents are added and subtracted to the "_Cubepos" and "_CubeExtent" to find the minimum and maximum extents. After this it is added back to be in the correct position. This is subracted by the world pos as the rotation matrix rotates around the origin. We also get a "_Cubepos" which is the position of the cube to intersect with (E.g it would be the intersector if shader is on the intersectee). However, it is inversed as the rotation matrix rotates the cube into world space, therefore, inversing this would rotate the world space point into object space. The rotation matrix is used to rotate a point. Most of the variables will be defined in script. Next we need to get the surface point in object space:

This will ensure the back face is actually rendered (This can be optimized by decided depending on where the cube is in the intersector).

After this we can get into the actually shader node stuff.įirst we need to make sure "Cull Mode" is off (Output Node > Cull Mode > off).

So as you've done with the plane, the cutout works because the back face of the intersector is shown when inside the intersectee and the intersectee front face is show when it is inside the intersector.Ĭreate a shader (which is used by both cubes) and put them into two seperate materials - apply individual materials to each cube. Here is the result of doing the shader using "Amplify Shader":įirst we'll call the green cube the "intersector" and the red cube the "intersectee".
