void Camera::ApplyViewProjTransform() { glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMultMatrixf(GetProjMatrix()); // or glLoadMatrixf() glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glMultMatrixf(GetViewMatrix()); // or glLoadMatrixf() }
void RenderInputScene::SetCamera(const GraphicsCamera & cam) { cam_position = cam.pos; cam_rotation = cam.rot; lod_far = cam.view_distance; projMatrix = GetProjMatrix(cam); viewMatrix = GetViewMatrix(cam); frustum.Extract(projMatrix.GetArray(), viewMatrix.GetArray()); }
void GameObject::Draw(){ //ゲームステージが無効ならリターン if (m_GameStgae.expired()){ return; } //デバイスの取得 auto Dev = App::GetApp()->GetDeviceResources(); auto pDx11Device = Dev->GetD3DDevice(); auto pID3D11DeviceContext = Dev->GetD3DDeviceContext(); //ステータスのポインタ auto RenderStatePtr = Dev->GetRenderState(); auto Stage = m_GameStgae.lock(); auto ViewPtr = Stage->GetView(); //ビューからカメラを取り出す auto PtrCamera = ViewPtr->GetCamera(); //カメラの取得 Matrix4X4 View, Proj; View = PtrCamera->GetViewMatrix(); Proj = PtrCamera->GetProjMatrix(); //コンスタントバッファの設定 Texture3DConstantBuffer cb1; //行列の設定(転置する) cb1.Model = Matrix4X4EX::Transpose(m_WorldMatrix); cb1.View = Matrix4X4EX::Transpose(View); cb1.Projection = Matrix4X4EX::Transpose(Proj); //ライトの設定 //ステージから0番目のライトを取り出す auto PtrLight = ViewPtr->GetMultiLight()->GetLight(0); cb1.LightDir = PtrLight->GetDirectional(); cb1.LightDir.w = 1.0f; //コンスタントバッファの更新 pID3D11DeviceContext->UpdateSubresource(CBTexture3D::GetPtr()->GetBuffer(), 0, nullptr, &cb1, 0, 0); //ストライドとオフセット UINT stride = sizeof(VertexPositionNormalTexture); UINT offset = 0; //頂点バッファの設定 pID3D11DeviceContext->IASetVertexBuffers(0, 1, m_VertexBuffer.GetAddressOf(), &stride, &offset); //インデックスバッファのセット pID3D11DeviceContext->IASetIndexBuffer(m_IndexBuffer.Get(), DXGI_FORMAT_R16_UINT, 0); //描画方法(3角形) pID3D11DeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); //透明処理 pID3D11DeviceContext->OMSetBlendState(RenderStatePtr->GetAlphaBlendEx(), nullptr, 0xffffffff); //デプスステンシルは使用する pID3D11DeviceContext->OMSetDepthStencilState(RenderStatePtr->GetDepthDefault(), 0); //シェーダの設定 pID3D11DeviceContext->VSSetShader(VSTexture3D::GetPtr()->GetShader(), nullptr, 0); pID3D11DeviceContext->PSSetShader(PSTexture3D::GetPtr()->GetShader(), nullptr, 0); //リニアサンプラーを設定 ID3D11SamplerState* samplerState = RenderStatePtr->GetLinearClamp(); pID3D11DeviceContext->PSSetSamplers(0, 1, &samplerState); for (auto& m : m_Materials){ //テクスチャを設定 pID3D11DeviceContext->PSSetShaderResources(0, 1, m.m_ShaderResView.GetAddressOf()); //インプットレイアウトの設定 pID3D11DeviceContext->IASetInputLayout(VSTexture3D::GetPtr()->GetInputLayout()); //コンスタントバッファの設定 ID3D11Buffer* pConstantBuffer = CBTexture3D::GetPtr()->GetBuffer(); pID3D11DeviceContext->VSSetConstantBuffers(0, 1, &pConstantBuffer); pID3D11DeviceContext->PSSetConstantBuffers(0, 1, &pConstantBuffer); //レンダリングステート pID3D11DeviceContext->RSSetState(RenderStatePtr->GetCullFront()); //描画 pID3D11DeviceContext->DrawIndexed(m.m_IndexCount, m.m_StartIndex, 0); //レンダリングステート pID3D11DeviceContext->RSSetState(RenderStatePtr->GetCullBack()); //描画 pID3D11DeviceContext->DrawIndexed(m.m_IndexCount, m.m_StartIndex,0); } //後始末 Dev->InitializeStates(RenderStatePtr); }
void GraphicsGL2::CullScenePass( const GraphicsConfigPass & pass, std::map <std::string, PtrVector <Drawable> > & culled_static_drawlist, std::ostream & error_output) { // for each pass, we have which camera and which draw layer to use // we want to do culling for each unique camera and draw layer combination // use camera/layer as the unique key assert(!pass.draw.empty()); if (pass.draw.back() == "postprocess" || !pass.conditions.Satisfied(conditions)) return; for (std::vector <std::string>::const_iterator d = pass.draw.begin(); d != pass.draw.end(); d++) { // determine if we're dealing with a cubemap render_output_map_type::iterator oi = render_outputs.find(pass.output); if (oi == render_outputs.end()) { ReportOnce(&pass, "Render output "+pass.output+" couldn't be found", error_output); return; } const bool cubemap = (oi->second.IsFBO() && oi->second.RenderToFBO().IsCubemap()); const int cubesides = cubemap ? 6 : 1; std::string cameraname = pass.camera; for (int cubeside = 0; cubeside < cubesides; cubeside++) { if (cubemap) { // build sub-camera // build a name for the sub camera { std::stringstream converter; converter << pass.camera << "_cubeside" << cubeside; cameraname = converter.str(); } // get the base camera camera_map_type::iterator bci = cameras.find(pass.camera); if (bci == cameras.end()) { ReportOnce(&pass, "Camera "+pass.camera+" couldn't be found", error_output); return; } // create our sub-camera GraphicsCamera & cam = cameras[cameraname]; cam = bci->second; // set the sub-camera's properties cam.rot = GetCubeSideOrientation(cubeside, cam.rot, error_output); cam.fov = 90; assert(oi->second.IsFBO()); const FrameBufferObject & fbo = oi->second.RenderToFBO(); cam.w = fbo.GetWidth(); cam.h = fbo.GetHeight(); } std::string key = BuildKey(cameraname, *d); if (pass.cull) { camera_map_type::iterator ci = cameras.find(cameraname); if (ci == cameras.end()) { ReportOnce(&pass, "Camera "+cameraname+" couldn't be found", error_output); return; } GraphicsCamera & cam = ci->second; if (culled_static_drawlist.find(key) == culled_static_drawlist.end()) { Frustum frustum; frustum.Extract(GetProjMatrix(cam).GetArray(), GetViewMatrix(cam).GetArray()); reseatable_reference <AabbTreeNodeAdapter <Drawable> > container = static_drawlist.GetDrawlist().GetByName(*d); if (!container) { ReportOnce(&pass, "Drawable container "+*d+" couldn't be found", error_output); return; } container->Query(frustum, culled_static_drawlist[key]); } } else { reseatable_reference <AabbTreeNodeAdapter <Drawable> > container = static_drawlist.GetDrawlist().GetByName(*d); if (!container) { ReportOnce(&pass, "Drawable container "+*d+" couldn't be found", error_output); return; } container->Query(Aabb<float>::IntersectAlways(), culled_static_drawlist[key]); } } } }
void GraphicsGL2::SetupScene( float fov, float new_view_distance, const Vec3 cam_position, const Quat & cam_rotation, const Vec3 & dynamic_reflection_sample_pos) { // setup the default camera from the passed-in parameters { GraphicsCamera & cam = cameras["default"]; cam.fov = fov; cam.pos = cam_position; cam.rot = cam_rotation; cam.view_distance = new_view_distance; cam.w = w; cam.h = h; } // create a camera for the skybox with a long view distance { GraphicsCamera & cam = cameras["skybox"]; cam = cameras["default"]; cam.view_distance = 10000; cam.pos = Vec3(0); } // create a camera for the dynamic reflections { GraphicsCamera & cam = cameras["dynamic_reflection"]; cam.pos = dynamic_reflection_sample_pos; cam.fov = 90; // this gets automatically overridden with the correct fov (which is 90 anyway) cam.rot.LoadIdentity(); // this gets automatically rotated for each cube side cam.view_distance = 100; cam.w = 1; // this gets automatically overridden with the cubemap dimensions cam.h = 1; // this gets automatically overridden with the cubemap dimensions } // create a camera for the dynamic reflection skybox { GraphicsCamera & cam = cameras["dynamic_reflection_skybox"]; cam = cameras["dynamic_reflection"]; cam.view_distance = 10000; cam.pos = Vec3(0); } // create an ortho camera for 2d drawing { GraphicsCamera & cam = cameras["2d"]; // this is the glOrtho call we want: glOrtho( 0, 1, 1, 0, -1, 1 ); cam.orthomode = true; cam.orthomin = Vec3(0, 1, -1); cam.orthomax = Vec3(1, 0, 1); } glMatrixMode(GL_TEXTURE); // put the default camera transform into texture3, needed by shaders only Mat4 viewMatrix; cam_rotation.GetMatrix4(viewMatrix); float translate[4] = {-cam_position[0], -cam_position[1], -cam_position[2], 0}; viewMatrix.MultiplyVector4(translate); viewMatrix.Translate(translate[0], translate[1], translate[2]); glstate.ActiveTexture(3); glLoadMatrixf(viewMatrix.GetArray()); // create cameras for shadow passes if (shadows) { Mat4 viewMatrixInv = viewMatrix.Inverse(); // derive light rotation quaternion from light direction vector Quat light_rotation; Vec3 up(0, 0, 1); float cosa = up.dot(light_direction); if (cosa * cosa < 1.0f) { float a = -acosf(cosa); Vec3 x = up.cross(light_direction).Normalize(); light_rotation.SetAxisAngle(a, x[0], x[1], x[2]); } std::vector <std::string> shadow_names; shadow_names.push_back("near"); shadow_names.push_back("medium"); shadow_names.push_back("far"); for (int i = 0; i < 3; i++) { float shadow_radius = (1<<i)*closeshadow+(i)*20.0; //5,30,60 Vec3 shadowbox(1,1,1); shadowbox = shadowbox * (shadow_radius*sqrt(2.0)); Vec3 shadowoffset(0,0,-1); shadowoffset = shadowoffset * shadow_radius; (-cam_rotation).RotateVector(shadowoffset); shadowbox[2] += 60.0; GraphicsCamera & cam = cameras["shadows_"+shadow_names[i]]; cam = cameras["default"]; cam.orthomode = true; cam.orthomin = -shadowbox; cam.orthomax = shadowbox; cam.pos = cam.pos + shadowoffset; cam.rot = light_rotation; // get camera clip matrix const Mat4 cam_proj_mat = GetProjMatrix(cam); const Mat4 cam_view_mat = GetViewMatrix(cam); Mat4 clip_mat; clip_mat.Scale(0.5f); clip_mat.Translate(0.5f, 0.5f, 0.5f); clip_mat = cam_proj_mat.Multiply(clip_mat); clip_mat = cam_view_mat.Multiply(clip_mat); // premultiply the clip matrix with default camera view inverse matrix clip_mat = viewMatrixInv.Multiply(clip_mat); // storing it in a texture matrix glstate.ActiveTexture(4 + i); glLoadMatrixf(clip_mat.GetArray()); } } glstate.ActiveTexture(0); glMatrixMode(GL_MODELVIEW); }
void CustomDrawBox::Draw(){ //デバイスの取得 auto Dev = App::GetApp()->GetDeviceResources(); auto pDx11Device = Dev->GetD3DDevice(); auto pID3D11DeviceContext = Dev->GetD3DDeviceContext(); //ステータスのポインタ auto RenderStatePtr = GetStage()->GetRenderState(); auto PtrT = GetComponent<Transform>(); //ステージからカメラを取り出す auto PtrCamera = GetStage()->GetTargetCamera(); //カメラの取得 Matrix4X4 View, Proj, WorldViewProj; View = PtrCamera->GetViewMatrix(); Proj = PtrCamera->GetProjMatrix(); //ストライドとオフセット UINT stride = sizeof(VertexPositionNormalTexture); UINT offset = 0; //頂点バッファの設定 auto PtrMeshResource = App::GetApp()->GetResource<MeshResource>(L"DEFAULT_CUBE"); pID3D11DeviceContext->IASetVertexBuffers(0, 1, PtrMeshResource->GetVertexBuffer().GetAddressOf(), &stride, &offset); //インデックスバッファのセット pID3D11DeviceContext->IASetIndexBuffer(PtrMeshResource->GetIndexBuffer().Get(), DXGI_FORMAT_R16_UINT, 0); //描画方法(3角形) pID3D11DeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); //ステータスのポインタ //テクスチャを取得 ID3D11ShaderResourceView* pNull[1] = { 0 }; ID3D11SamplerState* pNullSR[1] = { 0 }; //テクスチャを設定 auto PtrTextureResource = App::GetApp()->GetResource<TextureResource>(L"TRACE_TX"); pID3D11DeviceContext->PSSetShaderResources(0, 1, PtrTextureResource->GetShaderResourceView().GetAddressOf()); //リニアサンプラーを設定 ID3D11SamplerState* samplerState = RenderStatePtr->GetLinearClamp(); pID3D11DeviceContext->PSSetSamplers(0, 1, &samplerState); //半透明処理 pID3D11DeviceContext->OMSetBlendState(RenderStatePtr->GetAlphaBlendEx(), nullptr, 0xffffffff); //デプスステンシルは使用する pID3D11DeviceContext->OMSetDepthStencilState(RenderStatePtr->GetDepthDefault(), 0); //シェーダの設定 pID3D11DeviceContext->VSSetShader(m_VirtexShader->GetShader(), nullptr, 0); pID3D11DeviceContext->PSSetShader(m_PixelShader->GetShader(), nullptr, 0); //インプットレイアウトの設定 pID3D11DeviceContext->IASetInputLayout(m_VirtexShader->GetInputLayout()); //コンスタントバッファの設定 ConstantBuffer cb1; ZeroMemory(&cb1, sizeof(cb1)); //行列の設定(転置する) cb1.World = Matrix4X4EX::Transpose(PtrT->GetWorldMatrix());; cb1.View = Matrix4X4EX::Transpose(View); cb1.Projection = Matrix4X4EX::Transpose(Proj); //ライトの設定 //ステージから0番目のライトを取り出す auto PtrLight = GetStage()->GetTargetLight(0); cb1.LightDir = PtrLight->GetDirectional(); //xとzだけ逆にする cb1.LightDir.x *= -1.0f; cb1.LightDir.z *= -1.0f; cb1.LightDir.w = 1.0f; //トータルタイムをコンスタントバッファに渡す float ElapsedTime = App::GetApp()->GetElapsedTime(); m_TotalTime += ElapsedTime; if (m_TotalTime >= 1.0f){ m_TotalTime = 0.0f; } cb1.Param.x = m_TotalTime; //コンスタントバッファの更新 pID3D11DeviceContext->UpdateSubresource(m_ConstantBuffer->GetBuffer(), 0, nullptr, &cb1, 0, 0); //コンスタントバッファの設定 ID3D11Buffer* pConstantBuffer = m_ConstantBuffer->GetBuffer(); pID3D11DeviceContext->VSSetConstantBuffers(0, 1, &pConstantBuffer); pID3D11DeviceContext->PSSetConstantBuffers(0, 1, &pConstantBuffer); //レンダリングステート pID3D11DeviceContext->RSSetState(RenderStatePtr->GetCullFront()); //内側描画 pID3D11DeviceContext->DrawIndexed(PtrMeshResource->GetNumIndicis(), 0, 0); //ライトの向きを変える cb1.LightDir = PtrLight->GetDirectional(); cb1.LightDir.w = 1.0f; //コンスタントバッファの更新 pID3D11DeviceContext->UpdateSubresource(m_ConstantBuffer->GetBuffer(), 0, nullptr, &cb1, 0, 0); //コンスタントバッファの設定 pConstantBuffer = m_ConstantBuffer->GetBuffer(); pID3D11DeviceContext->VSSetConstantBuffers(0, 1, &pConstantBuffer); pID3D11DeviceContext->PSSetConstantBuffers(0, 1, &pConstantBuffer); //レンダリングステート pID3D11DeviceContext->RSSetState(RenderStatePtr->GetCullBack()); //描画(外側) pID3D11DeviceContext->DrawIndexed(PtrMeshResource->GetNumIndicis(), 0, 0); //後始末 Dev->InitializeStates(RenderStatePtr); }
void GraphicsGL2::CullScenePass( const GraphicsConfigPass & pass, std::ostream & error_output) { // for each pass, we have which camera and which draw layer to use // we want to do culling for each unique camera and draw layer combination // use camera/layer as the unique key assert(!pass.draw.empty()); if (pass.draw.back() == "postprocess" || !pass.conditions.Satisfied(conditions)) return; for (std::vector <std::string>::const_iterator d = pass.draw.begin(); d != pass.draw.end(); d++) { // determine if we're dealing with a cubemap RenderOutputMap::iterator oi = render_outputs.find(pass.output); if (oi == render_outputs.end()) { ReportOnce(&pass, "Render output "+pass.output+" couldn't be found", error_output); return; } const bool cubemap = (oi->second.IsFBO() && oi->second.RenderToFBO().IsCubemap()); const int cubesides = cubemap ? 6 : 1; std::string cameraname = pass.camera; for (int cubeside = 0; cubeside < cubesides; cubeside++) { if (cubemap) { // build a name for the sub camera { std::ostringstream s; s << pass.camera << "_cubeside" << cubeside; cameraname = s.str(); } // get the base camera CameraMap::iterator bci = cameras.find(pass.camera); if (bci == cameras.end()) { ReportOnce(&pass, "Camera " + pass.camera + " couldn't be found", error_output); return; } // create our sub-camera GraphicsCamera & cam = cameras[cameraname]; cam = bci->second; // set the sub-camera's properties cam.rot = GetCubeSideOrientation(cubeside, cam.rot, error_output); cam.fov = 90; assert(oi->second.IsFBO()); const FrameBufferObject & fbo = oi->second.RenderToFBO(); cam.w = fbo.GetWidth(); cam.h = fbo.GetHeight(); } const std::string drawlist_name = BuildKey(cameraname, *d); CulledDrawList & drawlist = culled_drawlists[drawlist_name]; if (drawlist.valid) break; drawlist.valid = true; if (pass.cull) { // cull static drawlist reseatable_reference <AabbTreeNodeAdapter <Drawable> > container = static_drawlist.GetByName(*d); if (!container) { ReportOnce(&pass, "Drawable container " + *d + " couldn't be found", error_output); return; } CameraMap::iterator ci = cameras.find(cameraname); if (ci == cameras.end()) { ReportOnce(&pass, "Camera " + cameraname + " couldn't be found", error_output); return; } const GraphicsCamera & cam = ci->second; Frustum frustum; frustum.Extract(GetProjMatrix(cam).GetArray(), GetViewMatrix(cam).GetArray()); container->Query(frustum, drawlist.drawables); // cull dynamic drawlist reseatable_reference <PtrVector <Drawable> > container_dynamic = dynamic_drawlist.GetByName(*d); if (!container_dynamic) { ReportOnce(&pass, "Drawable container " + *d + " couldn't be found", error_output); return; } for (size_t i = 0; i < container_dynamic->size(); ++i) { if (!Cull(frustum, *(*container_dynamic)[i])) drawlist.drawables.push_back((*container_dynamic)[i]); } } else { // copy static drawlist reseatable_reference <AabbTreeNodeAdapter <Drawable> > container = static_drawlist.GetByName(*d); if (!container) { ReportOnce(&pass, "Drawable container " + *d + " couldn't be found", error_output); return; } container->Query(Aabb<float>::IntersectAlways(), drawlist.drawables); // copy dynamic drawlist reseatable_reference <PtrVector <Drawable> > container_dynamic = dynamic_drawlist.GetByName(*d); if (!container_dynamic) { ReportOnce(&pass, "Drawable container " + *d + " couldn't be found", error_output); return; } drawlist.drawables.insert( drawlist.drawables.end(), container_dynamic->begin(), container_dynamic->end()); } } } }
void GraphicsGL2::SetupScene( float fov, float new_view_distance, const Vec3 cam_position, const Quat & cam_rotation, const Vec3 & dynamic_reflection_sample_pos, std::ostream & error_output) { // setup the default camera from the passed-in parameters { GraphicsCamera & cam = cameras["default"]; cam.fov = fov; cam.pos = cam_position; cam.rot = cam_rotation; cam.view_distance = new_view_distance; cam.w = w; cam.h = h; } // create a camera for the skybox with a long view distance { GraphicsCamera & cam = cameras["skybox"]; cam = cameras["default"]; cam.view_distance = 10000; cam.pos = Vec3(0); if (fixed_skybox) cam.pos[2] = cam_position[2]; } // create a camera for the dynamic reflections { GraphicsCamera & cam = cameras["dynamic_reflection"]; cam.pos = dynamic_reflection_sample_pos; cam.fov = 90; // this gets automatically overridden with the correct fov (which is 90 anyway) cam.rot.LoadIdentity(); // this gets automatically rotated for each cube side cam.view_distance = 100; cam.w = 1; // this gets automatically overridden with the cubemap dimensions cam.h = 1; // this gets automatically overridden with the cubemap dimensions } // create a camera for the dynamic reflection skybox { GraphicsCamera & cam = cameras["dynamic_reflection_skybox"]; cam = cameras["dynamic_reflection"]; cam.view_distance = 10000; cam.pos = Vec3(0); } // create an ortho camera for 2d drawing { GraphicsCamera & cam = cameras["2d"]; // this is the glOrtho call we want: glOrtho( 0, 1, 1, 0, -1, 1 ); cam.orthomode = true; cam.orthomin = Vec3(0, 1, -1); cam.orthomax = Vec3(1, 0, 1); } // create cameras for shadow passes if (shadows) { Mat4 view_matrix; cam_rotation.GetMatrix4(view_matrix); float translate[4] = {-cam_position[0], -cam_position[1], -cam_position[2], 0}; view_matrix.MultiplyVector4(translate); view_matrix.Translate(translate[0], translate[1], translate[2]); Mat4 view_matrix_inv = view_matrix.Inverse(); // derive light rotation quaternion from light direction vector Quat light_rotation; Vec3 up(0, 0, 1); float cosa = up.dot(light_direction); if (cosa * cosa < 1.0f) { float a = -acosf(cosa); Vec3 x = up.cross(light_direction).Normalize(); light_rotation.SetAxisAngle(a, x[0], x[1], x[2]); } std::vector <std::string> shadow_names; shadow_names.push_back("near"); shadow_names.push_back("medium"); shadow_names.push_back("far"); for (int i = 0; i < 3; i++) { float shadow_radius = (1<<i)*closeshadow+(i)*20.0; //5,30,60 Vec3 shadowbox(1,1,1); shadowbox = shadowbox * (shadow_radius*sqrt(2.0)); Vec3 shadowoffset(0,0,-1); shadowoffset = shadowoffset * shadow_radius; (-cam_rotation).RotateVector(shadowoffset); shadowbox[2] += 60.0; GraphicsCamera & cam = cameras["shadows_"+shadow_names[i]]; cam = cameras["default"]; cam.orthomode = true; cam.orthomin = -shadowbox; cam.orthomax = shadowbox; cam.pos = cam.pos + shadowoffset; cam.rot = light_rotation; // get camera clip matrix const Mat4 cam_proj_mat = GetProjMatrix(cam); const Mat4 cam_view_mat = GetViewMatrix(cam); Mat4 clip_matrix; clip_matrix.Scale(0.5f); clip_matrix.Translate(0.5f, 0.5f, 0.5f); clip_matrix = cam_proj_mat.Multiply(clip_matrix); clip_matrix = cam_view_mat.Multiply(clip_matrix); // premultiply the clip matrix with default camera view inverse matrix clip_matrix = view_matrix_inv.Multiply(clip_matrix); shadow_matrix[i] = clip_matrix; } assert(shadow_distance < 3); renderscene.SetShadowMatrix(shadow_matrix, shadow_distance + 1); postprocess.SetShadowMatrix(shadow_matrix, shadow_distance + 1); } else { renderscene.SetShadowMatrix(NULL, 0); postprocess.SetShadowMatrix(NULL, 0); } // sort the two dimentional drawlist so we get correct ordering std::sort(dynamic_drawlist.twodim.begin(), dynamic_drawlist.twodim.end(), &SortDraworder); // do fast culling queries for static geometry per pass ClearCulledDrawLists(); for (std::vector <GraphicsConfigPass>::const_iterator i = config.passes.begin(); i != config.passes.end(); i++) { CullScenePass(*i, error_output); } renderscene.SetFSAA(fsaa); renderscene.SetContrast(contrast); renderscene.SetSunDirection(light_direction); postprocess.SetContrast(contrast); postprocess.SetSunDirection(light_direction); }
void StaticCamera::SetFromSunlight(D3DXVECTOR3* position, D3DXVECTOR3* direction, D3DXVECTOR4 Power, float Width, float Height, float Depth) { D3DXVECTOR3 d3dLookAt = D3DXVECTOR3(Width, Height, Depth) * 0.5f;//(*position + *Direction * m_fFarPlane); D3DXVECTOR3 eye = *position / D3DXVec3Length(position); eye *= D3DXVec3Length(&d3dLookAt) * 1.1f; eye += d3dLookAt; CBaseCamera::SetViewParams(&eye, &d3dLookAt); mLightColor = Power; *position = eye; d3dLookAt = d3dLookAt - eye; d3dLookAt /= D3DXVec3Length(&d3dLookAt); *direction = d3dLookAt; D3DXVECTOR3 cornersWorld[] = { D3DXVECTOR3(0,0,0), D3DXVECTOR3(Width, 0, 0), D3DXVECTOR3(Width, Height, 0), D3DXVECTOR3(Width, Height, Depth), D3DXVECTOR3(0, Height, 0), D3DXVECTOR3(0, Height, Depth), D3DXVECTOR3(0,0,Depth), D3DXVECTOR3(Width, 0, Depth) }; D3DXVECTOR3 lightSpaceBoxMin = D3DXVECTOR3(FLT_MAX,FLT_MAX,FLT_MAX); D3DXVECTOR3 lightSpaceBoxMax = D3DXVECTOR3(FLT_MIN, FLT_MIN, FLT_MIN); for (int i = 0; i < 8; ++i) { D3DXVec3TransformCoord(&cornersWorld[i], &cornersWorld[i], GetViewMatrix()); lightSpaceBoxMin.x = lightSpaceBoxMin.x < cornersWorld[i].x ? lightSpaceBoxMin.x : cornersWorld[i].x; lightSpaceBoxMin.y = lightSpaceBoxMin.y < cornersWorld[i].y ? lightSpaceBoxMin.y : cornersWorld[i].y; lightSpaceBoxMin.z = lightSpaceBoxMin.z < cornersWorld[i].z ? lightSpaceBoxMin.z : cornersWorld[i].z; lightSpaceBoxMax.x = lightSpaceBoxMax.x > cornersWorld[i].x ? lightSpaceBoxMax.x : cornersWorld[i].x; lightSpaceBoxMax.y = lightSpaceBoxMax.y > cornersWorld[i].y ? lightSpaceBoxMax.y : cornersWorld[i].y; lightSpaceBoxMax.z = lightSpaceBoxMax.z > cornersWorld[i].z ? lightSpaceBoxMax.z : cornersWorld[i].z; }; SetOrthoParams(lightSpaceBoxMax.x - lightSpaceBoxMin.x, lightSpaceBoxMax.y - lightSpaceBoxMin.y, lightSpaceBoxMin.z, lightSpaceBoxMax.z); //set constant buffer D3DXMATRIX identityMatrix; D3DXMatrixIdentity(&identityMatrix); cameraCBuffer->Data.World = identityMatrix; cameraCBuffer->Data.refractiveIndexETA = 1.0f; cameraCBuffer->Data.View = *GetViewMatrix(); cameraCBuffer->Data.WorldViewProjection = identityMatrix * cameraCBuffer->Data.View * (*GetProjMatrix()); //float test = D3DXMatrixDeterminant(GetProjMatrix()); //test = D3DXMatrixDeterminant(GetViewMatrix()); //test = test +1; }
void StaticCamera::SetFromSpotlight(D3DXVECTOR3* position, D3DXVECTOR3* direction, float FoV, float farPlane, D3DXVECTOR4 power) { D3DXVECTOR3 d3dLookAt = (*position + *direction * farPlane); CBaseCamera::SetViewParams(position, &d3dLookAt); // let's calculate the appropriate opening angle //float fov = FoV; // aspect ratio according to BounceMap sizes float aspectRatio = BOUNCEMAP_WIDTH / BOUNCEMAP_HEIGHT; CBaseCamera::SetProjParams(FoV, aspectRatio, 1.0f, farPlane); mLightColor = power; //set constant buffer D3DXMATRIX identityMatrix; D3DXMatrixIdentity(&identityMatrix); cameraCBuffer->Data.World = identityMatrix; cameraCBuffer->Data.refractiveIndexETA = 1.0f; cameraCBuffer->Data.View = *GetViewMatrix(); cameraCBuffer->Data.WorldViewProjection = identityMatrix * cameraCBuffer->Data.View * (*GetProjMatrix()); }