Sign in to follow this  
Blasp

DX11 NVIDIA specific rendering artifact

Recommended Posts

My 3D game looks fine on AMD gpus (radeon HD 5800, 6300m)  and on integrated gpus (intel), but looks grainy on nvidia gpus (tested on 635m, 930m). Changing the shader, blending, depth buffer settings, fullscreen, doesnt seem to help. Anyone knows why this happens?

 

screen_bad.png

 

 

screen_good.png

 

 

Here is my D3D initialization code, it could be relevant:

 

 

bool InitializeDirect3d11App(HINSTANCE const hInstance)
{
    std::cout << NEWLINE << "InitializeDirect3d11App(" << hInstance << ")" << NEWLINE;
    // Describe our Display Mode
    DXGI_MODE_DESC bufferDesc = {};
    bufferDesc.Width = Width;
    bufferDesc.Height = Height;
    bufferDesc.RefreshRate.Numerator = 60;
    bufferDesc.RefreshRate.Denominator = 1;
    bufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
    bufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
    bufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;

    // Describe our Swap Chain
    DXGI_SWAP_CHAIN_DESC swapChainDesc = {};
    swapChainDesc.BufferDesc = bufferDesc;
    swapChainDesc.SampleDesc.Count = 1;
    swapChainDesc.SampleDesc.Quality = 0;
    swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
    swapChainDesc.BufferCount = 1;
    swapChainDesc.OutputWindow = hwnd;
    swapChainDesc.Windowed = windowed;
    swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;

    // Create our Direct3D 11 Device and SwapChain    // D3D11_CREATE_DEVICE_DEBUG, D3D11_CREATE_DEVICE_BGRA_SUPPORT, D3D11_CREATE_DEVICE_SINGLETHREADED
    D3D11CreateDeviceAndSwapChain(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, D3D11_CREATE_DEVICE_SINGLETHREADED,
                                       nullptr, NULL, D3D11_SDK_VERSION, &swapChainDesc, &SwapChain, &d3d11Device, nullptr, &d3d11DevCon);

    // BackBuffer
    D3D11_TEXTURE2D_DESC BackBuffer_Texture2D_Desc = {};
    BackBuffer_Texture2D_Desc.Width = Width;
    BackBuffer_Texture2D_Desc.Height = Height;
    BackBuffer_Texture2D_Desc.MipLevels = 1;
    BackBuffer_Texture2D_Desc.ArraySize = 1;
    BackBuffer_Texture2D_Desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
    BackBuffer_Texture2D_Desc.SampleDesc.Count = 1;
    BackBuffer_Texture2D_Desc.SampleDesc.Quality = 0;
    BackBuffer_Texture2D_Desc.Usage = D3D11_USAGE_DEFAULT;
    BackBuffer_Texture2D_Desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
    //BackBuffer_Texture2D_Desc.BindFlags = D3D11_BIND_RENDER_TARGET;
    BackBuffer_Texture2D_Desc.CPUAccessFlags = 0;
    BackBuffer_Texture2D_Desc.MiscFlags = 0;
    d3d11Device->CreateTexture2D(&BackBuffer_Texture2D_Desc, nullptr, &BackBuffer);

    D3D11_RENDER_TARGET_VIEW_DESC BackBuffer_RTV_Desc = {};
    BackBuffer_RTV_Desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
    BackBuffer_RTV_Desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
    BackBuffer_RTV_Desc.Texture2D.MipSlice = 0;
    SwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&BackBuffer);
    d3d11Device->CreateRenderTargetView(BackBuffer, nullptr, &BackBuffer_RTV);

    // Describe and create our Depth/Stencil Buffer
    BackBuffer_Texture2D_Desc.Format = DXGI_FORMAT_D32_FLOAT;
    BackBuffer_Texture2D_Desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
    d3d11Device->CreateTexture2D(&BackBuffer_Texture2D_Desc, nullptr, &DepthStencilBuffer);
    d3d11Device->CreateDepthStencilView(DepthStencilBuffer, nullptr, &DepthStencilBuffer_DSV);

    D3D11_DEPTH_STENCIL_DESC depth_write_enabled_desc = {};
    depth_write_enabled_desc.DepthEnable = TRUE;
    depth_write_enabled_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;    // depth write enabled
    depth_write_enabled_desc.DepthFunc = D3D11_COMPARISON_LESS;
    depth_write_enabled_desc.StencilEnable = false;
    depth_write_enabled_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
    depth_write_enabled_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
    depth_write_enabled_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
    depth_write_enabled_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
    depth_write_enabled_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_REPLACE;
    depth_write_enabled_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
    depth_write_enabled_desc.BackFace = depth_write_enabled_desc.FrontFace;
    d3d11Device->CreateDepthStencilState(&depth_write_enabled_desc, &pDepthenabledStencilState);

    depth_write_enabled_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;    // depth write disabled
    d3d11Device->CreateDepthStencilState(&depth_write_enabled_desc, &pDepthdisabledStencilState);

    D3D11_BLEND_DESC blendDesc = {};
    blendDesc.AlphaToCoverageEnable = false;    // transparency artifacts if true
    D3D11_RENDER_TARGET_BLEND_DESC rtbd = {};
    rtbd.BlendEnable = true;

    rtbd.SrcBlend = D3D11_BLEND_ONE;//D3D11_BLEND_BLEND_FACTOR;
    rtbd.DestBlend = D3D11_BLEND_ONE;
    rtbd.BlendOp = D3D11_BLEND_OP_ADD;
    rtbd.SrcBlendAlpha = D3D11_BLEND_ONE;//D3D11_BLEND_BLEND_FACTOR;
    rtbd.DestBlendAlpha = D3D11_BLEND_ZERO;//D3D11_BLEND_ONE;
    rtbd.BlendOpAlpha = D3D11_BLEND_OP_ADD;
    rtbd.RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
    blendDesc.RenderTarget[0] = rtbd;
    d3d11Device->CreateBlendState(&blendDesc, &Blend_Add);
    rtbd.SrcBlend = D3D11_BLEND_SRC_ALPHA;
    rtbd.DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
    rtbd.BlendOp = D3D11_BLEND_OP_ADD;
    rtbd.SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
    rtbd.DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
    rtbd.BlendOpAlpha = D3D11_BLEND_OP_ADD;
    blendDesc.RenderTarget[0] = rtbd;
    d3d11Device->CreateBlendState(&blendDesc, &Blend_Alpha);
    rtbd.SrcBlend = D3D11_BLEND_BLEND_FACTOR;
    rtbd.DestBlend = D3D11_BLEND_INV_BLEND_FACTOR;
    rtbd.BlendOp = D3D11_BLEND_OP_ADD;
    rtbd.SrcBlendAlpha = D3D11_BLEND_BLEND_FACTOR;
    rtbd.DestBlendAlpha = D3D11_BLEND_INV_BLEND_FACTOR;
    rtbd.BlendOpAlpha = D3D11_BLEND_OP_ADD;
    blendDesc.RenderTarget[0] = rtbd;
    d3d11Device->CreateBlendState(&blendDesc, &Blend_Overwrite);

    // Create and set the Viewport (subrectangle of the back buffer)
    D3D11_VIEWPORT viewport = {};
    viewport.TopLeftX = 0;
    viewport.TopLeftY = 0;
    viewport.Width = Width;
    viewport.Height = Height;
    viewport.MinDepth = 0.0;
    viewport.MaxDepth = 1.0;
    d3d11DevCon->RSSetViewports(1, &viewport);

    // Describe and create the Sampler state
    D3D11_SAMPLER_DESC sampDesc = {};
    sampDesc.Filter = D3D11_FILTER_ANISOTROPIC;
    sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
    sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
    sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
    sampDesc.MaxAnisotropy = 16;
    sampDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
    sampDesc.MinLOD = 0;
    sampDesc.MaxLOD = D3D11_FLOAT32_MAX;
    d3d11Device->CreateSamplerState(&sampDesc, &TextureSamplerState);
    d3d11DevCon->PSSetSamplers(0, 1, &TextureSamplerState);

    D3D11_RASTERIZER_DESC rsdesc = {};
    rsdesc.FillMode = D3D11_FILL_SOLID;
    rsdesc.CullMode = D3D11_CULL_BACK;
    rsdesc.FrontCounterClockwise = true;
    d3d11Device->CreateRasterizerState(&rsdesc, &CCWcullMode);
    rsdesc.FrontCounterClockwise = false;
    d3d11Device->CreateRasterizerState(&rsdesc, &CWcullMode);
    rsdesc.CullMode = D3D11_CULL_NONE;
    d3d11Device->CreateRasterizerState(&rsdesc, &NonecullMode);
    rsdesc.FillMode = D3D11_FILL_WIREFRAME;
    d3d11Device->CreateRasterizerState(&rsdesc, &WireFrameRState);

    //Compile Shaders from shader file
    D3DX11CompileFromFile(L"Effects.fx", 0, 0, "VS", "vs_5_0", 0, 0, 0, &VS_Buffer, 0, 0);
    D3DX11CompileFromFile(L"Effects.fx", 0, 0, "PS", "ps_5_0", 0, 0, 0, &PS_Buffer, 0, 0);

    //Create the Shader Objects
    d3d11Device->CreateVertexShader(VS_Buffer->GetBufferPointer(), VS_Buffer->GetBufferSize(), nullptr, &VS);
    d3d11Device->CreatePixelShader(PS_Buffer->GetBufferPointer(), PS_Buffer->GetBufferSize(), nullptr, &PS);

    //Set Vertex and Pixel Shaders
    d3d11DevCon->VSSetShader(VS, 0, 0);
    d3d11DevCon->PSSetShader(PS, 0, 0);

    //Create the buffer to send to the per object cbuffer in effect file
    D3D11_BUFFER_DESC cbbd = {};
    cbbd.Usage = D3D11_USAGE_DEFAULT;
    cbbd.ByteWidth = sizeof(cbVertex);
    cbbd.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
    cbbd.CPUAccessFlags = 0;
    cbbd.MiscFlags = 0;
    d3d11Device->CreateBuffer(&cbbd, nullptr, &cbVertexBuffer);

    //Create the buffer to send to the per frame cbuffer in effect file
    cbbd.ByteWidth = sizeof(cbPixel);
    d3d11Device->CreateBuffer(&cbbd, nullptr, &cbPixelBuffer);

    //Describe, create and set the Input Layout
    const D3D11_INPUT_ELEMENT_DESC layout[] =
    {
        { "POSITION",    0, DXGI_FORMAT_R32G32B32_FLOAT,        0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },        // 12
        { "TEXCOORD",    0, DXGI_FORMAT_R32G32_FLOAT,        0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },    // 8
        { "NORMAL",        0, DXGI_FORMAT_R32G32B32_FLOAT,        0, 20, D3D11_INPUT_PER_VERTEX_DATA, 0 },    // 12
        { "COLOR",        0, DXGI_FORMAT_R32G32B32A32_FLOAT,    0, 32, D3D11_INPUT_PER_VERTEX_DATA, 0 },    // 16
                                                                                                        // = 48 B
        { "COLORINST",    0, DXGI_FORMAT_R32G32B32A32_FLOAT,    1, 0, D3D11_INPUT_PER_INSTANCE_DATA, 1 },    // 16
        { "ATTRIBUTES", 0, DXGI_FORMAT_R32G32B32A32_FLOAT,    1, 16, D3D11_INPUT_PER_INSTANCE_DATA, 1 },    // 16
        { "WORLD",        0, DXGI_FORMAT_R32G32B32A32_FLOAT,    1, 32, D3D11_INPUT_PER_INSTANCE_DATA, 1 },    // 16
        { "WORLD",        1, DXGI_FORMAT_R32G32B32A32_FLOAT,    1, 48, D3D11_INPUT_PER_INSTANCE_DATA, 1 },    // 16
        { "WORLD",        2, DXGI_FORMAT_R32G32B32A32_FLOAT,    1, 64, D3D11_INPUT_PER_INSTANCE_DATA, 1 },    // 16
        { "WORLD",        3, DXGI_FORMAT_R32G32B32A32_FLOAT,    1, 80, D3D11_INPUT_PER_INSTANCE_DATA, 1 },    // 16
        { "TEXTUREIDS", 0, DXGI_FORMAT_R32G32B32A32_FLOAT,    1, 96, D3D11_INPUT_PER_INSTANCE_DATA, 1 }    // 16
    };                                                                                                    //    = 112 B
    d3d11Device->CreateInputLayout(layout, ARRAYSIZE(layout), VS_Buffer->GetBufferPointer(), VS_Buffer->GetBufferSize(), &vertLayout);
    d3d11DevCon->IASetInputLayout(vertLayout);

    d3d11DevCon->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

    FW1CreateFactory(FW1_VERSION, &pFW1Factory);
    pFW1Factory->CreateFontWrapper(d3d11Device, L"Arial", &pFontWrapper);

    //Set our Render Target
    d3d11DevCon->OMSetRenderTargets(1, &BackBuffer_RTV, DepthStencilBuffer_DSV);

    QueryPerformanceFrequency(&Frequency);
    min_frame_ticks.QuadPart = Frequency.QuadPart / fps_cap;
    std::cout << "Performance Counter Frequency: " << Frequency.QuadPart << NEWLINE;

    return true;
}

