Skip to content

Share the texture environment colour between stages, as the DirectX driver does - #16

Merged
nsgomez merged 1 commit into
nsgomez:mainfrom
aspctt:shared-texture-env-color
Oct 25, 2026
Merged

nsgomez merged 1 commit into
nsgomez:mainfrom
aspctt:shared-texture-env-color

Conversation

@aspctt

@aspctt aspctt commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Building shadows turn purple at night. TexEnv with a colour sets GL_TEXTURE_ENV_COLOR on the active unit only, but OpenGL keeps that colour per unit, while DirectX has a single one for every stage.

What the game and the DirectX driver do, from SimCity 4 version 641:

  • DirectX TexEnv with a colour (0x8830a0) sets D3DRS_TEXTUREFACTOR and ignores the stage.
  • The building shadow pass (0x736bf0) fades each shadow patch by scaling the colour's alpha, then sets it through 0x7d30b0, which calls TexEnv(0, 1, colour) without selecting a stage. That happens right after 0x7d4340 selected stage 1, but the colour is meant for stage 0's combiner, which reads GL_CONSTANT (the texture factor) for the alpha.

So on SCGL, stage 1 gets the faded colour and stage 0 keeps an older one, and the shadows come out with the wrong colour and strength.

Changes:

  • TexEnv writes the colour to every texture unit, then makes the previously active unit active again.
  • An unchanged colour is skipped, so the extra unit switches only happen when it changes.

scvk had the same bug (blue night shadows) and this fixed it there.

Tested in game on version 641 with an NVIDIA RTX 3070, against upstream main: night shadows are grey instead of purple.

…river does

- TexEnv writes the colour to every texture unit, since DirectX has one texture factor for all stages
- The game sets it right after selecting stage 1 for stage 0's combiner to read, which left the building shadows unfaded at night
- Unchanged colours are skipped
@aspctt

aspctt commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

Current upstream:

upstream-scgl

This PR:

patched-scgl

@nsgomez
nsgomez merged commit 898b5a8 into nsgomez:main Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants