- Documentation
- Client functions
- dxCreateShader
Function
dxCreateShader
Creates a shader from a resource .fx file or from code given as a string. In Trilogy Hub a shader performs texture replacement: the image set with dxSetShaderValue under a texture parameter replaces the world textures chosen with engineApplyShaderToWorldTexture (e.g. custom billboards, signs on buildings, car wraps). The game material stays (lighting, reflections); only the image changes. Pixel and vertex effects from HLSL code are not executed.
Syntax
element, string dxCreateShader(string filepath [, int priority = 0, float maxDistance = 0, bool layered = false, string elementTypes = "world,vehicle,object,other"])Arguments
filepathstring- Path to a .fx file in the resource, or the shader code.
priorityint, optional = 0- Priority when several shaders hit the same texture.Different type in MTA:SA: table macros = {}
maxDistancefloat, optional = 0- For compatibility with existing scripts.
layeredbool, optional = false- For compatibility with existing scripts.Different type in MTA:SA: float maxDistance = 0
elementTypesstring, optional = "world,vehicle,object,other"- For compatibility with existing scripts.Different type in MTA:SA: bool layered = false
Differences from MTA:SA
- Arguments in a different colour differ from MTA:SA.
- These MTA:SA arguments are not here:
string elementTypes = "world,vehicle,object,other"
In MTA:SA
dxCreateShader(string filepath/raw_data, table macros = {}, float priority = 0, float maxDistance = 0, bool layered = false, string elementTypes = "world,vehicle,object,other")Returns
A shader element and the technique name from the file, or false when the file cannot be loaded.
Example
local shader = dxCreateShader("texture gTexture; technique replace { pass P0 { Texture[0] = gTexture; } }")
local image = dxCreateTexture("billboard.png")
dxSetShaderValue(shader, "gTexture", image)
engineApplyShaderToWorldTexture(shader, "heat_02")
See also
dxSetShaderValueSets a shader parameter. When the parameter is a texture declared in the .fx code (or the shader has none) and the value is a texture (dxCreateTexture, render target, browser) or an image path, that image becomes the new texture swapped into the world. Numbers and vectors are stored for compatibility with existing scripts.engineApplyShaderToWorldTextureReplaces a San Andreas world texture with the given name with the shader's image. The name may contain*and?(e.g."vehiclegrunge*"). Without an element the replacement applies to all objects with that texture, including those loaded later; with an element (vehicle, object, ped) - only to it. The names of textures currently visible in the game are returned byengineGetVisibleTextureNames.engineApplyTextureToWorldTextureReplaces a world texture with a script texture without writing a shader: a texture fromdxCreateTexture, a render target, a screen source or a browser is enough. Works likeengineApplyShaderToWorldTexture(*and?patterns, optional element). A render target or browser gives a live image, e.g. an in-game TV showing a web page.