Skip to content

PBS: honour non-sRGB colour targets in the pass hash - #584

Open
steffen-roemer wants to merge 2 commits into
OGRECave:masterfrom
orkitec:pbs-honour-non-srgb-target
Open

PBS: honour non-sRGB colour targets in the pass hash#584
steffen-roemer wants to merge 2 commits into
OGRECave:masterfrom
orkitec:pbs-honour-non-srgb-target

Conversation

@steffen-roemer

Copy link
Copy Markdown
Contributor

What

HlmsPbs::preparePassHash hardcodes hw_gamma_write=1, assuming the colour target is always sRGB. When an app renders to a UNORM (non-sRGB) swapchain, PBS writes its linear lighting result raw into the target, and the image displays gamma-crushed — a mid-albedo surface under the zenith sun reads ~0.03 instead of ~0.5, and night/indoor scenes collapse to black.

This PR derives the property from the live pass descriptor instead: if the first colour target's format is sRGB, hardware conversion is used exactly as today; otherwise hw_gamma_write is 0 and the existing !hw_gamma_write template path gamma-encodes in the shader — that path was already written for this case but was unreachable with the hardcoded property.

Why not just use an sRGB swapchain?

Engines mixing PBS 3D with byte-exact 2D/UI pipelines (or matching a legacy renderer pixel-for-pixel) legitimately run UNORM swapchains. The template code says this configuration was meant to work; only the pass-hash property disagreed.

How tested

macOS 15 / Apple Silicon, Metal RS, static build via vcpkg at master ef2e8f3: measured readback of a mid-grey PBS reference under a known directional light on a UNORM swapchain — ~0.19 before, ~0.43 after (the sqrt-encode expectation); sRGB-target rendering byte-identical before/after (property still 1 there). Soaked through an engine's full desktop suite (789 green) including an Hlms-Unlit 2D parity pixel test that stays byte-identical.

preparePassHash hardcodes hw_gamma_write=1, assuming every colour target
is sRGB. On a UNORM swapchain the linear lighting result then lands raw in
the target and displays gamma-crushed (a mid-albedo surface under a zenith
sun reads ~0.03 instead of ~0.5). Derive the property from the current
pass descriptor's first colour target instead: sRGB targets keep hardware
conversion exactly as before, and non-sRGB targets engage the existing
!hw_gamma_write template path, whose shader-side encode was already
written for this case but unreachable.
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.

1 participant