Skip to content
This repository was archived by the owner on Mar 7, 2024. It is now read-only.
This repository was archived by the owner on Mar 7, 2024. It is now read-only.

[Need Help] BlurredMotion Filter Enhancement #1

@sohilmemon

Description

@sohilmemon

I am using your code for motion blur effect via Metalkit, which works well, but now I want to create a filter as shown in the below video and I have modified a code also but it doesn't work as expected, so can you pls help?

How Filter I want?

https://drive.google.com/file/d/1oEcC0DMOfvuW9pkLBPZhJmgMrhaK_Jcp/view?usp=sharing

Code:

kernel void blurredMotion(texture2d<float, access::read> inTexture [[ texture(0) ]],
                          texture2d<float, access::write> outTexture [[ texture(1) ]],
                          texture2d<float, access::read> lastTexture [[ texture(2) ]],
                          device const float *time [[ buffer(0) ]],
                          uint2 gid [[ thread_position_in_grid ]])
{
    float width = inTexture.get_width();
    float height = inTexture.get_height();
    float2 uv = float2(gid) / float2(width, height);
    
    float4 buf = lastTexture.read(gid);
    float4 bri = inTexture.read(gid);

    float3 grayScaleColor = float3(1.0, 0.0, 0.0);
    float myGrayScale = dot(bri.rgb, grayScaleColor);

    float diff = ((bri.r - buf.r) + (bri.g - buf.g) + (bri.b - buf.b)) / 3;
    
    float colR = inTexture.read(uint2(uv.x + diff, uv.y)).r * (1.0 - diff);
    float colG = inTexture.read(uint2(uv.x - diff, uv.y)).r * (1.0 - diff);
    float colB = inTexture.read(uint2(uv.x - diff, uv.y)).r * (1.0 - diff);
    
    float scanline = abs(cos(uv.y * 500.));
    scanline = smoothstep(0.0, 2.0, scanline);
    float3 col = float3(1.0,0.0,0.0);
    col -= (0.1 * scanline);
    
    float3 blendColor = float3(colR, colG, colB) - (0.1 * scanline);
    
    outTexture.write(float4(blendColor, 1.0), gid);
}

Can you pls help what I am missing here to achieve that?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions