I'm trying to render a skybox with a cubemap on it and to do so I'm using DDS Texture Loader from DirectXTex library. I use texassemble to generate the cubemap (texture array of 6 textures) into a DDS file that I load at runtime. I generated a cube "dome" and sample the texture using the position vector of the vertex as the sample coordinates (so far so good), but I always get the same face of the cubemap mapped on the sky. As I look around I always get the same face (and it wobbles a bit if I move the camera). My code:
//Texture.cpp:
Texture::Texture(const wchar_t *textureFilePath, const std::string &textureType) : mType(textureType)
{
//CreateDDSTextureFromFile(Game::GetInstance()->GetDevice(), Game::GetInstance()->GetDeviceContext(), textureFilePath, &mResource, &mShaderResourceView);
CreateDDSTextureFromFileEx(Game::GetInstance()->GetDevice(), Game::GetInstance()->GetDeviceContext(), textureFilePath, 0, D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, D3D11_RESOURCE_MISC_TEXTURECUBE, false, &mResource, &mShaderResourceView);
}
// SkyBox.cpp:
void SkyBox::Draw()
{
// set cube map
ID3D11ShaderResourceView *resource = mTexture.GetResource();
Game::GetInstance()->GetDeviceContext()->PSSetShaderResources(0, 1, &resource);
// set primitive topology
Game::GetInstance()->GetDeviceContext()->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
mMesh.Bind();
mMesh.Draw();
}
// Vertex Shader:
cbuffer Transform : register(b0)
{
float4x4 viewProjectionMatrix;
};
float4 main(inout float3 pos : POSITION) : SV_POSITION
{
return mul(float4(pos, 1.0f), viewProjectionMatrix);
}
// Pixel Shader:
SamplerState cubeSampler;
TextureCube cubeMap;
float4 main(in float3 pos : POSITION) : SV_TARGET
{
float4 color = cubeMap.Sample(cubeSampler, pos.xyz);
return color;
}
I tried both functions grom DDS loader but I keep getting the same result. All results I found on the web are about the old SDK toolkits, but I'm using the new DirectXTex lib.