more gamma tweak-ups

main
Dominik Madarász 2024-03-27 08:36:32 +01:00
parent fabbcc4aa7
commit 59c9f8be4e
10 changed files with 52 additions and 4 deletions

View File

@ -50,6 +50,7 @@ int main() {
// window (80% sized, MSAA x4 flag)
window_create(80.0, WINDOW_MSAA4);
window_title(__FILE__);
window_gamma(0);
// tiled map
tiled_t tmx = tiled(vfs_read("castle.tmx"));

View File

@ -128,6 +128,7 @@ void DrawModel(mesh_t *m) {
"out vec4 fragcolor;\n"
"void main() {\n"
"fragcolor = vec4(v_normal, 1.0);\n" // diffuse
"fragcolor.rgb = pow(fragcolor.rgb, vec3(2.2));\n" // diffuse
"}";
static unsigned program; do_once program = shader(vs, fs, "att_position,att_normal", "fragcolor", NULL);

View File

@ -1,4 +1,5 @@
void mainImage( out vec4 fragColor, in vec2 fragCoord );
void main() {
mainImage(fragColor, texcoord.xy * iResolution);
fragColor.rgb = pow(fragColor.rgb, vec3(1.0/2.2));
}

View File

@ -16,9 +16,11 @@ uniform sampler2D iChannel0; // input channel 0 /*sampler%s*/
uniform sampler2D iChannel1; // input channel 1
uniform sampler2D iChannel2; // input channel 2
uniform sampler2D iChannel3; // input channel 3
uniform float iGamma; /// set:2.2
in vec2 texCoord;
out vec4 fragColor;
void mainImage( out vec4 fragColor, in vec2 fragCoord );
void main() {
mainImage(fragColor, texCoord.xy);
fragColor.rgb = pow(fragColor.rgb, vec3(iGamma));
}

View File

@ -472,7 +472,7 @@ void main(void)
float e = 0.14f;
color = clamp((x*(a*x+b))/(x*(c*x+d)+e), 0.0, 1.0);
// gamma correction
color = pow( color, vec3(1. / 2.2) );
// color = pow( color, vec3(2.2) );
#endif
// dither with noise.

View File

@ -56,4 +56,5 @@ void main(void) {
color += vec3( (-1.5/256.) + (3./256.) * dither );
frag_color = vec4( color, 1.0f );
frag_color.rgb = pow( frag_color.rgb, vec3(2.2) );
}

View File

@ -371574,6 +371574,7 @@ cubemap_t cubemap6( const image_t images[6], int flags ) {
glGenTextures(1, &c.id);
glBindTexture(GL_TEXTURE_CUBE_MAP, c.id);
float gammabg = window_get_gamma() + !window_get_gamma();
int samples = 0;
for (int i = 0; i < 6; i++) {
image_t img = images[i]; //image(textures[i], IMAGE_RGB);
@ -371595,6 +371596,9 @@ cubemap_t cubemap6( const image_t images[6], int flags ) {
skyDir[i]); // texelDirection;
float l = len3(n);
vec3 light = scale3(vec3(p[0], p[1], p[2]), 1 / (255.0f * l * l * l)); // texelSolidAngle * texel_radiance;
light.x = powf(light.x, gammabg);
light.y = powf(light.y, gammabg);
light.z = powf(light.z, gammabg);
n = norm3(n);
c.sh[0] = add3(c.sh[0], scale3(light, 0.282095f));
c.sh[1] = add3(c.sh[1], scale3(light, -0.488603f * n.y * 2.0 / 3.0));
@ -371611,6 +371615,7 @@ cubemap_t cubemap6( const image_t images[6], int flags ) {
}
}
for (int s = 0; s < 9; s++) {
c.sh[s] = scale3(c.sh[s], 32.f / samples);
}
@ -372647,6 +372652,7 @@ enum shadertoy_uniforms {
iSampleRate,
iChannelResolution,
iChannelTime,
iGamma,
// iCameraScreen
// iCameraPosition
// iCameraActive
@ -372688,6 +372694,7 @@ shadertoy_t shadertoy( const char *shaderfile, unsigned flags ) {
s.uniforms[iSampleRate] = glGetUniformLocation(s.program, "iSampleRate");
s.uniforms[iChannelResolution] = glGetUniformLocation(s.program, "iChannelResolution");
s.uniforms[iChannelTime] = glGetUniformLocation(s.program, "iChannelTime");
s.uniforms[iGamma] = glGetUniformLocation(s.program, "iGamma");
return s;
}
@ -372715,6 +372722,7 @@ shadertoy_t* shadertoy_render(shadertoy_t *s, float delta) {
glUniform1i(s->uniforms[iFrame], (int)window_frame());
glUniform1f(s->uniforms[iTime], time_ss());
glUniform1f(s->uniforms[iGamma], window_get_gamma() + !window_get_gamma());
glUniform4f(s->uniforms[iDate], tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_sec + tm->tm_min * 60 + tm->tm_hour * 3600);
int unit = 0;
@ -379490,7 +379498,13 @@ void glNewFrame() {
glViewport(0, 0, window_width(), window_height());
// GLfloat bgColor[4]; glGetFloatv(GL_COLOR_CLEAR_VALUE, bgColor);
glClearColor(winbgcolor.r, winbgcolor.g, winbgcolor.b, window_has_transparent() ? 0 : winbgcolor.a); // @transparent
vec4 bgcolor = winbgcolor;
float gammabg = gamma + !gamma;
bgcolor.x = powf(bgcolor.x, gammabg);
bgcolor.y = powf(bgcolor.y, gammabg);
bgcolor.z = powf(bgcolor.z, gammabg);
bgcolor.w = powf(bgcolor.w, gammabg);
glClearColor(bgcolor.r, bgcolor.g, bgcolor.b, window_has_transparent() ? 0 : bgcolor.a); // @transparent
//glClearColor(0.15,0.15,0.15,1);
//glClearColor( clearColor.r, clearColor.g, clearColor.b, clearColor.a );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );

View File

@ -1551,6 +1551,7 @@ cubemap_t cubemap6( const image_t images[6], int flags ) {
glGenTextures(1, &c.id);
glBindTexture(GL_TEXTURE_CUBE_MAP, c.id);
float gammabg = window_get_gamma() + !window_get_gamma();
int samples = 0;
for (int i = 0; i < 6; i++) {
image_t img = images[i]; //image(textures[i], IMAGE_RGB);
@ -1572,6 +1573,9 @@ cubemap_t cubemap6( const image_t images[6], int flags ) {
skyDir[i]); // texelDirection;
float l = len3(n);
vec3 light = scale3(vec3(p[0], p[1], p[2]), 1 / (255.0f * l * l * l)); // texelSolidAngle * texel_radiance;
light.x = powf(light.x, gammabg);
light.y = powf(light.y, gammabg);
light.z = powf(light.z, gammabg);
n = norm3(n);
c.sh[0] = add3(c.sh[0], scale3(light, 0.282095f));
c.sh[1] = add3(c.sh[1], scale3(light, -0.488603f * n.y * 2.0 / 3.0));
@ -1588,6 +1592,7 @@ cubemap_t cubemap6( const image_t images[6], int flags ) {
}
}
for (int s = 0; s < 9; s++) {
c.sh[s] = scale3(c.sh[s], 32.f / samples);
}
@ -2624,6 +2629,7 @@ enum shadertoy_uniforms {
iSampleRate,
iChannelResolution,
iChannelTime,
iGamma,
// iCameraScreen
// iCameraPosition
// iCameraActive
@ -2665,6 +2671,7 @@ shadertoy_t shadertoy( const char *shaderfile, unsigned flags ) {
s.uniforms[iSampleRate] = glGetUniformLocation(s.program, "iSampleRate");
s.uniforms[iChannelResolution] = glGetUniformLocation(s.program, "iChannelResolution");
s.uniforms[iChannelTime] = glGetUniformLocation(s.program, "iChannelTime");
s.uniforms[iGamma] = glGetUniformLocation(s.program, "iGamma");
return s;
}
@ -2692,6 +2699,7 @@ shadertoy_t* shadertoy_render(shadertoy_t *s, float delta) {
glUniform1i(s->uniforms[iFrame], (int)window_frame());
glUniform1f(s->uniforms[iTime], time_ss());
glUniform1f(s->uniforms[iGamma], window_get_gamma() + !window_get_gamma());
glUniform4f(s->uniforms[iDate], tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_sec + tm->tm_min * 60 + tm->tm_hour * 3600);
int unit = 0;

View File

@ -264,7 +264,13 @@ void glNewFrame() {
glViewport(0, 0, window_width(), window_height());
// GLfloat bgColor[4]; glGetFloatv(GL_COLOR_CLEAR_VALUE, bgColor);
glClearColor(winbgcolor.r, winbgcolor.g, winbgcolor.b, window_has_transparent() ? 0 : winbgcolor.a); // @transparent
vec4 bgcolor = winbgcolor;
float gammabg = gamma + !gamma;
bgcolor.x = powf(bgcolor.x, gammabg);
bgcolor.y = powf(bgcolor.y, gammabg);
bgcolor.z = powf(bgcolor.z, gammabg);
bgcolor.w = powf(bgcolor.w, gammabg);
glClearColor(bgcolor.r, bgcolor.g, bgcolor.b, window_has_transparent() ? 0 : bgcolor.a); // @transparent
//glClearColor(0.15,0.15,0.15,1);
//glClearColor( clearColor.r, clearColor.g, clearColor.b, clearColor.a );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );

View File

@ -18724,6 +18724,7 @@ cubemap_t cubemap6( const image_t images[6], int flags ) {
glGenTextures(1, &c.id);
glBindTexture(GL_TEXTURE_CUBE_MAP, c.id);
float gammabg = window_get_gamma() + !window_get_gamma();
int samples = 0;
for (int i = 0; i < 6; i++) {
image_t img = images[i]; //image(textures[i], IMAGE_RGB);
@ -18745,6 +18746,9 @@ cubemap_t cubemap6( const image_t images[6], int flags ) {
skyDir[i]); // texelDirection;
float l = len3(n);
vec3 light = scale3(vec3(p[0], p[1], p[2]), 1 / (255.0f * l * l * l)); // texelSolidAngle * texel_radiance;
light.x = powf(light.x, gammabg);
light.y = powf(light.y, gammabg);
light.z = powf(light.z, gammabg);
n = norm3(n);
c.sh[0] = add3(c.sh[0], scale3(light, 0.282095f));
c.sh[1] = add3(c.sh[1], scale3(light, -0.488603f * n.y * 2.0 / 3.0));
@ -18761,6 +18765,7 @@ cubemap_t cubemap6( const image_t images[6], int flags ) {
}
}
for (int s = 0; s < 9; s++) {
c.sh[s] = scale3(c.sh[s], 32.f / samples);
}
@ -19797,6 +19802,7 @@ enum shadertoy_uniforms {
iSampleRate,
iChannelResolution,
iChannelTime,
iGamma,
// iCameraScreen
// iCameraPosition
// iCameraActive
@ -19838,6 +19844,7 @@ shadertoy_t shadertoy( const char *shaderfile, unsigned flags ) {
s.uniforms[iSampleRate] = glGetUniformLocation(s.program, "iSampleRate");
s.uniforms[iChannelResolution] = glGetUniformLocation(s.program, "iChannelResolution");
s.uniforms[iChannelTime] = glGetUniformLocation(s.program, "iChannelTime");
s.uniforms[iGamma] = glGetUniformLocation(s.program, "iGamma");
return s;
}
@ -19865,6 +19872,7 @@ shadertoy_t* shadertoy_render(shadertoy_t *s, float delta) {
glUniform1i(s->uniforms[iFrame], (int)window_frame());
glUniform1f(s->uniforms[iTime], time_ss());
glUniform1f(s->uniforms[iGamma], window_get_gamma() + !window_get_gamma());
glUniform4f(s->uniforms[iDate], tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_sec + tm->tm_min * 60 + tm->tm_hour * 3600);
int unit = 0;
@ -26640,7 +26648,13 @@ void glNewFrame() {
glViewport(0, 0, window_width(), window_height());
// GLfloat bgColor[4]; glGetFloatv(GL_COLOR_CLEAR_VALUE, bgColor);
glClearColor(winbgcolor.r, winbgcolor.g, winbgcolor.b, window_has_transparent() ? 0 : winbgcolor.a); // @transparent
vec4 bgcolor = winbgcolor;
float gammabg = gamma + !gamma;
bgcolor.x = powf(bgcolor.x, gammabg);
bgcolor.y = powf(bgcolor.y, gammabg);
bgcolor.z = powf(bgcolor.z, gammabg);
bgcolor.w = powf(bgcolor.w, gammabg);
glClearColor(bgcolor.r, bgcolor.g, bgcolor.b, window_has_transparent() ? 0 : bgcolor.a); // @transparent
//glClearColor(0.15,0.15,0.15,1);
//glClearColor( clearColor.r, clearColor.g, clearColor.b, clearColor.a );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );