TextureBuffer
GPU에 텍스처를 전달하여 렌더링 해준다. UI나 포스트 프로세싱에 사용한다고 하는데 아직까지는 잘 모르겠다 허헣….
일단 2D 렌더링 할게 필요한데 만드는 방법은 크게 어렵지 않기 때문에 넘어간다. (점 6개 찍고 이어주는게 끝이다)
Shader
Texture2DArray<float4> Input;
RWTexture2DArray<float4> Output;
// 1024가 최대
[numthreads(32,32,1)]
void CS(uint3 id : SV_DispatchThreadID)
{
float4 color = Input.Load(int4(id, 0));
//Output[id] = 1.0f - color;
Output[id] = (color.r + color.g + color.b) / 3;
//Output[id] = color;
}
technique11 T0
{
pass P0
{
SetVertexShader(NULL);
SetPixelShader(NULL);
SetComputeShader(CompileShader(cs_5_0, CS()));
}
}
GPU에서 받을 쉐이더이다. 왜 32개로 잘랐냐면, 각 칸을 32로 계산했을 때, GPU에 넘겨줄 최대 크기인 1024가 되기 때문이다.
ID를 받아서 각 부분마다 위에서 차례대로 반전, 흑백, 원래 색상 표현해준다.
TextureBufferDemo
void TextureBufferDemo::Initialize()
{
Shader* shader = new Shader(L"62_TextureBuffer.fx");
texture = new Texture(L"Environment/Compute.png");
render2D = new Render2D();
render2D->GetTransform()->Scale(D3D::Width(), D3D::Height(), 1);
render2D->GetTransform()->Position(D3D::Width() * 0.5f, D3D::Height() * 0.5f, 0);
textureBuffer = new TextureBuffer(texture->GetTexture());
shader->AsSRV("Input")->SetResource(textureBuffer->SRV());
shader->AsUAV("Output")->SetUnorderedAccessView(textureBuffer->UAV());
UINT width = textureBuffer->Width();
UINT height = textureBuffer->Height();
UINT arraySize = textureBuffer->ArraySize();
float x = ((float)width / 32) < 1.0f ? 1.0f : ((float)width / 32);
float y = ((float)height / 32) < 1.0f ? 1.0f : ((float)height / 32);
shader->Dispatch(0, 0, (UINT)ceilf(x), (UINT)ceilf(y), arraySize);
render2D->SRV(textureBuffer->OutputSRV());
}
현재 화면에 맞게 2D Texture를 출력해준다. 그리고 Shader안에 있는 Dispatch를 통해 값을 보내준다.
이렇게 하면
생각한 대로 잘 나온다.