Jump to content

Blurred Background


Image

Recommended Posts

Eh, he means you use Photoshop to blur a background image, and then add it in-game via DirectX functions.
dxDrawImage 

If this is still not what you mean, you should check out the shader feature, which was added a while ago.

http://wiki.multitheftauto.com/wiki/Shader

I know the function but not the effect file, or the lua script I can not prepare

p.s.: sry for my bad english, i used google translator

If you can't make such easy thing like drawing an image in the screen, then you should start learning Lua -- drawing an image is a very basic thing.

Link to comment

As far as i can say , that is not that tough to realise how this effect is drawn and modify it .. just play with the .x and .y stuff.

or ..

you might check this out:

http://www.geeks3d.com/20100909/shader- ... r-in-glsl/

this is what you have on mind ? - it's not HLSL, but it's not that hard to understand/convert it.

update:

How about looking at shader_bloom from examples...

Edited by Guest
Link to comment

Another thought. blurH and V effect from shader_bloom.

If you want to use just one effect do that:

blurH: changes from line 95

    for(int i = 0; i < 7; ++i) 
    { 
        coord.x = PS.TexCoord.x + Kernel[i]/sTex0Size.x; 
        coord.y = PS.TexCoord.y + Kernel[i]/sTex0Size.y; 
        Color += tex2D(Sampler0, coord.xy) * Weights[i] * sBloom; 
    } 

Link to comment

i have another problem :/

it uses extremely amount of performance and my fps drops

here's my lua code:

-- 
-- c_bloom.lua 
-- 
  
local scx, scy = guiGetScreenSize() 
  
----------------------------------------------------------------------------------- 
-- Le settings 
----------------------------------------------------------------------------------- 
Settings = {} 
Settings.var = {} 
Settings.var.bloom = 1.5 
Settings.var.blendR = 255 
Settings.var.blendG = 255 
Settings.var.blendB = 255 
Settings.var.blendA = 100 
  
  
  
---------------------------------------------------------------- 
-- onClientResourceStart 
---------------------------------------------------------------- 
addEventHandler( "onClientResourceStart", resourceRoot, 
    function() 
  
        -- Version check 
        if getVersion ().sortable < "1.1.0" then 
            outputChatBox( "Resource is not compatible with this client." ) 
            return 
        end 
  
        -- Create things 
        myScreenSource = dxCreateScreenSource( scx/2, scy/2 ) 
  
        blurHShader,tecName = dxCreateShader( "blurH.fx" ) 
        outputDebugString( "blurHShader is using technique " .. tostring(tecName) ) 
  
        --blurVShader,tecName = dxCreateShader( "blurV.fx" ) 
        --outputDebugString( "blurVShader is using technique " .. tostring(tecName) ) 
  
        -- Check everything is ok 
        bAllValid = myScreenSource and blurHShader 
  
        if not bAllValid then 
            outputChatBox( "Could not create some things. Please use debugscript 3" ) 
        end 
    end 
) 
  
  
----------------------------------------------------------------------------------- 
-- onClientHUDRender 
----------------------------------------------------------------------------------- 
addEventHandler( "onClientHUDRender", root, 
    function() 
        if not Settings.var then 
            return 
        end 
        if bAllValid then 
            -- Reset render target pool 
            RTPool.frameStart() 
  
            -- Update screen 
            dxUpdateScreenSource( myScreenSource ) 
  
            -- Start with screen 
            local current = myScreenSource 
                 
            -- Apply all the effects, bouncing from one render target to another 
            current = applyGBlurH( current, Settings.var.bloom ) 
            --current = applyGBlurV( current, Settings.var.bloom ) 
  
            -- When we're done, turn the render target back to default 
            dxSetRenderTarget() 
  
            -- Mix result onto the screen using 'add' rather than 'alpha blend' 
            if current then 
                dxSetShaderValue( blurHShader, "TEX0", current ) 
                local col = tocolor(Settings.var.blendR, Settings.var.blendG, Settings.var.blendB, Settings.var.blendA) 
                dxDrawImage( 0, 0, scx, scy, blurHShader, 0,0,0, col) 
            end 
        end 
    end 
) 
  
  
----------------------------------------------------------------------------------- 
-- Apply the different stages 
----------------------------------------------------------------------------------- 
  
function applyGBlurH( Src, bloom ) 
    if not Src then return nil end 
    local mx,my = dxGetMaterialSize( Src ) 
    local newRT = RTPool.GetUnused(mx,my) 
    if not newRT then return nil end 
    dxSetRenderTarget( newRT, true )  
    dxSetShaderValue( blurHShader, "TEX0", Src ) 
    dxSetShaderValue( blurHShader, "TEX0SIZE", mx,my ) 
    dxSetShaderValue( blurHShader, "BLOOM", bloom ) 
    dxDrawImage( 0, 0, mx, my, blurHShader ) 
    return newRT 
end 
  
  
----------------------------------------------------------------------------------- 
-- Pool of render targets 
----------------------------------------------------------------------------------- 
RTPool = {} 
RTPool.list = {} 
  
function RTPool.frameStart() 
    for rt,info in pairs(RTPool.list) do 
        info.bInUse = false 
    end 
end 
  
function RTPool.GetUnused( mx, my ) 
    -- Find unused existing 
    for rt,info in pairs(RTPool.list) do 
        if not info.bInUse and info.mx == mx and info.my == my then 
            info.bInUse = true 
            return rt 
        end 
    end 
    -- Add new 
    local rt = dxCreateRenderTarget( mx, my ) 
    if rt then 
        outputDebugString( "creating new RT " .. tostring(mx) .. " x " .. tostring(mx) ) 
        RTPool.list[rt] = { bInUse = true, mx = mx, my = my } 
    end 
    return rt 
end 

and the .fx code:

// 
// Example shader - blurH.fx 
// 
// Horizontal blur 
// 
  
//--------------------------------------------------------------------- 
// blurH settings 
//--------------------------------------------------------------------- 
float sBloom : BLOOM = 1; 
texture sTex0 : TEX0; 
float2 sTex0Size : TEX0SIZE; 
  
  
//--------------------------------------------------------------------- 
// Include some common stuff 
//--------------------------------------------------------------------- 
#include "mta-helper.fx" 
  
  
//----------------------------------------------------------------------------- 
// Static data 
//----------------------------------------------------------------------------- 
static const float Kernel[13] = {-6, -5,     -4,     -3,     -2,     -1,     0,      1,      2,      3,      4,      5,      6}; 
static const float Weights[13] = {      0.002216,       0.008764,       0.026995,       0.064759,       0.120985,       0.176033,       0.199471,       0.176033,       0.120985,       0.064759,       0.026995,       0.008764,       0.002216}; 
//static const float Weights[13] = {      0.2270270270,       0.3162162162,       0.0702702703,       0.064759,       0.120985,       0.176033,       0.199471,       0.176033,       0.120985,       0.064759,       0.026995,       0.008764,       0.002216}; 
  
//--------------------------------------------------------------------- 
// Sampler for the main texture 
//--------------------------------------------------------------------- 
sampler Sampler0 = sampler_state 
{ 
    Texture         = (sTex0); 
    MinFilter       = Linear; 
    MagFilter       = Linear; 
    MipFilter       = Linear; 
}; 
  
  
//--------------------------------------------------------------------- 
// Structure of data sent to the vertex shader 
//--------------------------------------------------------------------- 
struct VSInput 
{ 
    float3 Position : POSITION0; 
    float4 Diffuse : COLOR0; 
    float2 TexCoord : TEXCOORD0; 
}; 
  
