-
Notifications
You must be signed in to change notification settings - Fork 63
renderer: implement native sRGB support #1687
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
c914db4
to
ce0a6e3
Compare
Hmmm… I don't know where to write the line |
You only really need to call it once, it's global state and will affect all sRGB framebuffers. |
Which framebuffer should be sRGB there? |
ce0a6e3
to
387cac8
Compare
As a matter of fact, I have zero confidence this implementation is correct, unlike the GLSL alternative implementation. Said otherway, I know how to implement the whole computation myself in GLSL, but I don't know how to configure OpenGL to let it do the computation by itself without me writing the explicit computation. The GLSL implementation is a math algorithm, the OpenGL implementation is a puzzle. |
387cac8
to
feee7ff
Compare
@VReaperV what is expected if I, for example, set upload an image with |
86e853b
to
b2f3100
Compare
The question is now likely irrelevant. |
It now works with both maps built with and without the But you have to disable the tone mapper when running maps compiled with I don't know anything about the tone mapper so I don't know if something is wrong. Right now the camera post-process GLSL shader doesn't run in linear space because colorgrades were done for the non-linear space. |
8702bec
to
b2a9fba
Compare
The 2D rendering is done like before, as @slipher suggested:
Actually it makes many things far easier, especially it doesn't require to know how the map should be rendered to render the UI, and it means the UI isn't affected by what's done there. |
Wait, why would we even want GL_FRAMEBUFFER_SRGB? I don't think it can do anything useful for us. Apparently it is only useful for converting from colors linear to sRGB at a final stage of rendering, as described here. In principle, this is something we need to do at the point of the I wonder why GL_FRAMEBUFFER_SRGB would have any effect in the current version of the code though. Supposedly you have to create the framebuffer with an SRGB format for it to have an effect but the code does not appear to do that. |
What I understood (but maybe I'm wrong), is that once Maybe we also need to set |
Also, something I've read (but I may be wrong) is that sRGB variants only exist for 8-bit formats, and some of our framebuffers are 16-bit… I don't know what to do with that information. |
5383610
to
4e28980
Compare
I found various people complaining of buggy handling of the framebuffer SRGB stuff. Like Nvidia applies it even when the framebuffer was not created as sRGB, or that Intel doesn't do it at all... another reason not to use it. Some more random considerations:
|
4e28980
to
acceb04
Compare
Hmm, comparing a Xonotic map like |
8c6565a
to
772a065
Compare
So unless I'm wrong it looks like |
I implemented the conversion of |
Ah I missed that answer:
It is implemented in the cgame… |
OK so I added a table in the first post to check the status. |
bf930dd
to
22ffeb5
Compare
src/common/Color.h
Outdated
@@ -256,6 +281,22 @@ class BasicColor | |||
data_[ 3 ] = v; | |||
} | |||
|
|||
CONSTEXPR_FUNCTION_RELAXED component_type ConvertFromSRGB( component_type v, bool accurate = true ) NOEXCEPT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be static
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do I just need to a static
keyword before the return type?
Do I need to do the same on the next ConvertFromSRGB()
returning BasicColor
?
Is the addition of static
there to help the compiler to optimize out the accurate
selector and drop the alternate code?
Also what to do with CONSTEXPR_FUNCTION_RELAXED
or CONSTEXPR_FUNCTION
, which one to use? I have no idea what is the difference, I just copy-pasted that from previous lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do I need to do the same on the next
ConvertFromSRGB()
returningBasicColor
?
I tested this one, this one I cannot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static
because you don't need a Color
object to use the function. static
means there is no this
argument.
Also what to do with
CONSTEXPR_FUNCTION_RELAXED
orCONSTEXPR_FUNCTION
, which one to use? I have no idea what is the difference, I just copy-pasted that from previous lines.
Just use constexpr
, those are workarounds for the compilers of 10 years ago. Also you can add const
since for functions constexpr does not imply const.
src/engine/renderer/tr_surface.cpp
Outdated
@@ -728,7 +734,12 @@ static void Tess_SurfacePolychain( srfPoly_t *p ) | |||
normals[i], qtangents); | |||
|
|||
VectorCopy(p->verts[i].xyz, tess.verts[tess.numVertexes + i].xyz); | |||
tess.verts[tess.numVertexes + i].color = Color::Adapt(p->verts[i].modulate); | |||
|
|||
Color::Color color = Color::Adapt( p->verts[ i ].modulate ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Color::Color
is a float color while the source and destination are bytes, so you could avoid a round trip by using Color32Bit
. (The API ought to be changed so it is not so easy to accidentally do that.) Also it is pointless to clamp with byte colors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also done in two similar places in tr_backend.cpp
.
Tess_AddQuadStamp( backEnd.currentEntity->e.origin, left, up, | ||
backEnd.currentEntity->e.shaderRGBA ); | ||
Color::Color color = backEnd.currentEntity->e.shaderRGBA; | ||
color.Clamp(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Useless clamping of byte colors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
32f7d0b
to
1c181ef
Compare
Revamp `R_LoadEntities()`: - Use `std::string` as much as possible. - Parse `_q3map2_cmdline` using Cmd::Args, so options are read in expected order. - Let `deluxeMapping` override `_q3map2_cmdline`. - Check for deluxe mapping being explicitely disabled. - Check for the deluxe map being in model space. - Make `vertexremapshader` do something when vertex lighting is enabled.
47bb6dd
to
27a80b0
Compare
What the heck is that (macOS CI)?
|
da16c59
to
45834ab
Compare
I added on the testing server the maps |
Some gameplay textures are loaded as linear when they should be sRGB, like the flames. |
Implement native sRGB support.
Obsoletes #1543:
It includes the commit from #1686:
This is based on an even older branch from 2019 as I initially tested native sRGB support before attempting to implement it in GLSL.
I rebased on current
master
and merged improvements from thesrgb-naive
branch as it implemented more corner cases than this one.It still suffers from the problems I faced in 2019: 2D colors are wrong. I need help on that part.
Status: