Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix texture scroll, optimise texture matrix operations a bit #1538

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

VReaperV
Copy link
Contributor

@VReaperV VReaperV commented Jan 31, 2025

Fixes #1278.

The previous code assumed that a texture with a scroll textureMod would always wrap around when scroll * backEnd.refdef.floatTime == floor( scroll * backEnd.refdef.floatTime ). This is incorrect if the texture matrix had already been modified by another texMod, so the relevant values are no longer 1.0f and 0.0f. Fix this by using scrollPeriod[0] / ( matrix[0] + matrix[4] ) and scrollPeriod[0] / ( matrix[0] + matrix[4] ) to get the actual time at which wrap-around for x and y will occur, and use fmodf( backEnd.refdef.floatTime, period ) to get the part that is equivalent to just using backEnd.refdef.floatTime, but without the value getting continuously larger.

Also NUKED some useless matrix computations from texMod scroll, and added some functions to only calculate the relevant part of a matrix for texture matrices.

This change can be observed on:
Map tds, r_forceRendererTime 49999 and r_forceRendererTime 50000:
Old:
https://imgsli.com/MzQ0MjYy
New:
https://imgsli.com/MzQ0MjY1
Map pulse, r_forceRendererTime 50000 and r_forceRendererTime 50001:
Old:
https://imgsli.com/MzQ0MjY0
New:
https://imgsli.com/MzQ0MjY2

Previous code assumed that a texture with a scroll textureMod would always wrap around when `scroll * backEnd.refdef.floatTime == floor( scroll * backEnd.refdef.floatTime )`. This is incorrect if the texture matrix had already been modified by another texMod, so the relevant values are no longer 1.0f and 0.0f. Fix this by using `scrollPeriod[0] / ( matrix[0] + matrix[4] )` and `scrollPeriod[0] / ( matrix[0] + matrix[4] )` to get the actual time at which wrap-around for `x` and `y` will occur, and use `fmodf( backEnd.refdef.floatTime, period )` to get the part that is equivalent to just using `backEnd.refdef.floatTime`, but without the value getting continuously larger.

Also NUKED some useless matrix computations from texMod scroll.
The texture matrices only use elements 0, 1, 4, 5, 12, and 13, so doing all the other computations there is wasteful.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Texture scrolling glitch
1 participant