dxCreateShader
Client-side
Server-side
Shared
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 existing PC.
Tip
- It is highly recommended that dxSetTestMode is used when writing and testing scripts using dxCreateShader.
- You should always check to see if this function has returned false.
OOP Syntax Help! I don't understand this!
- Constructor: DxShader (...)
Syntax
shader|false, string dxCreateShader ( string filepath/raw_data, [ table macros = {}, float priority = 0, float maxDistance = 0, bool layered = false, string elementTypes = "world,vehicle,object,other" ] )Required Arguments
- filepath/raw_data: The filepath of the shader Effect File (.fx) file or whole data buffer of the shader file.
Optional Arguments
NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use.
- macros (default: {}): A table contains macros in an ordered and/or unordered way. See example below.
- priority (default: 0): 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 created shader is used.
- maxDistance (default: 0): If non-zero, the shader will be applied to textures nearer than maxDistance only. This can speed up rendering, but (to look good) may require the shader to fade out it's own effect as the texture reaches maxDistance.
- layered (default: false): When set to true, the shader will be drawn in a separate render pass. Several layered shaders can be drawn on the same world texture. (To avoid Z fighting artifacts, you may have to add
DepthBias=-0.0002;to the technique pass, but this might cause visual artifacts when applied on vehicles). - elementTypes (default: "world,vehicle,object,other"): A comma seperated list of element types to restrict this shader to. Valid element types are:
- world - Textures in the GTA world
- ped - Player and ped textures
- vehicle - Vehicles textures
- object - Objects textures other
- other - Element textures which are not peds, vehicles or objects
- all - Everything
Returns
- shader|false: shader element
- string: technique
Returns a shader element and the name of the technique that will be used if successful, false if invalid arguments were passed to the function or there is insufficient resources available.
Code Examples
client
local myShader
addEventHandler("onClientRender", root, function() if myShader then dxDrawImage(100, 350, 300, 350, myShader) endend)
-- Use 'toggle' command to switch shader on and offaddCommandHandler("toggle", function() if not myShader then myShader = dxCreateShader("fancything.fx") -- Create shader else destroyElement(myShader) -- Destroy shader myShader = nil endend)Changelog
See Also
Drawing Functions
- dxConvertPixels
- dxCreateFont
- dxCreateRenderTargetUpdated
- dxCreateScreenSource
- dxCreateShader
- dxCreateTextureUpdated
- dxDrawCircle
- dxDrawImage
- dxDrawImageSection
- dxDrawLine
- dxDrawLine3D
- dxDrawMaterialLine3D
- dxDrawMaterialPrimitive
- dxDrawMaterialPrimitive3D
- dxDrawMaterialSectionLine3D
- dxDrawModel3DNew
- dxDrawPrimitive
- dxDrawPrimitive3D
- dxDrawRectangle
- dxDrawText
- dxDrawWiredSphere
- dxGetBlendMode
- dxGetFontHeight
- dxGetMaterialSize
- dxGetPixelColor
- dxGetPixelsFormat
- dxGetPixelsSize
- dxGetStatusUpdated
- dxGetTextSize
- dxGetTexturePixelsUpdated
- dxGetTextWidth
- dxIsAspectRatioAdjustmentEnabled
- dxSetAspectRatioAdjustmentEnabled
- dxSetBlendMode
- dxSetPixelColor
- dxSetRenderTarget
- dxSetShaderTessellation
- dxSetShaderTransform
- dxSetShaderValue
- dxSetTestMode
- dxSetTextureEdge
- dxSetTexturePixels
- dxUpdateScreenSource