Jump to content

Evaluating textures at hitpoints

Recommended Posts

I shoot rays from gdp to gdp2 and check if they intersect. If they do intersect then I would like to evaluate a texture map on gdp2.


I can get the hit positions, but how would I get the values of the texturemap at those points?


This is what I have to get the hit positions:

GA_FOR_ALL_PTOFF(gdp, ptoff)

// searchdir attribs
UT_Vector3 searchdir;
tupleN->get(hN.getAttribute(), ptoff, searchdir.data(), 3);

GU_RayIntersect *myCollision = new GU_RayIntersect;
GU_RayInfo hitInfo(searchdir.normalize());

UT_Vector4 pos(gdp->getPos3(ptoff));
int hitNum = myCollision->sendRay(pos, searchdir, hitInfo);

const GEO_Primitive *hitPrim = hitInfo.myPrim;
fpreal32 hitU = hitInfo.myU;
fpreal32 hitV = hitInfo.myV;
//get pos of hit
UT_Vector4 hitPos;
hitPrim->evaluateInteriorPoint(hitPos, hitU, hitV);

delete myCollision;
Edited by Macha
Link to comment
Share on other sites


i had a similar problem and i've written my own function evaluateUVPoint(...). I would be very interested too if someone knows an already existing HDK function to get the texture point.
Anyway, this is my method which returns the texture UV coordinate of a hit position on a triangle.
UT_Vector3D evaluateUVPoint(GA_Offset primOff, float u, float v, float w = 0)
    UT_Vector3D uv = 0;
    GA_Primitive* prim = myGdp->getPrimitiveList().get(primOff);
    if (prim)
        UT_Vector3D pt0, pt1, pt2;
        GA_ROHandleV3 primUV;
        primUV = myGdp->findPointAttribute(GEO_STD_ATTRIB_TEXTURE); // or findVertexAttribute(...)
        if (primUV.isValid())
            pt0 = primUV.get(prim->getPointOffset(0)); // or getVertexOffset(...)
            pt1 = primUV.get(prim->getPointOffset(1));
            pt2 = primUV.get(prim->getPointOffset(2));
            uv  = (pt1 - pt0) * u;
            uv += (pt2 - pt0) * v;
            uv += pt0;
    return uv;

This works only for triangles. If someone knows a solution for quads i would be very gratefull.


Link to comment
Share on other sites

  • 2 weeks later...

Thanks Claus, that works quite well. I've only come back to this now.


I'm thinking of using the uvs I get from the hitpoints to read pixels from an image.I don't see anything obvious in the HDK about images and uvs.


Is anybody aware of a sample code somewhere?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...