0
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ Your comment says "vertex shader" but you've actually posted your pixel shader; can you post your actual vertex shader please? There is most likely an issue with the position you pass from it to the pixel shader. \$\endgroup\$ Apr 12 '18 at 9:29
  • \$\begingroup\$ @MaximusMinimus Sorry, my mistake, I edited the post \$\endgroup\$
    – Luca
    Apr 12 '18 at 9:35
2
\$\begingroup\$

I found my error. The vertex shader outputs the homogeneous clip coordinates with SV_POSITION semantic before the model space position with POSITION semantic. The Pixel shader reads the input position from the first register so I was sampling the texture cube map using clip space coordinates, hence I was always facing the same direction. I was ignoring the warning from the compiler.

\$\endgroup\$

You must log in to answer this question.

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