From 72f126943cc59ec545b5b51d0eb5b7ff69ef1e7c Mon Sep 17 00:00:00 2001 From: "re.kovalev" Date: Mon, 16 Jan 2023 19:08:26 +0300 Subject: [PATCH] =?UTF-8?q?=D0=93=D0=B0=D0=BC=D0=BC=D0=B0-=D0=BA=D0=BE?= =?UTF-8?q?=D1=80=D1=80=D0=B5=D0=BA=D1=86=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shaders/bulb.frag | 7 ++++++- shaders/lighting.frag | 8 ++++++++ shaders/skybox.frag | 9 +++++++-- src/main.cpp | 3 +++ 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/shaders/bulb.frag b/shaders/bulb.frag index d6aaf90..533af2b 100644 --- a/shaders/bulb.frag +++ b/shaders/bulb.frag @@ -10,6 +10,11 @@ layout(std140, binding = 1) uniform Material in vec3 pos_local; +layout(std140, binding = 4) uniform gamma +{ + float inv_gamma; +}; + out vec4 color; uniform float angle; @@ -19,7 +24,7 @@ void main() { float cosA = dot(normalize(pos_local), normalize(direction)); if (degrees(acos(cosA)) <= angle) - color = vec4(ka, 1); + color = vec4(pow(ka, vec3(inv_gamma)), 1); else discard; } \ No newline at end of file diff --git a/shaders/lighting.frag b/shaders/lighting.frag index dfd4b76..87944d3 100644 --- a/shaders/lighting.frag +++ b/shaders/lighting.frag @@ -41,6 +41,11 @@ uniform sampler2DArray sunShadowDepth; uniform samplerCubeArray pointShadowDepth; uniform sampler2D ssao; +layout(std140, binding = 4) uniform gamma +{ + float inv_gamma; +}; + out vec4 color; void main() @@ -190,4 +195,7 @@ void main() } } } + + // Применение гамма-коррекции + color.rgb = pow(color.rgb, vec3(inv_gamma)); } \ No newline at end of file diff --git a/shaders/skybox.frag b/shaders/skybox.frag index 3ad7d0b..1b291e6 100644 --- a/shaders/skybox.frag +++ b/shaders/skybox.frag @@ -1,12 +1,17 @@ -#version 330 core +#version 420 core out vec4 FragColor; in vec3 TexCoords; uniform samplerCube skybox; +layout(std140, binding = 4) uniform gamma +{ + float inv_gamma; +}; + void main() { - FragColor = texture(skybox, TexCoords); + FragColor.rgb = pow(texture(skybox, TexCoords).rgb, vec3(inv_gamma)); gl_FragDepth = 0.9999f; } \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 66d7e32..e2cc05d 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -425,6 +425,9 @@ int main(void) const char* skybox_shader_names[] = {"skybox"}; skyboxShader.bindTextures(skybox_shader_names, sizeof(skybox_shader_names)/sizeof(const char*)); + // Значение гамма-коррекции + float inv_gamma = 1/2.2; + UBO gamma(&inv_gamma, sizeof(inv_gamma), 4); // Пока не произойдет событие запроса закрытия окна while(!glfwWindowShouldClose(window))