Welcome, Guest.
Username: Password: Remember me

TOPIC: Custom motion blur

Custom motion blur 2 years 3 hours ago #1

  • matsilagi
  • matsilagi's Avatar
  • Offline
  • NEVER GIVE UP
  • Posts: 245
  • Thank you received: 76
Hey!
So, im retouching that shader im porting from Unity, and i need help figuring out what im doing wrong (again :v )

So, the code is exactly the same than the source, but no matter how i try, it always ends up looking like this:



Now, as you can see, the code is not entirely wrong, as the red motion blur infact WORKS, but, it should look like this:


My code is almost 1:1, so i don't see why the results would be wrong, here's both codes for reference: pastebin.com/C9sfLJvt

Im pretty sure its either something on the samplers or the frame copy, but im not sure what exactly.
The administrator has disabled public write access.

Custom motion blur 1 year 11 months ago #2

try these settings:
#define feedbackAmount 0.5
#define feedbackThresh 0.3
#define feedbackFade 0.8
#define feedbackAmp 5


some note to your code:

line 114: use previous frame
line 126, 127, 128: use previous feed back buffer

pixel shader 3 write to feedbackbuffer

line 141: use current feed back buffer (result of pixel shader 3)

and mine implementation:
#define feedbackAmount  0.5
#define feedbackThresh  0.3
#define feedbackColor   float3(1.0,0.5,0.0)
#define feedbackFade    0.8
#define feedbackAmp     5

texture2D VHS_InputTexA    { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; Format = RGBA8; };
texture2D VHS_InputTexB    { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; Format = RGBA8; };
texture2D VHS_FeedbackTexA { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; Format = RGBA8; };
texture2D VHS_FeedbackTexB { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; Format = RGBA8; };

sampler2D VHS_InputA    { Texture = VHS_InputTexA;    };
sampler2D VHS_InputB    { Texture = VHS_InputTexB;    };
sampler2D VHS_FeedbackA { Texture = VHS_FeedbackTexA; };
sampler2D VHS_FeedbackB { Texture = VHS_FeedbackTexB; };


float3 bm_screen(float3 a, float3 b) { return 1.0 - ( 1.0 - a) * ( 1.0 - b); }

void VS_VHS(in uint id : SV_VertexID, out float4 pos : SV_Position, out float2 texcoord : TEXCOORD)
{
    texcoord.x = (id == 2) ? 2.0 : 0.0;
    texcoord.y = (id == 1) ? 2.0 : 0.0;
    pos = float4(texcoord * float2(2.0, -2.0) + float2(-1.0, 1.0), 0.0, 1.0);
}

void PS_VHS_Main(float4 vpos     : SV_Position, out float4 output   : SV_Target0,     
            float2 texcoord : TEXCOORD,    out float4 feedback : SV_Target1 )
{
    float3 color     = tex2D( RFX_backbufferColor, texcoord).rgb;    // curent frame

    //new feedback
    float3 lastframe = tex2D( VHS_InputB, texcoord).rgb;    //last frame without feedback
    float  diff      = dot(abs(lastframe - color), 0.3333); //dfference between frames
    diff             = (diff < feedbackThresh)? 0.0: diff;
    float3 fbn       = color * diff * feedbackAmount;       //feedback new
    // fbn = float3(0.0, 0.0, 0.0);

    //feedback buffer
    float3 fbb = tex2D( VHS_FeedbackB, texcoord).rgb; 
    fbb       += tex2D( VHS_FeedbackB, texcoord + float2(RFX_PixelSize.x, 0.0)).rgb + 
                 tex2D( VHS_FeedbackB, texcoord - float2(RFX_PixelSize.x, 0.0)).rgb;
    fbb       /= 3.0;
    fbb        = bm_screen(fbn, fbb * feedbackFade) * feedbackColor;    //feedback

    //blend
    color    = bm_screen(color, fbb * feedbackAmp);
//    color = color + fbb * feedbackAmp;
    output   = float4( color, 1.0); 
    feedback = float4( fbb,   1.0);
}

void PS_VHS_Lastframe(float4 vpos     : SV_Position, out float4 output   : SV_Target0, 
                      float2 texcoord : TEXCOORD,    out float4 feedback : SV_Target1)
{
    output   = tex2D( VHS_InputA,    texcoord);
    feedback = tex2D( VHS_FeedbackA, texcoord);
}

float4 PS_VHS(float4 vpos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target
{
    return tex2D( VHS_InputB,    texcoord);
}

technique VHS < enabled = true; toggle = VK_F2;>
{
    pass VHS_Main
    {
        VertexShader  = VS_VHS;
        PixelShader   = PS_VHS_Main;
        RenderTarget0 = VHS_InputTexA;
        RenderTarget1 = VHS_FeedbackTexA;
    }
    pass VHS_Lastframe
    {
        VertexShader  = VS_VHS;
        PixelShader   = PS_VHS_Lastframe;   
        RenderTarget0 = VHS_InputTexB;
        RenderTarget1 = VHS_FeedbackTexB;
    }
    pass VHS
    {
        VertexShader  = VS_VHS;
        PixelShader   = PS_VHS;
    }    
}
Last Edit: 1 year 11 months ago by kingeric1992.
The administrator has disabled public write access.
The following user(s) said Thank You: matsilagi

Custom motion blur 1 year 11 months ago #3

  • matsilagi
  • matsilagi's Avatar
  • Offline
  • NEVER GIVE UP
  • Posts: 245
  • Thank you received: 76
Thanks a lot, but its giving a error for me (on OpenGL)
0(53) : error C0000: syntax error, unexpected reserved word at token "output"
0(57) : error C0000: syntax error, unexpected '(' at token "("
0(60) : error C0000: syntax error, unexpected '(' at token "("
0(63) : error C0000: syntax error, unexpected '(' at token "("
0(74) : error C1121: main: function type parameters not allowed

nvm, fixed it, the shader now works completely (and just like Unity).

Send me your e-mail right away to pick up a prize.
Last Edit: 1 year 11 months ago by matsilagi.
The administrator has disabled public write access.
The following user(s) said Thank You: kingeric1992

Custom motion blur 1 year 11 months ago #4

good to hear.
and a prize? you can send mails here:
Last Edit: 1 year 11 months ago by kingeric1992.
The administrator has disabled public write access.