정의
GPU의 렌더링 파이프라인에서 렌더링 동작을 제어하는 설정들의 집합니다. 렌더 상태를 통해 드로우 콜이 수행될 때 픽셀이 어떻게 그려지고, 어떤 방식으로 깊이 테스트나 블렌딩, 래스터라이징이 이루어질지 등을 제어할 수 있다.
1. Rasterizer State (D3D11RasterizerState)
- 폴리곤을 어떻게 래스터화(화면에 점으로 변환)할지를 설정한다.
| 속성 | 설명 |
|---|
CullMode | 컬링 방식 (D3D11_CULL_NONE, D3D11_CULL_BACK, D3D11_CULL_FRONT) |
FillMode | 면 채우기 방식 (D3D11_FILL_SOLID, D3D11_FILL_WIREFRAME) |
FrontCounterClockwise | 앞면을 반시계로 판단할지 여부 |
DepthClipEnable | 깊이 클리핑 사용 여부 |
예제
D3D11_RASTERIZER_DESC rasterDesc = {};
rasterDesc.FillMode = D3D11_FILL_SOLID;
rasterDesc.CullMode = D3D11_CULL_BACK;
rasterDesc.FrontCounterClockwise = false;
ID3D11RasterizerState* rasterState;
device->CreateRasterizerState(&rasterDesc, &rasterState);
deviceContext->RSSetState(rasterState);
2. Depth-Stencil State (ID3D11DepthStencilState)
| 속성 | 설명 |
|---|
DepthEnable | 깊이 테스트 사용 여부 |
DepthFunc | 깊이 비교 함수 (LESS, GREATER, LEQUAL 등) |
StencilEnable | 스텐실 테스트 사용 여부 |
StencilReadMask, StencilWriteMask | 스텐실 마스크 설정 |
예제
D3D11_DEPTH_STENCIL_DESC depthStencilDesc = {};
depthStencilDesc.DepthEnable = true;
depthStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
depthStencilDesc.DepthFunc = D3D11_COMPARISON_LESS;
ID3D11DepthStencilState* depthState;
device->CreateDepthStencilState(&depthStencilDesc, &depthState);
deviceContext->OMSetDepthStencilState(depthState, 1);
3. Blend State (ID3D11BlendState)
- 픽셀 색상과 프레임버퍼의 색상을 혼합할지 여부를 제어한다.
| 속성 | 설명 |
|---|
BlendEnable | 블렌딩 활성화 여부 |
SrcBlend, DestBlend | 소스/목적지 블렌딩 방식 |
BlendOp | 블렌딩 연산 방식 (ADD, SUBTRACT 등) |
RenderTargetWriteMask | 어떤 색상 채널에 쓸지 지정 (RGBA 마스크) |
예제
D3D11_BLEND_DESC blendDesc = {};
blendDesc.RenderTarget[0].BlendEnable = true;
blendDesc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
blendDesc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
blendDesc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
blendDesc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
ID3D11BlendState* blendState;
device->CreateBlendState(&blendDesc, &blendState);
float blendFactor[4] = { 0, 0, 0, 0 };
deviceContext->OMSetBlendState(blendState, blendFactor, 0xffffffff);
4. Sampler State (ID3D11SamplerState)
- 텍스처 샘플링 시 필터링 및 래핑 방식을 정의한다.
| 속성 | 설명 |
|---|
Filter | 필터링 방식 (Point, Linear, Anisotropic 등) |
AddressU/V/W | 텍스처 좌표가 경계를 넘었을 때 래핑 방식 (Wrap, Clamp 등) |
예제
D3D11_SAMPLER_DESC samplerDesc = {};
samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
ID3D11SamplerState* samplerState;
device->CreateSamplerState(&samplerDesc, &samplerState);
deviceContext->PSSetSamplers(0, 1, &samplerState);