Hi, I've been trying to implement a skybox for some time now and there's probably only a tiny problem left to solve. When I load a texture using DirectXTK's CreateDDSTextureFromFileEx with a TEXTURECUBE flag, the resulting shader resource has its view dimension set to Texture2D and not TextureCube, which means I can't treat it as a TextureCube in HLSL. Also the file I'm loading contains all six faces. Here's snippets of my code where I load the texture, set the shader resource view to the pixel shader and then sample it in HLSL:
// Loading the texture
HRESULT hr = DirectX::CreateDDSTextureFromFileEx(device, filename, 0, D3D11_USAGE_IMMUTABLE, D3D11_BIND_SHADER_RESOURCE,
0, D3D11_RESOURCE_MISC_TEXTURECUBE, false, &texture, &mSkyboxSRV);
// Setting the texture
DeviceContext->PSSetShaderResources(0, 1, mSkybox->GetSkyboxSRV());
// HLSL: Sampling the texture
TextureCube skyboxTexture : register(t0);
SamplerState sampWrap : register(s0);
struct PS_IN
{
float4 Pos : SV_POSITION;
float3 lookVector : TEXCOORD0;
};
float4 PS_main(PS_IN input) : SV_TARGET
{
return skyboxTexture.Sample(sampWrap, input.lookVector);
}
This is the error message being output by DirectX:
D3D11 ERROR: ID3D11DeviceContext::Draw: The Shader Resource View dimension declared in the shader code (TEXTURECUBE) does not match the view type bound to slot 0 of the Pixel Shader unit (TEXTURE2D). This mismatch is invalid if the shader actually uses the view (e.g. it is not skipped due to shader code branching). [ EXECUTION ERROR #354: DEVICE_DRAW_VIEW_DIMENSION_MISMATCH]
Does anyone have any ideas on what to do? Any help is much appreciated!