Compare commits

..
7 Commits
Author SHA1 Message Date
david 4ff265bc44 Added slides for Network Programming 2026-11-24 18:35:40 +01:00
david e35a61c2a9 Added: lighting 2026-10-20 18:27:15 +02:00
david 2246370722 Added: assimp implementation 2026-10-19 18:30:50 +02:00
david 13691e3da3 Added: mesh transformation
Added: input
Added: texture shader
2026-10-13 18:30:21 +02:00
david d2a487a4f6 Added: matrix buffer
Added: world, view & projection matrices
Added: delta time calculation
Added: quad mesh
2026-10-12 18:47:53 +02:00
david daa04be788 Added: simple vertex & pixel shader 2026-10-06 18:27:21 +02:00
david 2fb45a5c02 Added: vertex structure
Added: mesh creation & rendering
2026-10-05 18:35:10 +02:00
35 changed files with 2025 additions and 13 deletions
+4 -1
View File
@@ -418,4 +418,7 @@ FodyWeavers.xsd
# JetBrains Rider # JetBrains Rider
.idea/ .idea/
*.sln.iml *.sln.iml
# vcpkg
vcpkg_installed/
+17
View File
@@ -2,6 +2,23 @@
UINT Camera::init(UINT width, UINT height) UINT Camera::init(UINT width, UINT height)
{ {
// view matrix
XMVECTOR position = XMVectorSet(0.0f, 100.0f, -500.0f, 0.0f);
XMVECTOR forward = XMVectorSet(0.0f, 0.0f, 1.0f, 0.0f);
XMVECTOR up = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);
XMMATRIX view = XMMatrixLookToLH(position, forward, up);
XMStoreFloat4x4(&_viewMatrix, view);
// projection matrix
float fov = XMConvertToRadians(60.0f);
float aspectRatio = static_cast<float>(width) / static_cast<float>(height);
float nearClippingPlane = 0.3f;
float farClippingPlane = 1000.0f;
XMMATRIX projection = XMMatrixPerspectiveFovLH(fov, aspectRatio, nearClippingPlane, farClippingPlane);
XMStoreFloat4x4(&_projectionMatrix, projection);
return 0; return 0;
} }
Binary file not shown.
@@ -0,0 +1,11 @@
struct PixelInput
{
float4 position : SV_Position;
float4 color : COLOR;
};
float4 main(PixelInput INPUT) : SV_TARGET
{
//return float4(1.0f, 1.0f, 1.0f, 1.0f); // solid color
return INPUT.color; // vertex color
}
Binary file not shown.
@@ -0,0 +1,33 @@
// semantics: https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-semantics
cbuffer MatrixBuffer
{
float4x4 WorldViewProjectionMatrix;
float4x4 WorldMatrix;
};
struct VertexInput
{
float4 position : POSITION;
float4 color : COLOR;
};
struct VertexOutput
{
float4 position : SV_Position;
float4 color : COLOR;
};
VertexOutput main(VertexInput INPUT)
{
// mul -> matrix multiplication
// * -> number/scalar calculation
//return mul(INPUT.position, WorldViewProjectionMatrix);
VertexOutput OUTPUT;
OUTPUT.position = mul(INPUT.position, WorldViewProjectionMatrix);
OUTPUT.color = INPUT.color;
return OUTPUT;
}
+72
View File
@@ -97,6 +97,9 @@
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup> </ImportGroup>
<PropertyGroup Label="UserMacros" /> <PropertyGroup Label="UserMacros" />
<PropertyGroup Label="Vcpkg">
<VcpkgEnableManifest>true</VcpkgEnableManifest>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile> <ClCompile>
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
@@ -184,6 +187,7 @@
<ClCompile Include="Mesh.cpp" /> <ClCompile Include="Mesh.cpp" />
<ClCompile Include="Time.cpp" /> <ClCompile Include="Time.cpp" />
<ClCompile Include="Utilities.cpp" /> <ClCompile Include="Utilities.cpp" />
<ClCompile Include="WICTextureLoader11.cpp" />
<ClCompile Include="Window.cpp" /> <ClCompile Include="Window.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@@ -194,9 +198,77 @@
<ClInclude Include="Mesh.h" /> <ClInclude Include="Mesh.h" />
<ClInclude Include="Time.h" /> <ClInclude Include="Time.h" />
<ClInclude Include="Utilities.h" /> <ClInclude Include="Utilities.h" />
<ClInclude Include="Vertex.h" />
<ClInclude Include="WICTextureLoader11.h" />
<ClInclude Include="Window.h" /> <ClInclude Include="Window.h" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<FxCompile Include="ColorPixelShader.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Pixel</ShaderType>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">%(Filename).cso</ObjectFileOutput>
</FxCompile>
<FxCompile Include="ColorVertexShader.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Vertex</ShaderType>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">%(Filename).cso</ObjectFileOutput>
</FxCompile>
<FxCompile Include="LightingPixelShader.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Pixel</ShaderType>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">%(Filename).cso</ObjectFileOutput>
</FxCompile>
<FxCompile Include="LightingVertexShader.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Vertex</ShaderType>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">%(Filename).cso</ObjectFileOutput>
</FxCompile>
<FxCompile Include="TexturePixelShader.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Pixel</ShaderType>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">%(Filename).cso</ObjectFileOutput>
</FxCompile>
<FxCompile Include="TextureVertexShader.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Vertex</ShaderType>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">%(Filename).cso</ObjectFileOutput>
</FxCompile>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="..\packages\Assimp.redist.3.0.0\build\native\Assimp.redist.targets" Condition="Exists('..\packages\Assimp.redist.3.0.0\build\native\Assimp.redist.targets')" />
</ImportGroup> </ImportGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Assimp.redist.3.0.0\build\native\Assimp.redist.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Assimp.redist.3.0.0\build\native\Assimp.redist.targets'))" />
</Target>
</Project> </Project>
@@ -42,6 +42,9 @@
<ClCompile Include="Window.cpp"> <ClCompile Include="Window.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="WICTextureLoader11.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="Camera.h"> <ClInclude Include="Camera.h">
@@ -68,5 +71,34 @@
<ClInclude Include="Window.h"> <ClInclude Include="Window.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Vertex.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="WICTextureLoader11.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<FxCompile Include="ColorVertexShader.hlsl">
<Filter>Resource Files</Filter>
</FxCompile>
<FxCompile Include="ColorPixelShader.hlsl">
<Filter>Resource Files</Filter>
</FxCompile>
<FxCompile Include="TextureVertexShader.hlsl">
<Filter>Resource Files</Filter>
</FxCompile>
<FxCompile Include="TexturePixelShader.hlsl">
<Filter>Resource Files</Filter>
</FxCompile>
<FxCompile Include="LightingPixelShader.hlsl">
<Filter>Resource Files</Filter>
</FxCompile>
<FxCompile Include="LightingVertexShader.hlsl">
<Filter>Resource Files</Filter>
</FxCompile>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup> </ItemGroup>
</Project> </Project>
+37 -1
View File
@@ -54,8 +54,39 @@ INT Direct3D::init(HWND hWnd, UINT width, UINT height, BOOL isFullscreen)
safeRelease(pBackBuffer); safeRelease(pBackBuffer);
// 4. create depth stencil buffer // 4. create depth stencil buffer
ID3D11Texture2D* pDepthStencilBuffer = nullptr;
D3D11_TEXTURE2D_DESC depthStencilBufferDesc = {};
depthStencilBufferDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
depthStencilBufferDesc.Width = width;
depthStencilBufferDesc.Height = height;
depthStencilBufferDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
depthStencilBufferDesc.ArraySize = 1;
depthStencilBufferDesc.Usage = D3D11_USAGE_DEFAULT;
depthStencilBufferDesc.SampleDesc.Count = 1;
hr = _pD3DDevice->CreateTexture2D(&depthStencilBufferDesc, nullptr, &pDepthStencilBuffer);
CheckFailed(hr, 225);
hr = _pD3DDevice->CreateDepthStencilView(pDepthStencilBuffer, nullptr, &_pD3DDepthStencilView);
CheckFailed(hr, 230);
safeRelease(pDepthStencilBuffer);
D3D11_DEPTH_STENCIL_DESC depthStencilDesc = {};
depthStencilDesc.DepthEnable = true;
depthStencilDesc.DepthFunc = D3D11_COMPARISON_LESS_EQUAL;
depthStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
hr = _pD3DDevice->CreateDepthStencilState(&depthStencilDesc, &_pD3DDepthStencilState);
CheckFailed(hr, 240);
// 5. create rasterizer state // 5. create rasterizer state
D3D11_RASTERIZER_DESC rasterizerDesc = {};
rasterizerDesc.FillMode = D3D11_FILL_SOLID;
rasterizerDesc.CullMode = D3D11_CULL_BACK;
hr = _pD3DDevice->CreateRasterizerState(&rasterizerDesc, &_pD3DRasterizerState);
CheckFailed(hr, 250);
// 6. describe viewport // 6. describe viewport
D3D11_VIEWPORT viewport = {}; D3D11_VIEWPORT viewport = {};
@@ -66,17 +97,22 @@ INT Direct3D::init(HWND hWnd, UINT width, UINT height, BOOL isFullscreen)
// 7. setup render pipeline (device context) // 7. setup render pipeline (device context)
_pD3DDeviceContext->RSSetViewports(1, &viewport); _pD3DDeviceContext->RSSetViewports(1, &viewport);
_pD3DDeviceContext->OMSetRenderTargets(1, &_pD3DRenderTargetView, nullptr); // TODO: create depth stencil view and set it for ouput merger stage _pD3DDeviceContext->OMSetRenderTargets(1, &_pD3DRenderTargetView, _pD3DDepthStencilView);
_pD3DDeviceContext->OMSetDepthStencilState(_pD3DDepthStencilState, 0xFFFFFFFF);
_pD3DDeviceContext->RSSetState(_pD3DRasterizerState);
return 0; return 0;
} }
void Direct3D::beginScene() void Direct3D::beginScene()
{ {
// TODO: implement a custom color via parameters
// TODO: (optional) implement a random color every frame
FLOAT color[4] = { 0.0f, 0.0f, 0.0f, 1.0f }; FLOAT color[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
// 8. clear the buffers // 8. clear the buffers
_pD3DDeviceContext->ClearRenderTargetView(_pD3DRenderTargetView, color); _pD3DDeviceContext->ClearRenderTargetView(_pD3DRenderTargetView, color);
_pD3DDeviceContext->ClearDepthStencilView(_pD3DDepthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0xFFFFFFFF);
} }
void Direct3D::endScene() void Direct3D::endScene()
+3
View File
@@ -19,5 +19,8 @@ private:
ID3D11DeviceContext* _pD3DDeviceContext = nullptr; // access to render pipeline, e.g. set matrices or draw command, used in run phase ID3D11DeviceContext* _pD3DDeviceContext = nullptr; // access to render pipeline, e.g. set matrices or draw command, used in run phase
IDXGISwapChain* _pDXGISwapChain = nullptr; // holds references to front & back buffer & swaps them IDXGISwapChain* _pDXGISwapChain = nullptr; // holds references to front & back buffer & swaps them
ID3D11RenderTargetView* _pD3DRenderTargetView = nullptr; // target device context is rendering to ID3D11RenderTargetView* _pD3DRenderTargetView = nullptr; // target device context is rendering to
ID3D11DepthStencilView* _pD3DDepthStencilView = nullptr; // saves depth & stencil value of every pixel
ID3D11DepthStencilState* _pD3DDepthStencilState = nullptr; // set the current settings for depth-stenciling
ID3D11RasterizerState* _pD3DRasterizerState = nullptr; // set additional settings for the render pipeline
}; };
+13
View File
@@ -1,7 +1,19 @@
#include "Light.h" #include "Light.h"
#include "Utilities.h"
UINT Light::init(ID3D11Device* pD3DDevice, LightBuffer& lightData) UINT Light::init(ID3D11Device* pD3DDevice, LightBuffer& lightData)
{ {
D3D11_BUFFER_DESC desc = {};
desc.ByteWidth = sizeof(LightBuffer);
desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
desc.Usage = D3D11_USAGE_IMMUTABLE;
D3D11_SUBRESOURCE_DATA data = {};
data.pSysMem = &lightData;
HRESULT hr = pD3DDevice->CreateBuffer(&desc, &data, &_pLightBuffer);
CheckFailed(hr, 700);
return 0; return 0;
} }
@@ -11,6 +23,7 @@ void Light::update(FLOAT dt)
void Light::render(ID3D11DeviceContext* pD3DDeviceContext) void Light::render(ID3D11DeviceContext* pD3DDeviceContext)
{ {
pD3DDeviceContext->PSSetConstantBuffers(0, 1, &_pLightBuffer);
} }
void Light::deInit() void Light::deInit()
+3 -1
View File
@@ -9,8 +9,10 @@ class Light
public: public:
struct LightBuffer struct LightBuffer
{ {
XMFLOAT3 LightVector; XMFLOAT3A LightVector;
XMFLOAT3 LightPosition;
FLOAT LightIntensity; FLOAT LightIntensity;
XMFLOAT3A LightAttenuation;
XMFLOAT4 DiffuseColor; XMFLOAT4 DiffuseColor;
XMFLOAT4 SpecularColor; XMFLOAT4 SpecularColor;
XMFLOAT3 CameraPosition; XMFLOAT3 CameraPosition;
Binary file not shown.
@@ -0,0 +1,59 @@
Texture2D MainTexture;
SamplerState MainSampler;
cbuffer LightBuffer
{
float3 LightVector;
float3 LightPosition;
float LightIntensity;
float3 LightAttenuation;
float4 DiffuseColor;
float4 SpecularColor;
float3 CameraPosition;
float Phong;
};
struct PixelInput
{
float4 position : SV_Position;
float3 positionWorld : POSITION1;
float2 uv : TEXCOORD;
float4 color : COLOR;
float3 normal : NORMAL;
};
float4 main(PixelInput INPUT) : SV_TARGET
{
float4 texColor = MainTexture.Sample(MainSampler, INPUT.uv) * INPUT.color;
float4 ambientColor = float4(0.2f, 0.2f, 0.2f, 1.0f);
float4 diffuseColor = 0;
float4 specularColor = 0;
float4 emissionColor = 0;
//float4 emissionColor = float4(0.7f, 0.0f, 0.0f, 1.0f);
// directional
//float lightIntensity = LightIntensity;
// point light
float3 light = LightPosition - INPUT.positionWorld;
float lightLength = length(light);
float attenuation = 1 / (LightAttenuation.x + LightAttenuation.y * lightLength + LightAttenuation.z * lightLength * lightLength); // 1 / (constant + linear + quadratic)
float lightIntensity = LightIntensity * attenuation;
// normalize vectors
float3 normal = normalize(INPUT.normal);
//float3 light = normalize(-LightVector); // directional light
light = light / lightLength; // point or spot light
// diffuse color
float diffuse = max(0, dot(normal, light));
diffuseColor = DiffuseColor * (diffuse * lightIntensity);
// specular color
float3 reflect = 2 * diffuse * normal - light;
float3 view = normalize(CameraPosition - INPUT.positionWorld);
float specular = pow(max(0, dot(reflect, view)), Phong);
specularColor = SpecularColor * (specular * lightIntensity);
return saturate(saturate(texColor * saturate(ambientColor + diffuseColor) + specularColor) + emissionColor);
}
Binary file not shown.
@@ -0,0 +1,35 @@
cbuffer MatrixBuffer
{
float4x4 WorldViewProjectionMatrix;
float4x4 WorldMatrix;
};
struct VertexInput
{
float4 position : POSITION;
float2 uv : TEXCOORD;
float4 color : COLOR;
float3 normal : NORMAL;
};
struct VertexOutput
{
float4 position : SV_Position;
float3 positionWorld : POSITION1;
float2 uv : TEXCOORD;
float4 color : COLOR;
float3 normal : NORMAL;
};
VertexOutput main(VertexInput INPUT)
{
VertexOutput OUTPUT;
OUTPUT.position = mul(INPUT.position, WorldViewProjectionMatrix);
OUTPUT.positionWorld = mul(INPUT.position, WorldMatrix).xyz;
OUTPUT.normal = mul(INPUT.normal, (float3x3)WorldMatrix);
OUTPUT.uv = INPUT.uv;
OUTPUT.color = INPUT.color;
return OUTPUT;
}
+157
View File
@@ -1,5 +1,6 @@
#include "Material.h" #include "Material.h"
#include "Utilities.h" #include "Utilities.h"
#include "WICTextureLoader11.h"
UINT Material::init(ID3D11Device* pD3DDevice, LPCWSTR textureFileName) UINT Material::init(ID3D11Device* pD3DDevice, LPCWSTR textureFileName)
{ {
@@ -22,37 +23,193 @@ UINT Material::init(ID3D11Device* pD3DDevice, LPCWSTR textureFileName)
void Material::render(ID3D11DeviceContext* pD3DDeviceContext) void Material::render(ID3D11DeviceContext* pD3DDeviceContext)
{ {
// setup shaders
pD3DDeviceContext->VSSetShader(_pVertexShader, nullptr, 0);
pD3DDeviceContext->PSSetShader(_pPixelShader, nullptr, 0);
// setup the input layout
pD3DDeviceContext->IASetInputLayout(_pInputLayout);
// setup the matrix buffer
pD3DDeviceContext->VSSetConstantBuffers(0, 1, &_pMatrixBuffer);
// setup texture & sampler
pD3DDeviceContext->PSSetShaderResources(0, 1, &_pTexture);
pD3DDeviceContext->PSSetSamplers(0, 1, &_pSamplerState);
} }
void Material::deInit() void Material::deInit()
{ {
safeRelease(_pSamplerState);
safeRelease(_pTexture);
safeRelease(_pMatrixBuffer);
safeRelease(_pInputLayout);
safeRelease(_pPixelShader);
safeRelease(_pVertexShader);
} }
void Material::setMatrixBuffer(ID3D11DeviceContext* pD3DDeviceContext, const XMFLOAT4X4& worldMatrix, const XMFLOAT4X4& viewMatrix, const XMFLOAT4X4& projectionMatrix) void Material::setMatrixBuffer(ID3D11DeviceContext* pD3DDeviceContext, const XMFLOAT4X4& worldMatrix, const XMFLOAT4X4& viewMatrix, const XMFLOAT4X4& projectionMatrix)
{ {
// 1. prepare the data
XMMATRIX w = XMLoadFloat4x4(&worldMatrix);
XMMATRIX v = XMLoadFloat4x4(&viewMatrix);
XMMATRIX p = XMLoadFloat4x4(&projectionMatrix);
XMMATRIX wvp = w * v * p;
// 2. map the buffer memory
D3D11_MAPPED_SUBRESOURCE data = {};
HRESULT hr = pD3DDeviceContext->Map(
_pMatrixBuffer, // resource to map
0, // resources can have sub resources
D3D11_MAP_WRITE_DISCARD, // resource map type, read & write access, what happen to the old data
0, // optional flags
&data
);
if (FAILED(hr)) return;
// 3. assign the data
MatrixBuffer* pMatrixBuffer = static_cast<MatrixBuffer*>(data.pData);
XMStoreFloat4x4(&pMatrixBuffer->WorldViewProjectionMatrix, XMMatrixTranspose(wvp));
XMStoreFloat4x4(&pMatrixBuffer->WorldMatrix, XMMatrixTranspose(w));
// 4. unmap the buffer memory
pD3DDeviceContext->Unmap(_pMatrixBuffer, 0);
} }
UINT Material::createVertexShader(ID3D11Device* pD3DDevice) UINT Material::createVertexShader(ID3D11Device* pD3DDevice)
{ {
HRESULT hr = {};
ID3DBlob* pCompiledShaderCode = nullptr;
// 1. get compiled shader code
// 2 options for creating a vertex shader object
// option 1: compile at runtime
//hr = D3DCompileFromFile(
// L"ColorVertexShader.hlsl", // shader file name
// nullptr, // optional define class
// nullptr, // optional include class
// "main", // entry point of the shader
// "vs_4_0", // shader type and version
// 0, // optional flags
// 0, // optional flags
// &pCompiledShaderCode, // target object for compiled shader code
// nullptr // optional target object for compiler error messages
//);
// option 2: load compiled shader from disk
//hr = D3DReadFileToBlob(L"ColorVertexShader.cso", &pCompiledShaderCode);
//hr = D3DReadFileToBlob(L"TextureVertexShader.cso", &pCompiledShaderCode);
hr = D3DReadFileToBlob(L"LightingVertexShader.cso", &pCompiledShaderCode);
CheckFailed(hr, 600);
// 2. create vertex shader object
hr = pD3DDevice->CreateVertexShader(
pCompiledShaderCode->GetBufferPointer(), // pointer to compiled shader code
pCompiledShaderCode->GetBufferSize(), // size of compiled shader code
nullptr, // optional linkage class
&_pVertexShader
);
CheckFailed(hr, 610);
// 3. create input layout
UINT error = createInputLayout(pD3DDevice, pCompiledShaderCode);
CheckError(error);
// 4. tidy up
safeRelease(pCompiledShaderCode);
return 0; return 0;
} }
UINT Material::createPixelShader(ID3D11Device* pD3DDevice) UINT Material::createPixelShader(ID3D11Device* pD3DDevice)
{ {
ID3DBlob* pCompiledShaderCode = nullptr;
//HRESULT hr = D3DReadFileToBlob(L"ColorPixelShader.cso", &pCompiledShaderCode);
//HRESULT hr = D3DReadFileToBlob(L"TexturePixelShader.cso", &pCompiledShaderCode);
HRESULT hr = D3DReadFileToBlob(L"LightingPixelShader.cso", &pCompiledShaderCode);
CheckFailed(hr, 620);
hr = pD3DDevice->CreatePixelShader(pCompiledShaderCode->GetBufferPointer(), pCompiledShaderCode->GetBufferSize(), nullptr, &_pPixelShader);
CheckFailed(hr, 630);
safeRelease(pCompiledShaderCode);
return 0; return 0;
} }
UINT Material::createInputLayout(ID3D11Device* pD3DDevice, ID3DBlob* pCompiledVertexShaderCode) UINT Material::createInputLayout(ID3D11Device* pD3DDevice, ID3DBlob* pCompiledVertexShaderCode)
{ {
D3D11_INPUT_ELEMENT_DESC elements[4] = {};
// position
elements[0].SemanticName = "POSITION";
elements[0].Format = DXGI_FORMAT_R32G32B32_FLOAT;
// normal
elements[1].SemanticName = "NORMAL";
elements[1].Format = DXGI_FORMAT_R32G32B32_FLOAT;
elements[1].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
// color
elements[2].SemanticName = "COLOR";
elements[2].Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
elements[2].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
// uv
elements[3].SemanticName = "TEXCOORD";
elements[3].Format = DXGI_FORMAT_R32G32_FLOAT;
elements[3].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
HRESULT hr = pD3DDevice->CreateInputLayout(
elements, // array of input layout elements
std::size(elements), // count of elements
pCompiledVertexShaderCode->GetBufferPointer(), pCompiledVertexShaderCode->GetBufferSize(), // compiled vertex shader code
&_pInputLayout
);
CheckFailed(hr, 650);
return 0; return 0;
} }
UINT Material::createMatrixBuffer(ID3D11Device* pD3DDevice) 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;
HRESULT hr = pD3DDevice->CreateBuffer(&desc, nullptr, &_pMatrixBuffer);
CheckFailed(hr, 660);
return 0; return 0;
} }
UINT Material::createTextureAndSamplerState(ID3D11Device* pD3DDevice, LPCWSTR textureFileName) UINT Material::createTextureAndSamplerState(ID3D11Device* pD3DDevice, LPCWSTR textureFileName)
{ {
// load texture & create ShaderResourceView
// https://github.com/microsoft/DirectXTex/tree/main
HRESULT hr = DirectX::CreateWICTextureFromFile(pD3DDevice, textureFileName, nullptr, &_pTexture);
CheckFailed(hr, 670);
// create SamplerState
D3D11_SAMPLER_DESC samplerDesc = {};
samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP; // always set W
samplerDesc.BorderColor[0] = 1.0f;
samplerDesc.BorderColor[1] = 0.0f;
samplerDesc.BorderColor[2] = 1.0f;
samplerDesc.BorderColor[3] = 1.0f;
samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
samplerDesc.MinLOD = 0;
samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;
hr = pD3DDevice->CreateSamplerState(&samplerDesc, &_pSamplerState);
CheckFailed(hr, 680);
return 0; return 0;
} }
+216 -7
View File
@@ -1,37 +1,246 @@
#include "Mesh.h" #include "Mesh.h"
#include "Utilities.h" #include "Utilities.h"
#include "Vertex.h"
#include <assimp/Importer.hpp>
#include <assimp/scene.h>
#include <assimp/postprocess.h>
#include <vector>
UINT Mesh::init(ID3D11Device* pD3DDevice) UINT Mesh::init(ID3D11Device* pD3DDevice)
{ {
UINT error = 0; UINT error = 0;
error = createVertexBuffer(pD3DDevice); XMStoreFloat4x4(&_worldMatrix, XMMatrixIdentity());
CheckError(error);
error = createIndexBuffer(pD3DDevice);
CheckError(error);
return 0; return 0;
} }
void Mesh::update(FLOAT dt) void Mesh::update(FLOAT dt)
{ {
static float x = 0.0f;
static float y = 0.0f;
static float z = 0.0f;
static float rotY = 0.0f;
static float rotZ = 0.0f;
static float scale = 0.5f;
rotY += XM_PIDIV4 * dt;
//rotZ += XM_PIDIV4 * dt;
float move = 100.0f * dt;
if (GetAsyncKeyState(VK_LEFT) & 0x8000 || GetAsyncKeyState('A') & 0x8000) x -= move;
if (GetAsyncKeyState(VK_RIGHT) & 0x8000 || GetAsyncKeyState('D') & 0x8000) x += move;
if (GetAsyncKeyState(VK_UP) & 0x8000 || GetAsyncKeyState('W') & 0x8000) y += move;
if (GetAsyncKeyState(VK_DOWN) & 0x8000 || GetAsyncKeyState('S') & 0x8000) y -= move;
if (GetAsyncKeyState(VK_SUBTRACT) & 0x8000 || GetAsyncKeyState('Q') & 0x8000) z -= move;
if (GetAsyncKeyState(VK_ADD) & 0x8000 || GetAsyncKeyState('E') & 0x8000) z += move;
XMMATRIX translation = XMMatrixTranslation(x, y, z);
XMMATRIX rotation = XMMatrixRotationRollPitchYaw(0.0f, rotY, rotZ);
XMMATRIX localScale = XMMatrixScaling(scale, scale, scale);
XMStoreFloat4x4(&_worldMatrix, localScale * rotation * translation);
} }
void Mesh::render(ID3D11DeviceContext* pD3DDeviceContext) void Mesh::render(ID3D11DeviceContext* pD3DDeviceContext)
{ {
// setup pipeline
static UINT offset = 0;
pD3DDeviceContext->IASetVertexBuffers(
0, // starting slot, if you want to dump the data with offset in memory
1, // amount of vertex buffers
&_pVertexBuffer, // array of vertex buffers
&_vertexStride, // array of size of vertices in vertex buffers
&offset // array of vertex buffer offsets (to skip vertices)
);
pD3DDeviceContext->IASetIndexBuffer(
_pIndexBuffer,
DXGI_FORMAT_R16_UINT, // index format
0 // index buffer offset
);
pD3DDeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
// draw call
pD3DDeviceContext->DrawIndexed(
_indexCount,
0, // bias of first index
0 // bias of vertex index
);
} }
void Mesh::deInit() void Mesh::deInit()
{ {
safeRelease(_pVertexBuffer);
safeRelease(_pIndexBuffer);
} }
UINT Mesh::createVertexBuffer(ID3D11Device* pD3DDevice) UINT Mesh::loadMeshFromFile(ID3D11Device* pD3DDevice, string filename)
{ {
// clear old buffers
safeRelease(_pVertexBuffer);
safeRelease(_pIndexBuffer);
// assimp implementation
Assimp::Importer importer;
const aiScene* pScene = importer.ReadFile(
filename,
aiProcess_Triangulate | aiProcess_JoinIdenticalVertices | aiProcess_ConvertToLeftHanded | aiProcess_PreTransformVertices
);
if (pScene == nullptr || !pScene->HasMeshes()) return 350;
const aiMesh* pMesh = pScene->mMeshes[0];
// import vertices
vector<Vertex> vertices;
for (size_t v = 0; v < pMesh->mNumVertices; v++)
{
// position
const aiVector3D& position = pMesh->mVertices[v];
// normal
aiVector3D normal(0.0f, 0.0f, 0.0f);
if (pMesh->HasNormals())
{
normal = pMesh->mNormals[v];
}
// uv
if (pMesh->HasTextureCoords(0))
{
const aiVector3D& uv = pMesh->mTextureCoords[0][v];
vertices.emplace_back(
position.x, position.y, position.z,
normal.x, normal.y, normal.z,
uv.x, uv.y
);
}
// vertex color
if (pMesh->HasVertexColors(0))
{
const aiColor4D& color = pMesh->mColors[0][v];
vertices.emplace_back(
position.x, position.y, position.z,
color.r, color.g, color.b
);
}
}
// import indices
vector<USHORT> indices;
if (pMesh->mNumVertices > USHRT_MAX) return 360;
for (size_t f = 0; f < pMesh->mNumFaces; f++)
{
const aiFace& face = pMesh->mFaces[f];
if (face.mNumIndices != 3) continue;
indices.push_back(face.mIndices[0]);
indices.push_back(face.mIndices[1]);
indices.push_back(face.mIndices[2]);
}
// update mesh properties
_vertexCount = vertices.size();
_vertexStride = sizeof(Vertex);
_indexCount = indices.size();
UINT error = createVertexBuffer(pD3DDevice, vertices.data());
CheckError(error);
error = createIndexBuffer(pD3DDevice, indices.data());
CheckError(error);
return 0; return 0;
} }
UINT Mesh::createIndexBuffer(ID3D11Device* pD3DDevice) UINT Mesh::loadDefaultMesh(ID3D11Device* pD3DDevice)
{ {
// clear old buffers
safeRelease(_pVertexBuffer);
safeRelease(_pIndexBuffer);
// TODO: create a cube
// vertices
Vertex vertices[] = {
// triangle
//Vertex(0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f), // 0
//Vertex(1.0f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f), // 1
//Vertex(-1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f) // 2
// quad
Vertex(-0.5f, 0.5f, 0.0f, 0.0f, 0.0f),
Vertex(0.5f, 0.5f, 0.0f, 1.0f, 0.0f),
Vertex(0.5f, -0.5f, 0.0f, 1.0f, 1.0f),
Vertex(-0.5f, -0.5f, 0.0f, 0.0f, 1.0f)
};
_vertexCount = std::size(vertices);
_vertexStride = sizeof(Vertex);
// indices
USHORT indices[] = {
// triangles
//0, 1, 2
// quad
0, 1, 2,
0, 2, 3
};
_indexCount = std::size(indices);
UINT error = createVertexBuffer(pD3DDevice, vertices);
CheckError(error);
error = createIndexBuffer(pD3DDevice, indices);
CheckError(error);
return 0;
}
UINT Mesh::createVertexBuffer(ID3D11Device* pD3DDevice, Vertex* vertices)
{
D3D11_BUFFER_DESC desc = {};
desc.ByteWidth = _vertexCount * _vertexStride; // size of the buffer
desc.BindFlags = D3D11_BIND_VERTEX_BUFFER; // buffer type
desc.Usage = D3D11_USAGE_IMMUTABLE; // memory management type
D3D11_SUBRESOURCE_DATA initialData = {};
initialData.pSysMem = vertices;
HRESULT hr = pD3DDevice->CreateBuffer(&desc, &initialData, &_pVertexBuffer);
CheckFailed(hr, 300);
return 0;
}
UINT Mesh::createIndexBuffer(ID3D11Device* pD3DDevice, USHORT* indices)
{
D3D11_BUFFER_DESC desc = {};
desc.ByteWidth = _indexCount * sizeof(USHORT);
desc.BindFlags = D3D11_BIND_INDEX_BUFFER;
desc.Usage = D3D11_USAGE_IMMUTABLE;
D3D11_SUBRESOURCE_DATA initialData = {};
initialData.pSysMem = indices;
HRESULT hr = pD3DDevice->CreateBuffer(&desc, &initialData, &_pIndexBuffer);
CheckFailed(hr, 310);
return 0; return 0;
} }
+8 -2
View File
@@ -1,8 +1,12 @@
#pragma once #pragma once
#include <d3d11.h> #include <d3d11.h>
#include <DirectXMath.h> #include <DirectXMath.h>
#include <string>
#include "Vertex.h"
using namespace DirectX; using namespace DirectX;
using namespace std;
class Mesh class Mesh
{ {
@@ -13,10 +17,12 @@ public:
void deInit(); void deInit();
const XMFLOAT4X4& getWorldMatrix() const { return _worldMatrix; } const XMFLOAT4X4& getWorldMatrix() const { return _worldMatrix; }
UINT loadMeshFromFile(ID3D11Device* pD3DDevice, string filename);
UINT loadDefaultMesh(ID3D11Device* pD3DDevice);
private: private:
UINT createVertexBuffer(ID3D11Device* pD3DDevice); UINT createVertexBuffer(ID3D11Device* pD3DDevice, Vertex* vertices);
UINT createIndexBuffer(ID3D11Device* pD3DDevice); UINT createIndexBuffer(ID3D11Device* pD3DDevice, USHORT* indices);
ID3D11Buffer* _pVertexBuffer = nullptr; // dumps mesh vertices ID3D11Buffer* _pVertexBuffer = nullptr; // dumps mesh vertices
ID3D11Buffer* _pIndexBuffer = nullptr; // dumps mesh indices ID3D11Buffer* _pIndexBuffer = nullptr; // dumps mesh indices
Binary file not shown.
@@ -0,0 +1,14 @@
Texture2D MainTexture;
SamplerState MainSampler;
struct PixelInput
{
float4 position : SV_Position;
float2 uv : TEXCOORD;
float4 color : COLOR;
};
float4 main(PixelInput INPUT) : SV_TARGET
{
return MainTexture.Sample(MainSampler, INPUT.uv) * INPUT.color;
}
Binary file not shown.
@@ -0,0 +1,32 @@
cbuffer MatrixBuffer
{
float4x4 WorldViewProjectionMatrix;
float4x4 WorldMatrix;
//float4 tilingOffset; // option 1
};
struct VertexInput
{
float4 position : POSITION;
float2 uv : TEXCOORD;
float4 color : COLOR;
};
struct VertexOutput
{
float4 position : SV_Position;
float2 uv : TEXCOORD;
float4 color : COLOR;
};
VertexOutput main(VertexInput INPUT)
{
VertexOutput OUTPUT;
OUTPUT.position = mul(INPUT.position, WorldViewProjectionMatrix);
OUTPUT.uv = INPUT.uv;
//OUTPUT.uv = INPUT.uv * float2(1.1f, 1.1f) + float2(-0.05f, -0.05f); // uv * tiling + offset
OUTPUT.color = INPUT.color;
return OUTPUT;
}
+13
View File
@@ -1,12 +1,25 @@
#include "Time.h" #include "Time.h"
#include <string>
UINT Time::init() UINT Time::init()
{ {
_lastTime = CLOCK::now();
return 0; return 0;
} }
void Time::update() void Time::update()
{ {
TIME_POINT now = CLOCK::now();
SECONDS diff = now - _lastTime;
_deltaTime = diff.count();
_lastTime = now;
#if _DEBUG && UNICODE
wstring output = L"delta time: " + to_wstring(_deltaTime) + L"\n";
output += L"fps: " + to_wstring(1.0f / _deltaTime) + L"\n";
OutputDebugString(output.c_str());
#endif // _DEBUG && UNICODE
} }
void Time::deInit() void Time::deInit()
+20
View File
@@ -0,0 +1,20 @@
#pragma once
#include <DirectXMath.h>
using namespace DirectX;
struct Vertex
{
XMFLOAT3 position;
XMFLOAT3 normal;
XMFLOAT4 color;
XMFLOAT2 uv;
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(XMFLOAT3 p) : position(p), 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 r, float g, float b) : position(x, y, z), color(r, g, b, 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) : 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) :
position(x, y, z), normal(nx, ny, nz), uv(u, v), color(1.0f, 1.0f, 1.0f, 1.0f) {}
};
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,141 @@
//--------------------------------------------------------------------------------------
// File: WICTextureLoader11.h
//
// Function for loading a WIC image and creating a Direct3D runtime texture for it
// (auto-generating mipmaps if possible)
//
// Note: Assumes application has already called CoInitializeEx
//
// Warning: CreateWICTexture* functions are not thread-safe if given a d3dContext instance for
// auto-gen mipmap support.
//
// Note these functions are useful for images created as simple 2D textures. For
// more complex resources, DDSTextureLoader is an excellent light-weight runtime loader.
// For a full-featured DDS file reader, writer, and texture processing pipeline see
// the 'Texconv' sample and the 'DirectXTex' library.
//
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
//
// https://go.microsoft.com/fwlink/?LinkId=248926
// http://go.microsoft.com/fwlink/?LinkId=248929
//--------------------------------------------------------------------------------------
#pragma once
#include <d3d11_1.h>
#pragma comment(lib, "dxguid.lib")
#pragma comment(lib, "windowscodecs.lib")
#include <cstddef>
#include <cstdint>
namespace DirectX
{
#ifndef WIC_LOADER_FLAGS_DEFINED
#define WIC_LOADER_FLAGS_DEFINED
enum WIC_LOADER_FLAGS : uint32_t
{
WIC_LOADER_DEFAULT = 0,
WIC_LOADER_FORCE_SRGB = 0x1,
WIC_LOADER_IGNORE_SRGB = 0x2,
WIC_LOADER_SRGB_DEFAULT = 0x4,
WIC_LOADER_FIT_POW2 = 0x20,
WIC_LOADER_MAKE_SQUARE = 0x40,
WIC_LOADER_FORCE_RGBA32 = 0x80,
};
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-dynamic-exception-spec"
#pragma clang diagnostic ignored "-Wextra-semi-stmt"
#endif
DEFINE_ENUM_FLAG_OPERATORS(WIC_LOADER_FLAGS);
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#endif
// Standard version
HRESULT CreateWICTextureFromMemory(_In_ ID3D11Device* d3dDevice,
_In_reads_bytes_(wicDataSize) const uint8_t* wicData,
_In_ size_t wicDataSize,
_Outptr_opt_ ID3D11Resource** texture,
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
_In_ size_t maxsize = 0) noexcept;
HRESULT CreateWICTextureFromFile(_In_ ID3D11Device* d3dDevice,
_In_z_ const wchar_t* szFileName,
_Outptr_opt_ ID3D11Resource** texture,
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
_In_ size_t maxsize = 0) noexcept;
// Standard version with optional auto-gen mipmap support
HRESULT CreateWICTextureFromMemory(_In_ ID3D11Device* d3dDevice,
_In_opt_ ID3D11DeviceContext* d3dContext,
_In_reads_bytes_(wicDataSize) const uint8_t* wicData,
_In_ size_t wicDataSize,
_Outptr_opt_ ID3D11Resource** texture,
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
_In_ size_t maxsize = 0) noexcept;
HRESULT CreateWICTextureFromFile(_In_ ID3D11Device* d3dDevice,
_In_opt_ ID3D11DeviceContext* d3dContext,
_In_z_ const wchar_t* szFileName,
_Outptr_opt_ ID3D11Resource** texture,
_Outptr_opt_ ID3D11ShaderResourceView** textureView,
_In_ size_t maxsize = 0) noexcept;
// Extended version
HRESULT CreateWICTextureFromMemoryEx(_In_ ID3D11Device* d3dDevice,
_In_reads_bytes_(wicDataSize) const uint8_t* wicData,
_In_ size_t wicDataSize,
_In_ size_t maxsize,
_In_ D3D11_USAGE usage,
_In_ unsigned int bindFlags,
_In_ unsigned int cpuAccessFlags,
_In_ unsigned int miscFlags,
_In_ WIC_LOADER_FLAGS loadFlags,
_Outptr_opt_ ID3D11Resource** texture,
_Outptr_opt_ ID3D11ShaderResourceView** textureView) noexcept;
HRESULT CreateWICTextureFromFileEx(_In_ ID3D11Device* d3dDevice,
_In_z_ const wchar_t* szFileName,
_In_ size_t maxsize,
_In_ D3D11_USAGE usage,
_In_ unsigned int bindFlags,
_In_ unsigned int cpuAccessFlags,
_In_ unsigned int miscFlags,
_In_ WIC_LOADER_FLAGS loadFlags,
_Outptr_opt_ ID3D11Resource** texture,
_Outptr_opt_ ID3D11ShaderResourceView** textureView) noexcept;
// Extended version with optional auto-gen mipmap support
HRESULT CreateWICTextureFromMemoryEx(_In_ ID3D11Device* d3dDevice,
_In_opt_ ID3D11DeviceContext* d3dContext,
_In_reads_bytes_(wicDataSize) const uint8_t* wicData,
_In_ size_t wicDataSize,
_In_ size_t maxsize,
_In_ D3D11_USAGE usage,
_In_ unsigned int bindFlags,
_In_ unsigned int cpuAccessFlags,
_In_ unsigned int miscFlags,
_In_ WIC_LOADER_FLAGS loadFlags,
_Outptr_opt_ ID3D11Resource** texture,
_Outptr_opt_ ID3D11ShaderResourceView** textureView) noexcept;
HRESULT CreateWICTextureFromFileEx(_In_ ID3D11Device* d3dDevice,
_In_opt_ ID3D11DeviceContext* d3dContext,
_In_z_ const wchar_t* szFileName,
_In_ size_t maxsize,
_In_ D3D11_USAGE usage,
_In_ unsigned int bindFlags,
_In_ unsigned int cpuAccessFlags,
_In_ unsigned int miscFlags,
_In_ WIC_LOADER_FLAGS loadFlags,
_Outptr_opt_ ID3D11Resource** texture,
_Outptr_opt_ ID3D11ShaderResourceView** textureView) noexcept;
} // namespace DirectX
Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

+17 -1
View File
@@ -36,6 +36,9 @@ int WINAPI WinMain(
Mesh mesh = {}; Mesh mesh = {};
error = mesh.init(d3d.getDevice()); error = mesh.init(d3d.getDevice());
CheckError(error); CheckError(error);
//error = mesh.loadDefaultMesh(d3d.getDevice());
error = mesh.loadMeshFromFile(d3d.getDevice(), "ship-pirate-large.fbx");
CheckError(error);
// 4. create a camera // 4. create a camera
Camera camera = {}; Camera camera = {};
@@ -49,12 +52,25 @@ int WINAPI WinMain(
// 6. create a material // 6. create a material
Material material = {}; Material material = {};
error = material.init(d3d.getDevice(), TEXT("wall.jpg")); error = material.init(d3d.getDevice(), TEXT("colormap.png"));
CheckError(error); CheckError(error);
// 7. create light source // 7. create light source
Light light = {}; Light light = {};
Light::LightBuffer lightData = {}; Light::LightBuffer lightData = {};
// directional light
lightData.LightVector = { -1.0f, -1.0f, 1.0f };
// point light
lightData.LightPosition = { -50.0f, 400.0f, 0.0f };
lightData.LightAttenuation = { 1.0f, 0.3f, 0.1f };
lightData.LightIntensity = 1000.0f;
lightData.DiffuseColor = { 1.0f, 1.0f, 1.0f, 1.0f };
lightData.SpecularColor = { 0.2f, 0.2f, 0.2f, 1.0f };
lightData.Phong = 8.0f;
lightData.CameraPosition = camera.getCameraPosition();
error = light.init(d3d.getDevice(), lightData); error = light.init(d3d.getDevice(), lightData);
CheckError(error); CheckError(error);
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Assimp.redist" version="3.0.0" targetFramework="native" />
</packages>
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 213 KiB

@@ -0,0 +1,14 @@
{
"default-registry": {
"kind": "git",
"baseline": "3af1d1e60af2b2abf55760538cd607829029b07a",
"repository": "https://github.com/microsoft/vcpkg"
},
"registries": [
{
"kind": "artifact",
"location": "https://github.com/microsoft/vcpkg-ce-catalog/archive/refs/heads/main.zip",
"name": "microsoft"
}
]
}
+5
View File
@@ -0,0 +1,5 @@
{
"dependencies": [
"assimp"
]
}
Binary file not shown.