//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ SkyService::pSky_type SkyService::createSky(config_type& _config) { Sky* pRawSky = new Sky(); pSky_type pSky = pSky_type(pRawSky, boost::bind(&SkyService::onDestroySky, this, _1)); if (//!m_pPhysicsService.isValid() || !m_pRenderingService.isValid() || //!m_pPhysicsResourceService.isValid() || !m_pRenderingResourceService.isValid()) { // TODO error - must setup required services prior to creating sky objects. return pSky; } config_type renderingConfig; if (_config["type"] == "skybox") { renderingConfig["type"] = "skybox"; renderingConfig["scene"] = "default"; renderingConfig["resourceName"] = _config["resourceName"]; renderingConfig["distance"] = _config["distance"]; pSky->setResource(m_pRenderingResourceService->loadResource(renderingConfig)); } else { std::cout << "Error: unsupported type in SkyService::createSky()" << std::endl; } wpSky_type wpSky(pSky); pRawSky->setSelfReference(wpSky); return pSky; }
void CubeMap::RenderScene(){ m_d3dDeviceContext->ClearRenderTargetView(m_renderTargetView, reinterpret_cast<const float*>(&COLORS::Silver)); m_d3dDeviceContext->ClearDepthStencilView(m_depthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0); m_d3dDeviceContext->IASetInputLayout(InputLayouts::Basic); m_d3dDeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); UINT stride = sizeof(Vertex::Basic); UINT offset = 0; m_camera.UpdateViewMat(); XMMATRIX view = m_camera.getViewMat(); XMMATRIX proj = m_camera.getProjMat(); XMMATRIX viewproj = m_camera.getViewProjMat(); float blendFactor[] = { 0.0f, 0.0f, 0.0f, 0.0f}; //Set Per frame constants Effects::BasicFX->setDirLights(m_dirLights); Effects::BasicFX->setEyePosVec(m_camera.getPosition()); Effects::BasicFX->setCubeMap(m_sky->CreateSkySRV()); m_sky->Draw(m_d3dDeviceContext, m_camera); //restore default states, as the SkyFX changes them in the effect file. m_d3dDeviceContext->RSSetState(0); m_d3dDeviceContext->OMSetDepthStencilState(0, 0); HR(m_swapChain->Present(0, 0)); }
SkyVAO::SkyVAO(const ProgramSP& program, const Sky& sky) : VAO(program) { generateVAO(); glBindBuffer(GL_ARRAY_BUFFER, sky.getVboVertices()); glVertexAttribPointer(program->getAttribLocation(a_vertex), 4, GL_FLOAT, GL_FALSE, 0, 0); glEnableVertexAttribArray(program->getAttribLocation(a_vertex)); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, sky.getVboIndices()); glEnableVertexAttribArray(0); unbind(); }
void WaterDemo::onLostDevice() { mGfxStats->onLostDevice(); mSky->onLostDevice(); mWater->onLostDevice(); HR(mFX->OnLostDevice()); }
void EnvMapper::Impl::generate(const Point &pos, const Frustum &frustum, Sky &sky, Terrain &tr) { int side = CubeMap::PosX; CamCont::iterator i, end; if(Settings::current.environment_mapping == 2) { i = cams.begin(); end = cams.end(); } else { static int update = 0; if(++update > 5) { update = 0; } i = cams.begin() + update; end = i + 1; side += update; } setup_viewport(cubemap); for(; i != end; ++i) { i->pos = pos; i->setup_view(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glDisable(GL_CULL_FACE); glDisable(GL_DEPTH_TEST); sky.render(*i); glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); tr.render(*i); cubemap.copy_to_texture(static_cast<CubeMap::Side>(side++)); } restore_viewport(); }
// ---------------------------------------------------------------------------- void TerrPanel::skyChange(u32 id) { Sky* sky = Viewport::get()->getSky(); TexSel* ts = TexSel::getTexSel(); switch (id) { case S_T1: ts->subscribe(m_sb1); sky->setSubIx(1); break; case S_T2: ts->subscribe(m_sb2); sky->setSubIx(2); break; case S_T3: ts->subscribe(m_sb3); sky->setSubIx(3); break; case S_T4: ts->subscribe(m_sb4); sky->setSubIx(4); break; case S_T5: ts->subscribe(m_sb5); sky->setSubIx(5); break; case S_T6: ts->subscribe(m_sb6); sky->setSubIx(6); break; } ts->subscribe(sky); } // skyChange
void Simulation::LoadAssets() { ID3D11SamplerState* wrapSampler; D3D11_SAMPLER_DESC wsd; ZeroMemory(&wsd, sizeof(D3D11_SAMPLER_DESC)); wsd.AddressU = D3D11_TEXTURE_ADDRESS_WRAP; wsd.AddressV = D3D11_TEXTURE_ADDRESS_WRAP; wsd.AddressW = D3D11_TEXTURE_ADDRESS_WRAP; wsd.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; wsd.MaxAnisotropy = 0; wsd.ComparisonFunc = D3D11_COMPARISON_NEVER; wsd.MinLOD = 0; wsd.MaxLOD = 0; wsd.MipLODBias = 0; dev->CreateSamplerState(&wsd, &wrapSampler); Material* heightmap = new Material(L"Textures/grass.png", wrapSampler, dev); heightmap->LoadShader(L"Heightmap.cso", Vert, dev); heightmap->LoadShader(L"TexturedDiffuse.cso", Pixel, dev); Material* waterMat = new Material(L"Textures/water.png", wrapSampler, dev); waterMat->LoadShader(L"WaterVertex.cso", Vert, dev); waterMat->LoadShader(L"WaterPixel.cso", Pixel, dev); MeshData skySphere; MeshGenerator::CreateSphere(1000.0, 2, skySphere); Mesh* skySphereMesh = new Mesh(skySphere, dev); Sky* sky = new Sky(skySphereMesh, dev); sky->LoadCubeMap(L"Textures/oceansky.dds", dev); sky->SetMaterial(L"SkyVertex.cso", L"SkyPixel.cso", wrapSampler, dev); objects.push_back(sky); Terrain* terrain = new Terrain(500.0f, 500.0f, 500, 500, heightmap, L"Textures/heightmap.png", dev); terrain->LoadNormalMap(L"Textures/normalmap2.png", dev); terrain->SetBufferData(100.0, dev); terrain->SetTextures(L"Textures/sand.png", L"Textures/grass.png", L"Textures/cliff.png",dev); objects.push_back(terrain); Terrain* water = new Terrain(500.0f, 500.0f, 500, 500, waterMat, L"Textures/waterHeightMap.png", dev); water->LoadNormalMap(L"Textures/waterNormalMap.png", dev); water->SetBufferData(5.0, 0.0, 0.0, dev); water->SetPosition(XMFLOAT3(0, 27.0, 0)); objects.push_back(water); }
float FlyingCamera::getFarPlane() { if (manager == NULL) return DEFAULT_FAR_PLANE; Sky* pSky = (Sky*)manager->findObject(TribesSkyId); if (pSky != NULL) { // Use the sky distance, plus a tad. return pSky->getDistance() * 1.1f; } SimTerrain* pTerrain = (SimTerrain*)manager->findObject(SimTerrainId); if (pTerrain != NULL) { // Use the terrain visible distance, plus a tad return pTerrain->getVisibleDistance() * 1.1f; } // else, well, crap. return DEFAULT_FAR_PLANE; }
void ProjTexDemo::onResetDevice() { mGfxStats->onResetDevice(); mSky->onResetDevice(); HR(mFX->OnResetDevice()); // The aspect ratio depends on the backbuffer dimensions, which can // possibly change after a reset. So rebuild the projection matrix. float w = (float)md3dPP.BackBufferWidth; float h = (float)md3dPP.BackBufferHeight; gCamera->setLens(D3DX_PI * 0.25f, w/h, 1.0f, 2000.0f); }
int main() { Sky sky; load_all_sound(); bgm.play(); Player player; while (window.isOpen()) { window.clear(); sky.drawsky(); Event event; while (window.pollEvent(event)) { if (event.type == Event::Closed) window.close(); if(event.type==Event::KeyPressed&& event.key.code == Keyboard::Up) player.moveup(); if(event.type==Event::KeyPressed&& event.key.code == Keyboard::Down) player.movedown(); if(event.type==Event::KeyPressed&& event.key.code == Keyboard::Left) player.moveleft(); if(event.type==Event::KeyPressed&& event.key.code == Keyboard::Right) player.moveright(); if(event.type==Event::KeyPressed&& event.key.code == Keyboard::Space) player.gun(); } player.bullet_refresh(); window.display(); } return 0; }
void WaterDemo::drawScene() { HR(gd3dDevice->BeginScene()); mSky->draw(); HR(mFX->SetValue(mhLight, &mLight, sizeof(DirLight))); HR(mFX->SetMatrix(mhWVP, &(mSceneWorld*gCamera->viewProj()))); HR(mFX->SetValue(mhEyePosW, &gCamera->pos(), sizeof(D3DXVECTOR3))); UINT numPasses = 0; HR(mFX->Begin(&numPasses, 0)); HR(mFX->BeginPass(0)); for(UINT j = 0; j < mSceneMtrls.size(); ++j) { HR(mFX->SetValue(mhMtrl, &mSceneMtrls[j], sizeof(Mtrl))); // If there is a texture, then use. if(mSceneTextures[j] != 0) { HR(mFX->SetTexture(mhTex, mSceneTextures[j])); } // But if not, then set a pure white texture. When the texture color // is multiplied by the color from lighting, it is like multiplying by // 1 and won't change the color from lighting. else { HR(mFX->SetTexture(mhTex, mWhiteTex)); } HR(mFX->SetTexture(mhNormalMap, mSceneNormalMaps[j])); HR(mFX->CommitChanges()); HR(mSceneMesh->DrawSubset(j)); } HR(mFX->EndPass()); HR(mFX->End()); // Draw alpha blended object last. mWater->draw(); mGfxStats->display(); HR(gd3dDevice->EndScene()); // Present the backbuffer. HR(gd3dDevice->Present(0, 0, 0, 0)); }
void CubeMapApp::initApp() { D3DApp::initApp(); fx::InitAll(md3dDevice); InputLayout::InitAll(md3dDevice); GetTextureMgr().init(md3dDevice); mTech = fx::CubeMapFX->GetTechniqueByName("CubeMapTech"); mfxLightVar = fx::CubeMapFX->GetVariableByName("gLight"); mfxEyePosVar = fx::CubeMapFX->GetVariableByName("gEyePosW"); mfxWVPVar = fx::CubeMapFX->GetVariableByName("gWVP")->AsMatrix(); mfxWorldVar = fx::CubeMapFX->GetVariableByName("gWorld")->AsMatrix(); mfxTexMtxVar = fx::CubeMapFX->GetVariableByName("gTexMtx")->AsMatrix(); mfxReflectMtrlVar = fx::CubeMapFX->GetVariableByName("gReflectMtrl")->AsVector(); mfxCubeMapEnabledVar = fx::CubeMapFX->GetVariableByName("gCubeMapEnabled")->AsScalar(); mfxDiffuseMapVar = fx::CubeMapFX->GetVariableByName("gDiffuseMap")->AsShaderResource(); mfxSpecMapVar = fx::CubeMapFX->GetVariableByName("gSpecMap")->AsShaderResource(); mfxCubeMapVar = fx::CubeMapFX->GetVariableByName("gCubeMap")->AsShaderResource(); //mClearColor = D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f); GetCamera().position() = D3DXVECTOR3(0.0f, 1.8f, -10.0f); mBallMapRV = GetTextureMgr().createTex(L"blackdiffuse.dds"); //mSpecMapRV = GetTextureMgr().createTex(L"spec.dds"); mDefaultSpecMapRV = GetTextureMgr().createTex(L"defaultspec.dds"); mEnvMapRV = GetTextureMgr().createCubeTex(L"grassenvmap1024.dds"); mFloor.init(md3dDevice, 41, 21, 1.0f); mBase.init(md3dDevice, 2.0f); mBall.init(md3dDevice, 0.5f, 30, 30); mColumn.init(md3dDevice, 0.25f, 1.0f, 3.0f, 30, 30); mSky.init(md3dDevice, mEnvMapRV, 5000.0f); mParallelLight.dir = D3DXVECTOR3(0.57735f, -0.57735f, 0.57735f); mParallelLight.ambient = D3DXCOLOR(0.3f, 0.3f, 0.3f, 1.0f); mParallelLight.diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); mParallelLight.specular = D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f); }
void TerrainApp::initApp() { D3DApp::initApp(); fx::InitAll(md3dDevice); InputLayout::InitAll(md3dDevice); GetTextureMgr().init(md3dDevice); mClearColor = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); GetCamera().position() = D3DXVECTOR3(0.0f, 10.0f, -10.0f); mEnvMapRV = GetTextureMgr().createCubeTex(L"grassenvmap1024.dds"); mSky.init(md3dDevice, mEnvMapRV, 5000.0f); Terrain::InitInfo tii; tii.HeightmapFilename = L"coastMountain513.raw"; tii.LayerMapFilename0 = L"grass.dds"; tii.LayerMapFilename1 = L"lightdirt.dds"; tii.LayerMapFilename2 = L"darkdirt.dds"; tii.LayerMapFilename3 = L"stone.dds"; tii.LayerMapFilename4 = L"snow.dds"; tii.BlendMapFilename = L"blend.dds"; tii.HeightScale = 0.35f; tii.HeightOffset = -20.0f; tii.NumRows = 513; tii.NumCols = 513; tii.CellSpacing = 1.0f; mLand.init(md3dDevice, tii); mParallelLight.dir = D3DXVECTOR3(0.707f, -0.707f, 0.0f); mParallelLight.ambient = D3DXCOLOR(0.3f, 0.3f, 0.3f, 1.0f); mParallelLight.diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); mParallelLight.specular = D3DXCOLOR(0.5f, 0.4843f, 0.3f, 1.0f); mLand.setDirectionToSun(-mParallelLight.dir); }
void TerrainApp::drawScene() { D3DApp::drawScene(); // Restore default states, input layout and primitive topology // because mFont->DrawText changes them. Note that we can // restore the default states by passing null. md3dDevice->OMSetDepthStencilState(0, 0); float blendFactor[] = {0.0f, 0.0f, 0.0f, 0.0f}; md3dDevice->OMSetBlendState(0, blendFactor, 0xffffffff); md3dDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST); mLand.draw(mLandWorld); // Draw sky last to save fill rate. mSky.draw(); // We specify DT_NOCLIP, so we do not care about width/height of the rect. RECT R = {5, 5, 0, 0}; md3dDevice->RSSetState(0); mFont->DrawText(0, mFrameStats.c_str(), -1, &R, DT_NOCLIP, WHITE); mSwapChain->Present(0, 0); }
void ColoredCubeApp::drawScene() { D3DApp::drawScene(); //Step through animation frame animationTimeElapsed += mTimer.getGameTime() - animationTimePrev; animationTimePrev = mTimer.getGameTime(); if(animationTimeElapsed > 0.0666f) { animationTimeElapsed = 0.0f; frameOfAnimation++; if(frameOfAnimation > fireFrameCount-1) { frameOfAnimation = 0; } } // Restore default states, input layout and primitive topology // because mFont->DrawText changes them. Note that we can // restore the default states by passing null. md3dDevice->OMSetDepthStencilState(0, 0); float blendFactors[] = {0.0f, 0.0f, 0.0f, 0.0f}; md3dDevice->OMSetBlendState(0, blendFactors, 0xffffffff); md3dDevice->IASetInputLayout(mVertexLayout); md3dDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST); // Set per frame constants mfxEyePosVar->SetRawValue(&mCameraPos, 0, sizeof(D3DXVECTOR3)); mfxLightVar->SetRawValue(&mLights[0], 0, sizeof(Light)); mfxLightVar2->SetRawValue(&mLights[1], 0, sizeof(Light)); mfxCubeMapVR->SetResource(mCubeMapRV); // set constants mWVP = mView*mProj; mfxWVPVar->SetMatrix((float*)&mWVP); //set gWVP in color.fx to mWVP mTree.setEyePos(mCameraPos); mTree.setLights(mLights, 2); mTree.draw(mView, mProj); mObjBox.setEyePos(mCameraPos); mObjBox.setLights(mLights, 2); mObjBox.draw(mView, mProj); D3D10_TECHNIQUE_DESC techDesc; mTech->GetDesc( &techDesc ); for(UINT p = 0; p < techDesc.Passes; ++p) { ID3D10EffectPass* pass = mTech->GetPassByIndex( p ); //zero is always used in D3D10 D3DXMATRIX texMtx; mWVP = mBoxWorld*mView*mProj; mfxWVPVar->SetMatrix((float*)&mWVP); mfxWorldVar->SetMatrix((float*)&mBoxWorld); mfxDiffuseMapVar->SetResource(mCrateMapRV); //mfxDiffuseMapVar->SetResource(mFireAnimationMapRVs[frameOfAnimation]); mfxSpecularMapVar->SetResource(mSpecularMapRV); mfxNormalMapVR->SetResource(mDefaultNormalMapRV); mfxReflectEnabledVar->SetBool(false); D3DXMatrixIdentity(&texMtx); mfxTexMtxVar->SetMatrix((float*)&texMtx); pass->Apply(0); mBox.draw(); mWVP = mPlaneWorld*mView*mProj; mfxWVPVar->SetMatrix((float*)&mWVP); mfxWorldVar->SetMatrix((float*)&mPlaneWorld); mfxDiffuseMapVar->SetResource(mGrassMapRV); mfxNormalMapVR->SetResource(mBrickNormalMapRV); mfxReflectEnabledVar->SetBool(true); D3DXMATRIX s; D3DXMatrixScaling(&s, 5.0f, 5.0f, 1.0f); texMtx = s; D3DXMatrixIdentity(&texMtx); mfxTexMtxVar->SetMatrix((float*)&texMtx); pass->Apply(0); mPlane.draw(); } mSky.draw(mWVP); // We specify DT_NOCLIP, so we do not care about width/height of the rect. RECT R = {5, 5, 0, 0}; md3dDevice->RSSetState(0); mFont->DrawText(0, mFrameStats.c_str(), -1, &R, DT_NOCLIP, BLACK); mSwapChain->Present(0, 0); }
bool InitWindowsApp(HINSTANCE instanceHandle, int show) { //ShowCursor(0); // The first task to creating a window is to describe some of its // characteristics by filling out a WNDCLASS structure. WNDCLASS wc; wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = instanceHandle; wc.hIcon = LoadIcon(0, IDI_APPLICATION); wc.hCursor = LoadCursor(0, IDC_CROSS); wc.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH); wc.lpszMenuName = 0; wc.lpszClassName = L"BasicWndClass"; // Next, we register this WNDCLASS instance with Windows so that we can // create a window based on it. if(!RegisterClass(&wc)) { MessageBox(0, L"RegisterClass FAILED", 0, 0); return false; } // With our WNDCLASS instance registered, we can create a window with the // CreateWindow function. This function returns a handle to the window it // creates (an HWND). If the creation failed, the handle will have the value // of zero. A window handle is a way to refer to the window, which is internally // managed by Windows. Many of the Win32 API functions that operate on windows // require an HWND so that they know what window to act on. RECT rc; rc.left = 0; rc.top = 0; rc.right = SCREEN_WIDTH; rc.bottom = SCREEN_HEIGHT; AdjustWindowRect(&rc, WS_OVERLAPPEDWINDOW, false); g_Hwnd = CreateWindow( L"BasicWndClass", // Registered WNDCLASS instance to use. L"Gruppuppgift", // window title WS_OVERLAPPEDWINDOW, // style flags CW_USEDEFAULT, // x-coordinate CW_USEDEFAULT, // y-coordinate rc.right - rc.left, // width rc.bottom - rc.top, // height 0, // parent window 0, // menu handle instanceHandle, // app instance 0); // extra creation parameters if(g_Hwnd == 0) { MessageBox(0, L"CreateWindow FAILED", 0, 0); return false; } // Even though we just created a window, it is not initially shown. // Therefore, the final step is to show and update the window we just // created, which can be done with the following two function calls. // Observe that we pass the handle to the window we want to show and // update so that these functions know which window to show and update. ShowWindow(g_Hwnd, show); UpdateWindow(g_Hwnd); //________________________________ // Fill out a DXGI_SWAP_CHAIN_DESC to describe our swap chain. DXGI_SWAP_CHAIN_DESC sd; sd.BufferDesc.Width = SCREEN_WIDTH; sd.BufferDesc.Height = SCREEN_HEIGHT; sd.BufferDesc.RefreshRate.Numerator = 60; sd.BufferDesc.RefreshRate.Denominator = 1; sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; // No multisampling. sd.SampleDesc.Count = 1; sd.SampleDesc.Quality = 0; sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; sd.BufferCount = 1; sd.OutputWindow = g_Hwnd; sd.Windowed = true; sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; sd.Flags = 0; D3D10CreateDeviceAndSwapChain( 0, //default adapter D3D10_DRIVER_TYPE_HARDWARE, 0, // no software device 0, D3D10_SDK_VERSION, &sd, &mSwapChain, &md3dDevice); ID3D10Texture2D* backBuffer; mSwapChain->GetBuffer(0, __uuidof(ID3D10Texture2D), (LPVOID*)&backBuffer); md3dDevice->CreateRenderTargetView(backBuffer, 0, &mRenderTargetView); backBuffer->Release(); backBuffer = 0; // Create depth stencil texture D3D10_TEXTURE2D_DESC descDepth; ZeroMemory( &descDepth, sizeof(descDepth) ); descDepth.Width = SCREEN_WIDTH; descDepth.Height = SCREEN_HEIGHT; descDepth.MipLevels = 1; descDepth.ArraySize = 1; descDepth.Format = DXGI_FORMAT_D24_UNORM_S8_UINT; descDepth.SampleDesc.Count = 1; descDepth.SampleDesc.Quality = 0; descDepth.Usage = D3D10_USAGE_DEFAULT; descDepth.BindFlags = D3D10_BIND_DEPTH_STENCIL; descDepth.CPUAccessFlags = 0; descDepth.MiscFlags = 0; md3dDevice->CreateTexture2D( &descDepth, NULL, &mDepthStencil ); // Create the depth stencil view D3D10_DEPTH_STENCIL_VIEW_DESC descDSV; ZeroMemory( &descDSV, sizeof(descDSV) ); descDSV.Format = descDepth.Format; descDSV.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2D; descDSV.Texture2D.MipSlice = 0; // Bind the render target view and depth/stencil view to the pipeline. md3dDevice->CreateDepthStencilView( mDepthStencil, &descDSV, &mDepthStencilView ); md3dDevice->OMSetRenderTargets( 1, &mRenderTargetView, mDepthStencilView ); // Set the viewport transform. vp.TopLeftX = 0; vp.TopLeftY = 0; vp.Width = SCREEN_WIDTH; vp.Height = SCREEN_HEIGHT; vp.MinDepth = 0.0f; vp.MaxDepth = 1.0f; md3dDevice->RSSetViewports(1, &vp); //________________________________ Effects::InitAll(md3dDevice); fxU.init(md3dDevice, Effects::MeshFX); Terrain::InitInfo tii; tii.CellSpacing = 1.0f; tii.HeightmapFilename = L"flat513.raw"; tii.HeightOffset = -30.0f; tii.HeightScale = 0.2f; tii.NumCols = 513; tii.NumRows = 513; land.init(md3dDevice, tii); //mTerrain.init(md3dDevice, (std::string)"Textures/Terrain/HeightMap.raw", 0.35f, -50.0f, 0.1f, 512, 512); //Cube c; //c.init(md3dDevice, D3DXVECTOR3(2.0f, 2.0f, 2.0f), D3DXVECTOR3(-16.0f, land.getHeight(-16.0f, -16.0f)+1.0f, -16.0f)); //mCubes.push_back(c); //nr.push_back(0); nrOfTowers.push_back(0); mCubes.resize(10); for(int i = 0; i < mCubes.size();i++) { mCubes[i].init(i, md3dDevice, D3DXVECTOR3(5.0f,5.0f,5.0f), D3DXVECTOR3(0.0f, land.getHeight(0.0f,0.0f), 0.0f), (i*0.50f+0.50f)); nr.push_back(0); } pWave = new wave(1, 20, md3dDevice, &land); pWave->initMonsters(); mPyramid.init(md3dDevice, D3DXVECTOR3(2.0f, 2.0f, 2.0f), D3DXVECTOR3(-16.0f, land.getHeight(-16.0f, -16.0f)+5.0f, -16.0f)); mCylinder.init(md3dDevice, 1.0f, D3DXVECTOR3(-2.0f, land.getHeight(-2.0f, -8.0f)+1.0f, -8.0f)); //GetCamera().setPosY(land.getHeight(GetCamera().getPos().x, GetCamera().getPos().z)); GetCamera().setLens(0.30f*pi, (float)SCREEN_WIDTH/SCREEN_HEIGHT, 1.0f, 1000.0f); fire.init(md3dDevice, Effects::FireFX, L"Textures/Particle/flare0.dds", 500); fire.setEmitPos(D3DXVECTOR3(-2.0f, land.getHeight(-5.0f, 2.0f)+2.5f, -8.0f)); rain.init(md3dDevice, Effects::RainFX, L"Textures/Particle/raindrop.gif", 1000); sky.init(md3dDevice, L"Textures/Terrain/grassenvmap1024.dds", 5000.0f); //Trees D3DXVECTOR3 treeCenters[6]; float x = -20.0f; float z = 20.0f; treeCenters[0] = D3DXVECTOR3(x,land.getHeight(x,z) + 10.0f,z); x = -23.0f; z = 16.0f; treeCenters[1] = D3DXVECTOR3(x,land.getHeight(x,z) + 10.0f,z); x = -3.0f; z = 18.0f; treeCenters[2] = D3DXVECTOR3(x,land.getHeight(x,z) + 10.0f,z); x = 22.0f; z = 13.0f; treeCenters[3] = D3DXVECTOR3(x,land.getHeight(x,z) + 10.0f,z); x = 17.0f; z = -23.0f; treeCenters[4] = D3DXVECTOR3(x,land.getHeight(x,z) + 10.0f,z); x = 22.0f; z = -20.0f; treeCenters[5] = D3DXVECTOR3(x,land.getHeight(x,z) + 10.0f,z); mTrees.init(md3dDevice, treeCenters, 6, L"Textures/Wood/tree3.dds"); //QuadTree qtc.init(md3dDevice, &land, GetCamera().proj(), GetCamera().view()); //init GUI gui.Init(md3dDevice,SCREEN_WIDTH,SCREEN_HEIGHT); //set gui callback gui.SetCallback(OnGUIEvent); //adding a button gui.AddButton(PLACE_TOWER,L"test.png",10,10,100,100); GetTowerScript().Init("tower"); return true; }
void ColoredCubeApp::initApp() { D3DApp::initApp(); myOutFile.open("debug.txt"); fx::InitAll(md3dDevice); mBox.init(md3dDevice, 1.0f); mPlane.init(md3dDevice, 1.0f); //we send scale of 1.0f what does that mean?? mTree.initObject(md3dDevice); std::string treeFileName = "MediumPolyTree.3ds"; mTree.load(md3dDevice, treeFileName); mTree.createTexturesAll(L"LeafCol.jpg", L"LeafAlpha.jpg", L"mySpec.jpg", L"LeafnormalX_normals.PNG"); mTree.setCubeMap(Object::createCubeTex(md3dDevice, L"grassenvmap1024.dds")); mTree.rotate(-1.5f,0.0f,0.0f); mTree.translate(3.0f,-3.0f,-2.6f); mObjBox.initObject(md3dDevice); std::string boxFileName = "man2.fbx"; mObjBox.load(md3dDevice, boxFileName); mObjBox.createTexturesAll( L"manD.jpg", L"defaultAlpha.jpg", L"defaultspec.dds", L"manN.jpg"); mObjBox.createTexturesAt(0, L"bricks.dds", L"defaultAlpha.jpg", L"spec.dds", L"womanHairN.jpg"); mObjBox.setCubeMap(Object::createCubeTex(md3dDevice, L"grassenvmap1024.dds")); mObjBox.rotate(0.0f,0.0f,3.14f); mObjBox.translate(-3.0f,0.0f,2.5f); mObjBox.scale(2.0f,2.0f,2.0f); buildFX(); buildVertexLayouts(); //mLights[0].dir = D3DXVECTOR3(0.57735f, -0.57735f, 0.57735f); mLights[0].dir = D3DXVECTOR3(0.576f, -0.576f, -0.576f); mLights[0].ambient = D3DXCOLOR(0.8f, 0.8f, 0.8f, 1.0f); mLights[0].diffuse = D3DXCOLOR(0.8f, 0.8f, 0.8f, 1.0f); mLights[0].specular = D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f); // Pointlight--position is changed every frame to animate. mLights[1].pos = D3DXVECTOR3(2.0f,2.0f,2.0f); mLights[1].ambient = D3DXCOLOR(0.8f, 0.8f, 0.0f, 1.0f); mLights[1].diffuse = D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f); mLights[1].specular = D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f); mLights[1].att.x = 0.0f; mLights[1].att.y = 1.0f; mLights[1].att.z = 0.0f; mLights[1].range = 120.0f; animationTimeElapsed = 0.0f; animationTimePrev = mTimer.getGameTime(); for(int i = 0; i < fireFrameCount; i++) { std::wostringstream fileName; fileName << L"FireAnim\\Fire"; if(i+1 < 10) fileName << L"00"; else if(i+1 < 100) fileName << L"0"; fileName << i+1 << L".bmp"; std::wstring wbuffer = fileName.str(); LPCWSTR usableName = wbuffer.c_str(); HR(D3DX10CreateShaderResourceViewFromFile(md3dDevice, usableName, 0, 0, &mFireAnimationMapRVs[i], 0)); } HR(D3DX10CreateShaderResourceViewFromFile(md3dDevice, L"bricks.dds", 0, 0, &mCrateMapRV, 0 )); HR(D3DX10CreateShaderResourceViewFromFile(md3dDevice, L"bricks_normal.dds", 0, 0, &mDefaultNormalMapRV, 0 )); HR(D3DX10CreateShaderResourceViewFromFile(md3dDevice, L"stone_diffuse.dds", 0, 0, &mGrassMapRV, 0 )); HR(D3DX10CreateShaderResourceViewFromFile(md3dDevice, L"stone_normal.dds", 0, 0, &mBrickNormalMapRV, 0 )); HR(D3DX10CreateShaderResourceViewFromFile(md3dDevice, L"spec.dds", 0, 0, &mSpecularMapRV, 0 )); // If not, create it. D3DX10_IMAGE_LOAD_INFO loadInfo; loadInfo.MiscFlags = D3D10_RESOURCE_MISC_TEXTURECUBE; ID3D10Texture2D* tex = 0; HR(D3DX10CreateTextureFromFile(md3dDevice, L"grassenvmap1024.dds", &loadInfo, 0, (ID3D10Resource**)&tex, 0) ); D3D10_TEXTURE2D_DESC texDesc; tex->GetDesc(&texDesc); D3D10_SHADER_RESOURCE_VIEW_DESC viewDesc; viewDesc.Format = texDesc.Format; viewDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURECUBE; viewDesc.TextureCube.MipLevels = texDesc.MipLevels; viewDesc.TextureCube.MostDetailedMip = 0; HR(md3dDevice->CreateShaderResourceView(tex, &viewDesc, &mCubeMapRV)); ReleaseCOM(tex); mSky.init(md3dDevice, mCubeMapRV, 5000.0f); }
void DuckHuntMain::DrawScene() { // // Render the scene to the shadow map. // mSmap->BindDsvAndSetNullRenderTarget(md3dImmediateContext); md3dImmediateContext->RSSetState(0); md3dImmediateContext->ClearDepthStencilView(mDepthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0); md3dImmediateContext->RSSetViewports(1, &mScreenViewport); mSsao->SetNormalDepthRenderTarget(mDepthStencilView); // // Restore the back and depth buffer and viewport to the OM stage. // ID3D11RenderTargetView* renderTargets[1] = { mRenderTargetView }; md3dImmediateContext->OMSetRenderTargets(1, renderTargets, mDepthStencilView); md3dImmediateContext->ClearRenderTargetView(mRenderTargetView, reinterpret_cast<const float*>(&Colors::Silver)); XMMATRIX view = mCam.View(); XMMATRIX proj = mCam.Proj(); XMMATRIX viewProj = mCam.ViewProj(); float blendFactor[] = { 0.0f, 0.0f, 0.0f, 0.0f }; // Set per frame constants. Effects::BasicFX->SetDirLights(mDirLights); Effects::BasicFX->SetEyePosW(mCam.GetPosition()); Effects::BasicFX->SetCubeMap(mSky->CubeMapSRV()); Effects::BasicFX->SetShadowMap(mSmap->DepthMapSRV()); Effects::BasicFX->SetSsaoMap(mSsao->AmbientSRV()); ID3DX11EffectTechnique* tech = Effects::BasicFX->Light3TexTech; md3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); XMMATRIX world; XMMATRIX worldInvTranspose; XMMATRIX worldViewProj; // Transform NDC space [-1,+1]^2 to texture space [0,1]^2 XMMATRIX toTexSpace( 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, -0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.5f, 0.5f, 0.0f, 1.0f); XMMATRIX shadowTransform = XMLoadFloat4x4(&mShadowTransform); UINT stride = sizeof(Vertex::PosNormalTexTan); UINT offset = 0; md3dImmediateContext->IASetInputLayout(InputLayouts::Basic32); if (GetAsyncKeyState('1') & 0x8000) md3dImmediateContext->RSSetState(RenderStates::WireframeRS); mTerrain.Draw(md3dImmediateContext, mCam, mDirLights); // // Draw opaque objects. // D3DX11_TECHNIQUE_DESC techDesc; tech->GetDesc(&techDesc); for (UINT p = 0; p < techDesc.Passes; ++p) { for (UINT modelIndex = 0; modelIndex < mModelInstances.size(); ++modelIndex) { world = XMLoadFloat4x4(&mModelInstances[modelIndex].World); worldInvTranspose = MathHelper::InverseTranspose(world); worldViewProj = world*view*proj; Effects::BasicFX->SetWorld(world); Effects::BasicFX->SetWorldInvTranspose(worldInvTranspose); Effects::BasicFX->SetWorldViewProj(worldViewProj); Effects::BasicFX->SetWorldViewProjTex(worldViewProj*toTexSpace); Effects::BasicFX->SetShadowTransform(world*shadowTransform); Effects::BasicFX->SetTexTransform(XMMatrixScaling(1.0f, 1.0f, 1.0f)); for (UINT subset = 0; subset < mModelInstances[modelIndex].Model->SubsetCount; ++subset) { Effects::BasicFX->SetMaterial(mModelInstances[modelIndex].Model->Mat[subset]); Effects::BasicFX->SetDiffuseMap(mModelInstances[modelIndex].Model->DiffuseMapSRV[subset]); //Effects::BasicFX->SetNormalMap(mModelInstances[modelIndex].Model->NormalMapSRV[subset]); tech->GetPassByIndex(p)->Apply(0, md3dImmediateContext); mModelInstances[modelIndex].Model->ModelMesh.Draw(md3dImmediateContext, subset); } } } // Turn off wireframe. md3dImmediateContext->RSSetState(0); // Restore from RenderStates::EqualsDSS md3dImmediateContext->OMSetDepthStencilState(0, 0); // Debug view SSAO map. //DrawScreenQuad(mSsao->AmbientSRV()); mSky->Draw(md3dImmediateContext, mCam); mCrosshair->Draw(md3dImmediateContext, mCam, mScreenViewport.Width, mScreenViewport.Height); // restore default states, as the SkyFX changes them in the effect file. md3dImmediateContext->RSSetState(0); md3dImmediateContext->OMSetDepthStencilState(0, 0); // Unbind shadow map and AmbientMap as a shader input because we are going to render // to it next frame. These textures can be at any slot, so clear all slots. ID3D11ShaderResourceView* nullSRV[16] = { 0 }; md3dImmediateContext->PSSetShaderResources(0, 16, nullSRV); HR(mSwapChain->Present(0, 0)); }
void LightList::QueueDraw(Renderer& rRenderer, const Sky& rSky, const Camera& rCamera, const float sceneDepthMin, const float sceneDepthMax, RdrLightingMethod lightingMethod, RdrLightResources* pOutResources) { Camera lightCamera; int curShadowMapIndex = 0; int curShadowCubeMapIndex = 0; int shadowMapsThisFrame = 0; // Update shadow casting lights and the global light constants // todo: Choose shadow lights based on location and dynamic object movement GlobalLightData* pGlobalLights = (GlobalLightData*)RdrFrameMem::AllocAligned(sizeof(GlobalLightData), 16); // Temporarily add sky light to the light list. m_directionalLights.push(rSky.GetSunLight()); for (uint i = 0, count = m_directionalLights.size(); i < count; ++i) { DirectionalLight& rDirLight = m_directionalLights[i]; int remainingShadowMaps = MAX_SHADOW_MAPS - curShadowMapIndex - 1; const int kNumCascades = 4; if (remainingShadowMaps >= kNumCascades) { // Directional lights always change because they're based on camera position/rotation rDirLight.shadowMapIndex = curShadowMapIndex; Rect viewport(0.f, 0.f, (float)s_shadowMapSize, (float)s_shadowMapSize); float zMin = sceneDepthMin; float zMax = sceneDepthMax; float zDiff = (zMax - zMin); float nearDepth = zMin; float lamda = rSky.GetPssmLambda(); for (int iPartition = 0; iPartition < kNumCascades; ++iPartition) { float zUni = zMin + (zDiff / kNumCascades) * (iPartition + 1); float zLog = zMin * powf(zMax / zMin, (iPartition + 1) / (float)kNumCascades); float farDepth = lamda * zLog + (1.f - lamda) * zUni; Vec3 center = rCamera.GetPosition() + rCamera.GetDirection() * ((farDepth + nearDepth) * 0.5f); Matrix44 lightViewMtx = getLightViewMatrix(center, rDirLight.direction); Quad nearQuad = rCamera.GetFrustumQuad(nearDepth); QuadTransform(nearQuad, lightViewMtx); Quad farQuad = rCamera.GetFrustumQuad(farDepth); QuadTransform(farQuad, lightViewMtx); Vec3 boundsMin(FLT_MAX, FLT_MAX, FLT_MAX); Vec3 boundsMax(-FLT_MAX, -FLT_MAX, -FLT_MAX); accumQuadMinMax(nearQuad, boundsMin, boundsMax); accumQuadMinMax(farQuad, boundsMin, boundsMax); float height = (boundsMax.y - boundsMin.y); float width = (boundsMax.x - boundsMin.x); lightCamera.SetAsOrtho(center, rDirLight.direction, std::max(width, height), -500.f, 500.f); rRenderer.QueueShadowMapPass(lightCamera, m_shadowMapDepthViews[curShadowMapIndex], viewport); Matrix44 mtxView; Matrix44 mtxProj; lightCamera.GetMatrices(mtxView, mtxProj); pGlobalLights->shadowData[curShadowMapIndex].mtxViewProj = Matrix44Multiply(mtxView, mtxProj); pGlobalLights->shadowData[curShadowMapIndex].mtxViewProj = Matrix44Transpose(pGlobalLights->shadowData[curShadowMapIndex].mtxViewProj); pGlobalLights->shadowData[curShadowMapIndex].partitionEndZ = (iPartition == kNumCascades - 1) ? FLT_MAX : farDepth; ++shadowMapsThisFrame; ++curShadowMapIndex; nearDepth = farDepth; } } else { rDirLight.shadowMapIndex = -1; } } for (uint i = 0, count = m_spotLights.size(); i < count; ++i) { SpotLight& rSpotLight = m_spotLights[i]; int remainingShadowMaps = MAX_SHADOW_MAPS - curShadowMapIndex - 1; if (remainingShadowMaps) { Matrix44 mtxView; Matrix44 mtxProj; float angle = rSpotLight.outerConeAngle + Maths::DegToRad(5.f); lightCamera.SetAsPerspective(rSpotLight.position, rSpotLight.direction, angle * 2.f, 1.f, 0.1f, 1000.f); lightCamera.GetMatrices(mtxView, mtxProj); pGlobalLights->shadowData[curShadowMapIndex].mtxViewProj = Matrix44Multiply(mtxView, mtxProj); pGlobalLights->shadowData[curShadowMapIndex].mtxViewProj = Matrix44Transpose(pGlobalLights->shadowData[curShadowMapIndex].mtxViewProj); Rect viewport(0.f, 0.f, (float)s_shadowMapSize, (float)s_shadowMapSize); rRenderer.QueueShadowMapPass(lightCamera, m_shadowMapDepthViews[curShadowMapIndex], viewport); rSpotLight.shadowMapIndex = curShadowMapIndex; ++shadowMapsThisFrame; ++curShadowMapIndex; } else { rSpotLight.shadowMapIndex = -1; } } for (uint i = 0, count = m_pointLights.size(); i < count; ++i) { PointLight& rPointLight = m_pointLights[i]; int remainingShadowCubeMaps = MAX_SHADOW_CUBEMAPS - curShadowCubeMapIndex - 1; if (remainingShadowCubeMaps) { rPointLight.shadowMapIndex = curShadowCubeMapIndex + MAX_SHADOW_MAPS; Rect viewport(0.f, 0.f, (float)s_shadowCubeMapSize, (float)s_shadowCubeMapSize); #if USE_SINGLEPASS_SHADOW_CUBEMAP rRenderer.QueueShadowCubeMapPass(rPointLight, m_shadowCubeMapDepthViews[curShadowCubeMapIndex], viewport); #else for (uint face = 0; face < 6; ++face) { lightCamera.SetAsCubemapFace(light.position, (CubemapFace)face, 0.1f, light.radius * 2.f); rRenderer.QueueShadowMapPass(lightCamera, m_shadowCubeMapDepthViews[curShadowCubeMapIndex * 6 + face], viewport); } #endif ++shadowMapsThisFrame; ++curShadowCubeMapIndex; } else { rPointLight.shadowMapIndex = -1; } } ////////////////////////////////////////////////////////////////////////// // Apply resource updates RdrResourceCommandList* pResCommandList = rRenderer.GetActionCommandList(); // Update spot lights SpotLight* pSpotLights = (SpotLight*)RdrFrameMem::Alloc(sizeof(SpotLight) * m_spotLights.size()); memcpy(pSpotLights, m_spotLights.getData(), sizeof(SpotLight) * m_spotLights.size()); if (!m_hSpotLightListRes) m_hSpotLightListRes = pResCommandList->CreateStructuredBuffer(pSpotLights, m_spotLights.capacity(), sizeof(SpotLight), RdrResourceUsage::Dynamic); else pResCommandList->UpdateBuffer(m_hSpotLightListRes, pSpotLights, sizeof(SpotLight) * m_spotLights.size()); // Update point lights PointLight* pPointLights = (PointLight*)RdrFrameMem::Alloc(sizeof(PointLight) * m_pointLights.size()); memcpy(pPointLights, m_pointLights.getData(), sizeof(PointLight) * m_pointLights.size()); if (!m_hPointLightListRes) m_hPointLightListRes = pResCommandList->CreateStructuredBuffer(pPointLights, m_pointLights.capacity(), sizeof(PointLight), RdrResourceUsage::Dynamic); else pResCommandList->UpdateBuffer(m_hPointLightListRes, pPointLights, sizeof(PointLight) * m_pointLights.size()); // Update environment lights EnvironmentLight* pEnvironmentLights = (EnvironmentLight*)RdrFrameMem::Alloc(sizeof(EnvironmentLight) * m_environmentLights.size()); memcpy(pEnvironmentLights, m_environmentLights.getData(), sizeof(EnvironmentLight) * m_environmentLights.size()); if (!m_hEnvironmentLightListRes) m_hEnvironmentLightListRes = pResCommandList->CreateStructuredBuffer(pEnvironmentLights, m_environmentLights.capacity(), sizeof(EnvironmentLight), RdrResourceUsage::Dynamic); else pResCommandList->UpdateBuffer(m_hEnvironmentLightListRes, pEnvironmentLights, sizeof(EnvironmentLight) * m_environmentLights.size()); // Light culling if (lightingMethod == RdrLightingMethod::Clustered) { QueueClusteredLightCulling(rRenderer, rCamera); } else { QueueTiledLightCulling(rRenderer, rCamera); } // Update global lights constant buffer last so the light culling data is up to date. pGlobalLights->numDirectionalLights = m_directionalLights.size(); pGlobalLights->globalEnvironmentLight = m_globalEnvironmentLight; pGlobalLights->clusterTileSize = m_clusteredLightData.clusterTileSize; memcpy(pGlobalLights->directionalLights, m_directionalLights.getData(), sizeof(DirectionalLight) * pGlobalLights->numDirectionalLights); m_hGlobalLightsCb = pResCommandList->CreateUpdateConstantBuffer(m_hGlobalLightsCb, pGlobalLights, sizeof(GlobalLightData), RdrCpuAccessFlags::Write, RdrResourceUsage::Dynamic); // Remove sky light. m_directionalLights.pop(); // Fill out resource params pOutResources->hGlobalLightsCb = m_hGlobalLightsCb; pOutResources->hSpotLightListRes = m_hSpotLightListRes; pOutResources->hPointLightListRes = m_hPointLightListRes; pOutResources->hEnvironmentLightListRes = m_hEnvironmentLightListRes; pOutResources->hShadowCubeMapTexArray = m_hShadowCubeMapTexArray; pOutResources->hShadowMapTexArray = m_hShadowMapTexArray; pOutResources->hEnvironmentMapTexArray = m_hEnvironmentMapTexArray; pOutResources->hLightIndicesRes = (lightingMethod == RdrLightingMethod::Clustered) ? m_clusteredLightData.hLightIndices : m_tiledLightData.hLightIndices; }
void ProjTexDemo::onLostDevice() { mGfxStats->onLostDevice(); mSky->onLostDevice(); HR(mFX->OnLostDevice()); }
//------------------------------------------------------------------------------------ bool AmbientCube::GenerateHDRCubeMap(const VEC3& pos, const STRING& filename, Scene* pScene) { const uint32 ENV_MAP_SIZE = 256; ID3D11DeviceContext* pDeviceContext = g_pRenderSys->GetDeviceContext(); ID3D11Device* pDevice = g_pRenderSys->GetDevice(); ID3D11Texture2D* pCubeMap = nullptr; ID3D11Texture2D* pDepthTex = nullptr; ID3D11DepthStencilView* pDSV = nullptr; HRESULT hr = S_OK; // Create cube texture { CD3D11_TEXTURE2D_DESC desc(DXGI_FORMAT_R16G16B16A16_FLOAT, ENV_MAP_SIZE, ENV_MAP_SIZE); desc.ArraySize = 6; desc.MipLevels = 1; desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE; desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE; V(pDevice->CreateTexture2D(&desc, nullptr, &pCubeMap)); } { CD3D11_TEXTURE2D_DESC desc(DXGI_FORMAT_R32_TYPELESS, ENV_MAP_SIZE, ENV_MAP_SIZE); desc.Usage = D3D11_USAGE_DEFAULT; desc.BindFlags = D3D11_BIND_DEPTH_STENCIL; V(pDevice->CreateTexture2D(&desc, nullptr, &pDepthTex)); D3D11_DEPTH_STENCIL_VIEW_DESC descDSV; ZeroMemory(&descDSV, sizeof(descDSV)); descDSV.Format = DXGI_FORMAT_D32_FLOAT; descDSV.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D; descDSV.Flags = 0; descDSV.Texture2D.MipSlice = 0; HRESULT hr = S_OK; V(pDevice->CreateDepthStencilView(pDepthTex, &descDSV, &pDSV)); } // Setup camera for cube map rendering Camera* pSceneCam = g_env.pSceneMgr->GetCamera(); Camera camCube(pSceneCam->GetNearClip(), pSceneCam->GetFarClip(), 90, 1, false); camCube._BuildProjMatrix(); camCube.SetPosition(pos); VEC3 vLookDirection[6] = { VEC3::UNIT_X, VEC3::NEG_UNIT_X, VEC3::UNIT_Y, VEC3::NEG_UNIT_Y, VEC3::UNIT_Z, VEC3::NEG_UNIT_Z }; VEC3 vUp[6] = { VEC3::UNIT_Y, VEC3::UNIT_Y, VEC3::NEG_UNIT_Z, VEC3::UNIT_Z, VEC3::UNIT_Y, VEC3::UNIT_Y }; g_env.pSceneMgr->SetCamera(&camCube); g_env.pSceneMgr->SetCurRenderPhase(eRenderPhase_Forward); // Viewport D3D11_VIEWPORT vp = { 0, 0, ENV_MAP_SIZE, ENV_MAP_SIZE, 0, 1 }; pDeviceContext->RSSetViewports(1, &vp); // For each face for (int i = 0; i < 6; ++i) { ID3D11RenderTargetView* pRTV = nullptr; D3D11_RENDER_TARGET_VIEW_DESC descRTV; descRTV.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY; descRTV.Format = DXGI_FORMAT_R16G16B16A16_FLOAT; descRTV.Texture2DArray.MipSlice = 0; descRTV.Texture2DArray.ArraySize = 1; descRTV.Texture2DArray.FirstArraySlice = i; V(pDevice->CreateRenderTargetView(pCubeMap, &descRTV, &pRTV)); pDeviceContext->OMSetRenderTargets(1, &pRTV, pDSV); FLOAT color[4] = { 0 }; pDeviceContext->ClearRenderTargetView(pRTV, color); pDeviceContext->ClearDepthStencilView(pDSV, D3D11_CLEAR_DEPTH, 1.0f, 0); camCube.SetUp(vUp[i]); camCube.SetDirection(vLookDirection[i]); camCube._BuildViewMatrix(); g_env.pRenderer->Update(0); pScene->RenderOpaque(); Sky* pSky = g_env.pSceneMgr->GetSky(); if (pSky) { pSky->Render(); } } g_pRenderSys->SwapBuffer(); V(D3DX11SaveTextureToFileA(pDeviceContext, pCubeMap, D3DX11_IFF_DDS, filename.c_str())); // Restore g_env.pSceneMgr->SetCurRenderPhase(eRenderPhase_None); g_env.pSceneMgr->SetCamera(pSceneCam); g_pRenderSys->SetRenderTarget(nullptr, g_pRenderSys->GetDepthBuffer(), 1, false, false); g_env.pRenderer->RestoreViewport(); SAFE_RELEASE(pCubeMap); return true; }
void draw(SphereComponent hemisphere, Sky const &sky, int firstActiveLayer, LayerData const *layerData) const { DENG2_ASSERT(layerData); if(verts.isEmpty()) return; if(firstActiveLayer < 0) return; bool const yflip = (hemisphere == LowerHemisphere); if(yflip) { // The lower hemisphere must be flipped. glMatrixMode(GL_MODELVIEW); glPushMatrix(); glScalef(1.0f, -1.0f, 1.0f); } // First draw the cap and the background for fadeouts, if needed. bool drawFadeOut = true; drawCap(chooseCapColor(hemisphere, sky.layer(firstActiveLayer), &drawFadeOut), drawFadeOut); for(int i = firstActiveLayer; i < MAX_LAYERS; ++i) { SkyLayer const *skyLayer = sky.layer(i); LayerData const &ldata = layerData[i]; if(!ldata.active) continue; TextureVariant *layerTex = nullptr; if(Material *mat = chooseMaterialForSkyLayer(skyLayer)) { MaterialSnapshot const &ms = mat->prepare(SkyDrawable::layerMaterialSpec(skyLayer->isMasked())); layerTex = &ms.texture(MTU_PRIMARY); GL_BindTexture(layerTex); glEnable(GL_TEXTURE_2D); glMatrixMode(GL_TEXTURE); glPushMatrix(); glLoadIdentity(); Vector2i const &texSize = layerTex->generalCase().dimensions(); if(texSize.x > 0) { glTranslatef(ldata.offset / texSize.x, 0, 0); glScalef(1024.f / texSize.x, 1, 1); } if(yflip) { glScalef(1, -1, 1); glTranslatef(0, -1, 0); } } else { GL_SetNoTexture(); } #define WRITESKYVERTEX(r_, c_) { \ svtx = &vertex(r_, c_); \ if(layerTex) \ { \ glTexCoord2f((c_) / float(columns), (r_) / float(rows)); \ } \ if(drawFadeOut) \ { \ if((r_) == 0) glColor4f(1, 1, 1, 0); \ else glColor3f(1, 1, 1); \ } \ else \ { \ if((r_) == 0) glColor3f(0, 0, 0); \ else glColor3f(1, 1, 1); \ } \ glVertex3f(svtx->x, svtx->y, svtx->z); \ } Vector3f const *svtx; for(int r = 0; r < rows; ++r) { glBegin(GL_TRIANGLE_STRIP); WRITESKYVERTEX(r, 0); WRITESKYVERTEX(r + 1, 0); for(int c = 1; c <= columns; ++c) { WRITESKYVERTEX(r, c); WRITESKYVERTEX(r + 1, c); } glEnd(); } if(layerTex) { glMatrixMode(GL_TEXTURE); glPopMatrix(); glDisable(GL_TEXTURE_2D); } #undef WRITESKYVERTEX } if(yflip) { glMatrixMode(GL_MODELVIEW); glPopMatrix(); } }
void Render() { md3dDevice->ClearRenderTargetView(mRenderTargetView, mClearColor); md3dDevice->ClearDepthStencilView(mDepthStencilView, D3D10_CLEAR_DEPTH|D3D10_CLEAR_STENCIL, 1.0f, 0); md3dDevice->OMSetDepthStencilState(0, 0); md3dDevice->OMSetBlendState(0, blendFactor, 0xffffffff); //draw Trees mTrees.draw(GetCamera().getPos(), GetCamera().view()*GetCamera().proj()); D3D10_TECHNIQUE_DESC techDesc; fxU.setRenderUtil(techDesc); for(UINT p = 0; p < techDesc.Passes; ++p) { //draw Cube pWave->render(fxU,p); //draw Cube "Tower" for (UINT i=0; i < mTowers.size(); ++i) { fxU.setMfx(GetCamera().wvp(mTowers.at(i).getWorld()), mTowers.at(i).getWorld(), 1, nrOfTowers[i]); fxU.ApplyPassByIndex(p); mTowers.at(i).Draw(); } //draw Pyramid fxU.setMfx(GetCamera().wvp(mPyramid.getWorld()), mPyramid.getWorld(), 2, 3); fxU.ApplyPassByIndex(p); mPyramid.Draw(); //draw Cylinder fxU.setMfx(GetCamera().wvp(mCylinder.getWorld()), mCylinder.getWorld(), 3, 6); fxU.ApplyPassByIndex(p); mCylinder.Draw(); //draw Terrain //fxU.setMfx(GetCamera().wvp(mTerrain.getWorld()), mTerrain.getWorld(), 0, 9); //fxU.ApplyPassByIndex(p); //mTerrain.Draw(); fxU.setMfx(GetCamera().wvp(land.getWorld()), land.getWorld(), 0, 9); fxU.ApplyPassByIndex(p); land.draw(); } //draw gui gui.Render(); //draw grid qtc.draw(GetCamera().view(), GetCamera().proj(), grid); //draw Sky sky.draw(GetCamera().view(), GetCamera().proj(), GetCamera().getPos(), mLight.lightType); //draw Fire fire.draw(GetCamera().view(), GetCamera().proj()); md3dDevice->OMSetBlendState(0, blendFactor, 0xffffffff); //draw Rain rain.draw(GetCamera().view(), GetCamera().proj()); mSwapChain->Present(0, 0); }
void Game::DrawScene() { md3dImmediateContext->ClearRenderTargetView(mRenderTargetView, reinterpret_cast<const float*>(&Colors::Silver)); md3dImmediateContext->ClearDepthStencilView(mDepthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0); md3dImmediateContext->IASetInputLayout(InputLayouts::Basic32); md3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); mCam.UpdateViewMatrix(); // Set per frame constants. Effects::GawkyFX->SetDirLights(mDirLights); Effects::GawkyFX->SetCubeMap( mSky->CubeMapSRV() ); Effects::GawkyFX->SetPlayerPos(PlayerOne->getPlayerPosition()); //fxColorVar->SetFloatVector((float*)&mPlayerPosition); // Figure out which technique to use. Skull does not have texture coordinates, // so we need a separate technique for it, and not every surface is reflective, // so don't pay for cubemap look up. ID3DX11EffectTechnique* activeTexTech = Effects::GawkyFX->Light1TexTech; ID3DX11EffectTechnique* activeReflectTech = Effects::GawkyFX->Light1TexReflectTech; ID3DX11EffectTechnique* activeSkullTech = Effects::GawkyFX->Light1ReflectTech; ID3DX11EffectTechnique* activeSkinnedTech = Effects::GawkyFX->Light1TexSkinnedTech; switch (mLightCount) { case 1: activeTexTech = Effects::GawkyFX->Light1TexTech; activeReflectTech = Effects::GawkyFX->Light1TexReflectTech; activeSkullTech = Effects::GawkyFX->Light1ReflectTech; activeSkinnedTech = Effects::GawkyFX->Light1TexSkinnedTech; break; case 2: activeTexTech = Effects::GawkyFX->Light2TexTech; activeReflectTech = Effects::GawkyFX->Light2TexReflectTech; activeSkullTech = Effects::GawkyFX->Light2ReflectTech; activeSkinnedTech = Effects::GawkyFX->Light2TexSkinnedTech; break; case 3: activeTexTech = Effects::GawkyFX->Light3TexTech; activeReflectTech = Effects::GawkyFX->Light3TexReflectTech; activeSkullTech = Effects::GawkyFX->Light3ReflectTech; activeSkinnedTech = Effects::GawkyFX->Light3TexSkinnedTech; break; } //draw the enemies theEnemies->draw(md3dImmediateContext, mCam, activeTexTech); //draw the objects Objects->draw(md3dImmediateContext, mCam, activeTexTech); //draw Level Level1->draw(md3dImmediateContext, mCam, activeTexTech); //draw player md3dImmediateContext->IASetInputLayout( InputLayouts::PosNormalTexTanSkinned ); PlayerOne->drawPlayer( md3dImmediateContext, mCam, activeSkinnedTech ); //////////////////////////////////////// mSky->Draw(md3dImmediateContext, mCam); // restore default states, as the SkyFX changes them in the effect file. md3dImmediateContext->RSSetState(0); md3dImmediateContext->OMSetDepthStencilState(0, 0); HR(mSwapChain->Present(0, 0)); }
int main() { //Sound::load(); /*sf::Texture DongPoint; sf::Texture PowerPoint; DongPoint.loadFromFile("DongPoint.JPG"); PowerPoint.loadFromFile("Ppoint.JPG"); sf::Sprite DongPoint1(DongPoint); sf::Sprite PowerPoint1(PowerPoint); DongPoint1.setPosition(sf::Vector2f(1052, 64)); PowerPoint1.setPosition(sf::Vector2f(1052, 164)); */ Sky* sky = Sky::getInstance(); sf::RenderWindow* window = sky->getWindow(); //Sound::BACK_GROUND.play(); Hero hero; sky->add(&hero); int a = 0; int usebomb = 0;//是否使用炸药 //int stage = 0;//0=小怪,1=boss战 sf::Time t1 = sf::seconds(20);//实验性质[][][]【】【】【】【】【】【】【】【】【】【】【【】【】 sf::Clock clock1;//实验性质[][][]【】【】【】【】【【【】【】【】【】【】【】【】【 window->setFramerateLimit(100); while (window->isOpen()) { sf::Event event; while (window->pollEvent(event)) { if (event.type == sf::Event::Closed) { window->close(); } if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Q) { window->close(); } } {//似乎是没有意义的大括号 if (event.type == sf::Event::Closed) { window->close(); } if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) { window->close(); }// if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) { if (sf::Keyboard::isKeyPressed(sf::Keyboard::LShift)) hero.move2leftslow(); else hero.move2left(); //研究按住与不安住 } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) { if (sf::Keyboard::isKeyPressed(sf::Keyboard::LShift)) hero.move2rightslow(); else hero.move2right(); } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) { if (sf::Keyboard::isKeyPressed(sf::Keyboard::LShift)) hero.move2upslow(); else hero.move2up(); } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) { if (sf::Keyboard::isKeyPressed(sf::Keyboard::LShift)) hero.move2downslow(); else hero.move2down(); } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Z)) { hero.fire(); } if (sf::Keyboard::isKeyPressed(sf::Keyboard::X)) { if (hero.havebomb()) //boss战不能用 { sky->bombclear();//改进,添加无敌时间 hero.bomblost(); hero.clockWD.restart(); hero.whetherWD = 1; } } sky->whetherIdied(&hero); sky->refresh(); sky->whetherIgetDong(&hero);//这句话放哪里比较好? } } return EXIT_SUCCESS; }
void hideSky() { if (m_sky) m_sky->hide();}
void Projekt::DrawScene() { //--------------------------------------------------------------------------- // Render scene to shadow map //--------------------------------------------------------------------------- mShadowMap->BindDsvAndSetNullRenderTarget(mDirect3D->GetImmediateContext()); drawSceneToShadowMap(); mDirect3D->GetImmediateContext()->RSSetState(0); // Restore back and depth buffer and viewport to the OM stage ID3D11RenderTargetView* renderTargets[1] = {mDirect3D->GetRenderTargetView()}; mDirect3D->GetImmediateContext()->OMSetRenderTargets(1, renderTargets, mDirect3D->GetDepthStencilView()); mDirect3D->GetImmediateContext()->ClearRenderTargetView(mDirect3D->GetRenderTargetView(), reinterpret_cast<const float*>(&Colors::LightSteelBlue)); mDirect3D->GetImmediateContext()->ClearDepthStencilView(mDirect3D->GetDepthStencilView(), D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL, 1.0f, 0); mDirect3D->GetImmediateContext()->RSSetViewports(1, &mDirect3D->GetScreenViewport()); // Possible Wireframe render state if (GetAsyncKeyState('E') & 0x8000) mDirect3D->GetImmediateContext()->RSSetState(WireFrameRS); XMMATRIX shadowTransform = XMLoadFloat4x4(&mShadowTransform); //--------------------------------------------------------------------------- // Draw terrain //--------------------------------------------------------------------------- //mTerrain.Draw(mDirect3D->GetImmediateContext(), mCam, mDirLights); mTerrain.DrawShadowed(mDirect3D->GetImmediateContext(), *mPlayer.GetCamera(), mDirLights, mShadowMap->getDepthMapSRV(), &shadowTransform); // -------------------------------------------------------------------------- // Camera matrices XMMATRIX view = mPlayer.GetCamera()->getViewMatrix(); XMMATRIX proj = mPlayer.GetCamera()->getProjMatrix(); XMMATRIX viewproj = mPlayer.GetCamera()->getViewProjMatrix(); float blendFactor[] = {0.0f, 0.0f, 0.0f, 0.0f}; // Set per frame constants Effects::BasicFX->SetDirLights(mDirLights); Effects::BasicFX->SetEyePosW(mPlayer.GetCamera()->getPosition()); Effects::BasicFX->setShadowMap(mShadowMap->getDepthMapSRV()); Effects::BasicFX->SetCubeMap(mSky->cubeMapSRV()); Effects::NormalMapFX->SetDirLights(mDirLights); Effects::NormalMapFX->SetEyePosW(mPlayer.GetCamera()->getPosition()); Effects::NormalMapFX->setShadowMap(mShadowMap->getDepthMapSRV()); Effects::NormalMapFX->SetCubeMap(mSky->cubeMapSRV()); XMMATRIX world; XMMATRIX worldInvTranspose; XMMATRIX worldViewProj; // Transform NDC space [-1,+1]^2 to texture space [0,1]^2 XMMATRIX toTexSpace( 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, -0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.5f, 0.5f, 0.0f, 1.0f); // Vertex size & offset UINT stride = sizeof(Vertex::Basic32); UINT offset = 0; // Draw player //mPlayer.Draw(mDirect3D->GetImmediateContext(), mDirLights, //mShadowMap->getDepthMapSRV(), &shadowTransform); //--------------------------------------------------------------------------- // Draw opaque objects //--------------------------------------------------------------------------- // Bind information about primitive type, and set input layout mDirect3D->GetImmediateContext()->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); mDirect3D->GetImmediateContext()->IASetInputLayout(InputLayouts::Basic32); // Set our effect technique to use ID3DX11EffectTechnique* activeTech = Effects::BasicFX->DirLights3FogTexTech; ID3DX11EffectTechnique* activeSkinnedTech = Effects::NormalMapFX->DirLights3TexTech; D3DX11_TECHNIQUE_DESC techDesc; //-------------------------------------------------------------------------------- // Draw opaque tessellated objects //-------------------------------------------------------------------------------- Effects::BasicTessFX->SetDirLights(mDirLights); Effects::BasicTessFX->SetEyePosW(mPlayer.GetCamera()->getPosition()); Effects::BasicTessFX->setShadowMap(mShadowMap->getDepthMapSRV()); Effects::BasicTessFX->SetCubeMap(mSky->cubeMapSRV()); mDirect3D->GetImmediateContext()->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_3_CONTROL_POINT_PATCHLIST); mDirect3D->GetImmediateContext()->IASetInputLayout(InputLayouts::PosNormalTexTan); activeTech = Effects::BasicTessFX->TessDirLights3FogTexTech; activeTech->GetDesc(&techDesc); for (UINT p = 0; p < techDesc.Passes; ++p) { for (UINT mIndex = 0; mIndex < mGenericInstances.size(); ++mIndex) { if (mGenericInstances[mIndex].isVisible) { world = XMLoadFloat4x4(&mGenericInstances[mIndex].world); worldInvTranspose = MathHelper::InverseTranspose(world); worldViewProj = world*view*proj; Effects::BasicTessFX->SetWorld(world); Effects::BasicTessFX->SetWorldInvTranspose(worldInvTranspose); Effects::BasicTessFX->SetWorldViewProj(worldViewProj); Effects::BasicTessFX->SetWorldViewProjTex(worldViewProj*toTexSpace); Effects::BasicTessFX->setShadowTransform(world*shadowTransform); Effects::BasicTessFX->SetTexTransform(XMMatrixScaling(1.0f, 1.0f, 1.0f)); Effects::BasicTessFX->SetMinTessDistance(20.0f); Effects::BasicTessFX->SetMaxTessDistance(200.0f); Effects::BasicTessFX->SetMinTessFactor(0.0f); Effects::BasicTessFX->SetMaxTessFactor(3.0f); Effects::BasicTessFX->setFogStart(GameSettings::Instance()->Fog()->fogStart); Effects::BasicTessFX->setFogRange(GameSettings::Instance()->Fog()->fogRange); Effects::BasicTessFX->setFogColor(Colors::Silver); for (UINT i = 0; i < mGenericInstances[mIndex].model->meshCount; ++i) { UINT matIndex = mGenericInstances[mIndex].model->meshes[i].MaterialIndex; Effects::BasicTessFX->SetMaterial(mGenericInstances[mIndex].model->mat[matIndex]); Effects::BasicTessFX->SetDiffuseMap(mGenericInstances[mIndex].model->diffuseMapSRV[matIndex]); //Effects::BasicTessFX->SetNormalMap(mGenericInstances[mIndex].model->normalMapSRV[matIndex]); activeTech->GetPassByIndex(p)->Apply(0, mDirect3D->GetImmediateContext()); mGenericInstances[mIndex].model->meshes[i].draw(mDirect3D->GetImmediateContext()); } } } } // FX sets tessellation stages, but it does not disable them. So do that here // to turn off tessellation. mDirect3D->GetImmediateContext()->HSSetShader(0, 0, 0); mDirect3D->GetImmediateContext()->DSSetShader(0, 0, 0); mDirect3D->GetImmediateContext()->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); mDirect3D->GetImmediateContext()->IASetInputLayout(InputLayouts::PosNormalTexTanSkinned); // Skinned objects activeSkinnedTech->GetDesc(&techDesc); for (UINT p = 0; p < techDesc.Passes; ++p) { for (UINT mIndex = 0; mIndex < mGenSkinnedInstances.size(); ++mIndex) { if (mGenSkinnedInstances[mIndex].isVisible) { world = XMLoadFloat4x4(&mGenSkinnedInstances[mIndex].world); worldInvTranspose = MathHelper::InverseTranspose(world); worldViewProj = world*view*proj; Effects::NormalMapFX->SetWorld(world); Effects::NormalMapFX->SetWorldInvTranspose(worldInvTranspose); Effects::NormalMapFX->SetWorldViewProj(worldViewProj); Effects::NormalMapFX->SetWorldViewProjTex(worldViewProj*toTexSpace); Effects::NormalMapFX->setShadowTransform(world*shadowTransform); Effects::NormalMapFX->SetTexTransform(XMMatrixScaling(1.0f, 1.0f, 1.0f)); Effects::NormalMapFX->setFogStart(GameSettings::Instance()->Fog()->fogStart); Effects::NormalMapFX->setFogRange(GameSettings::Instance()->Fog()->fogRange); Effects::NormalMapFX->setBoneTransforms(&mGenSkinnedInstances[mIndex].FinalTransforms[0], mGenSkinnedInstances[mIndex].FinalTransforms.size()); Effects::BasicTessFX->setFogColor(Colors::Silver); for (UINT i = 0; i < mGenSkinnedInstances[mIndex].model->numMeshes; ++i) { UINT matIndex = mGenSkinnedInstances[mIndex].model->meshes[i].MaterialIndex; Effects::NormalMapFX->SetMaterial(mGenSkinnedInstances[mIndex].model->mat[matIndex]); Effects::NormalMapFX->SetDiffuseMap(mGenSkinnedInstances[mIndex].model->diffuseMapSRV[matIndex]); Effects::NormalMapFX->setNormalMap(mGenSkinnedInstances[mIndex].model->normalMapSRV[matIndex]); activeSkinnedTech->GetPassByIndex(p)->Apply(0, mDirect3D->GetImmediateContext()); mGenSkinnedInstances[mIndex].model->meshes[i].draw(mDirect3D->GetImmediateContext()); } } } } //--------------------------------------------------------------------------- // Draw particle systems //--------------------------------------------------------------------------- mFire.setEyePos(mPlayer.GetCamera()->getPosition()); mFire.draw(mDirect3D->GetImmediateContext(), *mPlayer.GetCamera()); mDirect3D->GetImmediateContext()->OMSetBlendState(0, blendFactor, 0xffffffff); // restore default //--------------------------------------------------------------------------- // Draw sky //--------------------------------------------------------------------------- mSky->draw(mDirect3D->GetImmediateContext(), *mPlayer.GetCamera()); // Unbind shadow map and AmbientMap as a shader input because we are going to render // to it next frame. These textures can be at any slot, so clear all slots. ID3D11ShaderResourceView* nullSRV[16] = { 0 }; mDirect3D->GetImmediateContext()->PSSetShaderResources(0, 16, nullSRV); // Restore default states mDirect3D->GetImmediateContext()->RSSetState(0); mDirect3D->GetImmediateContext()->OMSetDepthStencilState(0, 0); mDirect3D->GetImmediateContext()->OMSetBlendState(0, blendFactor, 0xffffffff); HR(mDirect3D->GetSwapChain()->Present(0, 0)); }
void Projekt::DrawScene() { //--------------------------------------------------------------------------- // Render scene to shadow map //--------------------------------------------------------------------------- mShadowMap->BindDsvAndSetNullRenderTarget(mDirect3D->GetImmediateContext()); mShadowMap->DrawSceneToShadowMap(mGenericInstances, *mGame->GetCamera(), mDirect3D->GetImmediateContext()); mDirect3D->GetImmediateContext()->RSSetState(0); // Restore back and depth buffer and viewport to the OM stage ID3D11RenderTargetView* renderTargets[1] = {mDirect3D->GetRenderTargetView()}; mDirect3D->GetImmediateContext()->OMSetRenderTargets(1, renderTargets, mDirect3D->GetDepthStencilView()); mDirect3D->GetImmediateContext()->ClearRenderTargetView(mDirect3D->GetRenderTargetView(), reinterpret_cast<const float*>(&Colors::LightSteelBlue)); mDirect3D->GetImmediateContext()->ClearDepthStencilView(mDirect3D->GetDepthStencilView(), D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL, 1.0f, 0); mDirect3D->GetImmediateContext()->RSSetViewports(1, &mDirect3D->GetScreenViewport()); //--------------------------------------------------------------------------- // Possible Wireframe render state // if (mDirectInput->GetKeyboardState()[DIK_E] && 0x80) // mDirect3D->GetImmediateContext()->RSSetState(RenderStates::WireFrameRS); //-------------------------------------------------------------- // Set shader constants //-------------------------------------------------------------- Effects::BasicFX->SetDirLights(mDirLights); Effects::BasicFX->SetEyePosW(mGame->GetCamera()->GetPosition()); Effects::BasicFX->SetShadowMap(mShadowMap->getDepthMapSRV()); Effects::BasicFX->SetCubeMap(mSky->cubeMapSRV()); Effects::NormalMapFX->SetDirLights(mDirLights); Effects::NormalMapFX->SetEyePosW(mGame->GetCamera()->GetPosition()); Effects::NormalMapFX->SetShadowMap(mShadowMap->getDepthMapSRV()); Effects::NormalMapFX->SetCubeMap(mSky->cubeMapSRV()); // Draw sky mSky->draw(mDirect3D->GetImmediateContext(), *mGame->GetCamera(), Gui->InMenu()); // Draw game mGame->Draw(mDirect3D->GetImmediateContext(), mShadowMap); this->soundModule->updateAndPlay(mGame->GetCamera(), mGame->GetCamera()->GetPosition()); // Draw the GUI Gui->Render(mDirect3D->GetImmediateContext(), mGame->GetPlayer()->GetPosition()); // Unbind shadow map and AmbientMap as a shader input because we are going to render // to it next frame. These textures can be at any slot, so clear all slots. ID3D11ShaderResourceView* nullSRV[16] = { 0 }; mDirect3D->GetImmediateContext()->PSSetShaderResources(0, 16, nullSRV); // Restore default states float blendFactor[] = {0.0f, 0.0f, 0.0f, 0.0f}; mDirect3D->GetImmediateContext()->RSSetState(0); mDirect3D->GetImmediateContext()->OMSetDepthStencilState(0, 0); mDirect3D->GetImmediateContext()->OMSetBlendState(0, blendFactor, 0xffffffff); HR(mDirect3D->GetSwapChain()->Present(0, 0)); }
int main() { srand (time (0)); sf::RenderWindow window (sf::VideoMode(480*0.5, 800*0.5), "Fighters"); window.setFramerateLimit(60); PASS = 1; Things::load (); Sound::load (); Text::load (); Sky sky; Hero hero; Sound::GAME_MUSIC.play (); while (window.isOpen()) { // check all the window's events that were triggered since the last iteration of the loop sf::Event event; while (window.pollEvent(event)) { // "close requested" event: we close the window if (event.type == sf::Event::Closed) window.close(); } // clear the window with black color window.clear( sf::Color::Black ); int test = 0; if ( hero.getRed() < -1 ) test = 1; switch ( test ) { case 1: sky.gameover ( window ); Sound::GAME_MUSIC.play (); break; case 0: if ( hero.getRed() > 0 ) { Game ( hero ); if ( timeNow > TIME-PASS*10 ) { timeNow = 0; sky.addEnemy ( enemy, PASS); } timeNow++; gapNow++; sky.heroGunRunInto ( hero, enemy ); } hero.gunMove (); sky.draw ( window, hero ); drawEnemy ( window ); break; } levelUp (); Text::outText ( window, hero.getRed(), PASS ); // end the current frame window.display(); } return 0; }
// ---------------------------------------------------------------------------- void TerrPanel::init() { IGUIEnvironment* gui_env = Editor::getEditor()->getGUIEnv(); IGUIFont* font = gui_env->getFont(L"font/font1.png"); m_wndw->setRelativePosition(position2di(0, 50)); gui_env->addStaticText(L"Brush:", rect<s32>(10, 10, 200, 30), false, false, m_wndw, -1, false)->setOverrideFont(font); gui_env->addStaticText(L"Radius:", rect<s32>(15, 40, 100, 60), false, false, m_wndw, -1, false); m_h_radius = gui_env->addScrollBar(true, rect<s32>(100, 45, 240, 55), m_wndw, RADIUS); m_h_radius->setMin(1); m_h_radius->setMax(100); m_h_radius->setSmallStep(1); m_h_radius->setLargeStep(10); m_h_radius->setPos(60); gui_env->addStaticText(L"Intensity:", rect<s32>(15, 70, 100, 90), false, false, m_wndw, -1, false); m_h_intensity = gui_env->addScrollBar(true, rect<s32>(100, 75, 240, 85), m_wndw, INTENSITY); m_h_intensity->setMin(1); m_h_intensity->setMax(100); m_h_intensity->setSmallStep(1); m_h_intensity->setLargeStep(10); m_h_intensity->setPos(20); // edge begin IGUIButton* b1 = gui_env->addButton(rect<s32>(105, 100, 135, 130), m_wndw, EDGE_1); IGUIButton* b2 = gui_env->addButton(rect<s32>(155, 100, 185, 130), m_wndw, EDGE_2); IGUIButton* b3 = gui_env->addButton(rect<s32>(205, 100, 235, 130), m_wndw, EDGE_3); b1->setImage(Editor::loadImg("img/edge1.png")); b2->setImage(Editor::loadImg("img/edge2.png")); b3->setImage(Editor::loadImg("img/edge3.png")); gui_env->addStaticText(L"Edge:", rect<s32>(15, 100, 100, 120), false, false, m_wndw, -1, false); m_active_edge_frame = gui_env->addImage(rect<s32>(200, 95, 240, 135), m_wndw); m_active_edge_frame->setImage(Editor::loadImg("img/frame.png")); m_active_edge_frame->setUseAlphaChannel(true); // edge end m_tb1 = gui_env->addButton(rect<s32>(10, 150, 60, 200), m_wndw, M_T1); m_tb2 = gui_env->addButton(rect<s32>(70, 150, 120, 200), m_wndw, M_T2); m_tb3 = gui_env->addButton(rect<s32>(130, 150, 180, 200), m_wndw, M_T3); m_tb4 = gui_env->addButton(rect<s32>(190, 150, 240, 200), m_wndw, M_T4); m_tb1->setImage(Editor::loadImg(L"dirt.jpg")); m_tb2->setImage(Editor::loadImg(L"grass2.jpg")); m_tb3->setImage(Editor::loadImg(L"rock_brown.jpg")); m_tb4->setImage(Editor::loadImg(L"sand2.jpg")); gui_env->addButton(rect<s32>(10, 205, 60, 220), m_wndw, M_TC1); gui_env->addButton(rect<s32>(70, 205, 120, 220), m_wndw, M_TC2); gui_env->addButton(rect<s32>(130, 205, 180, 220), m_wndw, M_TC3); gui_env->addButton(rect<s32>(190, 205, 240, 220), m_wndw, M_TC4); // height modifier begin gui_env->addButton(rect<s32>(30, 255, 80, 305), m_wndw,H_BTN) ->setImage(Editor::loadImg("img/hm.png")); m_h_max_cb = gui_env->addCheckBox(false, rect<s32>(105, 250, 175, 280), m_wndw, H_MAX_CHECK_BOX, L"Max:"); m_h_max_value = gui_env->addEditBox(L"", rect<s32>(170, 255, 210, 275), true, m_wndw, H_MAX_EDIT_BOX); m_h_max_value->setText(L"3"); m_h_min_cb = gui_env->addCheckBox(false, rect<s32>(105, 280, 175, 310), m_wndw, H_MIN_CHECK_BOX, L"Min:"); m_h_min_value = gui_env->addEditBox(L"", rect<s32>(170, 285, 210, 305), true, m_wndw, H_MIN_EDIT_BOX); m_h_min_value->setText(L"-3"); // height modifier end // BRUSH gui_env->addButton(rect<s32>(30, 350, 80, 400), m_wndw,T_SOFT_BTN) ->setImage(Editor::loadImg("img/sb.png")); gui_env->addButton(rect<s32>(95, 350, 145, 400), m_wndw, T_HARD_BTN) ->setImage(Editor::loadImg("img/hb.png")); gui_env->addButton(rect<s32>(160, 350, 210, 400), m_wndw, T_BRIGHTNESS_BTN) ->setImage(Editor::loadImg("img/bb.png")); // SKYBOX ITexture* up = Editor::loadImg("summersky_t.jpg"); ITexture* down = Editor::loadImg("summersky_b.jpg"); ITexture* left = Editor::loadImg("summersky_w.jpg"); ITexture* right = Editor::loadImg("summersky_e.jpg"); ITexture* front = Editor::loadImg("summersky_n.jpg"); ITexture* back = Editor::loadImg("summersky_s.jpg"); m_sb1 = gui_env->addButton(rect<s32>(30, 475, 80, 525), m_wndw, S_T1); m_sb2 = gui_env->addButton(rect<s32>(95, 475, 145, 525), m_wndw, S_T2); m_sb3 = gui_env->addButton(rect<s32>(160, 475, 210, 525), m_wndw, S_T3); m_sb4 = gui_env->addButton(rect<s32>(30, 550, 80, 600), m_wndw, S_T4); m_sb5 = gui_env->addButton(rect<s32>(95, 550, 145, 600), m_wndw, S_T5); m_sb6 = gui_env->addButton(rect<s32>(160, 550, 210, 600), m_wndw, S_T6); m_sb1->setImage(up); m_sb2->setImage(down); m_sb3->setImage(left); m_sb4->setImage(right); m_sb5->setImage(front); m_sb6->setImage(back); Sky* sky = new Sky(up, down, left, right, front, back); sky->hide(); Viewport::get()->setSky(sky); m_tmod.type = HEIGHT_MOD; m_tmod.countdown = -1; m_tmod.edge_type = 3; m_tmod.max = false; m_tmod.min = false; m_tmod.col_mask = SColor(255, 0, 0, 0); refreshTerrModData(); } // init