Skip to content

Comments

Add a uint version of u_ColorModulate#1476

Merged
VReaperV merged 7 commits intoDaemonEngine:masterfrom
VReaperV:u-colormodulate-uint
Jan 17, 2025
Merged

Add a uint version of u_ColorModulate#1476
VReaperV merged 7 commits intoDaemonEngine:masterfrom
VReaperV:u-colormodulate-uint

Conversation

@VReaperV
Copy link
Contributor

@VReaperV VReaperV commented Dec 26, 2024

Picked from #1473.

u_Color was a vec4 that was being set from a Color object, which only has 8-bit precision per colour, so using up 4 times more memory than that to transfer it was quite atrocious. Instead, pack it into a uint32_t, then use unpackUnorm4x8() to unpack in the shader.

Also adds a macro for unpacking for hardware that doesn't support GL_ARB_gpu_shader5.

Add u_ColorModulateColorGen for use with shaders other than cameraEffects, since the latter can get an arbitrary vec4 for it. All other shaders only use 12 distinct states of u_ColorModulateColorGen, encoded as 5 bits. The map lightFactor is put into 8 bits of u_ColorModulateColorGen.

Also added an r_forceRendererTime cvar to debug time-based renderer effects, and since it's a very simple change that I used to test the u_Color change, it might as well be here.

Fixes an issue with material shader post-processing that was removing global uniforms that had similar names to a non-global one.

@VReaperV VReaperV added T-Improvement Improvement for an existing feature A-Renderer T-Performance labels Dec 26, 2024
@VReaperV VReaperV force-pushed the u-colormodulate-uint branch 2 times, most recently from 01b21fa to 6dd46bd Compare January 8, 2025 12:30
@VReaperV VReaperV mentioned this pull request Jan 13, 2025
@VReaperV VReaperV force-pushed the u-colormodulate-uint branch from 6dd46bd to 026ba65 Compare January 13, 2025 03:06
@slipher
Copy link
Member

slipher commented Jan 14, 2025

This seems to make the heat haze effect on the Plat23 forcefields lose its effect. It renders the same as if r_heatHaze 0 is set. The preexisting bug #1499 may be relevant. Weapon heat haze effects still appear fine.

@VReaperV
Copy link
Contributor Author

This seems to make the heat haze effect on the Plat23 forcefields lose its effect. It renders the same as if r_heatHaze 0 is set. The preexisting bug #1499 may be relevant. Weapon heat haze effects still appear fine.

It is the same issue, yeah. It just so happens that for plat23 on master the size of the struct generated for the heatHaze shader at least somewhat lines up to prdouce a (non-moving) heatHaze effect, but here changing the size of u_Color and u_ColorModulate changes the size of the struct, and the buffer offsets for dynamic surfaces no longer line up at all. In any case, #1473 fixes that issue entirely, and makes the code that computes the offsets simpler.

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.

This fixes the red and black dretch banners in metro-b1-2. Previously they were not displayed with the material system.

unvanquished-metro-autosprite2-flame-chains

@VReaperV VReaperV force-pushed the u-colormodulate-uint branch 2 times, most recently from c099442 to 43193c5 Compare January 16, 2025 02:21
@VReaperV
Copy link
Contributor Author

This fixes the red and black dretch banners in metro-b1-2. Previously they were not displayed with the material system.

unvanquished-metro-autosprite2-flame-chains

Oh, nice, I saw a few places that work correctly now with this pr, but hadn't seen this one.

@slipher
Copy link
Member

slipher commented Jan 16, 2025

Light styles are off again. It seems that the light factor is not being applied to light style stages: if I set r_overbrightDefaultBits 0, the diff goes away.

@VReaperV VReaperV force-pushed the u-colormodulate-uint branch from 43193c5 to 836e1e9 Compare January 16, 2025 04:44
@VReaperV
Copy link
Contributor Author

Light styles are off again. It seems that the light factor is not being applied to light style stages: if I set r_overbrightDefaultBits 0, the diff goes away.

This is now fixed.

When set to >= 0, the value of this cvar (in milliseconds) will be used for time-based shader effects.
`u_Color` was a vec4 that was being set from a `Color` object, which only has 8-bit precision per colour, so using up 4 times more memory than that to transfer it was quite atrocious. Instead, pack it into a uint32_t, then use `unpackUnorm4x8()` to unpack in the shader.

Also adds a macro for unpacking for hardware that doesn't support `GL_ARB_gpu_shader5`.
Add `u_ColorModulateColorGen` for use with shaders other than `cameraEffects`, since the latter can get an arbitrary vec4 for it. All other shaders only use 12 distinct states of `u_ColorModulateColorGen`, encoded as 5 bits. Also adds `u_ColorModulateLightFactor` as a global uniform, to be able to put the `genericMaterial` shader struct into 8 bytes.

Fixes an issue with material shader post-processing that was removing global uniforms that had similar names to a non-global one.
Move the multiplication by tr.mapLightFactor to the generic shader, store it in `u_ColorModulateColorGen`.
`tr.mapLightFactor` is already in `u_ColorModulateColorGen` anyway, so there's no need for the extra uniform.
Also fixes extra bits beng added to the `lightFactor` part `SetUniform_ColorModulateColorGen` in some cases.
@VReaperV VReaperV force-pushed the u-colormodulate-uint branch 2 times, most recently from f8359f3 to 2a37d2b Compare January 16, 2025 20:03
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.

LGTM (with one last comment)

@VReaperV VReaperV merged commit ad87861 into DaemonEngine:master Jan 17, 2025
9 checks passed
@VReaperV VReaperV deleted the u-colormodulate-uint branch January 17, 2025 01:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Renderer T-Improvement Improvement for an existing feature T-Performance

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants