0
\$\begingroup\$

It looks like that it's being sampled from the least detailed MIP level, at least RenderDoc sees the texture as it should be, and what the actual texture looks like is the same as MIP 9th. I'm using DirectXTex, so I think the shader resource view should be correct.

    DirectX::ScratchImage* pImageData = new DirectX::ScratchImage();
    LoadFromDDSFile(path.c_str(), DirectX::DDS_FLAGS_NONE, nullptr, *pImageData);
    const DirectX::TexMetadata& textureMetaData = pImageData->GetMetadata();
    const DirectX::Image* image = pImageData->GetImage(0, 0, 0);
    DirectX::CreateShaderResourceView(
        GetDevice(gfx),
        image, textureMetaData.mipLevels,
        textureMetaData,
        &pShaderResourceView);

and the sampler is

    D3D11_SAMPLER_DESC samplerDesc;
    samplerDesc.Filter = D3D11_FILTER_ANISOTROPIC;
    samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
    samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
    samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
    samplerDesc.MipLODBias = 0.0f;
    samplerDesc.MaxAnisotropy = 4;
    samplerDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
    samplerDesc.MinLOD = 0;
    samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;

    DX::ThrowIfFailed(GetDevice(gfx)->CreateSamplerState(&samplerDesc, &pSamplerState));
    pImageData->Release();

then

    GetContext(gfx)->PSSetShaderResources(0u, 1u, &pShaderResourceView);
    GetContext(gfx)->PSSetSamplers(0u, 1u, &pSamplerState);

Input layout might be relevant

    const std::vector<D3D11_INPUT_ELEMENT_DESC> inputElemDesc =
    {
        {"Position", 0u, DXGI_FORMAT_R32G32B32_FLOAT, 0u, D3D11_APPEND_ALIGNED_ELEMENT,
        D3D11_INPUT_PER_VERTEX_DATA, 0u},
        {"TexCoordinate", 0u, DXGI_FORMAT_R32G32_FLOAT, 0u, D3D11_APPEND_ALIGNED_ELEMENT,
        D3D11_INPUT_PER_VERTEX_DATA, 0u},
        {"Normal", 0u, DXGI_FORMAT_R8G8B8A8_UNORM, 0u, D3D11_APPEND_ALIGNED_ELEMENT,
        D3D11_INPUT_PER_VERTEX_DATA, 0u}
    };

Vertex shader

struct VertexIn
{
    float3 position : Position;
    float2 texCoord : TexCoordinate;
    float3 normal : Normal;
};

struct PSstruct
{
    float4 PosH : SV_Position;
    float3 PosW : Position;
    float3 NormalW : Normal;
    float2 Tex : TEXCOORD;
};
PSstruct main(VertexIn vin)
{
    PSstruct vout;

    vout.Tex = vin.texCoord;;
    return vout;
}

pixel shader. I removed light related code, I'm fairly sure that here it's not important. And I temporarily disabled it

Texture2D cubeTexture : register(t0);
SamplerState cubeSample : register(s0);

struct PSstruct
{
    float4 PosH : SV_Position;
    float3 PosW : Position;
    float3 NormalW : Normal;
    float2 tex : TEXCOORD;
};
float4 main(PSstruct pin) : SV_TARGET
{
    float4 texColor = float4(1, 1, 1, 1);
    texColor = cubeTexture.Sample(cubeSample, pin.tex);
    float4 litColor = texColor;
    return litColor;
}
\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

Texture coordinates were wrong. The ones that I was sending to vertex buffer.

\$\endgroup\$
2
  • \$\begingroup\$ This answer would be better if it explained how you diagnosed that the coordinates you were using were wrong, and how you corrected them. \$\endgroup\$
    – DMGregory
    Jun 21, 2020 at 17:02
  • \$\begingroup\$ In my google journeys I noticed that I'm suppose to give it's texture coordinates, while I got the impression it will make them itself. So I was sending zeroes. It's embarasing really... \$\endgroup\$
    – Andrey K
    Jun 21, 2020 at 17:39

You must log in to answer this question.

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