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

@slipher
Copy link
Member

slipher commented Feb 5, 2025

At another spot on Pulse, with this PR I get a new instance of the scrolling glitch where there wasn't one before. The lorem ipsum star wars text thing at the spectator spawn only shows the first 2 lines then resets.

@VReaperV VReaperV force-pushed the fix-texture-scroll branch 2 times, most recently from d1c963d to 5527ad1 Compare February 5, 2025 19:41
@VReaperV
Copy link
Contributor Author

VReaperV commented Feb 5, 2025

Oh, right, there were some divs by 0 and a wrong index. Fixed now.

Copy link
Member

@slipher slipher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried combining a rotate with a scroll and it still suffers from discontinuity:

textures/pulse/title
{
	qer_editorimage textures/pulse/title.jpg

	noPicMip

	surfaceparm noimpact
	surfaceparm nolightmap
   	surfaceparm trans
	surfaceparm nomarks
	{
		map textures/pulse/title.jpg
		tcMod rotate 5
		tcMod scroll 0 0.025
		blendFunc add
	}
}

This could still be merged as-is though, as it fixes some things and doesn't break anything that is not already broken AFAIK.

@@ -877,6 +877,38 @@ inline vec_t VectorNormalize2( const vec3_t v, vec3_t out )
MatrixFromAngles( m, angles[ PITCH ], angles[ YAW ], angles[ ROLL ] );
}

inline void Mat3x2MultiplyScale( matrix_t m, const float x, const float y ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These probably don't need to be in q_shared.h which is included by all files.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I guess I can move those to tr_shade_calc.cpp. I had just put those near where the original declarations were, no other reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've moved these to tr_shade_calc.cpp now.

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.
@VReaperV
Copy link
Contributor Author

VReaperV commented Feb 8, 2025

I tried combining a rotate with a scroll and it still suffers from discontinuity:

textures/pulse/title
{
	qer_editorimage textures/pulse/title.jpg

	noPicMip

	surfaceparm noimpact
	surfaceparm nolightmap
   	surfaceparm trans
	surfaceparm nomarks
	{
		map textures/pulse/title.jpg
		tcMod rotate 5
		tcMod scroll 0 0.025
		blendFunc add
	}
}

This could still be merged as-is though, as it fixes some things and doesn't break anything that is not already broken AFAIK.

Fixed, also fixed some more potential divisions by 0.

@slipher
Copy link
Member

slipher commented Feb 8, 2025

The rotation+scroll shader I wrote above got more buggy with the latest code. It still makes discontinuous jumps, and also seems to accelerate faster and faster over time.

@VReaperV
Copy link
Contributor Author

VReaperV commented Feb 8, 2025

Hmm, I probably messed something up before pushing to the remote.

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
2 participants