I am using this to project decal texture on terrain and it fails if triangle normal is 0, 1, 0 so i thought its because of "camera" up dir?
Here, rightmost decal:

Code:
// Used to setup decal "camera" matrices
struct Decal
{
D3DXVECTOR3 pos;// point of intersection on terrain
D3DXVECTOR3 nrm;// triangle normal at intersection
};
std::vector<Decal> v;
...
...
D3DXVECTOR2 decTexDim(256.0f, 256.0f);
D3DXVECTOR3 decCamPos, decCamUp, decCamTarget, decNrm;
decCamPos = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
decCamUp = D3DXVECTOR3(0.0f, 1.0f, 0.0f);
decCamTarget = (*it).pos;
D3DXMATRIX decCamView, decCamProj, camViewInv;
float OffsetX = 0.5f + (0.5f / decTexDim.x);
float OffsetY = 0.5f + (0.5f / decTexDim.y);
D3DXMATRIX texScaleBiasMat(
0.5f, 0.0f, 0.0f, 0.0f,
0.0f, -0.5f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
OffsetX, OffsetY, 0.0f, 1.0f );
D3DXMatrixPerspectiveFovLH(&decCamProj, D3DX_PI / 2.0f, decTexDim.x / decTexDim.y, 0.1f, volRadius * 2.0f);
D3DXVec3Normalize(&decNrm, &(*it).nrm);
decCamPos = decCamTarget + (decNrm * volRadius);
D3DXMatrixLookAtLH(&decCamView, &decCamPos, &decCamTarget, &decCamUp);
D3DXMatrixInverse(&camViewInv, 0, &cam->View);
D3DXMATRIX decCamViewProjScaleBias = decCamView * decCamProj * texScaleBiasMat;
D3DXMATRIX matViewToDecalViewProj = camViewInv * decCamViewProjScaleBias;
d3d9device->SetVertexShader(DECALvs);
d3d9device->SetPixelShader(DECALps);
d3d9device->SetPixelShaderConstantF(0, matViewToDecalViewProj, 4);
...
decalVolumeMesh->DrawSubset(0);
I tried to "swizzle" axis from tri normal and assign to UP witch apeirs to work but i don't know if it will work always?
decCamUP.xyz = triNormal.zxy;
Is there some other similar "hack" that i might use?
Edited by belfegor, 14 May 2012 - 03:07 AM.