PBR and the Gamma Correction of Textures

First post in the new camp, hooray!
Do data textures such as metallic / roughness, normal, ao, height maps need to be manually de-gammaed, using something like “texture.gammaSpace = false;” ?
Let’s assume these textures come out of Substance Painter or are downloaded from CGTextures.com PBR Resources.
Or maybe gamma is taken care of by the PBR shader in Babylon and I can just pass the textures in without worrying about any gamma (linear workflow) issues?
Thanks in advance!

Welcome :raised_hands:

I have the feeling that it’s automatic (I don’t succeed to see where it’s set, probably somewhere around these files), 'cause I haven’t seen yet artefacts due to this (except once, about lightmap in PBRMaterial, but it was fixed soon after).

Note that according to the doc, maybe one texture have to be forced to gammaSpace = false : the environmentTexture. I’m not sure if this have to be set if you’re using the .env format.

1 Like

(actually, in Shaders folder rather than Materials I think: Babylon.js/pbr.fragment.fx at master · BabylonJS/Babylon.js · GitHub)

Got it!.. I think :smiley:

Need a dev’ to confirm but, is the normalize function get pixels from texture in linear space?

Yep, this is the goal of the texture.gammaSpace property. There is no way to detect it in files so you have to provide it manually

OK so I was totally wrong :smiley:

Not completely :slight_smile:

Let me complement on this one.

In PBR mat, albedo, reflectivity and emissive are known to be gamma and can not be change by code.

In the shader we rely on toLinearSpace to convert. @Vinc3r normalize is mostly use for vector to keep their directions with a length of one.

That said, lightMap, reflection, refraction and environment Textures can be configured as they might be directly stored in linear space for hdr for instance. So you can use the gammaSpace flag for them.

Hope that helps,

are always considered in linear space and no transformation apply to them

3 Likes

Thanks alot folks!
This clears up my doubts. Color space has always made me a bit paranoid.:crazy_face:
So the dummy version:
HDR textures such as lightMap and environmentTexture, can be flag with gammaSpace=false if the data is stored linearly;
sRGB textures (usually in formats like jpg and png etc) don’t need gammaSpace flag and are taken care of by the shader.

1 Like

Perfect summary :slight_smile:

As soons as possible, I will add these precisions somewhere into the doc.

(also, in case people doesn’t know this great pdf, here the link: The Beginners Explanation of Gamma Correction and Linear Workflow)

2 Likes

That pdf is a great source of reference. When I was doing a lot of off-line rendering arch-viz type of work, it helped me alot with getting the lighting right.