C++ Algorithm & Study/Game Math & DirectX 11
[Direct11] 18. EX App Program - Texture Box
GameChoi
2023. 6. 16. 20:43
1. EX App Program
1.1 Texture Box
1.1.1 Texture Pos & Create
- 밑의 함수는 Texture 이미지 전체가 입방체의 각 면에 입혀지도록 Texture 좌표들을 적절히 설정
void GeometryGenerator::CreateBox(float width, float height, float depth, MeshData& meshData);
- 함수의 내용을 잠깐 보자면 입방체의 앞면일 경우 앞면 정점 자료를 채움
float w2 = 0.5f*width; float h2 = 0.5f*height; float d2 = 0.5f*depth;
v[0] = Vertex(-w2, -h2, -d2, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f);
v[1] = Vertex(-w2, +h2, -d2, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f);
v[2] = Vertex(+w2, +h2, -d2, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f);
v[3] = Vertex(+w2, -h2, -d2, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f);
- 이전 글에서 사용한 Texture를 생성하는 방식으로 이미지를 불러온 후 SRV를 통해 이미지를 저장
- 이후 Effect File에 있는 Texture2D의 주소를 받아 데이터 저장
HRESULT hr = ::LoadFromWICFile(L"../Resources/Textures/WoodCrate01.dds",
WIC_FLAGS_NONE, &md, img);
hr = ::CreateShaderResourceView(_device.Get(),
img.GetImages(), img.GetImageCount(), md, _diffuseMapSRV.GetAddressOf());
1.1.2 Effect File
- 응용프로그램을 비등방 필터링을 적용하고 순환 모드 적용
SamplerState samAnisotropic
{
Filter = ANISOTROPIC; MaxAnisotropy = 4;
AddressU = WRAP; AddressV = WRAP;
};
- 정점 셰이더로 부터 전달된 데이터로 부터 색상을 필터를 적용시켜 색 지정
float4 PS(VertexOut pin, uniform int gLightCount, uniform bool gUseTexure) : SV_Target
{
// ...
float4 texColor = float4(1, 1, 1, 1);
if (gUseTexure) { texColor = gDiffuseMap.Sample(samAnisotropic, pin.Tex); }
// ...
}
- 마지막으로 조명에 의해 변경된 색상 또한 계산을 한 후 색을 입힘
// 조명 계산...
litColor = texColor * (ambient + diffuse) + spec; litColor.a = gMaterial.Diffuse.a * texColor.a;
- 나머지 코드는 예제 프로그램의 초기 방식을 사용
[Direct11] 11. EX App Program - Color Box
1. EX App Program 1.1 Color Box 1.1.1 Geometry Buffer - 색상이 있는 박스를 생성하기 위해 각 정점에 대해 좌표 및 색상 적용 Vertex vertices[] = { { XMFLOAT3(-1.0f, -1.0f, -1.0f), XMFLOAT4((const float*)&Colors::White) }, { XMFLOAT3
choiprogramming.tistory.com