In TD088/TD099, I’m having some difficulty getting correct UVs in the callback of the Render Pick DAT. I have a vertex shader that shrinks rectangles whose primitive center are outside of the center of the screen. Shrinking is like giving them a scale factor that’s less than 1, which I’ve done in the shader code.
worldSpaceVert.xyz = mix(primCenter, worldSpaceVert.xyz, scale);
When scale is 0, the rectangle will be size zero because all four corners will end up at center.xy. When scale is 1, the rectangle is unchanged, and so on.
When I hard-code scale=0.2, scale=0.5, scale=1. etc, the render pick works well. I can click inside any region of any SOP, and the UV that is printed to the textport is correct.
However, if I allow the scale to be dynamic, based on screen space, the UVs are bad. If I click the upper-left corner of a larger rectangle, the render pick misses it. If I click the upper-middle edge of a smaller rectangle, the V-value is mysteriously low, (0.5,0.75) when I expect something like (0.5,0.99). If I click just outside of the upper-middle edge of a smaller rectangle, I get a UV of (0.5,0.84) even though I expect the render pick to not detect it.
I’m doing this in the vertex shader, but I’m not sure how much effect it has:
TDWritePickingValues();
vTDPickVert.worldSpacePosition = worldSpaceVert.xyz;
vTDPickVert.sopSpacePosition = mix(primCenter, P, scale);
vTDPickVert.camSpacePosition = camSpaceVert.xyz;
The sopSpacePosition line is a little questionable, but 1) it’s not UV-related, and 2) it works as long as scale is a constant value.
And even if you can’t help me fix the UV issue, I hope you can get some use out of the vertex shader idea.
Update:
I’m surprised that something like this doesn’t ruin the uv-picking.
[code]// early on
scale = 1.;
// much later
TDWritePickingValues();
worldSpaceVert.xyz += vec3(1000.);
camSpaceVert = uTDMat.cam * worldSpaceVert;
vTDPickVert.worldSpacePosition = worldSpaceVert.xyz;
vTDPickVert.sopSpacePosition = mix(primCenter, P, scale) + vec3(1000.);
vTDPickVert.camSpacePosition = camSpaceVert.xyz;
vTDPickVert.uv[0] = uv[0];[/code]
If render picking relies on a separate hidden buffer, shouldn’t that huge offset of vec3(1000.) ruin the placement of the SOPs in this buffer?
Update:
Side note that the docs are a little confusing because this suggested line won’t work
vTDPickVert.worldSpacePosition = uTDMats.world * vec4(newPosition, 1.0);
vTDPickVert.worldSpacePosition is a vec3 not a vec4.
render_pick_vTDPickVert.2.toe (7.05 KB)