//--------------------------------------------------------------------- 
// Structure of data sent to the pixel shader ( from the vertex shader ) 
//--------------------------------------------------------------------- 
struct PSInput 
{ 
    float4 Position : POSITION0; 
    float4 Diffuse : COLOR0; 
    float2 TexCoord: TEXCOORD0; 
}; 
  
  
//------------------------------------------------------------------------------------------ 
// VertexShaderFunction 
//  1. Read from VS structure 
//  2. Process 
//  3. Write to PS structure 
//------------------------------------------------------------------------------------------ 
PSInput VertexShaderFunction(VSInput VS) 
{ 
    PSInput PS = (PSInput)0; 
  
    // Calculate screen pos of vertex 
    PS.Position = MTACalcScreenPosition ( VS.Position ); 
  
    // Pass through color and tex coord 
    PS.Diffuse = VS.Diffuse; 
    PS.TexCoord = VS.TexCoord; 
  
    return PS; 
} 
  
  
//------------------------------------------------------------------------------------------ 
// PixelShaderFunction 
//  1. Read from PS structure 
//  2. Process 
//  3. Return pixel color 
//------------------------------------------------------------------------------------------ 
float4 PixelShaderFunction(PSInput PS) : COLOR0 
{ 
    float4 Color = 0; 
  
    float2 coord; 
    coord.y = PS.TexCoord.y; 
  
    for(int i = 0; i < 7; ++i) 
    { 
        coord.x = PS.TexCoord.x + Kernel[i]/sTex0Size.x; 
        coord.y = PS.TexCoord.y + Kernel[i]/sTex0Size.y; 
        Color += tex2D(Sampler0, coord.xy) * Weights[i] * sBloom; 
    } 
  
    Color = Color * PS.Diffuse; 
    Color.a = 1; 
    return Color;   
} 
  
  
//------------------------------------------------------------------------------------------ 
// Techniques 
//------------------------------------------------------------------------------------------ 
technique blurh 
{ 
    pass P0 
    { 
        VertexShader = compile vs_2_0 VertexShaderFunction(); 
        PixelShader  = compile ps_2_0 PixelShaderFunction(); 
    } 
} 
  
// Fallback 
technique fallback 
{ 
    pass P0 
    { 
        // Just draw normally 
    } 
} 
  

Link to comment

Forget the render targets.

How about just getting screen source , applying the effect and then writing it.

This might help. You have to understand that this bloom effect is quite demanding.

  
  
addEventHandler( "onClientHUDRender", resourceRoot, 
    function() 
        if not Settings.var then 
            return 
        end 
        if bAllValid then 
       dxUpdateScreenSource( myScreenSource ) 
       dxSetShaderValue( blurHShader, "TEX0", myScreenSource) 
       dxSetShaderValue( blurHShader, "TEX0SIZE",scx/2,scy/2) 
       dxSetShaderValue( blurHShader, "BLOOM", Settings.var.bloom ) 
       dxDrawImage( 0, 0, scx, scy, blurHShader, 0,0,0) 
       end 
    end 
) 
  

As for the FX file. In line 95 you can manipulate the value (how many times is the effect applied) the lower, the faster.

Link to comment
Forget the render targets.

How about just getting screen source , applying the effect and then writing it.

This might help. You have to understand that this bloom effect is quite demanding.

  
  
addEventHandler( "onClientHUDRender", resourceRoot, 
    function() 
        if not Settings.var then 
            return 
        end 
        if bAllValid then 
       dxUpdateScreenSource( myScreenSource ) 
       dxSetShaderValue( blurHShader, "TEX0", myScreenSource) 
       dxSetShaderValue( blurHShader, "TEX0SIZE",scx/2,scy/2) 
       dxSetShaderValue( blurHShader, "BLOOM", Settings.var.bloom ) 
       dxDrawImage( 0, 0, scx, scy, blurHShader, 0,0,0) 
       end 
    end 
) 
  

As for the FX file. In line 95 you can manipulate the value (how many times is the effect applied) the lower, the faster.

it doesn't work

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