English Amiga Board


Go Back   English Amiga Board > Support > support.WinUAE

 
 
Thread Tools
Old 10 December 2017, 17:32   #1
mark_k
Registered User
 
Join Date: Aug 2004
Location:
Posts: 2,966
Artifacts from non-gamma-aware interpolation

When images are scaled with bilinear filtering, the resulting image can have artifacts if gamma isn't taken into account. Some patterns appear darker than they should and certain colour transitions can result in a darker border around objects.

You might think a 50:50 blend of two colours is easy to calculate; an equal blend of black (R:G:B 0:0:0) and white (255:255:255) is 128:128:128. However on a normal monitor 128:128:128 is significantly darker than half white brightness. Half-white is roughly 187:187:187 for the commonly-used assumed gamma of 2.2 (sRGB).

To show what I mean, I have uploaded an archive with some images and a config/HDF to The Zone and:
Code:
https://www.media!fire.com/file/qmlp03l15pir98l/Test_images.zip
Load the config, boot Test_images.adf. In Filter settings toggle between point and bilinear. Notice darker edges around red-on-green shapes with bilinear filtering. Click left button to move to next image. The third image is a chequerboard pattern. Notice the overall image brightness drops with bilinear filtering.

At least for Direct3D, it could/should be easy to fix this since you can tell Direct3D to do gamma correction when it reads from the texture.

Gamma (Direct3D 9)
"Texture content is often stored in sRGB format. Traditionally, pixel pipelines assumed the colors to be linear so blending operations were performed in linear space. However, since sRGB content is gamma corrected, blending operations in linear space will produce incorrect results. Video cards can now fix this problem by undoing the gamma correction when they read any sRGB content, and convert pixel data back to the sRGB format when writing out pixels. In this case, all operations inside the pixel pipeline are performed in the linear space."

For Direct3D 11, see Converting data for the color space (MSDN):
"To ensure color accuracy in the pipeline
1. If a texture has sRGB content, ensure the ShaderResourceView has the _SRGB format modifier so when you read from the ShaderResourceView into the shader, you convert the texture content from gamma 2.2-corrected color space to linear color space.
2. Ensure the RenderTargetView also has the _SRGB format modifier so the shader output values are gamma converted."


Some more info on issues with interpolating colours incorrectly:
[ Show youtube player ] (Computer Color is Broken, YouTube video)
http://www.realtimerendering.com/blo...a-problematic/
http://tavmjong.free.fr/SVG/COLOR_INTERPOLATION/, in particular this image. (The sad faces are blended in sRGB colour space. Notice the darker border around the red-on-green face.)

Last edited by mark_k; 10 December 2017 at 17:45.
mark_k is offline  
Old 10 December 2017, 18:19   #2
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 43
Posts: 22,110
But does level 10 hardware support DXGI_FORMAT_B8G8R8A8_UNORM_SRGB or should it be only used if 11.0 level? Everyone seems to confuse 11 of Direct3D11 and feature level 11..

winuae.7z updated, image looks more brighter now. EDIT: wait a bit, it wasn't that simple..

(Interestingly enough, I have been playing with my new JVC X7900 projector and testing different custom gamma curves so that UHD HDR look as great as possible but I never thought about PC world gamma and how it is supposed to work)

EDIT2: MSDN article is useless as always. Trying to use SRGB in RenderTargetView() results in very overexposed image. ShaderResourceView fails with:

Quote:
D3D11 ERROR: ID3D11Device::CreateShaderResourceView: The Format (0x5b, B8G8R8A8_UNORM_SRGB) is invalid, when creating a View; the Resource was already created with a fully qualified Format, which is not castable (0x57, B8G8R8A8_UNORM). [ STATE_CREATION ERROR #127: CREATESHADERRESOURCEVIEW_INVALIDFORMAT]
D3D11: **BREAK** enabled for the previous message, which was: [ ERROR STATE_CREATION #127: CREATESHADERRESOURCEVIEW_INVALIDFORMAT ]

Last edited by Toni Wilen; 10 December 2017 at 18:50.
Toni Wilen is online now  
Old 11 December 2017, 17:53   #3
mark_k
Registered User
 
Join Date: Aug 2004
Location:
Posts: 2,966
Quote:
Originally Posted by Toni Wilen View Post
But does level 10 hardware support DXGI_FORMAT_B8G8R8A8_UNORM_SRGB or should it be only used if 11.0 level? Everyone seems to confuse 11 of Direct3D11 and feature level 11..
I think even feature level 9_1 hardware might support it. Hardware Support for Direct3D 10Level9 Formats mentions DXGI_FORMAT_R8G8B8A8_UNORM_SRGB being supported (note the different RGB component order though). And Format Support for Direct3D Feature 10Level9 9.1 Hardware shows hardware support required for B8G8R8A8_UNORM, B8G8R8A8_UNORM_SRGB, B8G8R8X8_UNORM, B8G8R8X8_UNORM_SRGB.

You can create your texture with format DXGI_FORMAT_B8G8R8A8_UNORM then specify the_SRGB format modifier. But do things work better (i.e. no error message) if you instead specify an _SRGB format when you create the texture/buffer?

It sounds like something is correcting/converting one way (e.g. when texture is read) but not the other (when data written to render target)? With point filtering (not bilinear), telling Windows texture data is sRGB should make no difference to the output image.
mark_k is offline  
Old 14 December 2017, 22:32   #4
mark_k
Registered User
 
Join Date: Aug 2004
Location:
Posts: 2,966
Did you have more luck with D3D 9 mode (D3DSAMP_SRGBTEXTURE)?

If you end up having to (or wanting to) perform correction manually with a shader, this blog post gives some formulae for very close approximations.
mark_k is offline  
Old 14 December 2017, 22:36   #5
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 43
Posts: 22,110
I won't touch D3D9 code anymore, it is frozen, only fixes are allowed.
Toni Wilen is online now  
Old 08 January 2018, 15:37   #6
mark_k
Registered User
 
Join Date: Aug 2004
Location:
Posts: 2,966
Quote:
Originally Posted by Toni Wilen View Post
winuae.7z updated, image looks more brighter now. EDIT: wait a bit, it wasn't that simple..

EDIT2: MSDN article is useless as always. Trying to use SRGB in RenderTargetView() results in very overexposed image. ShaderResourceView fails with:
Would you be able to upload (or create a fork on Github?) the not-properly-working code you used there? I can take a look and see if anything looks obviously wrong.
mark_k is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
OS wide gamma correction. Thorham Coders. System 62 27 June 2016 00:10
switch sound interpolation 4 chs turrican3 support.WinUAE 1 14 February 2016 11:39
WinUAE GUI in Windows 8.1 - not DPI-Aware? rsn8887 support.WinUAE 3 26 August 2014 22:51
Interpolation new Sound options Paul support.WinUAE 9 16 August 2006 01:34

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 11:37.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2018, vBulletin Solutions Inc.
Page generated in 0.06452 seconds with 14 queries