Edited by Blasp

Share this post


Link to post
Share on other sites

You've not helped anyone by leaving in chunks of commented out code in there. I assume your R32G32B32A32_FLOAT RTVs/SRVs are never used anywhere in the project?

 

The error looks either like shadow acne or z-fighting. If you have Shadow Mapping, have you tried disabling it to see if it goes away?

Share this post


Link to post
Share on other sites

I have updated the code above to remove unused code. No change. It is not shadow acne because I have no shadow mapping in the engine, and the problem persists even when I simply output diffuse, bypassing almost all of the pixel shader. Diffuse only screenshot:

 

screen.png

Edited by Blasp

Share this post


Link to post
Share on other sites

OK, there has been some progress. What we are seeing is two different textures fighting over each other. The correct texture and the one in pixel shader slot/register lower by one. Still cant figure out where the bug is, tough. Here is my texture loading code:

 

for (Texture& texture : Texture_Vector)
    {
        if (texture.loaded == Texture_Status::Load_Buffered)    // load
        {
            if (texture.resource != nullptr)
            {
                texture.resource->Release();
            }
            texture.resource = nullptr;
            if ((hr = D3DX11CreateShaderResourceViewFromMemory(d3d11Device, &(texture.byte_buffer[0]), texture.byte_buffer.size(), nullptr, nullptr, &(texture.resource), nullptr)) != 0)
            {
                std::wcout << NEWLINE << "ERROR: Texture loading failed. (HRESULT: " << int(hr) << "),  path: " << texture.path << " (" << texture.path_unloaded << ") reason: " << d3d11Device->GetDeviceRemovedReason() << NEWLINE;
                texture.loaded = Texture_Status::Unloaded;
            }
            else
            {
                //std::cout << texture.name << " loaded." << " (" << texture.byte_buffer.size() / 8000 << " kB)" << NEWLINE;
                texture.loaded = Texture_Status::Loaded;
            }
            texture.byte_buffer.clear();
            texture.byte_buffer.shrink_to_fit();
        }
        else if (texture.loaded == Texture_Status::Unload_Buffered)    // unload
        {
            if (texture.resource != nullptr)
            {
                texture.resource->Release();
            }
            texture.resource = nullptr;
            if ((hr = D3DX11CreateShaderResourceViewFromMemory(d3d11Device, &(texture.byte_buffer[0]), texture.byte_buffer.size(), nullptr, nullptr, &(texture.resource), nullptr)) != 0)
            {
                std::wcout << NEWLINE << "ERROR: Texture unloading failed. (HRESULT: " << int(hr) << "), path: " << texture.path << " (" << texture.path_unloaded << ") reason: " << d3d11Device->GetDeviceRemovedReason() << NEWLINE;
                texture.loaded = Texture_Status::Loaded;
            }
            else
            {
                //std::cout << texture.name << " unloaded." << " (" << texture.byte_buffer.size()/8000 << " kB)" << NEWLINE;
                texture.loaded = Texture_Status::Unloaded;
            }
            texture.byte_buffer.clear();
            texture.byte_buffer.shrink_to_fit();
        }
    }

 

// Set Textures
    std::vector<ID3D11ShaderResourceView*> Tex_Vector;
    for (Texture& texture : Texture_Vector)
    {
        if (texture.loaded == Texture_Status::Loaded && texture.resource != nullptr)
        {
            Tex_Vector.emplace_back(texture.resource);
        }
        else
        {
            Tex_Vector.emplace_back(texture.resource_unloaded);
        }
    }
    d3d11DevCon->PSSetShaderResources(0, Tex_Vector.size(), &Tex_Vector[0]);

 

 

and my texture sampling HLSL:

 

 

Texture2D Texture0 : register(ps, t0);
Texture2D Texture1 : register(ps, t1);
Texture2D Texture2 : register(ps, t2);
Texture2D Texture3 : register(ps, t3);
Texture2D Texture4 : register(ps, t4);
Texture2D Texture5 : register(ps, t5);
Texture2D Texture6 : register(ps, t6);
Texture2D Texture7 : register(ps, t7);
Texture2D Texture8 : register(ps, t8);
Texture2D Texture9 : register(ps, t9);
Texture2D Texture10 : register(ps, t10);
Texture2D Texture11 : register(ps, t11);
Texture2D Texture12 : register(ps, t12);
Texture2D Texture13 : register(ps, t13);
Texture2D Texture14 : register(ps, t14);
Texture2D Texture15 : register(ps, t15);
Texture2D Texture16 : register(ps, t16);
Texture2D Texture17 : register(ps, t17);
Texture2D Texture18 : register(ps, t18);
Texture2D Texture19 : register(ps, t19);
Texture2D Texture20 : register(ps, t20);
Texture2D Texture21 : register(ps, t21);
Texture2D Texture22 : register(ps, t22);
Texture2D Texture23 : register(ps, t23);
Texture2D Texture24 : register(ps, t24);
Texture2D Texture25 : register(ps, t25);
Texture2D Texture26 : register(ps, t26);
Texture2D Texture27 : register(ps, t27);
Texture2D Texture28 : register(ps, t28);
Texture2D Texture29 : register(ps, t29);
Texture2D Texture30 : register(ps, t30);
Texture2D Texture31 : register(ps, t31);
Texture2D Texture32 : register(ps, t32);
Texture2D Texture33 : register(ps, t33);
SamplerState ObjSamplerState : register(ps, s0);

float4 texture_sample(float id, float2 texcoord)
{
    [call] switch (id)
    {
        case 0:
        {
            return Texture0.Sample(ObjSamplerState, texcoord);
        }
        break;
        case 1:
        {
            return Texture1.Sample(ObjSamplerState, texcoord);
        }
        break;
        case 2:
        {
            return Texture2.Sample(ObjSamplerState, texcoord);
        }
        break;
        case 3:
        {
            return Texture3.Sample(ObjSamplerState, texcoord);
        }
        break;
        case 4:
        {
            return Texture4.Sample(ObjSamplerState, texcoord);
        }
        break;
        case 5:
        {
            return Texture5.Sample(ObjSamplerState, texcoord);
        }
        break;
        case 6:
        {
            return Texture6.Sample(ObjSamplerState, texcoord);
        }
        break;
        case 7:
        {
            return Texture7.Sample(ObjSamplerState, texcoord);
        }
        break;
        case 8:
        {
            return Texture8.Sample(ObjSamplerState, texcoord);
        }
        break;
        case 9:
        {
            return Texture9.Sample(ObjSamplerState, texcoord);
        }
        break;
        case 10:
        {
            return Texture10.Sample(ObjSamplerState, texcoord);
        }
        break;
        case 11:
        {
            return Texture11.Sample(ObjSamplerState, texcoord);
        }
        break;
        case 12:
        {
            return Texture12.Sample(ObjSamplerState, texcoord);
        }
        break;
        case 13:
        {
            return Texture13.Sample(ObjSamplerState, texcoord);
        }
        break;
        case 14:
        {
            return Texture14.Sample(ObjSamplerState, texcoord);
        }
        break;
        case 15:
        {
            return Texture15.Sample(ObjSamplerState, texcoord);
        }
        break;
        case 16:
        {
            return Texture16.Sample(ObjSamplerState, texcoord);
        }
        break;
        case 17:
        {
            return Texture17.Sample(ObjSamplerState, texcoord);
        }
        break;
        case 18:
        {
            return Texture18.Sample(ObjSamplerState, texcoord);
        }
        break;
        case 19:
        {
            return Texture19.Sample(ObjSamplerState, texcoord);
        }
        break;
        case 20:
        {
            return Texture20.Sample(ObjSamplerState, texcoord);
        }
        break;
        case 21:
        {
            return Texture21.Sample(ObjSamplerState, texcoord);
        }
        break;
        case 22:
        {
            return Texture22.Sample(ObjSamplerState, texcoord);
        }
        break;
        case 23:
        {
            return Texture23.Sample(ObjSamplerState, texcoord);
        }
        break;
        case 24:
        {
            return Texture24.Sample(ObjSamplerState, texcoord);
        }
        break;
        case 25:
        {
            return Texture25.Sample(ObjSamplerState, texcoord);
        }
        break;
        case 26:
        {
            return Texture26.Sample(ObjSamplerState, texcoord);
        }
        break;
        case 27:
        {
            return Texture27.Sample(ObjSamplerState, texcoord);
        }
        break;
        case 28:
        {
            return Texture28.Sample(ObjSamplerState, texcoord);
        }
        break;
        case 29:
        {
            return Texture29.Sample(ObjSamplerState, texcoord);
        }
        break;
        case 30:
        {
            return Texture30.Sample(ObjSamplerState, texcoord);
        }
        break;
        case 31:
        {
            return Texture31.Sample(ObjSamplerState, texcoord);
        }
        break;
        case 32:
        {
            return Texture32.Sample(ObjSamplerState, texcoord);
        }
        break;
        case 33:
        {
            return Texture33.Sample(ObjSamplerState, texcoord);
        }
        break;
        default:
        {
            return Texture0.Sample(ObjSamplerState, texcoord);
        }
        break;
    }
}

