From 97192e158740314726c4f1b41b2bdd8205c44cb7 Mon Sep 17 00:00:00 2001 From: David Hackbarth Date: Fri, 27 Nov 2026 16:08:22 +0100 Subject: [PATCH] Add input layout Add matrix buffer Convert camera to D3D11 --- GDP/D3D11/Camera.cpp | 17 ++--- GDP/D3D11/Camera.h | 14 ++-- GDP/D3D11/Material.cpp | 133 ++++++++++++++++++++++++++++++------ GDP/D3D11/Material.h | 14 ++++ GDP/D3D11/Mesh.cpp | 2 +- GDP/D3D11/Mesh.h | 2 + GDP/D3D11/PixelShader.cso | Bin 0 -> 12496 bytes GDP/D3D11/PixelShader.hlsl | 2 +- GDP/D3D11/Vertex.h | 34 +++------ GDP/D3D11/VertexShader.cso | Bin 0 -> 13060 bytes GDP/D3D11/VertexShader.hlsl | 7 +- GDP/D3D11/main.cpp | 15 ++-- 12 files changed, 171 insertions(+), 69 deletions(-) create mode 100644 GDP/D3D11/PixelShader.cso create mode 100644 GDP/D3D11/VertexShader.cso diff --git a/GDP/D3D11/Camera.cpp b/GDP/D3D11/Camera.cpp index 3ddd61a..f882c86 100644 --- a/GDP/D3D11/Camera.cpp +++ b/GDP/D3D11/Camera.cpp @@ -1,10 +1,6 @@ #include "Camera.h" -#include - -using namespace DirectX; - -UINT Camera::init(IDirect3DDevice9* pD3DDevice, UINT width, UINT height) +UINT Camera::init(UINT width, UINT height) { // view matrix XMVECTOR position = XMVectorSet(0.0f, 0.0f, -1.0f, 0.0f); @@ -12,10 +8,8 @@ UINT Camera::init(IDirect3DDevice9* pD3DDevice, UINT width, UINT height) XMVECTOR up = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f); XMMATRIX lookTo = XMMatrixLookToLH(position, forward, up); - XMFLOAT4X4 v; - XMStoreFloat4x4(&v, lookTo); - _viewMatrix = *reinterpret_cast(&v); - + XMStoreFloat4x4(&_viewMatrix, lookTo); + // projection matrix float fov = XMConvertToRadians(60.0f); float aspectRatio = static_cast(width) / static_cast(height); @@ -23,10 +17,7 @@ UINT Camera::init(IDirect3DDevice9* pD3DDevice, UINT width, UINT height) float farClippingPlane = 100.0f; XMMATRIX perspective = XMMatrixPerspectiveFovLH(fov, aspectRatio, nearClippingPlane, farClippingPlane); - XMStoreFloat4x4(reinterpret_cast(&_projectionMatrix), perspective); - - pD3DDevice->SetTransform(D3DTS_VIEW, &_viewMatrix); - pD3DDevice->SetTransform(D3DTS_PROJECTION, &_projectionMatrix); + XMStoreFloat4x4(&_projectionMatrix, perspective); return 0; } diff --git a/GDP/D3D11/Camera.h b/GDP/D3D11/Camera.h index 2922d26..8745026 100644 --- a/GDP/D3D11/Camera.h +++ b/GDP/D3D11/Camera.h @@ -1,15 +1,21 @@ #pragma once -#include +#include +#include + +using namespace DirectX; class Camera { public: - UINT init(IDirect3DDevice9* pD3DDevice, UINT width, UINT height); + UINT init(UINT width, UINT height); void update(FLOAT dt); void deInit(); + const XMFLOAT4X4& getViewMatrix() const { return _viewMatrix; } + const XMFLOAT4X4& getProjectionMatrix() const { return _projectionMatrix; } + private: - D3DMATRIX _viewMatrix = {}; - D3DMATRIX _projectionMatrix = {}; + XMFLOAT4X4 _viewMatrix = {}; + XMFLOAT4X4 _projectionMatrix = {}; }; diff --git a/GDP/D3D11/Material.cpp b/GDP/D3D11/Material.cpp index e504ae4..a5ec6e9 100644 --- a/GDP/D3D11/Material.cpp +++ b/GDP/D3D11/Material.cpp @@ -5,39 +5,86 @@ UINT Material::init(ID3D11Device* pD3DDevice, LPCTSTR textureFileName) { - HRESULT hr = DirectX::CreateWICTextureFromFile(pD3DDevice, textureFileName, &_pTexture, 0, DirectX::WIC_LOADER_MIP_AUTOGEN); - CheckFailed(hr, 600); + //HRESULT hr = DirectX::CreateWICTextureFromFile(pD3DDevice, textureFileName, &_pTexture, 0, DirectX::WIC_LOADER_MIP_AUTOGEN); + //CheckFailed(hr, 600); + + UINT error = 0; + + error = createVertexShader(pD3DDevice); + CheckError(error); + + error = createPixelShader(pD3DDevice); + CheckError(error); + + error = createMatrixBuffer(pD3DDevice); + CheckError(error); return 0; } void Material::render(ID3D11DeviceContext* pD3DDeviceContext) { - // set texture - pD3DDevice->SetTexture(0, _pTexture); + //// set texture + //pD3DDevice->SetTexture(0, _pTexture); - // set sampler state - pD3DDevice->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER); - pD3DDevice->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER); - pD3DDevice->SetSamplerState(0, D3DSAMP_BORDERCOLOR, D3DCOLOR_XRGB(100, 0, 100)); - pD3DDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); - pD3DDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); - pD3DDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR); - pD3DDevice->SetSamplerState(0, D3DSAMP_MAXMIPLEVEL, 0); + //// set sampler state + //pD3DDevice->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER); + //pD3DDevice->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER); + //pD3DDevice->SetSamplerState(0, D3DSAMP_BORDERCOLOR, D3DCOLOR_XRGB(100, 0, 100)); + //pD3DDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); + //pD3DDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); + //pD3DDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR); + //pD3DDevice->SetSamplerState(0, D3DSAMP_MAXMIPLEVEL, 0); - // set material - D3DMATERIAL9 material = {}; - material.Ambient = { 1.0f, 1.0f, 1.0f, 1.0f }; - material.Diffuse = { 1.0f, 1.0f, 1.0f, 1.0f }; - material.Specular = { 1.0f, 1.0f, 1.0f, 1.0f }; - material.Power = 100.0f; - material.Emissive = { 1.0f, 0.0f, 0.0f, 1.0f }; + //// set material + //D3DMATERIAL9 material = {}; + //material.Ambient = { 1.0f, 1.0f, 1.0f, 1.0f }; + //material.Diffuse = { 1.0f, 1.0f, 1.0f, 1.0f }; + //material.Specular = { 1.0f, 1.0f, 1.0f, 1.0f }; + //material.Power = 100.0f; + //material.Emissive = { 1.0f, 0.0f, 0.0f, 1.0f }; - pD3DDevice->SetMaterial(&material); + //pD3DDevice->SetMaterial(&material); + + // set shader + pD3DDeviceContext->VSSetShader(_pVertexShader, nullptr, 0); + pD3DDeviceContext->PSSetShader(_pPixelShader, nullptr, 0); + + // set input layout + pD3DDeviceContext->IASetInputLayout(_pInputLayout); + + // set matrix buffer + pD3DDeviceContext->VSSetConstantBuffers(0, 1, &_pMatrixBuffer); } void Material::deInit() { + safeRelease(_pInputLayout); + safeRelease(_pPixelShader); + safeRelease(_pVertexShader); +} + +UINT Material::setMatrices(ID3D11DeviceContext* pD3DDeviceContext, + const XMFLOAT4X4& worldMatrix, const XMFLOAT4X4& viewMatrix, const XMFLOAT4X4& projectionMatrix) +{ + // 1. load matrix data + XMMATRIX w = XMLoadFloat4x4(&worldMatrix); + XMMATRIX v = XMLoadFloat4x4(&viewMatrix); + XMMATRIX p = XMLoadFloat4x4(&projectionMatrix); + + // 2. map matrix buffer + D3D11_MAPPED_SUBRESOURCE data = {}; + HRESULT hr = pD3DDeviceContext->Map(_pMatrixBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &data); + CheckFailed(hr, 665); + + // 3. set data + MatrixBuffer* pMatrixBuffer = static_cast(data.pData); + XMStoreFloat4x4(&pMatrixBuffer->WorldViewProjectionMatrix, XMMatrixTranspose(w * v * p)); + + // 4. unmap matrix buffer + pD3DDeviceContext->Unmap(_pMatrixBuffer, 0); + + return 0; } UINT Material::createVertexShader(ID3D11Device* pD3DDevice) @@ -69,6 +116,9 @@ UINT Material::createVertexShader(ID3D11Device* pD3DDevice) ); CheckFailed(hr, 605); + UINT error = createInputLayout(pD3DDevice, pCompiledShaderCode); + CheckError(error); + safeRelease(pCompiledShaderCode); return 0; @@ -94,5 +144,48 @@ UINT Material::createPixelShader(ID3D11Device* pD3DDevice) UINT Material::createInputLayout(ID3D11Device* pD3DDevice, ID3DBlob* pCompiledVertexShader) { + // https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-semantics + D3D11_INPUT_ELEMENT_DESC inputs[4] = {}; + + // position + inputs[0].SemanticName = "POSITION"; + inputs[0].Format = DXGI_FORMAT_R32G32B32_FLOAT; + + // normal + inputs[1].SemanticName = "NORMAL"; + inputs[1].Format = DXGI_FORMAT_R32G32B32_FLOAT; + inputs[1].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT; + + // uv + inputs[2].SemanticName = "TEXCOORD"; + inputs[2].Format = DXGI_FORMAT_R32G32_FLOAT; + inputs[2].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT; + + // color + inputs[3].SemanticName = "COLOR"; + inputs[3].Format = DXGI_FORMAT_R32G32B32A32_FLOAT; + inputs[3].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT; + + HRESULT hr = pD3DDevice->CreateInputLayout( + inputs, std::size(inputs), // array of element descriptions & size of array + pCompiledVertexShader->GetBufferPointer(), pCompiledVertexShader->GetBufferSize(), // check vertex compatability with vertex shader + &_pInputLayout + ); + CheckFailed(hr, 640); + + return 0; +} + +UINT Material::createMatrixBuffer(ID3D11Device* pD3DDevice) +{ + D3D11_BUFFER_DESC desc = {}; + desc.ByteWidth = sizeof(MatrixBuffer); + desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; + desc.Usage = D3D11_USAGE_DYNAMIC; + desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; // has to be set if D3D11_USAGE_DYNAMIC or D3D11_USAGE_STAGING is used + + HRESULT hr = pD3DDevice->CreateBuffer(&desc, nullptr, &_pMatrixBuffer); + CheckFailed(hr, 660); + return 0; } diff --git a/GDP/D3D11/Material.h b/GDP/D3D11/Material.h index 1186fce..cc43bd0 100644 --- a/GDP/D3D11/Material.h +++ b/GDP/D3D11/Material.h @@ -1,9 +1,12 @@ #pragma once #include #include +#include #pragma comment(lib, "d3dcompiler.lib") +using namespace DirectX; + class Material { public: @@ -11,15 +14,26 @@ public: void render(ID3D11DeviceContext* pD3DDeviceContext); void deInit(); + UINT setMatrices(ID3D11DeviceContext* pD3DDeviceContext, + const XMFLOAT4X4& worldMatrix, const XMFLOAT4X4& viewMatrix, const XMFLOAT4X4& projectionMatrix); + private: UINT createVertexShader(ID3D11Device* pD3DDevice); UINT createPixelShader(ID3D11Device* pD3DDevice); UINT createInputLayout(ID3D11Device* pD3DDevice, ID3DBlob* pCompiledVertexShader); + UINT createMatrixBuffer(ID3D11Device* pD3DDevice); + ID3D11VertexShader* _pVertexShader = nullptr; ID3D11PixelShader* _pPixelShader = nullptr; ID3D11InputLayout* _pInputLayout = nullptr; //IDirect3DTexture9* _pTexture = nullptr; + + struct MatrixBuffer + { + XMFLOAT4X4 WorldViewProjectionMatrix; + }; + ID3D11Buffer* _pMatrixBuffer = nullptr; }; diff --git a/GDP/D3D11/Mesh.cpp b/GDP/D3D11/Mesh.cpp index 5c8b61b..24fcc7d 100644 --- a/GDP/D3D11/Mesh.cpp +++ b/GDP/D3D11/Mesh.cpp @@ -56,7 +56,7 @@ void Mesh::render(ID3D11DeviceContext* pD3DDeviceContext) ); pD3DDeviceContext->IASetIndexBuffer(_pIndexBuffer, DXGI_FORMAT_R16_UINT, 0); - pD3DDeviceContext->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST); + pD3DDeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); // draw call pD3DDeviceContext->DrawIndexed(_indexCount, 0, 0); diff --git a/GDP/D3D11/Mesh.h b/GDP/D3D11/Mesh.h index 7601877..5f30f23 100644 --- a/GDP/D3D11/Mesh.h +++ b/GDP/D3D11/Mesh.h @@ -12,6 +12,8 @@ public: void render(ID3D11DeviceContext* pD3DDeviceContext); void deInit(); + const XMFLOAT4X4& getWorldMatrix() const { return _worldMatrix; } + private: UINT createVertexBuffer(ID3D11Device* pD3DDevice); UINT createIndexBuffer(ID3D11Device* pD3DDevice); diff --git a/GDP/D3D11/PixelShader.cso b/GDP/D3D11/PixelShader.cso new file mode 100644 index 0000000000000000000000000000000000000000..061ab472c8aef47acb57d601ba5f8010b7b13108 GIT binary patch literal 12496 zcmeHNU2GIp6h5;Q-7YQtu@nSMCZ?KJaDQl(wqWVc_J^eC(k*JtChO8pY13u5&bItS zG@ED)iG!9*YWfFZFj#wSBG7-D>AG|`YK5Bg$wG--;&2PKT(H#1k4N`Z!gZJE=2 zbM8Io&N=siP0@|{frbfsK@mW?Ccnylqm8E~7L4Vz9l4$$B?pkO*XEP9QO#?n)%&ngR&jTIJ ziG4Z4%q50X1EWV1x$J~FU?faqEDO@LvnwjI~q$w>!XoKA~tfwNXLg$gN7L# zPUq4xH8n+FB9`?VuJl!e%fZx0hB{4FK~`kT*@}8zeUOv#z;S@`4}d)*17c+)$w2ggRzhN(xw!HDb?SuIjF2@AV$8;Cr=3wC_sFUyNup0q5Hcu%yi z5!zN@EntYOx}uk(B=W3?UzL5Wl-y{m1>K6rqU{na>{myqW6KtOPrOUt9t?*|0~@1p z-iqKdzUyfPAgyzlcU=Jy_{#F=L5@J9c)x%LdH%83hz@YACNUP|4*}G9w6Y`M>{eFx z7`@TWAA!@sh*tkr@hJDH*FOE^>?!}b?lTjAUOWHY``guB)DeaB^WOToqC&M-UM3O1 z>4!%N;aOrn(nVgKPv^;(cLct91!wUZO)kW+5;(`lNC>!pEW(-@yHGrH5NHWCaEZPo3IQ{=U7M`_@V1^M(EFP#WnpSeE6 zh5TD~>8_JzGSHluxP98~z~ES7uznC}w=t&Oas_F(#ri!m|M)i0&S3$C#PJpt3LfC{ zreDKa9^?NpfBxcYZ~me!bW_Ln%nvG#q8)GMPHB7Q#A7?UUH#4Gg6%!}|02NugLc_j zQO*g}0+`3ynyZH5cbc^pX_4nDG$ziw(y0SE2_JbzSnE%j2aItU%Ox9<;bhu4WTcZ# z$$DGYnHe{aItg`=r=+}sQHZ%ez#3LS0Dw_NuKiVISx+ z*$lp4lBdrFXO*6368%56eD-%`w8DPV2HSDpLQ*nvo|*W+*G6OzNPKlTgka2n`$jP;P%ZJ22`9hVTVjE_Bz~ zKb|J}pzw-I71JghncnP6b`G{+%=K<#L zEaErus6Dz55m0k_ zA6$7Zya;#^SYi=~_qX+rqfhP@%I+Ok-$I&OFVx+ve5dXEqMcpQIR-YfUSwITVT9#7 keFL#O-u=AV4UoTpI@c%mg>@ZJq;k<*hyHorjgR{O26O4*NdN!< literal 0 HcmV?d00001 diff --git a/GDP/D3D11/PixelShader.hlsl b/GDP/D3D11/PixelShader.hlsl index 68075ef..5c0e4c3 100644 --- a/GDP/D3D11/PixelShader.hlsl +++ b/GDP/D3D11/PixelShader.hlsl @@ -1,4 +1,4 @@ float4 main() : SV_TARGET { - return float4(1.0f, 1.0f, 1.0f, 1.0f); + return float4(1.0f, .0f, 1.0f, 1.0f); } \ No newline at end of file diff --git a/GDP/D3D11/Vertex.h b/GDP/D3D11/Vertex.h index 1d2b0de..2ccb526 100644 --- a/GDP/D3D11/Vertex.h +++ b/GDP/D3D11/Vertex.h @@ -1,36 +1,24 @@ #pragma once -#include +#include -#define FVF D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1 | D3DFVF_NORMAL +using namespace DirectX; struct Vertex { - // position - float x; - float y; - float z; + XMFLOAT3 position; + XMFLOAT3 normal; + XMFLOAT2 uv; + XMFLOAT4 color; - // normal - float nx; - float ny; - float nz; - - // color - D3DCOLOR color; - - // texture coordinates - float u; - float v; - - Vertex() : x(0.0f), y(0.0f), z(0.0f), color(0xffffffff), u(0.0f), v(0.0f), nx(0.0f), ny(0.0f), nz(0.0f) {} - Vertex(float x, float y, float z) : x(x), y(y), z(z), color(0xffffffff), u(0.0f), v(0.0f), nx(0.0f), ny(0.0f), nz(0.0f) {} + Vertex() : position(0.0f, 0.0f, 0.0f), color(1.0f, 1.0f, 1.0f, 1.0f), uv(0.0f, 0.0f), normal(0.0f, 0.0f, 0.0f) {} + Vertex(float x, float y, float z) : position(x, y, z), color(1.0f, 1.0f, 1.0f, 1.0f), uv(0.0f, 0.0f), normal(0.0f, 0.0f, 0.0f) {} Vertex(float x, float y, float z, UINT r, UINT g, UINT b) : - x(x), y(y), z(z), color(D3DCOLOR_XRGB(r, g, b)), u(0.0f), v(0.0f), nx(0.0f), ny(0.0f), nz(0.0f) {} + position(x, y, z), color(1.0f, 1.0f, 1.0f, 1.0f), uv(0.0f, 0.0f), normal(0.0f, 0.0f, 0.0f) {} Vertex(float x, float y, float z, float u, float v) : - x(x), y(y), z(z), color(0xffffffff), u(u), v(v), nx(0.0f), ny(0.0f), nz(0.0f) {} + position(x, y, z), color(1.0f, 1.0f, 1.0f, 1.0f), uv(u, v), normal(0.0f, 0.0f, 0.0f) {} Vertex(float x, float y, float z, float nx, float ny, float nz, float u, float v) : - x(x), y(y), z(z), color(0xffffffff), u(u), v(v), nx(nx), ny(ny), nz(nz) {} + position(x, y, z), color(1.0f, 1.0f, 1.0f, 1.0f), uv(u, v), normal(nx, ny, nz) {} }; \ No newline at end of file diff --git a/GDP/D3D11/VertexShader.cso b/GDP/D3D11/VertexShader.cso new file mode 100644 index 0000000000000000000000000000000000000000..f1fc02da347e7f8de64088269deffe22c2b61389 GIT binary patch literal 13060 zcmeHOO-x)>6h3ce5ST(4kp4IIS<%oRVJH|W(n?`UOF~=9P+H9-bb!Z?3^QbApj53P zwVIlk29u_CVPbbSVbdlq8oTMDF^%0cE{xGujdo$&G+?8ycz)mep(A0?3f2Pekn_$x z=iYnXIp@B)@7{ACfg`nb_rB_WZ~v|DzkBDy)`OXMzP+M|h^Jg66SNvQ;u5KGi|j2E zxeokjo5(HTu2^(?HR_1sn$)vED^OIV2v@&_Mc`S6PLym=(0)=6OQ819o?-}(SXCqu zU>0xyNY#D_FM-xog$^aOcp}sj?&v!nO2h`^9a<=^4a6Wi7T@OIR?*fT+7oCB1gC*UeXguL}YA?_Y%?d_o0*bIB(I57Nzr)-vE6A^lOX$Y|%eJ`@_9a zs2Wqm4UZmpg(`q<0PWUw#o!P+gSv3_Oto+u`WY>DV5~`9&VR@8-tCi84R^9)<4i2(c)^Ezobl_LYOl! z%p!TC*}@wrDBm4b}-I%O9S2k3KOLwN-HfE>~s zgV%MD;NCzp{iuP}C7`e1F{wYJqQvJ#qz#=Xd_IHkhG;@H%k(iHLsek$^&3pN-IpC$ zzcEd{-M=Gb)|J%wy67p_3Dcyet)iaZ6HWvppZIO z0Z)+!tTc&pT?7%h#viW(OEv|j*OhtdbI)9TdR5?R;@t0_w7=Y7_hKC}6>c9apDs$RcFGGR0@!hK zD4J9PUXW!VDjGNJ-)~*d6|2nQaY+agMXjv?Cu;0b(VJ`*EwY5Iuj|m&V~0xW+HU& zGJL>PU`PW%<^vyBSofn}8G&&pfAVFYc7>*a+*KGPAJ3MLcOqg!qSF5OOWyc(<06 zp+s9no4+lh4QY|K?QP{o-R@{Ie%w5i5ZNp~q^(76TMyAGG5}IH)**2`=t92wM*XP*_Q)0M_H%4f2T@|kR-e7bEeWO44pg4IBV)u(LvAZN#y>)zfl z`pqxrqMOUticCO03M44_v-bgB@Qf5=1OG=XDlHaoQAt|7Mdhr;TU0)^c#FcyQrKBC zD`lJC(9Z)TF#d!>lQ`FTjKH!l%9Kj#!!w)-97fTLEFfdA>t=RnJ<3FmLlKa$Qr4}g z0cAU%n5#eebz&SdM}hGZhAywHUO~Nlu9i!dkH3>ud7$5#;XPm9hk2Oq>ewwim+_j_?uGax)>wCeE-_)(s2%b4i<98G63ZjK%^4>ei)s)&|5?enT|cufm+@^Uwa{+rU^{-lNw8(4 z+;iA>n}@Wf*m+XJKHEt9ro5r9=NJZ^pbKARCQ9d?{N+}VpPn$nRX_sYPfW2gCBZrZKTX*Pv{M7laWtdy zFM#vE3cLxt1U!t$SAr6HP#yuj47`NjSP>|p7`PQY=Y{}~Spw!}a)D0*mjm(rtubI6 zpk+X=A32B|z&s%DTL3f`AD|BWKM~+Q&w-^Ifndw7mL%Ly{nn4KQ%=M-a5DZcpgFL+ z{uUHdKi3pEM2b_vwkh@8n*ZCt_N?m!)&OmI(<;<}(!cW-pMGC6 zHs;36#vHs2|MWDZA-HEh=SJGW`A-GfU}jV?2VxSmPr_;Ufi!)nW2z6zDF^8CC%?|A Avj6}9 literal 0 HcmV?d00001 diff --git a/GDP/D3D11/VertexShader.hlsl b/GDP/D3D11/VertexShader.hlsl index 94efe03..e2b675d 100644 --- a/GDP/D3D11/VertexShader.hlsl +++ b/GDP/D3D11/VertexShader.hlsl @@ -1,4 +1,9 @@ +cbuffer MatrixBuffer +{ + float4x4 WorldViewProjectionMatrix; +}; + float4 main( float4 pos : POSITION ) : SV_POSITION { - return pos; + return mul(pos, WorldViewProjectionMatrix); } \ No newline at end of file diff --git a/GDP/D3D11/main.cpp b/GDP/D3D11/main.cpp index 8674c7b..cf4cbb3 100644 --- a/GDP/D3D11/main.cpp +++ b/GDP/D3D11/main.cpp @@ -37,10 +37,10 @@ int WINAPI WinMain( error = mesh.init(d3d.getDevice()); CheckError(error); - //// 4. create a camera - //Camera camera = {}; - //error = camera.init(d3d.getDevice(), width, height); - //CheckError(error); + // 4. create a camera + Camera camera = {}; + error = camera.init(width, height); + CheckError(error); // 5. create time Time time = {}; @@ -75,14 +75,17 @@ int WINAPI WinMain( // 8.1. update objects time.update(); mesh.update(time.getDeltaTime()); - //camera.update(time.getDeltaTime()); + camera.update(time.getDeltaTime()); //light.update(time.getDeltaTime()); + material.setMatrices( + d3d.getDeviceContext(), mesh.getWorldMatrix(), camera.getViewMatrix(), camera.getProjectionMatrix()); + // 8.2. render objects d3d.beginScene(); //light.render(d3d.getDevice()); - material.render(d3d.getDevice()); + material.render(d3d.getDeviceContext()); mesh.render(d3d.getDeviceContext()); d3d.endScene();