12/20/2023 0 Comments Gamma control directx 11 code![]() The good news is that the code is a piece of cake…the bad news is that it’s not super cheap since it involves raising your RGB color value to a non-integral power. ![]() And even if they did work you’d still have the second problem, which is that the Xbox uses that piecewise approximation curve ( this presentation by Valve shows some of the nastiness that can occur with it).įortunately we can bypass those problems by doing the conversion ourselves in the shader. I don’t have access to my Xbox 360 at the moment so I can’t verify for sure, but I strongly suspect that the effect states won’t work. It instead uses the D3D10 convention of having special surface formats for textures and render targets that control whether conversion takes place. The first problem is that the Xbox 360 doesn’t use sampler and render states to control sRGB read and writes. ![]() There’s also the Xbox 360 problem, which is actually two problems in one. It’s probably possible with some sort of interop/reflection voodoo, but I don’t know enough about these things to recommend it. If you’re not using Effects, then I don’t know of any way to toggle those states. So we’ve solved our gamma problems…at least if you’re only targeting the PC and you’re using Effects. PixelShader = compile ps_3_0 TransparentPS() VertexShader = compile vs_3_0 TransparentVS() And hey, it worked! technique Transparent Too determined to give up, I followed the standard convention of effect states and chopped the prefix off the “D3DRS_” prefix. But unfortunately this time the Effect States documentation didn’t have anything for SRGBWRITEENABLE. Once again D3D9 has a convenient render state that does all of the work for us, and the Effects framework can set render states for us if we include them in a pass declaration. Okay now for the other half, sRGB writes. And it worked! For the lazy, all you have to do is this (important line in bold): texture2D DiffuseMap So I took a peek at the D3D9 Effect States documentation, and added the appropriate state declaration to my effect file. But fortunately that’s not the only way to set sampler states…we can also get the Effects framework to do it for us by defining a sampler_state in our effect files. Like I mentioned before there’s a nice convenient sampler state in D3D9 that will do the sRGB->linear automatically, but XNA’s SamplerState just doesn’t have it. So let’s start with the first half, sampling sRGB textures. But like most limitations in the framework you can work around them if you’re determined enough, and fortunately this one is a piece of cake. There is a cap to detect this behavior (D3DPMISCCAPS_POSTBLENDSRGBCONVERT) but it’s only available if you create an IDirect3D9Ex device. DX9 GPU’s will perform framebuffer blending after conversion to sRGB (which is mathematically incorrect), while DX10 GPU’s will do the blending in linear space and then convert the blended result to sRGB. The fact that blending behavior is different in DX9 and DX10-level GPU’s, regardless of which API you use. The fact that the 360 uses a 4-segment piecewise linear approximation curve to perform conversion to and from sRGB, which gives quite different results compared to what you get with PC GPU’s.Ģ. After looking through some presentations again I concluded that he was talking about…ġ. ![]() After refining my search terms I found this post by framework developer Shawn Hargreaves, confirming that those states were not exposed in the framework due to inconsistencies between Windows and Xbox. The thought of these being left out struck me as odd, so I did a bit of searching on Google. So I went looking through the XNA Framework documentation for framework’s equvalent of the D3DSAMP_SRGBTEXTURE sampler state (which automatically converts from sRGB to linear in the texture unit) and the D3DRS_SRGBWRITEENABLE render state (which automatically converts from linear to sRGB in the ROP)…and I didn’t find them. Lately I’ve been doing some research into inferred rendering (more on that later), and while working up a prototype renderer in XNA I decided that I would (for once) be gamma-correct throughout the pipeline. However it only took a few days at my new job for me to realize just how essential it is if you want professional-quality results. This is mainly because it rarely gets mentioned, and also because you can usually get pretty good results without ever even thinking about it. One thing I never used to pay attention to is gamma correction.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |