DxCreateShader: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 7: Line 7:
==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
element, string dxCreateShader ( string filepath )
element, string dxCreateShader ( string filepath[, float priority = 0, float maxDistance ] )
</syntaxhighlight>  
</syntaxhighlight>  


===Required Arguments===  
===Required Arguments===  
*'''filepath:''' The filepath of the [[shader|shader  Effect File]](.fx) file
*'''filepath:''' The filepath of the [[shader|shader  Effect File]](.fx) file
===Optional Arguments===
''The following arguments are only relevant when the shader is used with [[engineApplyShaderToWorldTexture]]''
*'''priority:''' If more than one shader is matched to a world texture, the shader with the highest priority will be used. If there is more than one shader with the same highest priority, the most recently applied shader is used.
*'''maxDistance:''' If defined, the shader will not be applied to objects further than maxDistance. This can speed up rendering, but (to look good) may require the shader to fade out it's own effect as the object reaches maxDistance.


===Returns===
===Returns===

Revision as of 19:56, 16 July 2012

This function creates a shader element that can be used in the dxDraw functions. Successful shader creation is not guaranteed unless the Effect File contains a fallback technique which will work on every PC in the universe.

It is highly recommended that dxSetTestMode is used when writing and testing scripts using dxCreateShader.

Syntax

element, string dxCreateShader ( string filepath[, float priority = 0, float maxDistance ] )

Required Arguments

Optional Arguments

The following arguments are only relevant when the shader is used with engineApplyShaderToWorldTexture

  • priority: If more than one shader is matched to a world texture, the shader with the highest priority will be used. If there is more than one shader with the same highest priority, the most recently applied shader is used.
  • maxDistance: If defined, the shader will not be applied to objects further than maxDistance. This can speed up rendering, but (to look good) may require the shader to fade out it's own effect as the object reaches maxDistance.

Returns

  • element: A shader element if successful, false if invalid arguments were passed to the function. You should always check to see if this function has returned false.
  • string: The name of the technique that will be used.

Example

addEventHandler( "onClientRender", root,
    function()
        if myShader then
            dxDrawImage( 100, 350, 300, 350, myShader )
        end
    end
)

-- Use 'toggle' command to switch shader on and off
addCommandHandler( "toggle",
    function()
        if not myShader then
            myShader = dxCreateShader( "fancything.fx" )  -- Create shader
        else        
            destroyElement( myShader )                    -- Destroy shader
            myShader = nil
        end
    end
)

See Also