Added: mesh transformation

Added: input
Added: texture shader
This commit is contained in:
2026-10-13 18:30:21 +02:00
parent d2a487a4f6
commit 13691e3da3
14 changed files with 1371 additions and 20 deletions
+35 -3
View File
@@ -1,5 +1,6 @@
#include "Material.h"
#include "Utilities.h"
#include "WICTextureLoader11.h"
UINT Material::init(ID3D11Device* pD3DDevice, LPCWSTR textureFileName)
{
@@ -32,6 +33,9 @@ void Material::render(ID3D11DeviceContext* pD3DDeviceContext)
// 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()
@@ -94,7 +98,8 @@ UINT Material::createVertexShader(ID3D11Device* pD3DDevice)
//);
// option 2: load compiled shader from disk
hr = D3DReadFileToBlob(L"ColorVertexShader.cso", &pCompiledShaderCode);
//hr = D3DReadFileToBlob(L"ColorVertexShader.cso", &pCompiledShaderCode);
hr = D3DReadFileToBlob(L"TextureVertexShader.cso", &pCompiledShaderCode);
CheckFailed(hr, 600);
@@ -121,7 +126,8 @@ UINT Material::createPixelShader(ID3D11Device* pD3DDevice)
{
ID3DBlob* pCompiledShaderCode = nullptr;
HRESULT hr = D3DReadFileToBlob(L"ColorPixelShader.cso", &pCompiledShaderCode);
//HRESULT hr = D3DReadFileToBlob(L"ColorPixelShader.cso", &pCompiledShaderCode);
HRESULT hr = D3DReadFileToBlob(L"TexturePixelShader.cso", &pCompiledShaderCode);
CheckFailed(hr, 620);
hr = pD3DDevice->CreatePixelShader(pCompiledShaderCode->GetBufferPointer(), pCompiledShaderCode->GetBufferSize(), nullptr, &_pPixelShader);
@@ -134,7 +140,7 @@ UINT Material::createPixelShader(ID3D11Device* pD3DDevice)
UINT Material::createInputLayout(ID3D11Device* pD3DDevice, ID3DBlob* pCompiledVertexShaderCode)
{
D3D11_INPUT_ELEMENT_DESC elements[2] = {};
D3D11_INPUT_ELEMENT_DESC elements[3] = {};
// position
elements[0].SemanticName = "POSITION";
@@ -145,6 +151,11 @@ UINT Material::createInputLayout(ID3D11Device* pD3DDevice, ID3DBlob* pCompiledVe
elements[1].Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
elements[1].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
// uv
elements[2].SemanticName = "TEXCOORD";
elements[2].Format = DXGI_FORMAT_R32G32_FLOAT;
elements[2].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
HRESULT hr = pD3DDevice->CreateInputLayout(
elements, // array of input layout elements
std::size(elements), // count of elements
@@ -172,5 +183,26 @@ UINT Material::createMatrixBuffer(ID3D11Device* pD3DDevice)
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;
}