Some questions on HDR and sRGB

How to use HDR? It doesn’t used in any of samples and I can’t find it’s mentions in documentations either.

Is it just:

renderpath.Append(cache.GetResource("XMLFile","PostProcess/BloomHDR.xml")); renderpath.Append(cache.GetResource("XMLFile","PostProcess/AutoExposure.xml"));
(or just second one), or there is something else I should do?

What is the bit depth of render buffers? I guess, it’s 8bit per channel. Can I change it?

Is it possible to enable sRGB conversion on write for backbuffer and rendertargets from script(or XML)?

Hey Bananaft,

If you take NinjaSnowWar as an example, you can enable it around CreateCamera() function or just create a viewport and with the code below…

[code]
renderer.viewports[0] = Viewport(gameScene, gameCamera);

RenderPath@ newRenderPath = renderer.viewports[0].renderPath.Clone();
newRenderPath.Append(cache.GetResource(“XMLFile”, “PostProcess/BloomHDR.xml”));
newRenderPath.Append(cache.GetResource(“XMLFile”, “PostProcess/FXAA2.xml”));
newRenderPath.SetEnabled(“BloomHDR”, true);
newRenderPath.SetEnabled(“FXAA2”, true);
renderer.viewports[0].renderPath = newRenderPath; [/code]

Hope that helps :slight_smile:

Thank you. So, there is nothing aside adding renderpath commands. But is there a way to rise buffers color precision? I’m getting some banding artifacts, when it’s too dark, and it become much worse, when I’m trying to use linear space.

Converting colors to gamma space before writing into framebuffer is one way to fight banding. The other would be to rise buffer’s color depth from 8 to 16 or even to floating point, and it’s preferable, I’m sure, because 8bit is too narrow range for HDR.

Is it easy to do? What place in source I should look into?

So you want to load all textures as sRGB? Then you need an XML tag for textures that don’t need conversion(like NormalMaps), and you will end up messing with tags anyway.

[quote=“Bananaft”]Is it just:
CODE: SELECT ALL
? ?renderpath.Append(cache.GetResource(“XMLFile”,“PostProcess/BloomHDR.xml”));
? ?renderpath.Append(cache.GetResource(“XMLFile”,“PostProcess/AutoExposure.xml”));

(or just second one), or there is something else I should do?[/quote]

Well, I figured, that there is also:

This option sets frame buffers to higher bit-depth. And Eliminates banding problem.

Stupid me. I also mixed up commands order. AutoExposure must go before BloomHDR. (And was wondering if bloom should be so poor and ugly).

So, if anyone will stumble on this thread, while having questions about HDR, here is the code I ended up with:

Viewport@ mainVP = Viewport(scene_, camera);
renderer.viewports[0] = mainVP;
renderpath = mainVP.renderPath.Clone();
renderpath.Append(cache.GetResource("XMLFile","PostProcess/AutoExposure.xml"));
renderpath.Append(cache.GetResource("XMLFile","PostProcess/BloomHDR.xml"));
mainVP.renderPath = renderpath;
renderer.hdrRendering = true;

And how Bloom shold look like:

When autoexplosure is enabled, game always start from whitescreen. It is possible to starting from normal gamma, or a black screen?

Simple hack:

  1. Change tag in last command in AutoExposure.xml
    <command type="quad" tag="AutoExposureFix" vs="AutoExposure" ps="AutoExposure" vsdefines="EXPOSE" psdefines="EXPOSE" output="viewport">
  1. In game on start disable this command and increase speed

viewport = Viewport(scene_, cameraNode.GetComponent("Camera")); renderer.viewports[0] = viewport; viewport.renderPath.Append(cache.GetResource("XMLFile","PostProcess/AutoExposure.xml")); viewport.renderPath.Append(cache.GetResource("XMLFile","PostProcess/BloomHDR.xml")); viewport.renderPath.shaderParameters["AutoExposureAdaptRate"] = 100000.0f; viewport.renderPath.SetEnabled("AutoExposureFix", false);

  1. Also we need to toggle on it lataer and restore speed

void HandleUpdate(StringHash eventType, VariantMap& eventData) { if (scene_.elapsedTime > 0.1f) { viewport.renderPath.shaderParameters["AutoExposureAdaptRate"] = 0.6f; viewport.renderPath.SetEnabled("AutoExposureFix", true); } ... }

Thanks 1vanK, that’s a nice hack. :slight_smile:

I played around with HDR a bit, and now have a question: Why auto exposure range is so narrow? By the look of it, it seems like 0.5-2.0, or even smaller. I’ve tried to change AutoExposureLumRange in AutoExposure.xml, but it only made a difference if I set it even narrower. Setting wider values like 0.001 - 1000 had no effect.

Then I made my own manual exposure pass, and it worked really well, buffer precision was so good, I was able to change exposure by the order of tens thousands!

So am I missing something? How to make auto exposure to work at higher range?

removing clamp from AutoExposure’s ADAPTLUMINANCE pass also does nothing. lum1 texture have rg16f format, so really don’t know what to think.