Repository navigation
Take a faded alpha from the material, as the DirectX driver does - #15
Merged
Merged
Conversation
- Below one, AlphaMultiplier stops the vertex colour feeding the diffuse material, so the fade wins over the vertex alpha - At one, the vertex colour feeds it again if EnableVertexColors asked for that - The diffuse material is written back whenever the vertex colour stops feeding it, since OpenGL leaves the last vertex colour there
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #7.
AlphaMultiplierwrites the faded alpha into the diffuse material, but whileglColorMaterialtracksGL_DIFFUSE, the vertex colour replaces the diffuse material, alpha included, so the fade never shows. It also skips the write entirely when neither vertex colour flag is set.What the DirectX driver does, from SimCity 4 version 641:
AlphaMultiplier(0x883310) sets the material's diffuse alpha, then setsD3DRS_DIFFUSEMATERIALSOURCEtoD3DMCS_MATERIALwhen the alpha is below 1.0, or back toD3DMCS_COLOR1at 1.0 if the diffuse flag ofEnableVertexColorsis set.EnableVertexColors(0x8833e0) setsD3DRS_AMBIENTMATERIALSOURCEandD3DRS_DIFFUSEMATERIALSOURCEfrom its two flags, whatever the alpha was.Changes:
EnableVertexColorsasked for that.EnableVertexColorssets the source outright, as on DirectX.This is what kept cars from fading in and out right.
#13 also targets #7, by always writing the alpha to the material. That covers the case where neither vertex colour flag is set, but while colour material tracks
GL_DIFFUSEthe material's alpha is still replaced, by the vertex colour or by theglColor4f(1, 1, 1, 1)thatInterleavedArrayssets for formats without one. Switching the source as DirectX does covers both cases.One side effect: while something fades, the directional light no longer adds the vertex colour, so it can look a little darker during the fade. DirectX never adds it: its driver gives Direct3D no normals (the FVF is built from XYZ, DIFFUSE and TEX only, 0x8891c0), so the light contributes nothing. With OpenGL's default normal of (0,0,1) it adds part of the vertex colour in two of the four camera rotations.
Tested in game on version 641 with an NVIDIA RTX 3070, against upstream main: cars fade in and out.