gfx: gamma correction
parent
253b931093
commit
b14c31b4e0
|
@ -1270,7 +1270,7 @@ enum MATERIAL_ENUMS {
|
|||
MATERIAL_CHANNEL_AO,
|
||||
MATERIAL_CHANNEL_AMBIENT,
|
||||
MATERIAL_CHANNEL_EMISSIVE,
|
||||
MAX_CHANNELS_PER_MATERIAL = MATERIAL_CHANNEL_EMISSIVE
|
||||
MAX_CHANNELS_PER_MATERIAL
|
||||
};
|
||||
typedef struct material_layer_t {
|
||||
char texname[32];
|
||||
|
|
|
@ -32,8 +32,8 @@ int main() {
|
|||
// load video, RGB texture, no audio
|
||||
video_t *v = video( "pexels-pachon-in-motion-17486489.mp4", VIDEO_RGB | VIDEO_NO_AUDIO | VIDEO_LOOP ); video_seek(v, 30);
|
||||
// load texture
|
||||
texture_t t1 = texture("kgirl/g01_texture.png", TEXTURE_RGB);
|
||||
texture_t t2 = texture("matcaps/material3", 0);
|
||||
texture_t t1 = texture("kgirl/g01_texture.png", TEXTURE_SRGB);
|
||||
texture_t t2 = texture("matcaps/material3", TEXTURE_SRGB);
|
||||
// load model
|
||||
model_t m1 = model("suzanne.obj", MODEL_NO_ANIMATIONS);
|
||||
model_t m2 = model("suzanne.obj", MODEL_NO_ANIMATIONS|MODEL_MATCAPS);
|
||||
|
|
|
@ -51,7 +51,7 @@ int main() {
|
|||
|
||||
// manual spawn & loading
|
||||
model_t m1 = model("kgirl/kgirls01.fbx", 0); //MODEL_NO_ANIMS);
|
||||
texture_t t1 = texture("kgirl/g01_texture.png", TEXTURE_RGB);
|
||||
texture_t t1 = texture("kgirl/g01_texture.png", TEXTURE_SRGB);
|
||||
object_t* obj3 = scene_spawn();
|
||||
object_model(obj3, m1);
|
||||
object_diffuse(obj3, t1);
|
||||
|
|
|
@ -20,7 +20,7 @@ int main() {
|
|||
|
||||
// present decoded textures as a fullscreen composed quad
|
||||
profile( "Video quad" ) {
|
||||
if(is_rgb) fullscreen_quad_rgb( textures[0], 1.3f );
|
||||
if(is_rgb) fullscreen_quad_rgb( textures[0], 2.2f );
|
||||
else fullscreen_quad_ycbcr( textures, 1.3f );
|
||||
}
|
||||
|
||||
|
|
|
@ -447,6 +447,8 @@ void main() {
|
|||
vec3 col = u_rimcolor*(pow(smoothstep(1.0-u_rimrange.x,u_rimrange.y,rim), u_rimrange.z));
|
||||
fragcolor += vec4(col, 1.0);}
|
||||
#endif
|
||||
|
||||
fragcolor.rgb = pow( fragcolor.rgb, vec3(1. / 2.2) );
|
||||
}
|
||||
#endif
|
||||
#ifdef SHADING_PBR
|
||||
|
@ -691,7 +693,7 @@ void main(void)
|
|||
color = (x * (6.2 * x + 0.5)) / (x * (6.2 * x + 1.7) + 0.06);
|
||||
// gamma correction
|
||||
// color = pow( color, vec3(1. / 2.2) );
|
||||
#elif 1
|
||||
#elif 0
|
||||
// aces film (CC0, src: https://knarkowicz.wordpress.com/2016/01/06/aces-filmic-tone-mapping-curve/)
|
||||
vec3 x = color;
|
||||
float a = 2.51f;
|
||||
|
@ -703,6 +705,7 @@ void main(void)
|
|||
// gamma correction
|
||||
color = pow( color, vec3(1. / 2.2) );
|
||||
#endif
|
||||
color = pow( color, vec3(1. / 2.2) );
|
||||
|
||||
// Technically this alpha may be too transparent, if there is a lot of reflected light we wouldn't
|
||||
// see the background, maybe we can approximate it well enough by adding a fresnel term
|
||||
|
|
|
@ -7,4 +7,5 @@ out vec4 fragcolor;
|
|||
|
||||
void main() {
|
||||
fragcolor = vec4(texture(u_cubemap, v_direction).rgb, 1.0);
|
||||
fragcolor.rgb = pow(fragcolor.rgb, vec3(1.0/2.2));
|
||||
}
|
|
@ -17476,7 +17476,8 @@ enum MATERIAL_ENUMS {
|
|||
MATERIAL_CHANNEL_AO,
|
||||
MATERIAL_CHANNEL_AMBIENT,
|
||||
MATERIAL_CHANNEL_EMISSIVE,
|
||||
MAX_CHANNELS_PER_MATERIAL = MATERIAL_CHANNEL_EMISSIVE
|
||||
|
||||
MAX_CHANNELS_PER_MATERIAL
|
||||
};
|
||||
|
||||
typedef struct material_layer_t {
|
||||
|
@ -371571,7 +371572,7 @@ cubemap_t cubemap6( const image_t images[6], int flags ) {
|
|||
for (int i = 0; i < 6; i++) {
|
||||
image_t img = images[i]; //image(textures[i], IMAGE_RGB);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB, img.w, img.h, 0, img.n == 3 ? GL_RGB : GL_RGBA, GL_UNSIGNED_BYTE, img.pixels);
|
||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_SRGB, img.w, img.h, 0, img.n == 3 ? GL_RGB : GL_RGBA, GL_UNSIGNED_BYTE, img.pixels);
|
||||
|
||||
// calculate SH coefficients (@ands)
|
||||
const vec3 skyDir[] = {{ 1, 0, 0},{-1, 0, 0},{ 0, 1, 0},{ 0,-1, 0},{ 0, 0, 1},{ 0, 0,-1}};
|
||||
|
@ -371663,7 +371664,7 @@ skybox_t skybox(const char *asset, int flags) {
|
|||
if( asset ) {
|
||||
int is_panorama = vfs_size( asset );
|
||||
if( is_panorama ) { // is file
|
||||
stbi_hdr_to_ldr_gamma(1.2f);
|
||||
// stbi_hdr_to_ldr_gamma(1.2f);
|
||||
image_t panorama = image( asset, IMAGE_RGBA );
|
||||
sky.cubemap = cubemap( panorama, 0 ); // RGBA required
|
||||
image_destroy(&panorama);
|
||||
|
@ -373335,7 +373336,7 @@ bool model_load_textures(iqm_t *q, const struct iqmheader *hdr, model_t *model,
|
|||
if( reused ) continue;
|
||||
|
||||
// decode texture+material
|
||||
int flags = TEXTURE_MIPMAPS|TEXTURE_REPEAT|TEXTURE_ANISOTROPY; // LINEAR, NEAREST
|
||||
int flags = TEXTURE_MIPMAPS|TEXTURE_REPEAT|TEXTURE_ANISOTROPY|TEXTURE_SRGB; // LINEAR, NEAREST
|
||||
if (!(_flags & MODEL_NO_FILTERING))
|
||||
flags |= TEXTURE_LINEAR;
|
||||
int invalid = texture_checker().id;
|
||||
|
@ -375414,7 +375415,7 @@ int scene_merge(const char *source) {
|
|||
//char *a = archive_read(animation_file);
|
||||
object_t *o = scene_spawn();
|
||||
object_model(o, m);
|
||||
if( texture_file[0] ) object_diffuse(o, texture_from_mem(vfs_read(texture_file), vfs_size(texture_file), opt_flip_uv ? IMAGE_FLIP : 0) );
|
||||
if( texture_file[0] ) object_diffuse(o, texture_from_mem(vfs_read(texture_file), vfs_size(texture_file), TEXTURE_SRGB|(opt_flip_uv ? IMAGE_FLIP : 0)) );
|
||||
object_scale(o, scale);
|
||||
object_teleport(o, position);
|
||||
object_pivot(o, rotation); // object_rotate(o, rotation);
|
||||
|
|
|
@ -1555,7 +1555,7 @@ cubemap_t cubemap6( const image_t images[6], int flags ) {
|
|||
for (int i = 0; i < 6; i++) {
|
||||
image_t img = images[i]; //image(textures[i], IMAGE_RGB);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB, img.w, img.h, 0, img.n == 3 ? GL_RGB : GL_RGBA, GL_UNSIGNED_BYTE, img.pixels);
|
||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_SRGB, img.w, img.h, 0, img.n == 3 ? GL_RGB : GL_RGBA, GL_UNSIGNED_BYTE, img.pixels);
|
||||
|
||||
// calculate SH coefficients (@ands)
|
||||
const vec3 skyDir[] = {{ 1, 0, 0},{-1, 0, 0},{ 0, 1, 0},{ 0,-1, 0},{ 0, 0, 1},{ 0, 0,-1}};
|
||||
|
@ -1647,7 +1647,7 @@ skybox_t skybox(const char *asset, int flags) {
|
|||
if( asset ) {
|
||||
int is_panorama = vfs_size( asset );
|
||||
if( is_panorama ) { // is file
|
||||
stbi_hdr_to_ldr_gamma(1.2f);
|
||||
// stbi_hdr_to_ldr_gamma(1.2f);
|
||||
image_t panorama = image( asset, IMAGE_RGBA );
|
||||
sky.cubemap = cubemap( panorama, 0 ); // RGBA required
|
||||
image_destroy(&panorama);
|
||||
|
@ -3319,7 +3319,7 @@ bool model_load_textures(iqm_t *q, const struct iqmheader *hdr, model_t *model,
|
|||
if( reused ) continue;
|
||||
|
||||
// decode texture+material
|
||||
int flags = TEXTURE_MIPMAPS|TEXTURE_REPEAT|TEXTURE_ANISOTROPY; // LINEAR, NEAREST
|
||||
int flags = TEXTURE_MIPMAPS|TEXTURE_REPEAT|TEXTURE_ANISOTROPY|TEXTURE_SRGB; // LINEAR, NEAREST
|
||||
if (!(_flags & MODEL_NO_FILTERING))
|
||||
flags |= TEXTURE_LINEAR;
|
||||
int invalid = texture_checker().id;
|
||||
|
|
|
@ -454,7 +454,8 @@ enum MATERIAL_ENUMS {
|
|||
MATERIAL_CHANNEL_AO,
|
||||
MATERIAL_CHANNEL_AMBIENT,
|
||||
MATERIAL_CHANNEL_EMISSIVE,
|
||||
MAX_CHANNELS_PER_MATERIAL = MATERIAL_CHANNEL_EMISSIVE
|
||||
|
||||
MAX_CHANNELS_PER_MATERIAL
|
||||
};
|
||||
|
||||
typedef struct material_layer_t {
|
||||
|
|
|
@ -440,7 +440,7 @@ int scene_merge(const char *source) {
|
|||
//char *a = archive_read(animation_file);
|
||||
object_t *o = scene_spawn();
|
||||
object_model(o, m);
|
||||
if( texture_file[0] ) object_diffuse(o, texture_from_mem(vfs_read(texture_file), vfs_size(texture_file), opt_flip_uv ? IMAGE_FLIP : 0) );
|
||||
if( texture_file[0] ) object_diffuse(o, texture_from_mem(vfs_read(texture_file), vfs_size(texture_file), TEXTURE_SRGB|(opt_flip_uv ? IMAGE_FLIP : 0)) );
|
||||
object_scale(o, scale);
|
||||
object_teleport(o, position);
|
||||
object_pivot(o, rotation); // object_rotate(o, rotation);
|
||||
|
|
|
@ -18729,7 +18729,7 @@ cubemap_t cubemap6( const image_t images[6], int flags ) {
|
|||
for (int i = 0; i < 6; i++) {
|
||||
image_t img = images[i]; //image(textures[i], IMAGE_RGB);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB, img.w, img.h, 0, img.n == 3 ? GL_RGB : GL_RGBA, GL_UNSIGNED_BYTE, img.pixels);
|
||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_SRGB, img.w, img.h, 0, img.n == 3 ? GL_RGB : GL_RGBA, GL_UNSIGNED_BYTE, img.pixels);
|
||||
|
||||
// calculate SH coefficients (@ands)
|
||||
const vec3 skyDir[] = {{ 1, 0, 0},{-1, 0, 0},{ 0, 1, 0},{ 0,-1, 0},{ 0, 0, 1},{ 0, 0,-1}};
|
||||
|
@ -18821,7 +18821,7 @@ skybox_t skybox(const char *asset, int flags) {
|
|||
if( asset ) {
|
||||
int is_panorama = vfs_size( asset );
|
||||
if( is_panorama ) { // is file
|
||||
stbi_hdr_to_ldr_gamma(1.2f);
|
||||
// stbi_hdr_to_ldr_gamma(1.2f);
|
||||
image_t panorama = image( asset, IMAGE_RGBA );
|
||||
sky.cubemap = cubemap( panorama, 0 ); // RGBA required
|
||||
image_destroy(&panorama);
|
||||
|
@ -20493,7 +20493,7 @@ bool model_load_textures(iqm_t *q, const struct iqmheader *hdr, model_t *model,
|
|||
if( reused ) continue;
|
||||
|
||||
// decode texture+material
|
||||
int flags = TEXTURE_MIPMAPS|TEXTURE_REPEAT|TEXTURE_ANISOTROPY; // LINEAR, NEAREST
|
||||
int flags = TEXTURE_MIPMAPS|TEXTURE_REPEAT|TEXTURE_ANISOTROPY|TEXTURE_SRGB; // LINEAR, NEAREST
|
||||
if (!(_flags & MODEL_NO_FILTERING))
|
||||
flags |= TEXTURE_LINEAR;
|
||||
int invalid = texture_checker().id;
|
||||
|
@ -22572,7 +22572,7 @@ int scene_merge(const char *source) {
|
|||
//char *a = archive_read(animation_file);
|
||||
object_t *o = scene_spawn();
|
||||
object_model(o, m);
|
||||
if( texture_file[0] ) object_diffuse(o, texture_from_mem(vfs_read(texture_file), vfs_size(texture_file), opt_flip_uv ? IMAGE_FLIP : 0) );
|
||||
if( texture_file[0] ) object_diffuse(o, texture_from_mem(vfs_read(texture_file), vfs_size(texture_file), TEXTURE_SRGB|(opt_flip_uv ? IMAGE_FLIP : 0)) );
|
||||
object_scale(o, scale);
|
||||
object_teleport(o, position);
|
||||
object_pivot(o, rotation); // object_rotate(o, rotation);
|
||||
|
|
|
@ -3543,7 +3543,8 @@ enum MATERIAL_ENUMS {
|
|||
MATERIAL_CHANNEL_AO,
|
||||
MATERIAL_CHANNEL_AMBIENT,
|
||||
MATERIAL_CHANNEL_EMISSIVE,
|
||||
MAX_CHANNELS_PER_MATERIAL = MATERIAL_CHANNEL_EMISSIVE
|
||||
|
||||
MAX_CHANNELS_PER_MATERIAL
|
||||
};
|
||||
|
||||
typedef struct material_layer_t {
|
||||
|
|
Loading…
Reference in New Issue