d3dcoder / d3d12book

Sample code for the book "Introduction to 3D Game Programming with DirectX 12"
1.53k stars 591 forks source link

Chapter 17 Picking - multy renderItem picking fail #13

Open RKGekk opened 7 years ago

RKGekk commented 7 years ago

if vector mRitemLayer contain more than one renderItem then rayOrigin and rayDir are overwrite with wrong values.

XMMATRIX W = XMLoadFloat4x4(&ri->World); XMMATRIX invWorld = XMMatrixInverse(&XMMatrixDeterminant(W), W); XMMATRIX toLocal = XMMatrixMultiply(invView, invWorld); //multiple times overwrite rayOrigin = XMVector3TransformCoord(rayOrigin, toLocal); rayDir = XMVector3TransformNormal(rayDir, toLocal); rayDir = XMVector3Normalize(rayDir);

fixed version: XMMATRIX W = XMLoadFloat4x4(&ri->World); XMMATRIX invWorld = XMMatrixInverse(&XMMatrixDeterminant(W), W); XMMATRIX toLocal = XMMatrixMultiply(invView, invWorld); XMVECTOR rayOriginLoc = XMVector3TransformCoord(rayOrigin, toLocal); XMVECTOR rayDirLoc = XMVector3TransformNormal(rayDir, toLocal); rayDirLoc = XMVector3Normalize(rayDirLoc);