Skip to content

Model uniforms: let a -reflect map win over a -shine map again - #8065

Merged
Goober5000 merged 2 commits into
scp-fs2open:masterfrom
AdmiralTolwyn:reflect-over-shine
Nov 19, 2026
Merged

Goober5000 merged 2 commits into
scp-fs2open:masterfrom
AdmiralTolwyn:reflect-over-shine

Conversation

@AdmiralTolwyn

Copy link
Copy Markdown
Contributor

When a texture has both a -reflect and a legacy -shine map, both are loaded, and the OpenGL and Vulkan binds put the -reflect (spec-gloss) map in the specular slot. convert_model_material() then lets the -shine map overwrite sSpecmapIndex and clear gammaSpec and alphaGloss. So the bound -reflect texture is shaded as a legacy shine map: its alpha isn't read as gloss, and the spec-gloss path in main-f.sdr (minimum specular, full fresnel) is skipped. The array layer also comes from the -shine map, so an animated -reflect map can sample the wrong frame.

The two checks were an if/else until #5055 split them into two ifs. This PR restores the else, so the uniforms follow the texture that is actually bound.

Only textures with both maps change; they now shade as their -reflect map intends. A Lua SpecularMap or $Texture Replace that supplies only -shine on a model with -reflect was already not bound, and now no longer changes the shading flags either.

Testing

  • I built c8d2f3d on macOS arm64 (Release) and ran the unit tests: 358 passed, 1 skipped. The skipped test is OptionsManagerOverride.ShadowRenderMethodDefaultFollowsTheGlobal, which is unrelated. No unit test covers convert_model_material().
  • Retail FS2 data, Vulkan. A throwaway Lua hook draws the GTF Ulysses tech model with fixed angles and takes a screenshot. Synthetic 256x256 maps for its three textures: -shine RGB 60, -reflect RGBA 200 with alpha 235.
    • No extra maps: master and this PR are pixel-identical. -reflect only: pixel-identical.
    • Both maps: this PR is pixel-identical to -reflect only. Master differs (about 80k changed pixels) and shows legacy shine highlights.

Ulysses with -shine and -reflect: master, this PR, -reflect only

Both maps are loaded when a texture has them. The OpenGL and Vulkan
binds put the spec-gloss (-reflect) map in the specular slot, but
convert_model_material() then let the legacy -shine map overwrite
sSpecmapIndex and clear gammaSpec and alphaGloss. The bound -reflect
texture was therefore shaded as a legacy shine map: its alpha was not
read as gloss, and the spec-gloss path (minimum specular, full fresnel)
was skipped. The array layer also came from the -shine map, so an
animated -reflect map could sample the wrong frame.

The two checks were an if/else until scp-fs2open#5055 split them into two ifs.
Restore the else.

@dustinspace217 dustinspace217 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tested with this PR applied onto current master (f0d45f6), against master. Debug builds, retail FS2 data plus MediaVPs 5.0.3, Linux.

Retail data has no -shine or -reflect maps, and in MediaVPs 5.0.3 only four textures have both: rak_01 to rak_03 and goldglass-trans. So I looked at the Rakshasa in SM1-04 (Behemoth) from 600 m, on OpenGL and on Vulkan. With this PR its hull shows the glossy highlights of the spec-gloss path, mostly along the bow; on master the same hull is flat. The two renderers agree.

From reading: when a texture has both maps, OpenGL and Vulkan both bind the -reflect map in the specular slot, so with the else back the uniforms describe the texture that is actually bound.

Optional: the binds and convert_model_material() each pick the specular map on their own, which is how they drifted apart. A small shared helper would keep them in step.

The renderer binds and uniform conversion selected the specular map
independently, which let their precedence drift apart. Share the choice
and encoding flag through material::get_specular_map(), preserving
-reflect precedence and the raw -shine fallback at every render site.

Pin selection and encoding in the material test, including reflect
handle 0, and document the fallback beside the shared accessor.
@AdmiralTolwyn

Copy link
Copy Markdown
Contributor Author

Thanks for testing it with the MediaVPs. Added the helper in 2c67d87: material::get_specular_map() now picks the specular map and its encoding flag for the OpenGL and Vulkan binds, Vulkan's descriptor-cache key, the uniforms and the shader flag. Behaviour is unchanged: on OpenGL and Vulkan, with -reflect only and with both maps, the repro renders pixel-identical to the previous head. A unit test pins the selection, including a reflect map at handle 0.

@Goober5000
Goober5000 merged commit 1520d4d into scp-fs2open:master Nov 19, 2026
18 checks passed
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.

3 participants