Mipmapping with gamma correction

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Hybrid Dog
Posts: 4
Joined: Sun Apr 22, 2018 7:18 am

Mipmapping with gamma correction

Post by Hybrid Dog »

https://github.com/minetest/minetest/issues/6867
How can I enable gamma correct downscaling for mipmap generation?
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Mipmapping with gamma correction

Post by hendu »

You cannot. The mipmap generation is done by your hardware, and both the alpha and srgb details are handled there. There is no option for tuning either.

However, you can compute mipmaps manually in software and do whatever calculations you like. Naturally that's slower vs the hardware generation. That's what Niko's blog entry did, and that's what BAW does too.
devsh
Competition winner
Posts: 2057
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Re: Mipmapping with gamma correction

Post by devsh »

Correction: IrrBAW lets you upload parts of the mipmap chain explicitly, so i.e. you can come with your own mipmaps with formats such as the .dds (and khr soon), we never calculate mip maps ourselves in software.

Its mostly for purposes of better lowpass filtering such as using a sinc filter when generating mip-maps or when you intend to use the mipmap chain for other weird purposes (Hierarchical depth Min/Max Z)

But we do support automatic mipmap generation, but thats after a texture is uploaded and in functions other than IVideoDriver::getTexture() it needs to be triggered explicitly.
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: Mipmapping with gamma correction

Post by Mel »

All this reminds me of an effect i saw with regard to uploading diferent mip images into a texture, from when the hardware didn't run pixel shaders :)
http://blog.mecheye.net/2018/03/deconst ... -sunshine/
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Hybrid Dog
Posts: 4
Joined: Sun Apr 22, 2018 7:18 am

Re: Mipmapping with gamma correction

Post by Hybrid Dog »

If I understand that correctly, the internal format of a texture can be set to GL_SRGB to enable gamma correction:
https://www.reddit.com/r/opengl/comment ... on_issues/
https://learnopengl.com/Advanced-Lighti ... Correction
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: Mipmapping with gamma correction

Post by Mel »

There is a toggle on the Irrlicht device creation parameters structure that enables the sRGB color space in textures automatically

http://irrlicht.sourceforge.net/docu/st ... eters.html

it is called "HandleSRGB"
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
devsh
Competition winner
Posts: 2057
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Re: Mipmapping with gamma correction

Post by devsh »

In my opinion it works rather badly and only affects the framebuffer OUTPUT.

For sRGB(A) you'd need to set the internal format correctly on the texture, and irrlicht supports a very limited subset of internal formats.
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: Mipmapping with gamma correction

Post by Mel »

Yeah... i mistook it by my own engine, i handle the sRGB as texture format indeed...

It wouldn't harm to have some sRGB texture formats, as well as being able to load and have mipmaps for floating point textures. but either i haven't found them, or D3D9 doesn't support sRGB texture formats, only changing the output gamma ramp.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Hybrid Dog
Posts: 4
Joined: Sun Apr 22, 2018 7:18 am

Re: Mipmapping with gamma correction

Post by Hybrid Dog »

HandleSRGB indeed gives wrong results.
Image
devsh
Competition winner
Posts: 2057
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Re: Mipmapping with gamma correction

Post by devsh »

In my opinion it works rather badly and only affects the framebuffer OUTPUT.
Post Reply