Hi,
Can someone help unjam my coders-block please ? I have a point in world space in my Pixel Shader and want to check if it lies within a bounding box (or conceptually any bounding mesh). Whats the quickest way of doing this check ? In 2D C# I'm used to taking an arbitrary line from a point and counting the number of times it crosses a line that makes up a containing polygon - it seems to me there must be an analogy for this in 3D that counts how many times my projected line crosses a plane making up the containing polygon (an odd count means I'm "inside", but an even count means I'm outside, as does a zero count). I'm doing this check for a lot of pixels so it can't be an expensive call.
I have searched around the phrases ("point in bounding box","point in mesh") and it does give me a lot of collision based solutions, but I'm already inside a shader so they dont seem appropriate. It seems like something I should just "get" but I can't seem to visualise it.
Thanks in advance,
Phillip
PS Just in case I'm going at this completely the wrong way, the problem occurs where I'm trying to "layer" a landscape feature over a previously rendered landscape mesh. I'm using a bounding cube that intersects the landscape, and back-calculating the world position of each pixel that is rendered on the surface of the cube, using the inverse projection matrix and the depth buffer to construct the world space of the pixel. Once I have the world space pixel, I want to check to see if it fell within the bounding volume - in which case I should render my texure (river, road, field etc) otherwise the viewer should see the previously rendered landscape.