Jump to content

Shaders


.:HyPeX:.

Recommended Posts

Hey guys I've done so far an implementantion of the UV_Scripted shader from the wiki on a map with an image, but, i want to know if it is possible to make it for ALL the objects under that category (billboard) to have that effect. Else i could just add various object under the line of creating...

Eg:

  
-- Create object with model 4729 (billboard) 
createObject ( 4729, 1850, -4370, 10, 0, 0, 22 ) 
createObject ( 4729, 1850, -4380, 10, 0, 0, 22 ) 
createObject ( 4729, 1850, -4390, 10, 0, 0, 22 ) 
  

Link to comment
  
-- 
-- c_uv_scripted.lua 
-- 
  
  
local myShader 
local startTickCount 
  
addEventHandler( "onClientResourceStart", resourceRoot, 
    function() 
  
        -- Version check 
        if getVersion ().sortable < "1.1.0" then 
            outputChatBox( "Resource is not compatible with this client." ) 
            return 
        end 
  
        -- Create shader 
        myShader, tec = dxCreateShader ( "uv_scripted.fx" ) 
  
        -- Create texture and add to shader 
        local myTexture = dxCreateTexture ( "images/env3.bmp" ); 
        dxSetShaderValue ( myShader, "CUSTOMTEX0", myTexture ); 
  
        if not myShader then 
            outputChatBox( "Could not create shader. Please use debugscript 3" ) 
        else 
            outputChatBox( "Using technique " .. tec ) 
  
            -- Apply to world texture 
            engineApplyShaderToWorldTexture ( myShader, "bobo_2" ) 
  
            -- Create object with model 4729 (billboard) 
            createObject ( 4729, 1843, -4385, 477, 0, 0, 22 ) 
  
            -- Begin updates for UV animation 
            startTickCount = getTickCount() 
            addEventHandler( "onClientRender", root, updateUVs ) 
        end 
    end 
) 
  
  
------------------------------------------------------ 
-- Update 
------------------------------------------------------ 
function updateUVs() 
    -- Valide shader to save bazillions of warnings 
    if not isElement( myShader ) then return end 
  
    -- Calc how many seconds have passed since uv anim started 
    local secondsElapsed = ( getTickCount() - startTickCount ) / 1000 
  
    -- Calc section (0-6) and time (0-1) within the section 
    local timeLooped = ( secondsElapsed / 2 ) % 6 
    local section = math.floor ( timeLooped ) 
    local time = timeLooped % 1 
  
    -- Figure out what uv anims to do 
    local bScrollLeft = section == 0 or section == 3 or section == 4 or section == 6 
    local bWobbleRotate = section == 1 or section == 3 or section == 5 or section == 6 
    local bGoneAllZoomy = section == 2 or section == 4 or section == 5 or section == 6 
  
    local u,v = 0, 0 
    local angle = 0 
    local scale = 1 
  
    -- Do uv anims 
    if bScrollLeft then 
        u = time 
    end 
    if bWobbleRotate then 
        angle = math.sin(time/2*6.28)/4 
    end 
    if bGoneAllZoomy then 
        scale = math.cos(time*6.28) * 0.5 + 0.5 
    end 
  
    -- Apply uv anims 
    dxSetShaderValue ( myShader, "gUVPosition", u,v ); 
    dxSetShaderValue ( myShader, "gUVRotAngle", angle ); 
    dxSetShaderValue ( myShader, "gUVScale", scale, scale ); 
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...