I have a texture problem with the cubemap I'm rendering and can't seem to figure it out. I've generated a cube map with direct x's texture tools and then read it using

D3DX11CreateShaderResourceViewFromFile(device, L"cubemap.dds", 0, 0, &fullcubemap, 0);

The cubemap texture is not high quality at all and it looks really stretched/distorted. I can definitely tell that the images used for the cubemap match correctly, but it's not great at all at the moment

enter image description here

I'm not sure why this is happening. Is it because my textures are too large/small or is it something else? If it's due to the size of the textures, what is a recommended texture size? I am using a sphere for the cubemap not a cube.



cbuffer SkyboxConstantBuffer {
    float4x4 world;
    float4x4 view;
    float4x4 projection;

TextureCube gCubeMap;

SamplerState samTriLinearSam {
    Filter = MIN_MAG_MIP_LINEAR;
    AddressU = Wrap;
    AddressV = Wrap;

struct VertexIn {
    float4 position : POSITION;

struct VertexOut {
    float4 position : SV_POSITION;
    float4 spherePosition : POSITION;

VertexOut VS(VertexIn vin) {
    VertexOut vout = (VertexOut)0;

    vin.position.w = 1.0f;

    vout.position = mul(vin.position, world);
    vout.position = mul(vout.position, view);
    vout.position = mul(vout.position, projection);

    vout.spherePosition = vin.position;

    return vout;

float4 PS(VertexOut pin) : SV_Target {
    return gCubeMap.Sample(samTriLinearSam, pin.spherePosition);//float4(1.0, 0.5, 0.5, 1.0);

RasterizerState NoCull {
    CullMode = None;

DepthStencilState LessEqualDSS {
    DepthFunc = LESS_EQUAL;

technique11 SkyTech {
    pass p0 {
        SetVertexShader(CompileShader(vs_4_0, VS()));
        SetPixelShader(CompileShader(ps_4_0, PS()));

        SetDepthStencilState(LessEqualDSS, 0);


immediateContext->OMSetRenderTargets(1, &renderTarget, nullptr);

XMMATRIX sworld, sview, sprojection;
SkyboxConstantBuffer scb;
sview = XMLoadFloat4x4(&_view);
sprojection = XMLoadFloat4x4(&_projection);
sworld = XMLoadFloat4x4(&_world);

scb.world = sworld;
scb.view = sview;
scb.projection = sprojection;

immediateContext->IASetIndexBuffer(cubeMapSphere->getIndexBuffer(), DXGI_FORMAT_R32_UINT, 0);
ID3D11Buffer*  vertexBuffer = cubeMapSphere->getVertexBuffer();
//ID3DX11EffectShaderResourceVariable * cMap;
////cMap = skyboxShader->GetVariableByName("gCubeMap")->AsShaderResource();
immediateContext->PSSetShaderResources(0, 1, &fullcubemap);//textures
immediateContext->IASetVertexBuffers(0, 1, &vertexBuffer, &stride, &offset);
immediateContext->VSSetShader(skyboxVertexShader, nullptr, 0);
immediateContext->VSSetConstantBuffers(0, 1, &skyboxConstantBuffer);
immediateContext->PSSetConstantBuffers(0, 1, &skyboxConstantBuffer);
immediateContext->PSSetShader(skyboxPixelShader, nullptr, 0);

immediateContext->UpdateSubresource(skyboxConstantBuffer, 0, nullptr, &scb, 0, 0);
immediateContext->DrawIndexed(cubeMapSphere->getIndexBufferSize(), 0, 0);

Initially I was planning to use this snippet to update the TextureCube variable in the shader

ID3DX11EffectShaderResourceVariable * cMap;
cMap = skyboxShader->GetVariableByName("gCubeMap")->AsShaderResource();

But it seems that has no effect, and in fact, without the following line, the sphere I'm using for the cubemap textures with a texture used with another object in the scene, so perhaps there's something going on here? I'm not sure what though.

immediateContext->PSSetShaderResources(0, 1, &fullcubemap);//textures

Edit: Probably not the above, realised that if this wasn't updated, the old texture would be applied as it's never wiped after each draw.

Edit: Tried the cubemap with both a sphere and a cube, still the same texture issue.

Edit: Tried loading the shader resource view differently


ID3D11Texture2D* SMTexture = 0;
hr = D3DX11CreateTextureFromFile(device, L"cubemap.dds",
    &loadSMInfo, 0, (ID3D11Resource**)&SMTexture, 0);


SMViewDesc.Format = SMTextureDesc.Format;
SMViewDesc.TextureCube.MipLevels = SMTextureDesc.MipLevels;
SMViewDesc.TextureCube.MostDetailedMip = 0;

hr = device->CreateShaderResourceView(SMTexture, &SMViewDesc, &fullcubemap);

Still produces the same output, any ideas?

Edit: Tried increasing the zfar distance and the texture remains the exact same no matter what value I put.

Example with second texture with increased view distance. enter image description here

This texture is used on another object in my scene and comes out fine.

  • 1
    \$\begingroup\$ Two possibilities come to mind: 1) your shader or render state are reading from a very small mip level of the texture or 2) you're using an orthographic camera or very narrow fov which tends to exaggerate the apparent scale of distant objects (like a sky at infinity). Can you give more details about your rendering/shader setup so we can diagnose this in more detail? \$\endgroup\$
    – DMGregory
    Jan 1, 2016 at 22:02
  • \$\begingroup\$ Thanks for the reply. I have updated my post with my shader and draw code, if there's anything else that you need to see just let me know. \$\endgroup\$
    – user
    Jan 1, 2016 at 22:10
  • \$\begingroup\$ Still no luck, tried a few things and it still comes out the same. Any ideas? \$\endgroup\$
    – user
    Jan 2, 2016 at 1:04
  • \$\begingroup\$ Is the sphere you're rendering centred at the origin in local space? The parameter you pass for sampling the cubemap should be a direction. \$\endgroup\$
    – Adam
    Jan 4, 2016 at 23:56
  • \$\begingroup\$ @Adam I believe so. Is it not currently taking a direction? The texturing I believe is fine, it's just really zoomed in. If I could somehow move it further away it would look fine. \$\endgroup\$
    – user
    Jan 5, 2016 at 0:46

1 Answer 1


It turned out to be that I needed to use XMMatrixTranspose


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .