#Need help with ImGui & DirectX Shaders

2 messages · Page 1 of 1 (latest)

timid wren
#

I'm sorry if i sound stupid, I'm new to DirectX & shaders (don't know anything about shaders still)
I'm working on a project where i wanna make use of a blur shader to blur images / rectangles, just anything that you can use through imgui ->DrawList

I'm Using ImGui's drawlist callbacks to achieve applying shaders to a image, rectangle ect. It works completely fine to example set the color or whatever. but once i try to use a shader that allows me to blur it, it either changes the color, distorts the image, or just makes the image disappear. I just don't understand why at all. this the my code that i'm using:

        void StartBlur(const ImDrawList* parent_list, const ImDrawCmd* cmd)
        {
            const auto context = reinterpret_cast<ID3D11DeviceContext*>(cmd->UserCallbackData);

            if (!renderTargetView)
            {
                CreateRenderTargetTexture(g_pd3dDevice, &renderTargetTexture, &renderTargetView);
            }

            context->PSGetShader(&ogShader, &ogClassShader, NULL);
            context->OMGetRenderTargets(1, &originalRenderTargetView, nullptr);

            context->PSSetShader(pixelShader, nullptr, 0);
            context->OMSetRenderTargets(1, &renderTargetView, nullptr);
        }

        void EndBlur(const ImDrawList* parent_list, const ImDrawCmd* cmd)
        {
            const auto context = reinterpret_cast<ID3D11DeviceContext*>(cmd->UserCallbackData);
            context->PSSetShader(ogShader, &ogClassShader, 0);
            context->OMSetRenderTargets(1, &originalRenderTargetView, nullptr);

            if (originalRenderTargetView)
                originalRenderTargetView->Release();
            if (ogShader)
                ogShader->Release();
            if (ogClassShader)
                ogClassShader->Release();
        }```

Current Shaders (Makes my Image Disappear)
```cpp
       const char* shaderSource = R"(
Texture2D<float4> Texture : register(t0);
SamplerState TextureSampler : register(s0);

#define SAMPLE_COUNT 15

cbuffer VS_BLUR_PARAMETERS : register(b0)
{
    float2 SampleOffsets[SAMPLE_COUNT];
    float SampleWeights[SAMPLE_COUNT];
}

float4 main(float4 pos : SV_POSITION, float4 col : COLOR0, float2 uv : TEXCOORD0) : SV_Target
{
    float4 color = float4(0, 0, 0, 0);
    // Combine a number of weighted image filter taps.
    for (int i = 0; i < SAMPLE_COUNT; i++)
    {
        color += Texture.Sample(TextureSampler, uv + SampleOffsets[i]) * SampleWeights[i];
    }

    return color;
}
)";
        ID3DBlob* shaderBlob = nullptr;
        ID3DBlob* errorBlob = nullptr;
        HRESULT hr = D3DCompile(shaderSource, strlen(shaderSource), nullptr, nullptr, nullptr, "main", "ps_4_0", 0, 0, &shaderBlob, &errorBlob);
        if (FAILED(hr))
        {

            char* errorMessage = reinterpret_cast<char*>(errorBlob->GetBufferPointer());
            printf("pixel: %s\n", errorMessage);
            errorBlob->Release();
            return 0;
        }
        hr = g_pd3dDevice->CreatePixelShader(shaderBlob->GetBufferPointer(), shaderBlob->GetBufferSize(), nullptr, &pixelShader);
       ```

somewhere in code:
```cpp
        auto drawlist = ImGui::GetWindowDrawList();
        drawlist->AddCallback(TEXTURES::StartBlur, g_pd3dDeviceContext);
        drawlist->AddImage(CurrentMap.texture, offset + mapPosition, (offset + mapPosition) + scaledSize);
        drawlist->AddCallback(TEXTURES::EndBlur, g_pd3dDeviceContext);

Would love to know what the issue is

sharp burrowBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.