AVOID DeferredRenderer::PrepareForLightPass(CameraPtr pCamera) { //set vertex buffer with positions m_pVertices->Set(0, 0); //set vertex buffer with texture data m_pTexCoords->Set(1, 0); //bind matrix constant buffer to the pipeline Mat4x4 trans; //trans.CreateTranslation(pCamera->GetLookAt() + 10000 * pCamera->GetDir()); trans.CreateTranslation(pCamera->GetPosition() + 500* pCamera->GetDir()); Mat4x4 rot; rot = rot.CreateRollPitchYaw(pCamera->GetRoll(), pCamera->GetPitch(), pCamera->GetYaw()); Mat4x4 WVP = rot * trans * pCamera->GetView() * CreateOrthoProjectionLH(SCREEN_WIDTH, SCREEN_HEIGHT, 1.0f, 1000.0f); WVP.Transpose(); m_pMatrixBuffer->UpdateSubresource(0, NULL, &WVP, 0, 0); m_pMatrixBuffer->Set(0, ST_Vertex); struct CameraBuffer { Mat4x4 inverseViewProjection; Vec pos; }; CameraBuffer cameraBuffer; Mat4x4 inverseViewProjection = pCamera->GetViewProjection(); inverseViewProjection.Inverse(); cameraBuffer.pos = pCamera->GetPosition(); cameraBuffer.inverseViewProjection = inverseViewProjection; cameraBuffer.inverseViewProjection.Transpose(); m_pcbCameraPos->UpdateSubresource(0, nullptr, &pCamera->GetPosition(), 0, 0); //m_pcbCameraPos->UpdateSubresource(0, NULL, &cameraBuffer, 0, 0); m_pcbCameraPos->Set(0, ST_Pixel); //pCamera->SetViewport(); SetGlobalViewport(); //set shader resources m_pSSAOBlurredSRV->Set(6, ST_Pixel); m_pDepthSRV->Set(8, ST_Pixel); //set blending functionality //this->BlendLightPass()->Set(nullptr); }
HRESULT RayCast::Pick(Scene * pScene, ActorId actorId, ModelClass * pMesh) { if (!m_bAllHits && m_numIntersections) return S_OK; HRESULT hr; const Mat4x4 matView = pScene->GetCamera()->GetView(); const Mat4x4 matWorld = pScene->GetTopMatrix(); const Mat4x4 proj = pScene->GetCamera()->GetProjection(); //Compute Pickray in screen space Vec3 v; v.x = (((2.0f * m_point.x) / g_pApp->GetScreenSize().x) - 1) / proj._11; v.y = (((2.0f * m_point.y) / g_pApp->GetScreenSize().y) - 1) / proj._22; v.z = 1.0f; Mat4x4 worldView = matWorld * matView; Mat4x4 inverseWorld = worldView.Inverse(); //Screen space pick ray into 3d space m_vPickRayDir.x = v.x * inverseWorld._11 + v.y * inverseWorld._21 + v.z * inverseWorld._31; m_vPickRayDir.y = v.x * inverseWorld._12 + v.y * inverseWorld._22 + v.z * inverseWorld._32; m_vPickRayDir.z = v.x * inverseWorld._13 + v.y * inverseWorld._23 + v.z * inverseWorld._33; m_vPickRayOrigin.x = inverseWorld._41; m_vPickRayOrigin.y = inverseWorld._42; m_vPickRayOrigin.z = inverseWorld._43; if (!m_bAllHits) { //Find closest intersection for (auto meshIt = pMesh->meshes.begin(); meshIt != pMesh->meshes.end(); meshIt++) { for (auto it = (*meshIt).vertices.begin(); it != (*meshIt).vertices.end(); it++) { } } } }
Transform::Transform( const Mat4x4& toWorld ) { m_ToWorld = toWorld; m_FromWorld = toWorld.Inverse(); m_IsFromWorldDirty = false; }