Jump to content

[HELP]shader-blurmotion


Desaster

Recommended Posts

hello I was working on a script made by orange... so I wanted to bind u with making the screen full of blur motion but idk how to make it work without moving my camera now work good but only if I move my camera if i stand not doing anything it won't do anything help me pls and thnx for reading this

local w, h = guiGetScreenSize( ); 
local x1, y1, z1 = getCameraMatrix() 
local sx1, sy1 = getScreenFromWorldPosition(x1, y1, z1) 
local enable = false; 
  
addEventHandler( "onClientResourceStart", getResourceRootElement( getThisResource() ), 
    function( ) 
        bindKey( "u", "up", enableBlackWhite ); 
    end 
) 
  
function findRotation(x1,y1,x2,y2) 
  
  local t = -math.deg(math.atan2(x2-x1,y2-y1)) 
  if t < 0 then t = t + t end; 
  return t; 
  
end 
  
function renderEffect( )     
    local x2, y2, z2 = getCameraMatrix() 
     
    local d = getDistanceBetweenPoints3D(x1, y1, z1, x2, y2, z2); 
     
    sx2, sy2 = w/2, h/2 
     
    local dx = x1 - x2 
    local dy = y1 - y2 
    local dz = z1 - z2 
     
    if getPedOccupiedVehicle(getLocalPlayer()) then 
        multiplier = 0.0010 
    else 
        multiplier = 0.0010 
    end 
     
    dxSetShaderValue( screenShader, "BlurAmount", d*multiplier ); 
    dxSetShaderValue( screenShader, "Angle", findRotation(dx, dx, dx, dz)) -- Fail code, but gives a nice effect 
     
    dxSetRenderTarget(); 
    dxUpdateScreenSource( screenSrc ); 
    dxDrawImage( 0, 0, w, h, screenShader ); 
     
    x1, y1, z1 =  getCameraMatrix() 
end 
  
function enableBlackWhite( ) 
    enable = not enable; 
    if enable then 
        outputChatBox("Motion Blur Enabled") 
        screenShader = dxCreateShader( "motion.fx" ); 
        screenSrc = dxCreateScreenSource( w, h ); 
        if screenShader and screenSrc then 
            dxSetShaderValue( screenShader, "ScreenTexture", screenSrc ); 
            addEventHandler( "onClientHUDRender", getRootElement( ), renderEffect ); 
        end 
    else 
        if screenShader and screenSrc then 
            outputChatBox("Motion Blur Disabled") 
            destroyElement( screenShader ); 
            destroyElement( screenSrc ); 
            screenShader, screenSrc = nil, nil; 
            removeEventHandler( "onClientHUDRender", getRootElement( ), renderEffect ); 
        end 
    end 
end 

and the FX file

texture ScreenTexture;   
  
float Angle = 0;  // Defines the blurring direction 
float BlurAmount = 0.001;  // Defines the blurring magnitude 
  
sampler ImageSampler = sampler_state 
{ 
    Texture = <ScreenTexture>; 
}; 
  
  
float4 main( float2 uv : TEXCOORD) : COLOR 
{ 
    float4 output = 0;  // Defines the output color of a pixel 
    float2 offset;  // Defines the blurring direction as a direction vector 
    int count = 24;  // Defines the number of blurring iterations 
  
    //First compute a direction vector which defines the direction of blurring.  
    //  This is done using the sincos instruction and the Angle input parameter,  
    //  and the result is stored in the offset variable. This vector is of unit  
    //  length. Multiply this unit vector by BlurAmount to adjust its length to  
    //  reflect the blurring magnitude. 
    sincos(Angle, offset.y, offset.x); 
    offset *= BlurAmount; 
  
    // To generate the blurred image, we  
    //  generate multiple copies of the input image, shifted  
    //  according to the blurring direction vector, and then sum  
    //  them all up to get the final image. 
    for(int i=0; i<count; i++) 
         { 
              output += tex2D(ImageSampler, uv - offset * i); 
         } 
    output /= count; // Normalize the color 
  
    return output; 
}; 
  
technique MotionBlur 
{ 
    pass P1 
    { 
        PixelShader = compile ps_2_0 main(); 
    } 
} 

Link to comment
local w, h = guiGetScreenSize( ); 
local enable = false; 
  
addEventHandler( "onClientResourceStart", resourceRoot, 
    function( ) 
        bindKey( "u", "up", enableBlackWhite ); 
    end 
) 
  
function renderEffect( )     
    dxSetRenderTarget(); 
    dxUpdateScreenSource( screenSrc ); 
    dxDrawImage( 0, 0, w, h, screenShader ); 
end 
  
function enableBlackWhite( ) 
    enable = not enable; 
    if enable then 
        outputChatBox("Motion Blur Enabled") 
        screenShader = dxCreateShader( "motion.fx" ); 
        screenSrc = dxCreateScreenSource( w, h ); 
        if screenShader and screenSrc then 
            dxSetShaderValue( screenShader, "ScreenTexture", screenSrc ); 
            addEventHandler( "onClientHUDRender", getRootElement( ), renderEffect ); 
        end 
    else 
        if screenShader and screenSrc then 
            outputChatBox("Motion Blur Disabled") 
            destroyElement( screenShader ); 
            destroyElement( screenSrc ); 
            screenShader, screenSrc = nil, nil; 
            removeEventHandler( "onClientHUDRender", getRootElement( ), renderEffect ); 
        end 
    end 
end 

Link to comment

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...