EngineApplyShaderToWorldTexture: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
(Replace to root.) |
||
(22 intermediate revisions by 7 users not shown) | |||
Line 2: | Line 2: | ||
__NOTOC__ | __NOTOC__ | ||
This function applies a [[shader]] to one or more world textures. | This function applies a [[shader]] to one or more world textures. | ||
{{Tip| | |||
'' | * The resource [[Shader_examples#Texture_names|shader_tex_names]] can help in finding the names of world textures. | ||
* When replacing the texture for a ped using the CJ skin, set '''textureName''' to "CJ" | |||
* The shader inherits the render states of the original when it is drawn, so texture stage 0 will already be set to the original texture. | |||
* When using with a 'ped', ensure you have set 'ped' or 'all' in the elementTypes when calling [[dxCreateShader]] | |||
* CJ body parts textures can be replaced by using: "cj_ped_head", "cj_ped_hat", "cj_ped_torso", "cj_ped_legs", "cj_ped_feet", "cj_ped_glasses", "cj_ped_necklace", "cj_ped_watch" and "cj_ped_extra1". Latest version of [http://wiki.multitheftauto.com/wiki/Shader_examples#Texture_names shader_tex_names] will show what is being used. | |||
}} | |||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
bool engineApplyShaderToWorldTexture ( element shader, string textureName [, element targetElement ] ) | bool engineApplyShaderToWorldTexture ( element shader, string textureName [, element targetElement = nil, bool appendLayers = true ] ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
{{New feature/item|3.0141|1.4.0|6987|{{OOP||[[shader]]:applyToWorldTexture}}}} | |||
===Required Arguments=== | ===Required Arguments=== | ||
Line 15: | Line 20: | ||
===Optional Arguments=== | ===Optional Arguments=== | ||
{{New feature/item| | {{New feature/item|3.0130|1.3.0|4140| | ||
*'''targetElement:''' The element to restrict applying the shader to. If this is not set the shader will be applied to everything using the texture name. Valid element types for targetElement are [[vehicle|vehicles]] | *'''targetElement:''' The element to restrict applying the shader to. If this is not set the shader will be applied to everything using the texture name. Valid element types for targetElement are [[vehicle|vehicles]], [[Object|objects]] and [[Ped|peds]]. | ||
}} | }} | ||
*'''appendLayers:''' allows two or more layered shaders to be applied in the same texture. You may want to modify the ''DepthBias'' in the technique pass to avoid Z-fighting artifacts when using this. | |||
===Returns=== | ===Returns=== | ||
Returns ''true'' if the shader was successfully applied, ''false'' otherwise. | Returns ''true'' if the shader was successfully applied, ''false'' otherwise. | ||
==Example== | ==Example== | ||
This example will replace the texture of a group of common explosions (grenades, rockets, etc) with a custom explosion effect | |||
<syntaxhighlight lang="lua"> | |||
theTechnique = dxCreateShader("shader.fx") | |||
explosionTexture = dxCreateTexture( "tex/Explosion.png") | |||
function replaceEffect() | |||
engineApplyShaderToWorldTexture(theTechnique, "fireball6") | |||
dxSetShaderValue (theTechnique, "gTexture", explosionTexture) | |||
end | |||
addEventHandler("onClientResourceStart", resourceRoot, replaceEffect) | |||
</syntaxhighlight> | |||
This example will apply a shader to the "des_logwall" world texture (which is used by the house near the 'play' gamemode spawn point) | This example will apply a shader to the "des_logwall" world texture (which is used by the house near the 'play' gamemode spawn point) | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
theTechnique = dxCreateShader("shader.fx") | |||
engineApplyShaderToWorldTexture( | engineApplyShaderToWorldTexture(theTechnique, "des_logwall") | ||
</syntaxhighlight> | </syntaxhighlight> | ||
This | This example will apply a shader to the current vehicle of the local player | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
theTechnique = dxCreateShader( "shader.fx" ) | |||
function applyShader(thePlayer, seat) | |||
local theVehicle = source | |||
if seat == 0 and thePlayer == localPlayer then | |||
engineApplyShaderToWorldTexture(theTechnique, "vehiclegrunge256", theVehicle) | |||
engineApplyShaderToWorldTexture(theTechnique, "?emap*", theVehicle) | |||
end | |||
end | |||
addEventHandler("onClientVehicleEnter", root, applyShader) | |||
) | |||
function removeShader(thePlayer, seat) | |||
local theVehicle = source | |||
if seat == 0 and thePlayer == localPlayer then | |||
engineRemoveShaderFromWorldTexture(theTechnique, "vehiclegrunge256", theVehicle) | |||
engineRemoveShaderFromWorldTexture(theTechnique, "?emap*", theVehicle) | |||
end | |||
end | |||
) | addEventHandler("onClientVehicleExit", root, removeShader) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
= | |||
{{ | Basic texture replacement shader example (compatible with all script examples on this page): | ||
<syntaxhighlight lang="fx"> | |||
texture gTexture; | |||
technique TexReplace | |||
{ | |||
pass P0 | |||
{ | |||
Texture[0] = gTexture; | |||
} | |||
} | |||
</syntaxhighlight> | |||
* Save the above code as [shadername]'''.fx''' | |||
==See Also== | ==See Also== | ||
{{Engine_functions}} | {{Engine_functions}} | ||
{{Drawing_functions}} | {{Drawing_functions}} |
Latest revision as of 23:50, 1 November 2022
This function applies a shader to one or more world textures.
Tip:
|
Syntax
bool engineApplyShaderToWorldTexture ( element shader, string textureName [, element targetElement = nil, bool appendLayers = true ] )
OOP Syntax Help! I don't understand this!
- Method: shader:applyToWorldTexture(...)
Required Arguments
- shader: The shader which is to be applied
- textureName: The name of the world texture to apply the shader to. Wildcard matching e.g. "ro?ds*" can be used to apply to more than one texture at a time.
Optional Arguments
- targetElement: The element to restrict applying the shader to. If this is not set the shader will be applied to everything using the texture name. Valid element types for targetElement are vehicles, objects and peds.
- appendLayers: allows two or more layered shaders to be applied in the same texture. You may want to modify the DepthBias in the technique pass to avoid Z-fighting artifacts when using this.
Returns
Returns true if the shader was successfully applied, false otherwise.
Example
This example will replace the texture of a group of common explosions (grenades, rockets, etc) with a custom explosion effect
theTechnique = dxCreateShader("shader.fx") explosionTexture = dxCreateTexture( "tex/Explosion.png") function replaceEffect() engineApplyShaderToWorldTexture(theTechnique, "fireball6") dxSetShaderValue (theTechnique, "gTexture", explosionTexture) end addEventHandler("onClientResourceStart", resourceRoot, replaceEffect)
This example will apply a shader to the "des_logwall" world texture (which is used by the house near the 'play' gamemode spawn point)
theTechnique = dxCreateShader("shader.fx") engineApplyShaderToWorldTexture(theTechnique, "des_logwall")
This example will apply a shader to the current vehicle of the local player
theTechnique = dxCreateShader( "shader.fx" ) function applyShader(thePlayer, seat) local theVehicle = source if seat == 0 and thePlayer == localPlayer then engineApplyShaderToWorldTexture(theTechnique, "vehiclegrunge256", theVehicle) engineApplyShaderToWorldTexture(theTechnique, "?emap*", theVehicle) end end addEventHandler("onClientVehicleEnter", root, applyShader) function removeShader(thePlayer, seat) local theVehicle = source if seat == 0 and thePlayer == localPlayer then engineRemoveShaderFromWorldTexture(theTechnique, "vehiclegrunge256", theVehicle) engineRemoveShaderFromWorldTexture(theTechnique, "?emap*", theVehicle) end end addEventHandler("onClientVehicleExit", root, removeShader)
Basic texture replacement shader example (compatible with all script examples on this page):
texture gTexture; technique TexReplace { pass P0 { Texture[0] = gTexture; } }
- Save the above code as [shadername].fx
See Also
- engineAddImage
- engineApplyShaderToWorldTexture
- engineFreeModel
- engineGetModelFlags
- engineGetModelIDFromName
- engineGetModelLODDistance
- engineGetModelNameFromID
- engineGetModelPhysicalPropertiesGroup
- engineGetModelTextureNames
- engineGetModelTextures
- engineGetModelTXDID
- engineGetModelVisibleTime
- engineGetObjectGroupPhysicalProperty
- engineGetSurfaceProperties
- engineGetVisibleTextureNames
- engineImageGetFilesCount
- engineImageGetFiles
- engineImageGetFile
- engineImageLinkDFF
- engineImageLinkTXD
- engineImportTXD
- engineLoadCOL
- engineLoadDFF
- engineLoadIMG
- engineLoadIFP
- engineLoadTXD
- engineRemoveImage
- engineRemoveShaderFromWorldTexture
- engineReplaceAnimation
- engineReplaceCOL
- engineReplaceModel
- engineRequestModel
- engineResetModelFlags
- engineResetModelLODDistance
- engineResetSurfaceProperties
- engineRestoreAnimation
- engineRestoreCOL
- engineRestoreDFFImage
- engineRestoreModel
- engineRestoreModelPhysicalPropertiesGroup
- engineRestoreObjectGroupPhysicalProperties
- engineRestoreTXDImage
- engineRestreamWorld
- engineSetAsynchronousLoading
- engineSetModelFlag
- engineSetModelFlags
- engineSetModelLODDistance
- engineSetModelPhysicalPropertiesGroup
- engineSetModelVisibleTime
- engineSetObjectGroupPhysicalProperty
- engineSetSurfaceProperties
- engineStreamingFreeUpMemory
- engineStreamingGetUsedMemory
- 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