0
votes

im trying to implement sharpen,blur hlsl shader code into my application

i referenced learnopengl tutorial and excuted glsl code and that was fine

https://learnopengl.com/Advanced-OpenGL/Framebuffers

when i implement those glsl code to hlsl code and run it

it doesnt apply effect here is my hlsl code

exture2D screenTex;
SamplerState splr :register(s0);
const float offsetX =1.0f/1600.0f;
const float offsetY = 1.0f / 900.0f;
float4 main(float2 tc : Texcoord) : SV_TARGET
{
    float4 color;
    //Kernels
    float2 offsets[9] = 
    {
        float2(-offsetX, offsetY),  //top - left
        float2(0.0f, offsetY),   //top - center
        float2(offsetX, offsetY),  //top - right
        float2(-offsetX, 0.0f),  //center-left
        float2(0.0f, 0.0f),      //center-center
        float2(offsetX, 0.0f),   //center-right
        float2(-offsetX, -offsetY), //bottom - left
        float2(0.0f, -offsetY),  //bottom - center
        float2(offsetX, -offsetY)  //bottom-right
    };
    //for sharpen effect
    /*float kernel[9] = {
        -1, -1, -1,
        -1,  9, -1,
        -1, -1, -1
    };*/
    float kernel[9]=
    {
        1.0f / 16.0f , 2.0f / 16.0f, 1.0f / 16.0f,
        2.0f / 16.0f , 4.0f / 16.0f, 2.0f / 16.0f,
        1.0f / 16.0f , 2.0f / 16.0f, 1.0f / 16.0f
    };
    float3 col = float3(0.0f, 0.0f, 0.0f);
    [unroll]
    for (int i = 0; i < 9; ++i)
    {
        col += screenTex.Sample(splr, tc + offsets[i]).rgb * kernel[i];
    }
    color = float4(col, 1.0f);
    return color;
}

if i run these code there is no change on my scene

i think there is issue in texture sampling with texture coordinate

ps i checked offscreen rendering works fine, and simple effect code like inversion and grayscale

it does work correctly

what is problem i need help

1

1 Answers

0
votes

i found what is problem in hlsl when sampling texture coordinates operation doesnt work

  col += screenTex.Sample(splr, tc + offsets[i]).rgb * kernel[i];

you should use index like

screen.Sample(splr,tc,int2(x,y)

im not sure there is other way to modifying texturecoordinates