我目前正在实现漫射灌溉(基于图像的闪电PBR)在我的游戏引擎中。我到了一个点,我必须采取一个HDR图像,并把它变成一个立方体地图。我目前使用的EquirectangularToCubemap着色器和它的工作罚款。我能够将HDR映像投影到一个(单位)立方体上。现在是我被卡住的部分,我不能把这个立方体变成一个cubemap。我尝试使用ShaderResourceView.和1 TextureCube,6 RenderTargetView's,我的计划是用90的FOV从不同的视图投影渲染6次(单元)立方体,以捕捉每个渲染目标中的整个边,最后将渲染目标的每个输出复制到纹理立方体的对应侧。我不知道如何做到这一点。
注意:--我使用DirextX11作为呈现后端。下面是关于我的问题的伪代码(不起作用)
glm::mat4 captureProjection = glm::perspective(glm::radians(90.0f), 1.0f, 0.1f, 10.0f);
glm::mat4 captureViews[] =
{
glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(0.0f, -1.0f, 0.0f)),
glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(-1.0f, 0.0f, 0.0f), glm::vec3(0.0f, -1.0f, 0.0f)),
glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f)),
glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, -1.0f, 0.0f), glm::vec3(0.0f, 0.0f, -1.0f)),
glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f), glm::vec3(0.0f, -1.0f, 0.0f)),
glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, -1.0f), glm::vec3(0.0f, -1.0f, 0.0f))
};
//Create the TextureCube
D3D11_TEXTURE2D_DESC textureDesc = {};
textureDesc.Width = 512;
textureDesc.Height = 512;
textureDesc.MipLevels = 1;
textureDesc.ArraySize = 6;
textureDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
textureDesc.CPUAccessFlags = 0;
textureDesc.SampleDesc.Count = 1;
textureDesc.SampleDesc.Quality = 0;
textureDesc.Usage = D3D11_USAGE_DEFAULT;
textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
textureDesc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE;
ID3D11Texture2D* tex = nullptr;
DX_CALL(DX11Internal::GetDevice()->CreateTexture2D(&textureDesc, nullptr, &tex));
// Create the Shader Resource view for the texture cube
D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
srvDesc.Format = textureDesc.Format;
srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE;
srvDesc.Texture2D.MostDetailedMip = 0;
srvDesc.Texture2D.MipLevels = 1;
DX_CALL(DX11Internal::GetDevice()->CreateShaderResourceView(tex, &srvDesc, &mSRV));
//Create the Render target views
Vector<ID3D11RenderTargetView*> rtvs;
for (Uint i = 0; i < 6; i++)
{
D3D11_RENDER_TARGET_VIEW_DESC renderTargetViewDesc = {};
renderTargetViewDesc.Format = textureDesc.Format;
renderTargetViewDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
renderTargetViewDesc.Texture2D.MipSlice = 0;
ID3D11RenderTargetView* view = nullptr;
DX11Internal::GetDevice()->CreateRenderTargetView(tex, &renderTargetViewDesc, &view);
rtvs.push_back(view);
}
tex->Release();
auto deviceContext = DX11Internal::GetDeviceContext();
for (Uint i = 0; i < 6; ++i)
{
float clearColor[4] = { 1.0f, 0.1f, 0.1f, 1.0f };
deviceContext->ClearRenderTargetView(rtvs[i], clearColor);
Vault::Get<Shader>("EquirectangularToCubemap.hlsl")->Bind();
auto data = captureProjection * captureViews[i];
cbuffer->Bind();
cbuffer->SetData(&data);
texture->Bind(0);
tempPipeline->Bind();
deviceContext->OMSetRenderTargets(1, &rtvs[i], nullptr);
//I am rendering the cube here from different view projection to capture the faces, but I dont't know where to copy the data to the //side of the TextureCube :( [Note that I am doing this only once]
RenderCommand::DrawIndexed(tempPipeline, 36);
}提前感谢!
发布于 2021-05-26 12:46:28
在创建呈现视图时,您没有指定要写入哪些片。切片的正确描述是:
D3D11_RENDER_TARGET_VIEW_DESC renderTargetViewDesc = {};
renderTargetViewDesc.Format = textureDesc.Format;
renderTargetViewDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
renderTargetViewDesc.Texture2DArray.MipSlice = 0;
renderTargetViewDesc.Texture2DArray.FirstArraySlice =i;
renderTargetViewDesc.Texture2DArray.ArraySize = 1;(注:如果您使用MSAA,ViewDimension将成为D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY)
另外,要为资源创建着色器视图,因为您想要创建默认视图,所以可以传递NULL,而不是一个自制的D3D11_SHADER_RESOURCE_VIEW_DESC。
DX_CALL(DX11Internal::GetDevice()->CreateShaderResourceView(tex, NULL, &mSRV));您还可以创建另一个呈现视图,该视图一次性映射整个多维数据集映射:
DX11Internal::GetDevice()->CreateRenderTargetView(tex, NULL, &cubeMapFullView);但是在这种情况下,您需要使用几何图形着色器来跨片复制几何图形(使用SV_RenderTargetArrayIndex),或者使用特定于供应商的扩展来提供相同的特性。
https://stackoverflow.com/questions/67145557
复制相似问题