Edited by Blasp

Share this post


Link to post
Share on other sites

That shader is amazing for all the wrong reasons! Are you familiar with Texture Arrays?

 

What simplifications have you tried making to that Pixel Shader before the problem goes away?

 

I am aware of texture arrays, but not familiar with them.  Do you think it could be the cause? I will try to sample the texture directly to see if it helps..

Share this post


Link to post
Share on other sites

My beautiful texture sampling shader was indeed the cause of the artifact, getting rid of it solves the shimmering. But now I have to redo the whole texturing code.. :(

 

https://www.youtube.com/watch?v=JbovJbKALzA

Share this post


Link to post
Share on other sites

If all your 34 textures are the same format and dimension then they can be stored in a single ID3D12Texture2D that happens to have 34 'slices'. From HLSL you declare that texture to be a Texture2DArray and then the .Load/.Sample methods take an extra int/float indicating which slice of that array to read from.

 

If your 34 textures are varying sizes and formats then I would reconsider your approach to rendering whatever it is you're rendering.

Share this post


Link to post
Share on other sites

Aside from being ugly and probably not great to maintain (and of course why is this happening if texture arrays exist), I bet it's a lot faster than y'all are thinking.

Edited by Dingleberry

Share this post


Link to post
Share on other sites

If your 34 textures are varying sizes and formats then I would reconsider your approach to rendering whatever it is you're rendering.

 

They are varying sizes so texture arrays will probably not work. Its mostly planet textures, and some of those are huge. They dont fit into memory all at once so I have to load/unload them on demand, preferably without the game freezing for multiple seconds while doing so, or worse, crashing. That shader actually runs quite well if not for that artifact..

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Forum Statistics

    • Total Topics
      628293
    • Total Posts
      2981869
  • Similar Content

    • By GreenGodDiary
      I'm attempting to implement some basic post-processing in my "engine" and the HLSL part of the Compute Shader and such I think I've understood, however I'm at a loss at how to actually get/use it's output for rendering to the screen.
      Assume I'm doing something to a UAV in my CS:
      RWTexture2D<float4> InputOutputMap : register(u0); I want that texture to essentially "be" the backbuffer.
       
      I'm pretty certain I'm doing something wrong when I create the views (what I think I'm doing is having the backbuffer be bound as render target aswell as UAV and then using it in my CS):
       
      DXGI_SWAP_CHAIN_DESC scd; ZeroMemory(&scd, sizeof(DXGI_SWAP_CHAIN_DESC)); scd.BufferCount = 1; scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT | DXGI_USAGE_SHADER_INPUT | DXGI_USAGE_UNORDERED_ACCESS; scd.OutputWindow = wndHandle; scd.SampleDesc.Count = 1; scd.Windowed = TRUE; HRESULT hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, NULL, NULL, NULL, D3D11_SDK_VERSION, &scd, &gSwapChain, &gDevice, NULL, &gDeviceContext); // get the address of the back buffer ID3D11Texture2D* pBackBuffer = nullptr; gSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pBackBuffer); // use the back buffer address to create the render target gDevice->CreateRenderTargetView(pBackBuffer, NULL, &gBackbufferRTV); // set the render target as the back buffer CreateDepthStencilBuffer(); gDeviceContext->OMSetRenderTargets(1, &gBackbufferRTV, depthStencilView); //UAV for compute shader D3D11_UNORDERED_ACCESS_VIEW_DESC uavd; ZeroMemory(&uavd, sizeof(uavd)); uavd.Format = DXGI_FORMAT_R8G8B8A8_UNORM; uavd.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D; uavd.Texture2D.MipSlice = 1; gDevice->CreateUnorderedAccessView(pBackBuffer, &uavd, &gUAV); pBackBuffer->Release();  
      After I render the scene, I dispatch like this:
      gDeviceContext->OMSetRenderTargets(0, NULL, NULL); m_vShaders["cs1"]->Bind(); gDeviceContext->CSSetUnorderedAccessViews(0, 1, &gUAV, 0); gDeviceContext->Dispatch(32, 24, 0); //hard coded ID3D11UnorderedAccessView* nullview = { nullptr }; gDeviceContext->CSSetUnorderedAccessViews(0, 1, &nullview, 0); gDeviceContext->OMSetRenderTargets(1, &gBackbufferRTV, depthStencilView); gSwapChain->Present(0, 0); Worth noting is the scene is rendered as usual, but I dont get any results from the CS (simple gaussian blur)
      I'm sure it's something fairly basic I'm doing wrong, perhaps my understanding of render targets / views / what have you is just completely wrong and my approach just makes no sense.

      If someone with more experience could point me in the right direction I would really appreciate it!

      On a side note, I'd really like to learn more about this kind of stuff. I can really see the potential of the CS aswell as rendering to textures and using them for whatever in the engine so I would love it if you know some good resources I can read about this!

      Thank you <3
       
      P.S I excluded the .hlsl since I cant imagine that being the issue, but if you think you need it to help me just ask

      P:P:S. As you can see this is my first post however I do have another account, but I can't log in with it because gamedev.net just keeps asking me to accept terms and then logs me out when I do over and over
    • By noodleBowl
      I was wondering if anyone could explain the depth buffer and the depth stencil state comparison function to me as I'm a little confused
      So I have set up a depth stencil state where the DepthFunc is set to D3D11_COMPARISON_LESS, but what am I actually comparing here? What is actually written to the buffer, the pixel that should show up in the front?
      I have these 2 quad faces, a Red Face and a Blue Face. The Blue Face is further away from the Viewer with a Z index value of -100.0f. Where the Red Face is close to the Viewer with a Z index value of 0.0f.
      When DepthFunc is set to D3D11_COMPARISON_LESS the Red Face shows up in front of the Blue Face like it should based on the Z index values. BUT if I change the DepthFunc to D3D11_COMPARISON_LESS_EQUAL the Blue Face shows in front of the Red Face. Which does not make sense to me, I would think that when the function is set to D3D11_COMPARISON_LESS_EQUAL the Red Face would still show up in front of the Blue Face as the Z index for the Red Face is still closer to the viewer
      Am I thinking of this comparison function all wrong?
      Vertex data just in case
      //Vertex date that make up the 2 faces Vertex verts[] = { //Red face Vertex(Vector4(0.0f, 0.0f, 0.0f), Color(1.0f, 0.0f, 0.0f)), Vertex(Vector4(100.0f, 100.0f, 0.0f), Color(1.0f, 0.0f, 0.0f)), Vertex(Vector4(100.0f, 0.0f, 0.0f), Color(1.0f, 0.0f, 0.0f)), Vertex(Vector4(0.0f, 0.0f, 0.0f), Color(1.0f, 0.0f, 0.0f)), Vertex(Vector4(0.0f, 100.0f, 0.0f), Color(1.0f, 0.0f, 0.0f)), Vertex(Vector4(100.0f, 100.0f, 0.0f), Color(1.0f, 0.0f, 0.0f)), //Blue face Vertex(Vector4(0.0f, 0.0f, -100.0f), Color(0.0f, 0.0f, 1.0f)), Vertex(Vector4(100.0f, 100.0f, -100.0f), Color(0.0f, 0.0f, 1.0f)), Vertex(Vector4(100.0f, 0.0f, -100.0f), Color(0.0f, 0.0f, 1.0f)), Vertex(Vector4(0.0f, 0.0f, -100.0f), Color(0.0f, 0.0f, 1.0f)), Vertex(Vector4(0.0f, 100.0f, -100.0f), Color(0.0f, 0.0f, 1.0f)), Vertex(Vector4(100.0f, 100.0f, -100.0f), Color(0.0f, 0.0f, 1.0f)), };  
    • By mellinoe
      Hi all,
      First time poster here, although I've been reading posts here for quite a while. This place has been invaluable for learning graphics programming -- thanks for a great resource!
      Right now, I'm working on a graphics abstraction layer for .NET which supports D3D11, Vulkan, and OpenGL at the moment. I have implemented most of my planned features already, and things are working well. Some remaining features that I am planning are Compute Shaders, and some flavor of read-write shader resources. At the moment, my shaders can just get simple read-only access to a uniform (or constant) buffer, a texture, or a sampler. Unfortunately, I'm having a tough time grasping the distinctions between all of the different kinds of read-write resources that are available. In D3D alone, there seem to be 5 or 6 different kinds of resources with similar but different characteristics. On top of that, I get the impression that some of them are more or less "obsoleted" by the newer kinds, and don't have much of a place in modern code. There seem to be a few pivots:
      The data source/destination (buffer or texture) Read-write or read-only Structured or unstructured (?) Ordered vs unordered (?) These are just my observations based on a lot of MSDN and OpenGL doc reading. For my library, I'm not interested in exposing every possibility to the user -- just trying to find a good "middle-ground" that can be represented cleanly across API's which is good enough for common scenarios.
      Can anyone give a sort of "overview" of the different options, and perhaps compare/contrast the concepts between Direct3D, OpenGL, and Vulkan? I'd also be very interested in hearing how other folks have abstracted these concepts in their libraries.
    • By turanszkij
      If I do a buffer update with MAP_NO_OVERWRITE or MAP_DISCARD, can I just write to the buffer after I called Unmap() on the buffer? It seems to work fine for me (Nvidia driver), but is it actually legal to do so? I have a graphics device wrapper and I don't want to expose Map/Unmap, but just have a function like void* AllocateFromRingBuffer(GPUBuffer* buffer, uint size, uint& offset); This function would just call Map on the buffer, then Unmap immediately and then return the address of the buffer. It usually does a MAP_NO_OVERWRITE, but sometimes it is a WRITE_DISCARD (when the buffer wraps around). Previously I have been using it so that the function expected the data upfront and would copy to the buffer between Map/Unmap, but now I want to extend functionality of it so that it would just return an address to write to.
    • By mister345
      Trying to write a multitexturing shader in DirectX11 - 3 textures work fine, but adding 4th gets sampled as black!
      Could you please look at the textureClass.cpp line 79? - I'm guess its D3D11_TEXTURE2D_DESC settings are wrong, 
      but no idea how to set it up right. I tried changing ArraySize from 1 to 4, but does nothing. If thats not the issue, please look
      at the LightShader_ps - maybe doing something wrong there? Otherwise, no idea.
          // Setup the description of the texture.
          textureDesc.Height = height;
          textureDesc.Width = width;
          textureDesc.MipLevels = 0;
          textureDesc.ArraySize = 1;
          textureDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
          textureDesc.SampleDesc.Count = 1;
          textureDesc.SampleDesc.Quality = 0;
          textureDesc.Usage = D3D11_USAGE_DEFAULT;
          textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
          textureDesc.CPUAccessFlags = 0;
          textureDesc.MiscFlags = D3D11_RESOURCE_MISC_GENERATE_MIPS;
      Please help, thanks.
      https://github.com/mister51213/DirectX11Engine/blob/master/DirectX11Engine/Texture.cpp
       
  • Popular Now