Jump to content

[HELP] Blur shader.


AlvarO

Recommended Posts

Hello, so I need to make a blur background to a script, the problem is i don't know how to script it, I just got the .fx file.

texture texture0; 
float factor; 
  
sampler Sampler0 = sampler_state 
{ 
    Texture = (texture0); 
    AddressU = MIRROR; 
    AddressV = MIRROR; 
}; 
  
struct PSInput 
{ 
  float2 TexCoord : TEXCOORD0; 
}; 
  
float4 PixelShader_Background(PSInput PS) : COLOR0 
{ 
        float4 sum = tex2D(Sampler0, PS.TexCoord); 
        for (float i = 1; i < 3; i++) { 
                sum += tex2D(Sampler0, float2(PS.TexCoord.x, PS.TexCoord.y + (i * factor))); 
                sum += tex2D(Sampler0, float2(PS.TexCoord.x, PS.TexCoord.y - (i * factor))); 
                sum += tex2D(Sampler0, float2(PS.TexCoord.x - (i * factor), PS.TexCoord.y)); 
                sum += tex2D(Sampler0, float2(PS.TexCoord.x + (i * factor), PS.TexCoord.y)); 
        } 
        sum /= 9; 
        sum.a = 1.0; 
        return sum; 
} 
  
technique complercated 
{ 
    pass P0 
    { 
        PixelShader = compile ps_2_0 PixelShader_Background(); 
    } 
} 
  
technique simple 
{ 
    pass P0 
    { 
        Texture[0] = texture0; 
    } 
} 

Link to comment

you can use this script: https://community.multitheftauto.com/in ... s&id=10163

there are some exported functions that let you create blur boxes

But if You want to apply your shader to a screen space, then you'll find a good amount of help on wiki:

https://wiki.multitheftauto.com/wiki/DxCreateShader

https://wiki.multitheftauto.com/wiki/DxSetShaderValue

Your texture0 should be the screenSource

https://wiki.multitheftauto.com/wiki/Dx ... reenSource

don't forget to update it.

your 'blurfactor' should be set as well. (0 - 1) i guess

Link to comment

I made this and it dosn't works :S

  
local x, y = guiGetScreenSize() 
local px, py = 1920, 1080 
local sx, sy = (x/px), (y/py) 
screen = dxCreateScreenSource ( px, py )  
  
function drawLogin() 
    dxUpdateScreenSource( screen ) 
    blurShader = dxCreateShader( "shader.fx" ) 
    dxSetShaderValue( blurShader, "bShowThing", true )             
    dxSetShaderValue( blurShader, "speed", 2.4 ) 
    dxSetShaderValue( blurShader, "positionOfCheese", 100, 200, 300 ) 
    setCameraMatrix(4141.2734375, -1625.0224609375, 72.958938598633, -300000, 0, 0) 
    showCursor(true) 
    dxDrawRectangle(x*0.385, y*0.35, 450, 50, tocolor(170, 35, 35, 255)) 
    dxDrawRectangle(x*0.385, y*0.38, 450, 250, tocolor(255, 255, 255, 255)) 
    dxDrawRectangle(x*0.385, y*0.6, 450, 50, tocolor(200, 200, 200, 255)) 
    dxDrawRectangle(x*0.48, y*0.613, 100, 25, rectanglecchanger1) 
    dxDrawRectangle(x*0.55, y*0.613, 100, 25, rectanglecchanger2) 
    dxDrawText("Login panel", x*(-0.15), x*(-0.15), x, y, tocolor(15, 15, 15, 255), 1.5, "arial", "center", "center", false, false, true, true, false) 
    dxDrawText("Username", x*(-0.15), y*(-0.15), x, y, tocolor(15, 15, 15, 255), 1.5, "arial", "center", "center", false, false, true, true, false) 
    dxDrawText("Password", x*(-0.15), y*0.01, x, y, tocolor(15, 15, 15, 255), 1.5, "arial", "center", "center", false, false, true, true, false) 
    dxDrawText("remember me?", x*(-0.1), x*0.14, x, y, tocolor(15, 15, 15, 255), 1, "arial", "center", "center", false, false, true, true, false) 
    dxDrawText("Login", x*0.01, x*0.14, x, y, tocolor(15, 15, 15, 255), 1, "arial", "center", "center", false, false, true, true, false) 
    dxDrawText("Register", x*0.152, x*0.14, x, y, tocolor(15, 15, 15, 255), 1, "arial", "center", "center", false, false, true, true, false) 
end 
addEventHandler("onClientRender", root, drawLogin) 
  

Link to comment

I do respect that you want to learn how to script. But seriously ...

dxSetShaderValue - that's what you need, it's like with any other function. Just read the wiki page, not just copy and paste stuff. Think and learn - you will gain something by that. Unless you want a ready solution. But i need to be a little bit more motivated to do so.

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...