Skip to content

Add fxAddShadow with custom DX texture support - #5337

Open
Xenius97 wants to merge 1 commit into
multitheftauto:masterfrom
Xenius97:new/fx_shadows
Open

Add fxAddShadow with custom DX texture support#5337
Xenius97 wants to merge 1 commit into
multitheftauto:masterfrom
Xenius97:new/fx_shadows

Conversation

@Xenius97

@Xenius97 Xenius97 commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR adds the client-side fxAddShadow Lua function by porting PR #4559.

The implementation originates from work by CrosRoad95 in PR #1003. After the original code was abandoned, it was reassembled and modernized in PR #4559, with known crashes and stability issues addressed.

This version extends that work further by allowing the first argument to be either a built-in shadow name or a live 2D DX texture element:

bool fxAddShadow(
    texture,
    x, y, z,
    frontX, frontY,
    sideX, sideY,
    color,
    shadowType,
    zDistance,
    drawOnWater,
    drawOnBuildings
)

Position and offset arguments may also be passed as Vector3 and Vector2 values. The function is client-side only and is also available through the Effect.createShadow OOP alias.

The supported built-in textures are:

car, ped, heli, bike, rcbaron, explosion,
headlight1, headlight2, blood, handman, wincrack, lamp

Custom textures may be created with dxCreateTexture. Two-dimensional render targets and screen sources are also supported.

Each call queues a shadow for one GTA render pass, so fxAddShadow must be called every frame, preferably from onClientPreRender. The queue shares GTA’s native 48-shadow limit and retains its own GPU reference until rendering completes.

https://imgur.com/l5s9lYC

Motivation

The original implementation provides a useful way for Lua resources to access GTA: San Andreas’ projected-shadow system, but it was never merged and was eventually left behind.

This PR brings the modernized implementation into the client while preserving the fixes from the previous work. Support for custom DX textures expands its use beyond GTA’s built-in shadows, allowing resources to render custom transparent masks, projected lighting, and similar world effects without requiring separate geometry.

Test plan

fx-shadow-test.zip

Checklist

  • Your code should follow the coding guidelines.
  • Smaller pull requests are easier to review. If your pull request is beefy, your pull request should be reviewable commit-by-commit.

@FileEX

FileEX commented Sep 8, 2026

Copy link
Copy Markdown
Member

What about #1003 (comment)?

@Xenius97

Xenius97 commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

What about #1003 (comment)?

I've used for long hours without any issues, no crashes.

@FileEX FileEX added the enhancement New feature or request label Sep 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants