1 / 25

GraphGame: Enhancing 3D Camera Functionality with Transformations and Effects

This comprehensive guide walks you through the essential steps to enhance the 3D camera functionality within the GraphGame engine. You'll learn to integrate transformations, manipulate shaders, and set up first-person camera controls. Key topics include unpacking necessary files, the role of HLSL types and structures in shader programming, and the creation of essential effect files. Additionally, you’ll discover how to manage swap chain resources for seamless rendering and adjust for aspect ratios, ensuring a robust gaming experience.

alicia
Download Presentation

GraphGame: Enhancing 3D Camera Functionality with Transformations and Effects

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. GraphGamegg005-Cam Kamera, 3D, transzformációk SzécsiLászló

  2. Egg bővítése • Math.zip kibontása az Egg projectkönyvtárba • float2, foat3, float4 típusok, HLSL-ben megszokott műveletekkel • float4x4 típus • Cam.zip kibontása az Egg projectkönyvtárba • Egg::Cam::Base – kamera interface • Egg::Cam::FirstPerson – WASD + egér • Math, Cam filterek létrehozása, forrásfileok hozzáadása az Egg projecthez

  3. Min, max • A windows.h-ben definiált makrók • nem kellenek • ezért a DXUT.h-ban • az #include <windows.h> előtt • #define NOMINMAX • és nem akad össze a Math::min, Math::max-xal

  4. gg005-Cam project • copy-paste-rename gg004-Mesh folder • vcxproj, filters átnevezés • solution/add existing project • rename project • working dir: $(SolutionDir) • Project Properties/ConfigurationProperties/Debugging/CommandArguments --solutionPath:"$(SolutionDir)" --projectPath:"$(ProjectDir)" • build, run

  5. Game osztályba • #include "Cam/FirstPerson.h" • Egg::Cam::FirstPerson::P firstPersonCam; • firstPersonCam = Egg::Cam::FirstPerson::create(); • void animate(double dt, double t); • boolprocessMessage( HWND hWnd, • UINT uMsg, WPARAM wParam, LPARAM lParam);

  6. Game.cpp void Game::animate(double dt, double t) { if(!firstPersonCam) return; firstPersonCam->animate(dt); } bool Game::processMessage( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { if(!firstPersonCam) return false; firstPersonCam->processMessage(hWnd, uMsg, wParam, lParam); return false; }

  7. Solution-level fxfileok • Solution/add solution folder: fx • A filerendszerben is hozzuk létre az fxalkönyvtárat a GraphGame-ben • GraphGame/fx/basic.fx létrehozása • sima text file • fx/add existingitem • basic.fx berakása • ez az effect file alapshadereket tartalmaz majd, ami mindig kellhet

  8. Új effect file: GraphGame/fx/basic.fx • transzformációkat végrehajtó vertexshader • be: modell pos, modelnormal, tex • ki: képernyő pos, világ pos, világnormal, tex • trafó mátrixok uniform paraméterek • kamerától fog majd függeni az érték • primitív árnyalást számoló pixel shader • ne legyen egyszínű • normal.zabszolútértéke a szín • (függőleges irányfény)

  9. #5.0 fx/basic.fx float4x4 modelMatrix; float4x4 modelMatrixInverse; float4x4 modelViewProjMatrix;

  10. #5.1 fx/basic.fx structIaosTrafo { float4 pos: POSITION; float3 normal: NORMAL; float2 tex: TEXCOORD; }; structVsosTrafo { float4 pos: SV_POSITION; float4 worldPos: WORLDPOS; float3 normal: NORMAL; float2 tex: TEXCOORD; };

  11. #5.2 fx/basic.fx VsosTrafo vsTrafo(IaosTrafo input) { VsosTrafo output = (VsosTrafo)0; output.pos = mul(input.pos, modelViewProjMatrix); output.worldPos = mul(input.pos, modelMatrix); output.normal = mul(modelMatrixInverse, float4(input.normal.xyz, 0.0)); output.tex = input.tex; return output; }

  12. #5.2 fx/basic.fx float4 psBasic(VsosTrafo input) : SV_Target { return saturate(input.normal).y; }

  13. #5.3 fx/basic.fx technique11 basic { pass basic { SetVertexShader ( CompileShader( vs_5_0, vsTrafo() ) ); SetPixelShader( CompileShader( ps_5_0, psBasic() ) ); } }

  14. #5.3 main.fx #include <basic.fx> // and nothing else

  15. #6.0 Game.cpp ID3DX11EffectPass* idlePass = effect->GetTechniqueByName("idle")->GetPassByName("idle"); Egg::Mesh::Material::P idleMaterial = Egg::Mesh::Material::create(idlePass, 0); ID3DX11EffectPass* basicPass = effect->GetTechniqueByName("basic")->GetPassByName("basic"); Egg::Mesh::Material::P idleMaterial = Egg::Mesh::Material::create(basicPass, 0);

  16. #include "Math/math.h"

  17. #6.1 Game.cpp using namespace Egg::Math; effect-> GetVariableByName("modelMatrix")-> AsMatrix()->SetMatrix( (float*)&float4x4::identity ); effect-> GetVariableByName("modelMatrixInverse") ->AsMatrix()->SetMatrix( (float*)&float4x4::identity ); float4x4 viewProjMatrix = firstPersonCam->getViewMatrix() * firstPersonCam->getProjMatrix(); effect->GetVariableByName("modelViewProjMatrix") ->AsMatrix()-> SetMatrix( (float*)&viewProjMatrix );

  18. Itttartunk, kameramozgatható

  19. Torz a kép – átmeretezéskor camera proj frissítése kell

  20. #6.1 main.cpp HRESULT CALLBACK OnD3D11ResizedSwapChain( ID3D11Device* pd3dDevice, IDXGISwapChain* pSwapChain, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext ) { app->setSwapChain(pSwapChain, pBackBufferSurfaceDesc); app->createSwapChainResources(); return S_OK; }

  21. #6.1 main.cpp void CALLBACK OnD3D11ReleasingSwapChain( void* pUserContext ) { app->releaseSwapChainResources(); }

  22. #6.1 Game.h HRESULT createSwapChainResources(); HRESULT releaseSwapChainResources();

  23. #6.1 Game.cpp HRESULT Game::createSwapChainResources() { firstPersonCam->setAspect( (float)backbufferSurfaceDesc.Width / backbufferSurfaceDesc.Height); return S_OK; }

  24. #6.1 Game.cpp HRESULT Game::releaseSwapChainResources() { return S_OK; }

  25. Nemtorzul

More Related