I am trying to create a Custom function to be used in Shader Graph that cuts out a box on an object.
I want to be able to feed in the World coordinates of a cube to the function and it to return a value float and connect it to the alpha channel.
So far i have this:
void IsVertexInsideBox_float(float3 vertexPosition, float3 boxPosition, float3 boxScale, float4 boxRotation, float4 objectWorldRotation , out float Out)
{
float4x4 rotationMatrix = quaternion_to_matrix(boxRotation);
// Transform the point into the local space of the cube
float3 localPoint = mul(rotationMatrix, vertexPosition - boxPosition) / boxScale;
// Check if the transformed point is within the cube
bool insideCube = abs(localPoint.x) <= 0.5 && abs(localPoint.y) <= 0.5 && abs(localPoint.z) <= 0.5;
Out = insideCube ? 1 : 0;
}
At first it seems like it works fine, i can move the box and rotate its Y axis and all looks good.
But if i rotate other axis or the “shaded” object it all goes wrong from there… ![]()
Any tips, links or solution on how to solve this?
Thanks in advance!!
Looks good,
Sad life

