   Ray addressing in a 3D grid?
  Hi,it's my first post here so i don't know if this is the right place...anyway, i have a triangle mesh that has its triangles subdivided in a grid of cells contained into its oriented bounding box.In a screen space shader i want to cast a ray from viewPos to intersect those cells and retrieve this way the nearest triangles... Knowing the world matrix of the mesh (because it can be rotated/moved/scaled) it is possibile to transform the ray in the object space so that i can easily traverse the cells?I think this can be done but i'm still amazed that my math skills allowed me to come this far xDFor sure i was not clear, so ask me if needed!Thanks for any reply!   
Quote:Original post by _Tom_Hi,it's my first post here so i don't know if this is the right place...anyway, i have a triangle mesh that has its triangles subdivided in a grid of cells contained into its oriented bounding box.In a screen space shader i want to cast a ray from viewPos to intersect those cells and retrieve this way the nearest triangles... Knowing the world matrix of the mesh (because it can be rotated/moved/scaled) it is possibile to transform the ray in the object space so that i can easily traverse the cells?I think this can be done but i'm still amazed that my math skills allowed me to come this far xDFor sure i was not clear, so ask me if needed!Thanks for any reply!I can't comment on the shader aspect of the problem, but to transform a ray into the local space of an object given the world matrix for that object, transform the ray origin and direction by the inverse of the object's world matrix (being sure to transform the origin as a point and the direction as a vector).   ;  The "world matrix of the mesh" M describes the local-to-global transformation for the object mesh. Assuming that the ray R is given in global space. Then both have a common reference frame (namely the global one). To tranform the ray from the global space to the object's local space, you hence have to multiply the ray with the inverse of the object's local-to-global transformation:R' := M-1 * R (for the case of column vectors)R' := R * M-1 (for the case of row vectors)Edit: jyk has won the race once again ;)   ;Quote:Original post by jykI can't comment on the shader aspect of the problem, but to transform a ray into the local space of an object given the world matrix for that object, transform the ray origin and direction by the inverse of the object's world matrix (being sure to transform the origin as a point and the direction as a vector).Thanks you were really fast :DI thought something on these lines, but the matter is more complex... this because the ray is built in view space, eg: for each pixel of the screen, i create the ray that goes from viewpos to pixelpos in the far plane, having a ray for each single pixel.It is a raycast, in fact.So i don't know exactly how to build the ray and how to transform it in world space...Anyway it isn't a shader, i'm trying to find a way to efficiently rasterize in CUDA and this looks promising :D   