Skip to content
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

Gamma adjustment shader. #5399

Open
renpytom opened this issue Mar 7, 2024 · 2 comments
Open

Gamma adjustment shader. #5399

renpytom opened this issue Mar 7, 2024 · 2 comments

Comments

@renpytom
Copy link
Member

renpytom commented Mar 7, 2024

No description provided.

@renpytom
Copy link
Member Author

renpytom commented Mar 8, 2024

Here's an example of what it could be. I'm not sure it makes sense to add something like this to the engine, rather than (optionally) properly handling SRGB and linear colorspaces.

# A persistent variable that stores the result of the gamma adjustment.
default persistent.gamma_adjust = 1.0


# This shader performs gamma correction.
init python:

    renpy.register_shader("gamma", variables="""
        uniform float u_inv_gamma;
    """, fragment_900="""
            gl_FragColor = pow(gl_FragColor, vec4(u_inv_gamma));
    """)


# Create a Transform that performs gamma correction, and is replaced
# at every interaction and interaction restart.
init python:
    def GammaAdjust(d):
        gamma_adjust = max(persistent.gamma_adjust, 0.1)
        return Transform(d, shader="gamma", u_inv_gamma=1.0/gamma_adjust)

# Replace the default transform with the gamma correction transform.
define config.layer_transforms[None] = [ GammaAdjust ]



# Beneath this point is a simple test game, to demonstrate gamma correction
# in action.

define _confirm_quit = False

label main_menu:
    return

screen gamma_slider:
    vbox:
        label _("Gamma Correction")
        bar value FieldValue(persistent, "gamma_adjust", range=3.0) xmaximum 300
        text "[persistent.gamma_adjust:.2f]"

label start:

    scene bg washington
    show eileen happy

    call screen gamma_slider

    "..."

    return

@mirh
Copy link

mirh commented Mar 19, 2024

Idk about the precise details here, but I would guess you should also put some foresight into how to best support HDR content eventually.
Putting aside jxl, not only AVIF already supports it but by now both jpeg and png have their own retrocompatible way to do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants