Jump to content

Shader Help


Recommended Posts

i'll be short: I'm trying to create a windows 8 effect where the image should rotate 90° not clock-wise until dissapearing (becouse its being looked from the side and it hasnt got any width) but nothing is happening. No errors in debug. Image is drawn normally without problems.

  
local x,y = guiGetScreenSize() 
addEventHandler("onClientResourceStart", root, function() 
shader = dxCreateShader("shader.fx") 
image = dxCreateTexture("Image1.jpg") 
dxSetShaderValue(shader, "Texture0", image) 
RenderTarget = dxCreateRenderTarget(x*0.6,y*0.6) 
end) 
  
local Images = { 
 --[[ Start ]]  
     { 
        {0,0,0,0, y*0.5,0,true,0,y*0.5}, 
        1 
     }, 
 --[[ End ]]  
     { 
        {0,90,0,0, y*0.5,0,true,0,y*0.5}, 
        2 
     }, 
 --[[ Current ]] 
     { 
        {0,0,0,0, y*0.5,0,true,0,y*0.5}, 
        {1,1} 
     } 
} 
  
function onClientRenderTest() 
if not shader then return outputChatBox("Shader error") end 
if not image then return outputChatBox("Image error") end 
if not RenderTarget then return outputChatBox("Target error") end 
dxSetRenderTarget(RenderTarget) 
dxSetShaderTransform(shader, Images[3][1][1],Images[3][1][2], Images[3][1][3], Images[3][1][4],Images[3][1][5],Images[3][1][6],Images[3][1][7],Images[3][1][8], Images[3][1][9]) 
dxDrawImage(0, 0, x*0.6, y*0.6, image) 
dxSetRenderTarget() 
dxDrawImage(x*0.3, y*0.3, x*0.6, y*0.6, RenderTarget) 
end 
  
function toggle() 
if toggle then 
toggle = nil 
removeEventHandler("onClientPreRender", root, onClientRenderTest) 
else 
toggle = true 
outputChatBox("True") 
addEventHandler("onClientPreRender", root, onClientRenderTest) 
end 
end 
bindKey("F2", "down", toggle) 
  
function MoveAsd() 
    --[[ Check if start or end ]] 
    if Images[3][2][2] == 1 then 
    Images[3][2][1] = 2 
    start = getTickCount() 
    addEventHandler("onClientRender", root, AnimationProcess) 
    unbindKey("F", "down", MoveAsd) -- Stop it from being triggered before animation ends 
        setTimer(function() 
        Images[3][2][2] = 2 
        removeEventHandler("onClientRender", root, AnimationProcess) 
        bindKey("F", "down", MoveAsd) -- Bind it back after animation ends 
        end, 1000, 1) 
    else 
    Images[3][2][1] = 1 
    start = getTickCount() 
    addEventHandler("onClientRender", root, AnimationProcess) 
    unbindKey("F", "down", MoveAsd) -- Stop it from being triggered before animation ends 
        setTimer(function() 
        Images[3][2][2] = 1 
        removeEventHandler("onClientRender", root, AnimationProcess) 
        bindKey("F", "down", MoveAsd) -- Bind it back after animation ends 
        end, 1000, 1) 
    end 
     
end 
bindKey("F3", "down", MoveAsd) 
  
function AnimationProcess() 
if Images[3][2][1] == Images[3][2][2] then return end 
local now = getTickCount() 
local ending = start + 1000 
local elapsed = now - start 
local duration = ending - start 
local progress = elapsed / duration 
for i=1, #Images[3][1] do 
    if i == 7 then 
    else 
    Images[3][1][i] = interpolateBetween(Images[ Images[3][2][2] ][1][i],0,0,Images[ Images[3][2][1] ][1][i],0,0, progress, "Linear") 
    end 
end 
end 

 

shader:

 

  
// 
// image.fx 
// 
  
  
//--------------------------------------------------------------------- 
// texture settings 
//--------------------------------------------------------------------- 
texture Texture0; 
  
  
//------------------------------------------------------------------------------------------ 
// Techniques 
//------------------------------------------------------------------------------------------ 
technique tec0 
{ 
    pass P0 
    { 
        Texture[0] = Texture0; 
    } 
} 
  
// Fallback 
technique fallback 
{ 
    pass P0 
    { 
    } 
} 
  

 

Meta: (little bit extense, i'm only using C.lua, shader.fx and Image1.jpg, the others are just becouse i found out that it is faster for scripting to just have everything there and change names :).)

  
<meta> 
    <file src="mta-helper.fx" type="client" /> 
    <info author="HyPeX" name="LxGRadio" type="script" version="1.0" /> 
        <script src="Radio.lua" type="server" /> 
    <file src="fonts/podium.ttf" /> 
    <file src="fonts/asd.ttf" /> 
    <script src="C.lua" type="client"/> 
    <script src="S.lua" type="server"/> 
    <file src="container.col"/> 
    <file src="shader.fx" /> 
    <file src="container.dff"/> 
    <file src="container.txd"/> 
    <file src="fonts/BF3.ttf" /> 
    <file src="hud.png" /> 
    <file src="settings.png" /> 
    <file src="loading.png" /> 
    <file src="img/deploy.png" /> 
    <file src="achivements.png" /> 
    <file src="plus.png" /> 
    <file src="ranking.png" /> 
    <file src="360.png" /> 
    <file src="back.jpg" /> 
    <file src="backg.jpg" /> 
    <file src="Image1.jpg" /> 
    <file src="Image2.jpg" /> 
    <file src="Image3.jpg" /> 
    <file src="Image4.jpg" /> 
    <file src="img/Lobby.png" /> 
    <file src="img/chapa.png" /> 
    <file src="txd/nbball.txd" /> 
    <min_mta_version client="1.3.0-9.04431" /> 
<settings> 
    <setting name="*Labels" value="{Kills, Deaths, Headshots, PlayTime, EXP, Level, Rank}" friendlyname="Dashboard Labels" group="" accept="" examples="cash, kills" desc="" /> 
</settings> 
</meta> 
  
  

Link to comment

The first problem I notice is that you are not even using the shader to draw, also the render target is not needed.

You only need to do this:

function onClientRenderTest() 
if not shader then return outputChatBox("Shader error") end 
if not image then return outputChatBox("Image error") end 
dxSetShaderTransform(shader, Images[3][1][1],Images[3][1][2], Images[3][1][3], Images[3][1][4],Images[3][1][5],Images[3][1][6],Images[3][1][7],Images[3][1][8], Images[3][1][9]) 
dxDrawImage(x*0.3, y*0.3, x*0.6, y*0.6, shader) 
end 

Link to comment

Woops my bad, about the render target, i'm using it for other purpouses for now i wont mention :D .

@Gallardo: I think it wont give the desired effect, as it will probably just stretch it out.

I'll test it tomorrow, gotta study today, thanks for the help guys! (Btw, i'm quite ashamed of not even checking the image draw)

The idea was ineeded to load the shader with the texture loaded. (but looks like i messed up)

Link to comment

Well i got a problem, the rotationCenterOffset X,Y,Z seems to have no effect, why?

  
local x,y = guiGetScreenSize() 
addEventHandler("onClientResourceStart", root, function() 
shader = dxCreateShader("shader.fx") 
image = dxCreateTexture("Image1.jpg") 
dxSetShaderValue(shader, "gTexture", image) 
end) 
  
local Images = { 
 --[[ Start ]]  
     { 
        {0,0,0,x*0.1,y*0.5,x*0.5}, 
        1 
     }, 
 --[[ End ]]  
     { 
        {90,0,0,x*0.1,y*0.5,x*0.5}, 
        2 
     }, 
 --[[ Current ]] 
     { 
        {0,0,0}, 
        {1,1} 
     } 
} 
  
function onClientRenderTest() 
if not shader then return outputChatBox("Shader error") end 
if not image then return outputChatBox("Image error") end 
dxSetShaderTransform(shader, Images[3][1][1],Images[3][1][2], Images[3][1][3],Images[3][1][4],Images[3][1][5],Images[3][1][6]) 
dxDrawImage(x*0.1, y*0.1, x*0.6, y*0.6, shader) 
end 
  
function toggle() 
if toggle then 
toggle = nil 
removeEventHandler("onClientPreRender", root, onClientRenderTest) 
else 
toggle = true 
outputChatBox("True") 
addEventHandler("onClientPreRender", root, onClientRenderTest) 
end 
end 
bindKey("F2", "down", toggle) 
  
function MoveAsd() 
    --[[ Check if start or end ]] 
    if Images[3][2][2] == 1 then 
    Images[3][2][1] = 2 
    start = getTickCount() 
    addEventHandler("onClientRender", root, AnimationProcess) 
    unbindKey("F3", "down", MoveAsd) -- Stop it from being triggered before animation ends 
        setTimer(function() 
        Images[3][2][2] = 2 
        removeEventHandler("onClientRender", root, AnimationProcess) 
        bindKey("F3", "down", MoveAsd) -- Bind it back after animation ends 
        end, 1000, 1) 
    else 
    Images[3][2][1] = 1 
    start = getTickCount() 
    addEventHandler("onClientRender", root, AnimationProcess) 
    unbindKey("F3", "down", MoveAsd) -- Stop it from being triggered before animation ends 
        setTimer(function() 
        Images[3][2][2] = 1 
        removeEventHandler("onClientRender", root, AnimationProcess) 
        bindKey("F3", "down", MoveAsd) -- Bind it back after animation ends 
        end, 1000, 1) 
    end 
     
end 
bindKey("F3", "down", MoveAsd) 
  
function AnimationProcess() 
if Images[3][2][1] == Images[3][2][2] then return end 
local now = getTickCount() 
local ending = start + 1000 
local elapsed = now - start 
local duration = ending - start 
local progress = elapsed / duration 
for i=1, #Images[3][1] do 
    if i == 7 then 
    else 
    Images[3][1][i] = interpolateBetween(Images[ Images[3][2][2] ][1][i],0,0,Images[ Images[3][2][1] ][1][i],0,0, progress, "Linear") 
    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...