Jump to content

Help shader and script


0xCiBeR

Recommended Posts

  • MTA Team

How to make this Shell on a player last until i cancel de efect, and how do i make my shell visible for everyone when i activate it?..Thx

Lua:

-- 
-- c_ped_shell.lua 
-- 
  
local myShader 
local startTickCount = 0 
  
addEventHandler( "onClientResourceStart", resourceRoot, 
    function() 
  
        -- Version check 
        if getVersion ().sortable < "1.3.1-9.04939" then 
            outputChatBox( "Recurso incompatible" ) 
            outputChatBox( "Actualiza MTA." ) 
            return 
        end 
  
        -- Create shader 
        myShader, tec = dxCreateShader ( "fx/ped_shell_layer.fx", 0, 0, true, "ped" ) 
  
        if not myShader then 
            outputChatBox( "Could not create shader. Please use debugscript 3" ) 
        else 
        
  
            -- Apply shader to local player 
            engineApplyShaderToWorldTexture ( myShader, "*", localPlayer ) 
  
            -- Hack to make GTA render the ped last, so our shell effect appears on top of the background 
            setElementAlpha( localPlayer, 254 ) 
  
  
            -- Fire effect at startup 
            startEffect(); 
        end 
    end 
) 
  
  
---------------------------------------------------------------- 
-- Start effect here 
---------------------------------------------------------------- 
function startEffect() 
    startTickCount = getTickCount() 
end 
  
bindKey("m", "down", startEffect ) 
  
  
---------------------------------------------------------------- 
-- Update effect here 
---------------------------------------------------------------- 
addEventHandler( "onClientRender", root, 
    function() 
        if not myShader then return end 
  
            local timeElapsed = getTickCount() - startTickCount 
            local f = timeElapsed / 750 
            f = math.min( f, 1 ) 
  
            local alpha = math.lerp ( 1.0, 0.0, f ) 
            local size = math.lerp ( 0, 0.3, f ) 
  
            -- Expand shell 
            dxSetShaderValue( myShader, "sMorphSize", size, size, size ) 
  
            -- Fade out shell 
            dxSetShaderValue( myShader, "sMorphColor", 255, 0, 0, alpha ) 
    end 
) 
  
  
---------------------------------------------------------------- 
-- Math helper functions 
---------------------------------------------------------------- 
function math.lerp(from,to,alpha) 
    return from + (to-from) * alpha 
end 
  

Shader-Side

// 
// Example shader - ped_shell_layer.fx 
// 
  
  
//--------------------------------------------------------------------- 
// Ped shell settings 
//--------------------------------------------------------------------- 
float3 sMorphSize = float3(0,0,0); 
float4 sMorphColor = float4(1,1,1,1); 
  
  
//--------------------------------------------------------------------- 
// Include some common stuff 
//--------------------------------------------------------------------- 
#include "mta-helper.fx" 
  
  
//--------------------------------------------------------------------- 
// Structure of data sent to the vertex shader 
//--------------------------------------------------------------------- 
struct VSInput 
{ 
float3 Position : POSITION0; 
float3 Normal : NORMAL0; 
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; 
  
// Do morph effect by adding surface normal to the vertex position 
VS.Position += VS.Normal * sMorphSize; 
  
// Calculate screen pos of vertex 
PS.Position = MTACalcScreenPosition ( VS.Position ); 
  
// Pass through tex coords 
PS.TexCoord = VS.TexCoord; 
  
// Set our custom morph color 
PS.Diffuse.rgb = sMorphColor.rgb * sMorphColor.a; 
PS.Diffuse.a = 1; 
  
return PS; 
} 
  
  
//------------------------------------------------------------------------------------------ 
// Techniques 
//------------------------------------------------------------------------------------------ 
technique tec0 
{ 
pass P0 
{ 
// As this shader is used as a separate layer, we just have to draw our effect 
// and not worry about the main rendering 
  
// SrcBlend and DestBlend can be set for various effects 
// This combination gives a translucent look 
SrcBlend = SrcColor; 
DestBlend = One; 
  
VertexShader = compile vs_2_0 VertexShaderFunction(); 
} 
} 
  
// Fallback 
technique fallback 
{ 
pass P0 
{ 
// As this shader is used as a separate layer, don't draw anything 
SrcBlend = Zero; 
DestBlend = One; 
} 
} 
  
 

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