DxCreateShader: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 29: | Line 29: | ||
*'''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.''' | *'''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. | *'''string:''' The name of the technique that will be used. | ||
|20688}} | |20688}} | ||
{{ | {{Updated feature/item|3.0160|1.5.9|1.5.8|20688| | ||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
Line 58: | Line 57: | ||
*'''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.''' | *'''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. | *'''string:''' The name of the technique that will be used. | ||
}} | |||
==Example== | ==Example== | ||
Line 114: | Line 112: | ||
You can pass raw data (shader code) directly into the function (example uses variable ''myShader_raw_data''). | You can pass raw data (shader code) directly into the function (example uses variable ''myShader_raw_data''). | ||
}} | }} | ||
{{Updated feature/item|3.0160|1.5.9|1.5.8|20688| | |||
{{ | This example creates a basic shader using macros to change shader's behaviour: | ||
This example creates a basic shader using macros to change shader's behaviour | |||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
local shaderRawStr = [[ | local shaderRawStr = [[ | ||
Line 168: | Line 165: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
You can also pass macros in key-value pairs when the order is important. | You can also pass macros in key-value pairs when the order is important. | ||
}} | |||
==Changelog== | ==Changelog== |
Revision as of 13:13, 23 September 2021
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.
20688
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 )
This example creates basic shader from raw data (without i/o) on resource start:
local myShader_raw_data = [[ texture tex; technique replace { pass P0 { Texture[0] = tex; } } ]] addEventHandler("onClientResourceStart", resourceRoot, function() local myShader = dxCreateShader(myShader_raw_data) -- create shader from raw data if isElement(myShader) then local myTexture = dxCreateTexture("some_image.png") -- create texture from image file if isElement(myTexture) then -- apply image to world texture via shader dxSetShaderValue(myShader, "tex", myTexture) engineApplyShaderToWorldTexture(myShader, "shad_ped") else outputDebugString("Unable to load texture", 1) end else outputDebugString("Unable to create shader", 1) end end)
You can pass raw data (shader code) directly into the function (example uses variable myShader_raw_data).
20688
Changelog
Version | Description |
---|
1.3.0-9.04435 | Added layered and elementTypes arguments |
1.5.6-9.14403 | Added option to use raw data instead of a file name |
1.5.8-9.20688 | Added option to use macros |
See Also
- dxConvertPixels
- dxCreateFont
- dxCreateRenderTarget
- dxCreateScreenSource
- dxCreateShader
- dxCreateTexture
- dxDrawCircle
- dxDrawImage
- dxDrawImageSection
- dxDrawLine
- dxDrawLine3D
- dxDrawMaterialLine3D
- dxDrawMaterialPrimitive
- dxDrawMaterialPrimitive3D
- dxDrawMaterialSectionLine3D
- dxDrawPrimitive
- dxDrawPrimitive3D
- dxDrawRectangle
- dxDrawText
- dxDrawWiredSphere
- dxGetBlendMode
- dxGetFontHeight
- dxGetMaterialSize
- dxGetPixelColor
- dxGetPixelsSize
- dxGetPixelsFormat
- dxGetStatus
- dxGetTextSize
- dxGetTextWidth
- dxGetTexturePixels
- dxIsAspectRatioAdjustmentEnabled
- dxSetAspectRatioAdjustmentEnabled
- dxSetBlendMode
- dxSetPixelColor
- dxSetRenderTarget
- dxSetShaderValue
- dxSetShaderTessellation
- dxSetShaderTransform
- dxSetTestMode
- dxSetTextureEdge
- dxSetTexturePixels
- dxUpdateScreenSource