|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Senior Member
Iscritto dal: Feb 2002
Messaggi: 906
|
OMBRE tecnica Trapezoidal Shadow Map
ciao
lavoro con vs NET tutto in c++ e directx C'è qualcuno che sappia aiutarmi................. tramite il cono di vista del frustum a costruire il trapezio di cui si parla nel pdf????? Sto cercanco di implementare la tecnica dello shadow mapping per creare le ombre (e questa l'ho fatta) ma impegna molto la cpu. Per questo ho deciso di implementare un'altra tecnica recentissima che si chiama TIM Trapezoidal Shadow Map. ha questi link c'è il materiale di discussione e il tut fatti veramente bene. http://www.comp.nus.edu.sg/~tants/tsm.html Il primo .pdf che trovi è il testo ufficiale dove viene spiegata questa tecnica. http://www.comp.nus.edu.sg/~tants/tsm/TSM_recipe.html Qui ti spiega passo passo cosa devi fare una volta ottenuto il Trapezio. Dunque al paragrafo: 6.1. Base and Top Lines del pdf si può vedere il frustum di vista da dove ricavare il trapezio e forse perchè non conosco quelle formule avanzate non sono sicuro di aver fatto bene il codice non ne sono proprio sicuro!!!! Ovvero la costruzione dei piani del trapezio se riesco a fare questo trapezio forse riesco ad implementare il tutto. ------------- code------------------------ VOID CreateTrapezoid() { D3DXPLANE NearPlane, FarPlane; D3DXVECTOR3 vTempCorner[8]; D3DXVECTOR3 vNearCenter, vFarCenter; D3DXMATRIX matFrustum; D3DXMatrixInverse(&matFrustum, NULL, &m_matView); D3DXMatrixMultiply(&matFrustum, &matFrustum, &m_LightViewProj); for(int i=0; i<8; i++) D3DXVec3TransformCoord(&vTempCorner[i], &vFrustumCorner[i], &matFrustum); // Calcola il centro del Near e del Far plane vNearCenter = (vTempCorner[0] + vTempCorner[1] + vTempCorner[2] + vTempCorner[3]) * 0.25f; vFarCenter = (vTempCorner[4] + vTempCorner[5] + vTempCorner[6] + vTempCorner[7]) * 0.25f; // Questo codice serve per calcolare in che direzione guarda il cono visivo e creare i piani D3DXVECTOR3 vEyeDir; vEyeDir = vFarCenter - vNearCenter; D3DXVec3Normalize(&vEyeDir, &vEyeDir); D3DXPlaneFromPointNormal(&NearPlane, &vTempCorner[0], &vEyeDir); D3DXPlaneFromPointNormal(&NearPlane, &vTempCorner[8], &vEyeDir); D3DXVECTOR3 NewPoint = vTempCorner[0]; float ref = 0.0f; // Questi due ‘for’ scorrono i due gruppi di punti(Near e Far) e creano un piano per ogni punto per stabilire qual è il più esterno // Calcolo del Near Plane for(int i=1; i<4; i++) { float test = NearPlane.a * vTempCorner[i].x + NearPlane.b * vTempCorner[i].y + NearPlane.c * vTempCorner[i].z + NearPlane.d; if(test < ref) { NewPoint = vTempCorner[i]; ref = test; } } if(ref != 0.0f) D3DXPlaneFromPointNormal(&NearPlane, &NewPoint, &vEyeDir); // Calcolo del Far Plane ref = 0.0f; for(int i=4; i<7; i++) { float test = FarPlane.a * vTempCorner[i].x + FarPlane.b * vTempCorner[i].y + FarPlane.c * vTempCorner[i].z + FarPlane.d; if(test < ref) { NewPoint = vTempCorner[i]; ref = test; } } if(ref != 0.0f) D3DXPlaneFromPointNormal(&FarPlane, &NewPoint, &vEyeDir); // Calcola il valore di n, cioè la distanza tra il Near Plane e Q. PointL corrisponde a PL nel Paper ed è il mio punto dio focus float n = 0.0f; D3DXVECTOR3 PointL; PointL.x = vNearCenter.x * (vEyeDir.x * ((m_distFar - m_distNear)/100.0f * 30.0f)); PointL.y = vNearCenter.y * (vEyeDir.y * ((m_distFar - m_distNear)/100.0f * 30.0f)); PointL.z = vNearCenter.z * (vEyeDir.z * ((m_distFar - m_distNear)/100.0f * 30.0f)); float Dist = D3DXVec3Length(&(vNearCenter - PointL)); // Guardate la formula nel paper al capitolo 6.1(figura 5) n = ((m_distFar - m_distNear) * -Dist + (m_distFar - m_distNear) * Dist * -0.6f) / ((m_distFar - m_distNear) - 2 * Dist - (m_distFar - m_distNear) * -0.6f); // Calcola Q D3DXVECTOR3 q; q.x = vNearCenter.x * (-vEyeDir.x * n); q.y = vNearCenter.y * (-vEyeDir.y * n); q.z = vNearCenter.z * (-vEyeDir.z * n); } ------- end code-------------------------- Per i nomi delle variabili basta rifarsi al Paper tsm.pdf(capitolo 6), purtroppo non conosco la matematica avanzata e sicuramente questo codice fa schifo. Mi sono dimenticato: m_matView è la matrice di vista della telecamera m_LightViewProj è la matrice di vista_proiezione della luce |
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 15:31.