dxSetShaderTransform
Client-side
Server-side
Shared
This function applies a 3D transformation to a shader element when it is drawn with dxDrawImage.
Tip
To convert screen relative units into screen pixel coordinates, multiply by the screen size. Conversely, to convert screen pixel coordinates to screen relative units, divide by the screen size.
OOP Syntax Help! I don't understand this!
- Method:shader:setTransform(...)
Syntax
bool dxSetShaderTransform ( element theShader, float rotationX, float rotationY, float rotationZ, [ float rotationCenterOffsetX = 0, float rotationCenterOffsetY = 0, float rotationCenterOffsetZ = 0, bool bRotationCenterOffsetOriginIsScreen = false, float perspectiveCenterOffsetX = 0, float perspectiveCenterOffsetY = 0, bool bPerspectiveCenterOffsetOriginIsScreen = false ] )Required Arguments
- theShader: The shader element whose transformation is to be changed.
- rotationX: Rotation angle in degrees around the X axis (Left,right). This will make the shader rotate along its width.
- rotationY: Rotation angle in degrees around the Y axis (Up,down). This will make the shader rotate along its height.
- rotationZ: Rotation angle in degrees around the Z axis (In,out). This will make the shader rotate in a similar way to the rotation argument in dxDrawImage.
Optional Arguments
NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use.
- rotationCenterOffsetX (default: 0): The center of rotation offset X position in screen relative units.
- rotationCenterOffsetY (default: 0): The center of rotation offset Y position in screen relative units.
- rotationCenterOffsetZ (default: 0): The center of rotation offset Z position in screen relative units.
- bRotationCenterOffsetOriginIsScreen (default: false): Set to true if the center of rotation origin should be the center of the screen rather than the center of the image.
- perspectiveCenterOffsetX (default: 0): The center of perspective offset X position in screen relative units.
- perspectiveCenterOffsetY (default: 0): The center of perspective offset Y position in screen relative units.
- bPerspectiveCenterOffsetOriginIsScreen (default: false): Set to true if the center of perspective origin should be the center of the screen rather than the center of the image.
Returns
- bool: value
Returns true if the shader element's transform was successfully changed, false otherwise.
Code Examples
client
local shaderlocal texturelocal angle = 0 -- Initialize angle for rotationlocal radius = 50 -- Reduced radius for the circular motionlocal centerX, centerY -- Center of the screen
function startShaderExample() -- Create a shader shader = dxCreateShader("texture.fx")
-- Load a texture texture = dxCreateTexture("myTexture.png")
-- Apply the texture to the shader dxSetShaderValue(shader, "gTexture", texture)
-- Get the center of the screen local screenWidth, screenHeight = guiGetScreenSize() centerX = screenWidth / 2 centerY = screenHeight / 2
-- Start rendering the shader addEventHandler("onClientRender", root, renderShader)endaddEventHandler("onClientResourceStart", resourceRoot, startShaderExample)
function renderShader() -- Increment the angle to create rotation over time angle = angle + 0.02 if angle > 2 * math.pi then angle = 0 end
-- Calculate the position based on a smaller circular path local positionX = centerX + math.cos(angle) * radius local positionY = centerY + math.sin(angle) * radius
-- Apply transformation: translation along a smaller circular path and rotation dxSetShaderTransform(shader, positionX, positionY, 0, 0, 0, angle)
-- Draw a rectangle with the shader applied, following the circular path dxDrawImage(positionX - 128, positionY - 128, 256, 256, shader)end
function stopShaderExample() if shader then destroyElement(shader) shader = nil end if texture then destroyElement(texture) texture = nil end removeEventHandler("onClientRender", root, renderShader)endaddEventHandler("onClientResourceStop", resourceRoot, stopShaderExample)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