0
\$\begingroup\$

I'm attempting to create a skybox and I'm currently having some issues with the texture where it looks like this: enter image description here

It seems the textures are not really "sticking to their sides" correctly as it looks like different sides are blending with each other. I'm guessing this at least but it's basically a jumbled mess of textures and I'm honestly not sure why. I feel like I may of messed up my code as it's been a pain to get this working, so I'd love to know if I have.

Firstly I load in a basic cube model and as well load in the skybox texture using CreateDDSTextureFromFileEx from DirectXTK.

hr = CreateDDSTextureFromFileEx(Graphics::GetGraphics()->GetD3DDevice(), L"Skybox.dds", 0, D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, D3D11_RESOURCE_MISC_TEXTURECUBE, false, nullptr, &texture);

I then as well create the samplerLinear

    D3D11_SAMPLER_DESC sampDesc;
    ZeroMemory(&sampDesc, sizeof(sampDesc));
    sampDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
    sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
    sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
    sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
    sampDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
    sampDesc.MinLOD = 0;
    sampDesc.MaxLOD = D3D11_FLOAT32_MAX;

    Graphics::GetGraphics()->GetD3DDevice()->CreateSamplerState(&sampDesc, &samplerLinear);

I then just render everything using this:

// Set the input layout
    Graphics::GetGraphics()->GetImmediateContext()->IASetInputLayout(newVertexLayout);

    Graphics::GetGraphics()->GetImmediateContext()->IASetVertexBuffers(0, 1, &mesh->GetMeshData()->VertexBuffer, &mesh->GetMeshData()->VBStride, &mesh->GetMeshData()->VBOffset);
    Graphics::GetGraphics()->GetImmediateContext()->IASetIndexBuffer(mesh->GetMeshData()->IndexBuffer, DXGI_FORMAT_R16_UINT, 0);

    Graphics::GetGraphics()->GetImmediateContext()->VSSetConstantBuffers(0, 1, &shader->constantBuffer);
    Graphics::GetGraphics()->GetImmediateContext()->PSSetConstantBuffers(0, 1, &shader->constantBuffer);
    Graphics::GetGraphics()->GetImmediateContext()->PSSetShaderResources(0, 1, &texture);
    Graphics::GetGraphics()->GetImmediateContext()->PSSetSamplers(0, 1, &samplerLinear);

    Graphics::GetGraphics()->GetImmediateContext()->VSSetShader(shader->vertexShader, nullptr, 0);
    Graphics::GetGraphics()->GetImmediateContext()->PSSetShader(shader->pixelShader, nullptr, 0);

    Graphics::GetGraphics()->GetImmediateContext()->OMSetDepthStencilState(depthStencil, 0);
    Graphics::GetGraphics()->GetImmediateContext()->RSSetState(rasterState);

    shader->Update(_world);

    Graphics::GetGraphics()->GetImmediateContext()->DrawIndexed(mesh->GetMeshData()->IndexCount, 0, 0); //If you change the number of indices, you've got to change the 6 as well to the new number of indices

    Graphics::GetGraphics()->GetImmediateContext()->OMSetDepthStencilState(NULL, 0);
    Graphics::GetGraphics()->GetImmediateContext()->RSSetState(NULL);

The shader object I doesn't really have much that I imagine is worth noting. It pretty much just holds the constantbuffer, vertex and pixel shaders. Updating it then just updates the constant buffer.

I am also setting a new input layer as I found some sources when attempting to get my skybox working that I needed a different inputlayout to the one I had originally but I wasn't sure what exactly I needed so I just have this:

HRESULT hr;

    D3D11_INPUT_ELEMENT_DESC newLayout[] =
    {
        { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
        { "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
        { "TEXCOORD", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
    };

    UINT numElements = ARRAYSIZE(newLayout);

    // Create the input layout
    hr = Graphics::GetGraphics()->GetD3DDevice()->CreateInputLayout(newLayout, numElements, shader->pVSBlob->GetBufferPointer(),
        shader->pVSBlob->GetBufferSize(), &newVertexLayout);
    shader->pVSBlob->Release();

    if (FAILED(hr))
        return hr;

    return hr;

The skybox shader itself is nothing special:

TextureCube skyMap : register(t0);
SamplerState samLinear : register(s0);

//--------------------------------------------------------------------------------------
// Constant Buffer Variables
//--------------------------------------------------------------------------------------
cbuffer ConstantBuffer : register(b0)
{
    matrix World;
    matrix View;
    matrix Projection;
}

//--------------------------------------------------------------------------------------
struct VS_OUTPUT
{
    float4 Pos : SV_POSITION;
    float3 Normal : NORMAL;
    float3 Tex : TEXCOORD0;
};

//--------------------------------------------------------------------------------------
// Vertex Shader
//--------------------------------------------------------------------------------------
VS_OUTPUT VS(float4 Pos : POSITION, float3 Normal : NORMAL, float3 Tex : TEXCOORD) //The variables passed in need to be in the same layout as the input layout within Application.cpp
{
    VS_OUTPUT output = (VS_OUTPUT)0;

    // Convert from local space to world space 
    output.Pos = mul(Pos, World);
    output.Pos = mul(output.Pos, View);
    output.Pos = mul(output.Pos, Projection);
    //output.Pos.z = -1.0f;

    output.Tex = Tex;

    return output;
}

//--------------------------------------------------------------------------------------
// Pixel Shader
//--------------------------------------------------------------------------------------
float4 PS(VS_OUTPUT input) : SV_Target
{
    float4 textureColour = skyMap.Sample(samLinear, input.Tex);

    return textureColour;
}

That's pretty much everything related to the skybox but I'll be happy to give any more info if needed. I'm not sure if I've done something wrong with creating my skybox (The tutorials I found were not exactly helpful) or it may be my actual skybox texture. I wasn't sure how to behind all 6 cubemap images into one but I found a program called ATI CubeMapGen to do it but I'm not sure if it being so out of date would cause a problem like this or not? If it does then I'd love a recommendation on what to use instead.

\$\endgroup\$
  • \$\begingroup\$ How does your cube look when you use a 2d texture? \$\endgroup\$ – Jay Jan 10 at 21:35
  • \$\begingroup\$ It looks perfectly fine with a 2D texture \$\endgroup\$ – codelyoko373 Jan 11 at 0:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.