diff --git a/srgb.patch b/srgb.patch deleted file mode 100644 index ab2fc7c..0000000 --- a/srgb.patch +++ /dev/null @@ -1,1265 +0,0 @@ -diff --git a/bind/fwk.lua b/bind/fwk.lua -index 153f2f9..6421779 100644 ---- a/bind/fwk.lua -+++ b/bind/fwk.lua -@@ -1110,22 +1110,7 @@ typedef struct colormap_t { - vec4 color; - texture_t *texture; - } colormap_t; -- bool colormap( colormap_t *cm, const char *pbr_material_type, bool load_as_srgb ); --typedef struct pbr_material_t { -- char* name; -- colormap_t diffuse; -- colormap_t normals; -- colormap_t specular; -- colormap_t albedo; -- colormap_t roughness; -- colormap_t metallic; -- colormap_t ao; -- colormap_t ambient; -- colormap_t emissive; -- float specular_shininess; --} pbr_material_t; -- bool pbr_material(pbr_material_t *pbr, const char *material); -- void pbr_material_destroy(pbr_material_t *m); -+ bool colormap( colormap_t *cm, const char *texture_name, bool load_as_srgb ); - void fullscreen_quad_rgb( texture_t texture_rgb, float gamma ); - void fullscreen_quad_rgb_flipped( texture_t texture, float gamma ); - void fullscreen_quad_ycbcr( texture_t texture_YCbCr[3], float gamma ); -@@ -1285,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]; -diff --git a/demos/06-material.c b/demos/06-material.c -index 48f0466..9eb4a6f 100644 ---- a/demos/06-material.c -+++ b/demos/06-material.c -@@ -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); -diff --git a/demos/06-scene.c b/demos/06-scene.c -index 8bcd5a4..32467f7 100644 ---- a/demos/06-scene.c -+++ b/demos/06-scene.c -@@ -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); -diff --git a/demos/08-video.c b/demos/08-video.c -index aa7e933..2b96167 100644 ---- a/demos/08-video.c -+++ b/demos/08-video.c -@@ -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 ); - } - -diff --git a/demos/99-pbr.c b/demos/99-pbr.c -index 307d9fd..3b93577 100644 ---- a/demos/99-pbr.c -+++ b/demos/99-pbr.c -@@ -41,6 +41,33 @@ texture_t *LoadTextureRGBA8( const char *pathfile, unsigned flags ) { - return tex; - } - -+// ----------------------------------------------------------------------------- -+// pbr materials (kept for backwards compatibility) -+ -+typedef struct pbr_material_t { -+ char* name; -+ colormap_t diffuse; -+ colormap_t normals; -+ colormap_t specular; -+ colormap_t albedo; -+ colormap_t roughness; -+ colormap_t metallic; -+ colormap_t ao; -+ colormap_t ambient; -+ colormap_t emissive; -+ -+ float specular_shininess; -+} pbr_material_t; -+ -+bool pbr_material(pbr_material_t *pbr, const char *material) { -+ pbr->name = STRDUP(material); -+ return true; -+} -+ -+void pbr_material_destroy(pbr_material_t *m) { -+ -+} -+ - // ----------------------------------------------------------------------------- - // models - -@@ -58,6 +85,7 @@ typedef struct Mesh { - } Mesh; - - typedef struct Model { -+ model_t m; - array(Mesh) meshes; - array(pbr_material_t) materials; - unsigned shader; -@@ -90,7 +118,8 @@ bool ModelLoad( Model *G, const char *_path ) { - Model g = {0}; - *G = g; - -- model_t m = model(_path, 0); -+ model_t m = model(_path, MODEL_PBR); -+ G->m = m; - - int scn_num_meshes = m.num_meshes; - int scn_num_materials = array_count(m.materials); -@@ -143,12 +172,12 @@ bool ModelLoad( Model *G, const char *_path ) { - mesh.material_idx = material_index; - - // By importing materials before meshes we can investigate whether a mesh is transparent and flag it as such. -- const pbr_material_t* mtl = G->materials ? &G->materials[mesh.material_idx] : NULL; -- mesh.transparent = false; -- if( mtl ) { -- mesh.transparent |= mtl->albedo .texture ? mtl->albedo .texture->transparent : mtl->albedo .color.a < 1.0f; -- mesh.transparent |= mtl->diffuse.texture ? mtl->diffuse.texture->transparent : mtl->diffuse.color.a < 1.0f; -- } -+ // const pbr_material_t* mtl = G->materials ? &G->materials[mesh.material_idx] : NULL; -+ // mesh.transparent = false; -+ // if( mtl ) { -+ // mesh.transparent |= mtl->albedo .texture ? mtl->albedo .texture->transparent : mtl->albedo .color.a < 1.0f; -+ // mesh.transparent |= mtl->diffuse.texture ? mtl->diffuse.texture->transparent : mtl->diffuse.color.a < 1.0f; -+ // } - - array_push(G->meshes, mesh); - } -@@ -196,17 +225,17 @@ void ModelRender( Model *G, const mat44 _worldRootMatrix ) { - if(mesh->transparent != bTransparentPass) - continue; - -- const pbr_material_t *material = &G->materials[ mesh->material_idx ]; -- shader_colormap( "map_diffuse", material->diffuse ); -- shader_colormap( "map_normals", material->normals ); -- shader_colormap( "map_specular", material->specular ); -- shader_colormap( "map_albedo", material->albedo ); -- shader_colormap( "map_roughness", material->roughness ); -- shader_colormap( "map_metallic", material->metallic ); -- shader_colormap( "map_ao", material->ao ); -- shader_colormap( "map_ambient", material->ambient ); -- shader_colormap( "map_emissive", material->emissive ); -- shader_float( "specular_shininess", material->specular_shininess ); // unused, basic_specgloss.fs only -+ const material_t *material = &G->m.materials[ mesh->material_idx ]; -+ shader_colormap( "map_diffuse", material->layer[MATERIAL_CHANNEL_DIFFUSE].map ); -+ shader_colormap( "map_normals", material->layer[MATERIAL_CHANNEL_NORMALS].map ); -+ shader_colormap( "map_specular", material->layer[MATERIAL_CHANNEL_SPECULAR].map ); -+ shader_colormap( "map_albedo", material->layer[MATERIAL_CHANNEL_ALBEDO].map ); -+ shader_colormap( "map_roughness", material->layer[MATERIAL_CHANNEL_ROUGHNESS].map ); -+ shader_colormap( "map_metallic", material->layer[MATERIAL_CHANNEL_METALLIC].map ); -+ shader_colormap( "map_ao", material->layer[MATERIAL_CHANNEL_AO].map ); -+ shader_colormap( "map_ambient", material->layer[MATERIAL_CHANNEL_AMBIENT].map ); -+ shader_colormap( "map_emissive", material->layer[MATERIAL_CHANNEL_EMISSIVE].map ); -+ // shader_float( "specular_shininess", material->specular_shininess ); // unused, basic_specgloss.fs only - - shader_vec2( "resolution", vec2(window_width(),window_height())); - -@@ -613,38 +642,38 @@ int main() { - ui_panel_end(); - } - -- if( ui_panel( "Model", 0 ) ) { -- ui_label(va("Material count: %d", array_count(gModel.materials))); -- ui_label(va("Mesh count: %d", array_count(gModel.meshes))); -- int triCount = 0; for( int i = 0, end = array_count(gModel.meshes); i < end; ++i ) triCount += gModel.meshes[i].num_tris; -- ui_label(va("Triangle count: %d", triCount)); -- ui_separator(); -- -- bool xyzSpace = !do_xzySpace; -- if( ui_bool( "XYZ space", &xyzSpace ) ) { -- do_xzySpace = !do_xzySpace; -- } -- ui_bool( "XZY space", &do_xzySpace ); -- ui_bool( "invert Y", &do_flipY ); -- -- ui_separator(); -- for( int i = 0, end = array_count(gModel.materials); i < end; ++i ) { -- pbr_material_t *it = &gModel.materials[i]; -- ui_label(va("Name: %s", it->name)); -- ui_float( "Specular shininess", &it->specular_shininess ); -- ui_separator(); if(ui_colormap( "Albedo", &it->albedo )) colormap(&it->albedo , app_loadfile(), 1); -- ui_separator(); if(ui_colormap( "Ambient", &it->ambient )) colormap(&it->ambient , app_loadfile(), 0); -- ui_separator(); if(ui_colormap( "AO", &it->ao )) colormap(&it->ao , app_loadfile(), 0); -- ui_separator(); if(ui_colormap( "Diffuse", &it->diffuse )) colormap(&it->diffuse , app_loadfile(), 1); -- ui_separator(); if(ui_colormap( "Emissive", &it->emissive )) colormap(&it->emissive , app_loadfile(), 1); -- ui_separator(); if(ui_colormap( "Metallic", &it->metallic )) colormap(&it->metallic , app_loadfile(), 0); -- ui_separator(); if(ui_colormap( "Normal", &it->normals )) colormap(&it->normals , app_loadfile(), 0); -- ui_separator(); if(ui_colormap( "Roughness", &it->roughness )) colormap(&it->roughness, app_loadfile(), 0); -- ui_separator(); if(ui_colormap( "Specular", &it->specular )) colormap(&it->specular , app_loadfile(), 0); -- } -- -- ui_panel_end(); -- } -+ // if( ui_panel( "Model", 0 ) ) { -+ // ui_label(va("Material count: %d", array_count(gModel.materials))); -+ // ui_label(va("Mesh count: %d", array_count(gModel.meshes))); -+ // int triCount = 0; for( int i = 0, end = array_count(gModel.meshes); i < end; ++i ) triCount += gModel.meshes[i].num_tris; -+ // ui_label(va("Triangle count: %d", triCount)); -+ // ui_separator(); -+ -+ // bool xyzSpace = !do_xzySpace; -+ // if( ui_bool( "XYZ space", &xyzSpace ) ) { -+ // do_xzySpace = !do_xzySpace; -+ // } -+ // ui_bool( "XZY space", &do_xzySpace ); -+ // ui_bool( "invert Y", &do_flipY ); -+ -+ // ui_separator(); -+ // for( int i = 0, end = array_count(gModel.materials); i < end; ++i ) { -+ // pbr_material_t *it = &gModel.materials[i]; -+ // ui_label(va("Name: %s", it->name)); -+ // ui_float( "Specular shininess", &it->specular_shininess ); -+ // ui_separator(); if(ui_colormap( "Albedo", &it->albedo )) colormap(&it->albedo , app_loadfile(), 1); -+ // ui_separator(); if(ui_colormap( "Ambient", &it->ambient )) colormap(&it->ambient , app_loadfile(), 0); -+ // ui_separator(); if(ui_colormap( "AO", &it->ao )) colormap(&it->ao , app_loadfile(), 0); -+ // ui_separator(); if(ui_colormap( "Diffuse", &it->diffuse )) colormap(&it->diffuse , app_loadfile(), 1); -+ // ui_separator(); if(ui_colormap( "Emissive", &it->emissive )) colormap(&it->emissive , app_loadfile(), 1); -+ // ui_separator(); if(ui_colormap( "Metallic", &it->metallic )) colormap(&it->metallic , app_loadfile(), 0); -+ // ui_separator(); if(ui_colormap( "Normal", &it->normals )) colormap(&it->normals , app_loadfile(), 0); -+ // ui_separator(); if(ui_colormap( "Roughness", &it->roughness )) colormap(&it->roughness, app_loadfile(), 0); -+ // ui_separator(); if(ui_colormap( "Specular", &it->specular )) colormap(&it->specular , app_loadfile(), 0); -+ // } -+ -+ // ui_panel_end(); -+ // } - - if( ui_panel("Help", 0)) { - if( fps_mode ) { -diff --git a/engine/art/shaders/fs_32_4_model.glsl b/engine/art/shaders/fs_32_4_model.glsl -index f2f1604..391f6b0 100644 ---- a/engine/art/shaders/fs_32_4_model.glsl -+++ b/engine/art/shaders/fs_32_4_model.glsl -@@ -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 -diff --git a/engine/art/shaders/fs_3_4_skybox.glsl b/engine/art/shaders/fs_3_4_skybox.glsl -index 340562c..ad27e6d 100644 ---- a/engine/art/shaders/fs_3_4_skybox.glsl -+++ b/engine/art/shaders/fs_3_4_skybox.glsl -@@ -1,10 +1,11 @@ --uniform samplerCube u_cubemap; -- -- --in vec3 v_direction; --out vec4 fragcolor; -- -- --void main() { -- fragcolor = vec4(texture(u_cubemap, v_direction).rgb, 1.0); -+uniform samplerCube u_cubemap; -+ -+ -+in vec3 v_direction; -+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)); - } -\ No newline at end of file -diff --git a/engine/art/shaders/fs_3_4_skybox_rayleigh.glsl b/engine/art/shaders/fs_3_4_skybox_rayleigh.glsl -index 8f09732..4dd4210 100644 ---- a/engine/art/shaders/fs_3_4_skybox_rayleigh.glsl -+++ b/engine/art/shaders/fs_3_4_skybox_rayleigh.glsl -@@ -1,154 +1,154 @@ --uniform vec3 uSunPos; --uniform vec3 uRayOrigin; --uniform float uSunIntensity; --uniform float uPlanetRadius; --uniform float uAtmosphereRadius; --uniform vec3 uRayleighScattering; --uniform float uMieScattering; --uniform float uRayleighScaleHeight; --uniform float uMieScaleHeight; --uniform float uMiePreferredDirection; -- -- --in vec3 v_direction; --out vec4 fragcolor; -- -- --vec3 atmosphere(vec3 r, vec3 r0, vec3 pSun, float iSun, float rPlanet, float rAtmos, vec3 kRlh, float kMie, float shRlh, float shMie, float g); -- -- --void main() { -- vec3 color = atmosphere( -- normalize(v_direction), // normalized ray direction -- uRayOrigin, // ray origin -- uSunPos, // position of the sun -- uSunIntensity, // intensity of the sun -- uPlanetRadius, // radius of the planet in meters -- uAtmosphereRadius, // radius of the atmosphere in meters -- uRayleighScattering, // Rayleigh scattering coefficient -- uMieScattering, // Mie scattering coefficient -- uRayleighScaleHeight, // Rayleigh scale height -- uMieScaleHeight, // Mie scale height -- uMiePreferredDirection // Mie preferred scattering direction -- ); -- -- // Apply exposure. -- color = 1.0 - exp(-1.0 * color); -- -- fragcolor = vec4(color, 1); --} -- -- --// [src] https://github.com/wwwtyro/glsl-atmosphere by wwwtyro (Unlicensed) --// For more information, please refer to -- -- --#define PI 3.141592 --#define iSteps 16 --#define jSteps 8 -- -- --vec2 rsi(vec3 r0, vec3 rd, float sr) { -- // ray-sphere intersection that assumes -- // the sphere is centered at the origin. -- // No intersection when result.x > result.y -- float a = dot(rd, rd); -- float b = 2.0 * dot(rd, r0); -- float c = dot(r0, r0) - (sr * sr); -- float d = (b*b) - 4.0*a*c; -- if (d < 0.0) return vec2(1e5,-1e5); -- return vec2( -- (-b - sqrt(d))/(2.0*a), -- (-b + sqrt(d))/(2.0*a) -- ); --} -- -- --vec3 atmosphere(vec3 r, vec3 r0, vec3 pSun, float iSun, float rPlanet, float rAtmos, vec3 kRlh, float kMie, float shRlh, float shMie, float g) { -- // Normalize the sun and view directions. -- pSun = normalize(pSun); -- r = normalize(r); -- -- // Calculate the step size of the primary ray. -- vec2 p = rsi(r0, r, rAtmos); -- if (p.x > p.y) return vec3(0,0,0); -- p.y = min(p.y, rsi(r0, r, rPlanet).x); -- float iStepSize = (p.y - p.x) / float(iSteps); -- -- // Initialize the primary ray time. -- float iTime = 0.0; -- -- // Initialize accumulators for Rayleigh and Mie scattering. -- vec3 totalRlh = vec3(0,0,0); -- vec3 totalMie = vec3(0,0,0); -- -- // Initialize optical depth accumulators for the primary ray. -- float iOdRlh = 0.0; -- float iOdMie = 0.0; -- -- // Calculate the Rayleigh and Mie phases. -- float mu = dot(r, pSun); -- float mumu = mu * mu; -- float gg = g * g; -- float pRlh = 3.0 / (16.0 * PI) * (1.0 + mumu); -- float pMie = 3.0 / (8.0 * PI) * ((1.0 - gg) * (mumu + 1.0)) / (pow(1.0 + gg - 2.0 * mu * g, 1.5) * (2.0 + gg)); -- -- // Sample the primary ray. -- for (int i = 0; i < iSteps; i++) { -- -- // Calculate the primary ray sample position. -- vec3 iPos = r0 + r * (iTime + iStepSize * 0.5); -- -- // Calculate the height of the sample. -- float iHeight = length(iPos) - rPlanet; -- -- // Calculate the optical depth of the Rayleigh and Mie scattering for this step. -- float odStepRlh = exp(-iHeight / shRlh) * iStepSize; -- float odStepMie = exp(-iHeight / shMie) * iStepSize; -- -- // Accumulate optical depth. -- iOdRlh += odStepRlh; -- iOdMie += odStepMie; -- -- // Calculate the step size of the secondary ray. -- float jStepSize = rsi(iPos, pSun, rAtmos).y / float(jSteps); -- -- // Initialize the secondary ray time. -- float jTime = 0.0; -- -- // Initialize optical depth accumulators for the secondary ray. -- float jOdRlh = 0.0; -- float jOdMie = 0.0; -- -- // Sample the secondary ray. -- for (int j = 0; j < jSteps; j++) { -- -- // Calculate the secondary ray sample position. -- vec3 jPos = iPos + pSun * (jTime + jStepSize * 0.5); -- -- // Calculate the height of the sample. -- float jHeight = length(jPos) - rPlanet; -- -- // Accumulate the optical depth. -- jOdRlh += exp(-jHeight / shRlh) * jStepSize; -- jOdMie += exp(-jHeight / shMie) * jStepSize; -- -- // Increment the secondary ray time. -- jTime += jStepSize; -- } -- -- // Calculate attenuation. -- vec3 attn = exp(-(kMie * (iOdMie + jOdMie) + kRlh * (iOdRlh + jOdRlh))); -- -- // Accumulate scattering. -- totalRlh += odStepRlh * attn; -- totalMie += odStepMie * attn; -- -- // Increment the primary ray time. -- iTime += iStepSize; -- -- } -- -- // Calculate and return the final color. -- return iSun * (pRlh * kRlh * totalRlh + pMie * kMie * totalMie); -+uniform vec3 uSunPos; -+uniform vec3 uRayOrigin; -+uniform float uSunIntensity; -+uniform float uPlanetRadius; -+uniform float uAtmosphereRadius; -+uniform vec3 uRayleighScattering; -+uniform float uMieScattering; -+uniform float uRayleighScaleHeight; -+uniform float uMieScaleHeight; -+uniform float uMiePreferredDirection; -+ -+ -+in vec3 v_direction; -+out vec4 fragcolor; -+ -+ -+vec3 atmosphere(vec3 r, vec3 r0, vec3 pSun, float iSun, float rPlanet, float rAtmos, vec3 kRlh, float kMie, float shRlh, float shMie, float g); -+ -+ -+void main() { -+ vec3 color = atmosphere( -+ normalize(v_direction), // normalized ray direction -+ uRayOrigin, // ray origin -+ uSunPos, // position of the sun -+ uSunIntensity, // intensity of the sun -+ uPlanetRadius, // radius of the planet in meters -+ uAtmosphereRadius, // radius of the atmosphere in meters -+ uRayleighScattering, // Rayleigh scattering coefficient -+ uMieScattering, // Mie scattering coefficient -+ uRayleighScaleHeight, // Rayleigh scale height -+ uMieScaleHeight, // Mie scale height -+ uMiePreferredDirection // Mie preferred scattering direction -+ ); -+ -+ // Apply exposure. -+ color = 1.0 - exp(-1.0 * color); -+ -+ fragcolor = vec4(color, 1); -+} -+ -+ -+// [src] https://github.com/wwwtyro/glsl-atmosphere by wwwtyro (Unlicensed) -+// For more information, please refer to -+ -+ -+#define PI 3.141592 -+#define iSteps 16 -+#define jSteps 8 -+ -+ -+vec2 rsi(vec3 r0, vec3 rd, float sr) { -+ // ray-sphere intersection that assumes -+ // the sphere is centered at the origin. -+ // No intersection when result.x > result.y -+ float a = dot(rd, rd); -+ float b = 2.0 * dot(rd, r0); -+ float c = dot(r0, r0) - (sr * sr); -+ float d = (b*b) - 4.0*a*c; -+ if (d < 0.0) return vec2(1e5,-1e5); -+ return vec2( -+ (-b - sqrt(d))/(2.0*a), -+ (-b + sqrt(d))/(2.0*a) -+ ); -+} -+ -+ -+vec3 atmosphere(vec3 r, vec3 r0, vec3 pSun, float iSun, float rPlanet, float rAtmos, vec3 kRlh, float kMie, float shRlh, float shMie, float g) { -+ // Normalize the sun and view directions. -+ pSun = normalize(pSun); -+ r = normalize(r); -+ -+ // Calculate the step size of the primary ray. -+ vec2 p = rsi(r0, r, rAtmos); -+ if (p.x > p.y) return vec3(0,0,0); -+ p.y = min(p.y, rsi(r0, r, rPlanet).x); -+ float iStepSize = (p.y - p.x) / float(iSteps); -+ -+ // Initialize the primary ray time. -+ float iTime = 0.0; -+ -+ // Initialize accumulators for Rayleigh and Mie scattering. -+ vec3 totalRlh = vec3(0,0,0); -+ vec3 totalMie = vec3(0,0,0); -+ -+ // Initialize optical depth accumulators for the primary ray. -+ float iOdRlh = 0.0; -+ float iOdMie = 0.0; -+ -+ // Calculate the Rayleigh and Mie phases. -+ float mu = dot(r, pSun); -+ float mumu = mu * mu; -+ float gg = g * g; -+ float pRlh = 3.0 / (16.0 * PI) * (1.0 + mumu); -+ float pMie = 3.0 / (8.0 * PI) * ((1.0 - gg) * (mumu + 1.0)) / (pow(1.0 + gg - 2.0 * mu * g, 1.5) * (2.0 + gg)); -+ -+ // Sample the primary ray. -+ for (int i = 0; i < iSteps; i++) { -+ -+ // Calculate the primary ray sample position. -+ vec3 iPos = r0 + r * (iTime + iStepSize * 0.5); -+ -+ // Calculate the height of the sample. -+ float iHeight = length(iPos) - rPlanet; -+ -+ // Calculate the optical depth of the Rayleigh and Mie scattering for this step. -+ float odStepRlh = exp(-iHeight / shRlh) * iStepSize; -+ float odStepMie = exp(-iHeight / shMie) * iStepSize; -+ -+ // Accumulate optical depth. -+ iOdRlh += odStepRlh; -+ iOdMie += odStepMie; -+ -+ // Calculate the step size of the secondary ray. -+ float jStepSize = rsi(iPos, pSun, rAtmos).y / float(jSteps); -+ -+ // Initialize the secondary ray time. -+ float jTime = 0.0; -+ -+ // Initialize optical depth accumulators for the secondary ray. -+ float jOdRlh = 0.0; -+ float jOdMie = 0.0; -+ -+ // Sample the secondary ray. -+ for (int j = 0; j < jSteps; j++) { -+ -+ // Calculate the secondary ray sample position. -+ vec3 jPos = iPos + pSun * (jTime + jStepSize * 0.5); -+ -+ // Calculate the height of the sample. -+ float jHeight = length(jPos) - rPlanet; -+ -+ // Accumulate the optical depth. -+ jOdRlh += exp(-jHeight / shRlh) * jStepSize; -+ jOdMie += exp(-jHeight / shMie) * jStepSize; -+ -+ // Increment the secondary ray time. -+ jTime += jStepSize; -+ } -+ -+ // Calculate attenuation. -+ vec3 attn = exp(-(kMie * (iOdMie + jOdMie) + kRlh * (iOdRlh + jOdRlh))); -+ -+ // Accumulate scattering. -+ totalRlh += odStepRlh * attn; -+ totalMie += odStepMie * attn; -+ -+ // Increment the primary ray time. -+ iTime += iStepSize; -+ -+ } -+ -+ // Calculate and return the final color. -+ return iSun * (pRlh * kRlh * totalRlh + pMie * kMie * totalMie); - } -\ No newline at end of file -diff --git a/engine/joint/fwk.h b/engine/joint/fwk.h -index 317f56e..b371ff1 100644 ---- a/engine/joint/fwk.h -+++ b/engine/joint/fwk.h -@@ -17172,32 +17172,14 @@ API void texture_rec_end(texture_t *t); // texture_rec - API texture_t brdf_lut(); - - // ----------------------------------------------------------------------------- --// pbr materials -+// colormap - - typedef struct colormap_t { - vec4 color; - texture_t *texture; - } colormap_t; - --API bool colormap( colormap_t *cm, const char *pbr_material_type, bool load_as_srgb ); -- --typedef struct pbr_material_t { -- char* name; -- colormap_t diffuse; -- colormap_t normals; -- colormap_t specular; -- colormap_t albedo; -- colormap_t roughness; -- colormap_t metallic; -- colormap_t ao; -- colormap_t ambient; -- colormap_t emissive; -- -- float specular_shininess; --} pbr_material_t; -- --API bool pbr_material(pbr_material_t *pbr, const char *material); --API void pbr_material_destroy(pbr_material_t *m); -+API bool colormap( colormap_t *cm, const char *texture_name, bool load_as_srgb ); - - // ----------------------------------------------------------------------------- - // fullscreen quads -@@ -17494,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 { -@@ -363378,7 +363361,7 @@ void font_face_from_mem(const char *tag, const void *ttf_data, unsigned ttf_len, - glEnableVertexAttribArray(1); - glVertexAttribPointer(1,4,GL_FLOAT,GL_FALSE,0,(void*)0); - glVertexAttribDivisor(1, 1); -- //glEnable(GL_FRAMEBUFFER_SRGB); -+ // glEnable(GL_FRAMEBUFFER_SRGB); - - // setup and upload font bitmap texture - glGenTextures(1, &f->texture_fontdata); -@@ -371589,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}}; -@@ -371681,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); -@@ -372606,8 +372589,8 @@ texture_t brdf_lut() { - // ----------------------------------------------------------------------------- - // materials - --bool colormap( colormap_t *cm, const char *material_file, bool load_as_srgb ) { -- if( !material_file ) return false; -+bool colormap( colormap_t *cm, const char *texture_name, bool load_as_srgb ) { -+ if( !texture_name ) return false; - - if( cm->texture ) { - texture_destroy(cm->texture); -@@ -372615,8 +372598,8 @@ bool colormap( colormap_t *cm, const char *material_file, bool load_as_srgb ) { - } - - int srgb = load_as_srgb ? TEXTURE_SRGB : 0; -- int hdr = strendi(material_file, ".hdr") ? TEXTURE_FLOAT | TEXTURE_RGBA : 0; -- texture_t t = texture_compressed(material_file, TEXTURE_LINEAR | TEXTURE_MIPMAPS | TEXTURE_REPEAT | hdr | srgb); -+ int hdr = strendi(texture_name, ".hdr") ? TEXTURE_FLOAT | TEXTURE_RGBA : 0; -+ texture_t t = texture_compressed(texture_name, TEXTURE_LINEAR | TEXTURE_MIPMAPS | TEXTURE_REPEAT | hdr | srgb); - - if( t.id == texture_checker().id ) { - cm->texture = NULL; -@@ -372627,63 +372610,6 @@ bool colormap( colormap_t *cm, const char *material_file, bool load_as_srgb ) { - return true; - } - --bool pbr_material(pbr_material_t *pbr, const char *material) { -- if( !material || !pbr ) return false; -- -- //pbr_material_destroy(pbr); -- *pbr = (pbr_material_t){0}; -- -- pbr->name = STRDUP(material); -- -- pbr->specular_shininess = 1.0f; -- /* -- if( const float *f = aiGetMaterialFloat(scn_material[i], aiMaterialTypeString(MATERIAL_SHININESS)) ) { -- pbr->specular_shininess = *f; -- } -- */ -- -- pbr->diffuse.color = vec4(0.5,0.5,0.5,0.5); -- pbr->normals.color = vec4(0,0,0,0); -- pbr->specular.color = vec4(0,0,0,0); -- pbr->albedo.color = vec4(0.5,0.5,0.5,1.0); -- pbr->roughness.color = vec4(1,1,1,1); -- pbr->metallic.color = vec4(0,0,0,0); -- pbr->ao.color = vec4(1,1,1,1); -- pbr->ambient.color = vec4(0,0,0,1); -- pbr->emissive.color = vec4(0,0,0,0); -- -- array(char*) tokens = strsplit(material, "+"); -- for( int j = 0, end = array_count(tokens); j < end; ++j ) { -- char *t = tokens[j]; -- if( strstri(t, "_D.") || strstri(t, "Diffuse") || strstri(t, "BaseColor") || strstri(t, "Base_Color") ) colormap(&pbr->diffuse, t, 1); -- if( strstri(t, "_N.") || strstri(t, "Normal") ) colormap(&pbr->normals, t, 0); -- if( strstri(t, "_S.") || strstri(t, "Specular") ) colormap(&pbr->specular, t, 0); -- if( strstri(t, "_A.") || strstri(t, "Albedo") ) colormap(&pbr->albedo, t, 1); // 0? -- if( strstri(t, "_MR.")|| strstri(t, "Roughness") || strstri(t, "MetallicRoughness") ) colormap(&pbr->roughness, t, 0); -- else -- if( strstri(t, "_M.") || strstri(t, "Metallic") ) colormap(&pbr->metallic, t, 0); -- //if( strstri(t, "_S.") || strstri(t, "Shininess") ) colormap(&pbr->roughness, t, 0); -- //if( strstri(t, "_A.") || strstri(t, "Ambient") ) colormap(&pbr->ambient, t, 0); -- if( strstri(t, "_E.") || strstri(t, "Emissive") ) colormap(&pbr->emissive, t, 1); -- if( strstri(t, "_AO.") || strstri(t, "AO") || strstri(t, "Occlusion") ) colormap(&pbr->ao, t, 0); -- } -- -- return true; --} -- --void pbr_material_destroy(pbr_material_t *m) { -- if( m->name ) FREE(m->name), m->name = NULL; -- if( m->diffuse.texture) texture_destroy( m->diffuse.texture ); -- if( m->normals.texture) texture_destroy( m->normals.texture ); -- if( m->specular.texture) texture_destroy( m->specular.texture ); -- if( m->albedo.texture) texture_destroy( m->albedo.texture ); -- if( m->roughness.texture) texture_destroy( m->roughness.texture ); -- if( m->metallic.texture) texture_destroy( m->metallic.texture ); -- if( m->ao.texture ) texture_destroy( m->ao.texture ); -- if( m->ambient.texture ) texture_destroy( m->ambient.texture ); -- *m = (pbr_material_t){0}; --} -- - // ---------------------------------------------------------------------------- - // shadertoys - // -@@ -373410,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; -@@ -373484,16 +373410,11 @@ bool model_load_textures(iqm_t *q, const struct iqmheader *hdr, model_t *model, - material_t mt = {0}; - mt.name = STRDUP(&str[m->material]); - -- // initialise basic texture layer first -+ // initialise basic texture layer - mt.layer[MATERIAL_CHANNEL_DIFFUSE].map.color = material_color_hex ? material_color : vec4(1,1,1,1); - mt.layer[MATERIAL_CHANNEL_DIFFUSE].map.texture = CALLOC(1, sizeof(texture_t)); - mt.layer[MATERIAL_CHANNEL_DIFFUSE].map.texture->id = *out++; - -- // initialise PBR material workflow -- if (_flags & MODEL_PBR) { -- model_load_pbr(&mt); -- } -- - array_push(model->materials, mt); - } - -@@ -373905,7 +373826,9 @@ void model_shading(model_t *m, int shading) { - } - - // rebind shader -- // @fixme: destroy old shader program -+ // @fixme: app crashes rn -+ // glUseProgram(0); -+ // glDeleteProgram(m->program); - const char *symbols[] = { "{{include-shadowmap}}", vfs_read("shaders/fs_0_0_shadowmap_lit.glsl") }; // #define RIM - int shaderprog = shader(strlerp(1,symbols,vfs_read("shaders/vs_323444143_16_3322_model.glsl")), strlerp(1,symbols,vfs_read("shaders/fs_32_4_model.glsl")), //fs, - "att_position,att_texcoord,att_normal,att_tangent,att_instanced_matrix,,,,att_indexes,att_weights,att_vertexindex,att_color,att_bitangent,att_texcoord2","fragColor", -@@ -375492,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); -diff --git a/engine/split/fwk_font.c b/engine/split/fwk_font.c -index 0b6f9f8..0b952af 100644 ---- a/engine/split/fwk_font.c -+++ b/engine/split/fwk_font.c -@@ -1816,7 +1816,7 @@ void font_face_from_mem(const char *tag, const void *ttf_data, unsigned ttf_len, - glEnableVertexAttribArray(1); - glVertexAttribPointer(1,4,GL_FLOAT,GL_FALSE,0,(void*)0); - glVertexAttribDivisor(1, 1); -- //glEnable(GL_FRAMEBUFFER_SRGB); -+ // glEnable(GL_FRAMEBUFFER_SRGB); - - // setup and upload font bitmap texture - glGenTextures(1, &f->texture_fontdata); -diff --git a/engine/split/fwk_render.c b/engine/split/fwk_render.c -index 629a152..fb7cdf5 100644 ---- a/engine/split/fwk_render.c -+++ b/engine/split/fwk_render.c -@@ -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); -@@ -2572,8 +2572,8 @@ texture_t brdf_lut() { - // ----------------------------------------------------------------------------- - // materials - --bool colormap( colormap_t *cm, const char *material_file, bool load_as_srgb ) { -- if( !material_file ) return false; -+bool colormap( colormap_t *cm, const char *texture_name, bool load_as_srgb ) { -+ if( !texture_name ) return false; - - if( cm->texture ) { - texture_destroy(cm->texture); -@@ -2581,8 +2581,8 @@ bool colormap( colormap_t *cm, const char *material_file, bool load_as_srgb ) { - } - - int srgb = load_as_srgb ? TEXTURE_SRGB : 0; -- int hdr = strendi(material_file, ".hdr") ? TEXTURE_FLOAT | TEXTURE_RGBA : 0; -- texture_t t = texture_compressed(material_file, TEXTURE_LINEAR | TEXTURE_MIPMAPS | TEXTURE_REPEAT | hdr | srgb); -+ int hdr = strendi(texture_name, ".hdr") ? TEXTURE_FLOAT | TEXTURE_RGBA : 0; -+ texture_t t = texture_compressed(texture_name, TEXTURE_LINEAR | TEXTURE_MIPMAPS | TEXTURE_REPEAT | hdr | srgb); - - if( t.id == texture_checker().id ) { - cm->texture = NULL; -@@ -2593,63 +2593,6 @@ bool colormap( colormap_t *cm, const char *material_file, bool load_as_srgb ) { - return true; - } - --bool pbr_material(pbr_material_t *pbr, const char *material) { -- if( !material || !pbr ) return false; -- -- //pbr_material_destroy(pbr); -- *pbr = (pbr_material_t){0}; -- -- pbr->name = STRDUP(material); -- -- pbr->specular_shininess = 1.0f; -- /* -- if( const float *f = aiGetMaterialFloat(scn_material[i], aiMaterialTypeString(MATERIAL_SHININESS)) ) { -- pbr->specular_shininess = *f; -- } -- */ -- -- pbr->diffuse.color = vec4(0.5,0.5,0.5,0.5); -- pbr->normals.color = vec4(0,0,0,0); -- pbr->specular.color = vec4(0,0,0,0); -- pbr->albedo.color = vec4(0.5,0.5,0.5,1.0); -- pbr->roughness.color = vec4(1,1,1,1); -- pbr->metallic.color = vec4(0,0,0,0); -- pbr->ao.color = vec4(1,1,1,1); -- pbr->ambient.color = vec4(0,0,0,1); -- pbr->emissive.color = vec4(0,0,0,0); -- -- array(char*) tokens = strsplit(material, "+"); -- for( int j = 0, end = array_count(tokens); j < end; ++j ) { -- char *t = tokens[j]; -- if( strstri(t, "_D.") || strstri(t, "Diffuse") || strstri(t, "BaseColor") || strstri(t, "Base_Color") ) colormap(&pbr->diffuse, t, 1); -- if( strstri(t, "_N.") || strstri(t, "Normal") ) colormap(&pbr->normals, t, 0); -- if( strstri(t, "_S.") || strstri(t, "Specular") ) colormap(&pbr->specular, t, 0); -- if( strstri(t, "_A.") || strstri(t, "Albedo") ) colormap(&pbr->albedo, t, 1); // 0? -- if( strstri(t, "_MR.")|| strstri(t, "Roughness") || strstri(t, "MetallicRoughness") ) colormap(&pbr->roughness, t, 0); -- else -- if( strstri(t, "_M.") || strstri(t, "Metallic") ) colormap(&pbr->metallic, t, 0); -- //if( strstri(t, "_S.") || strstri(t, "Shininess") ) colormap(&pbr->roughness, t, 0); -- //if( strstri(t, "_A.") || strstri(t, "Ambient") ) colormap(&pbr->ambient, t, 0); -- if( strstri(t, "_E.") || strstri(t, "Emissive") ) colormap(&pbr->emissive, t, 1); -- if( strstri(t, "_AO.") || strstri(t, "AO") || strstri(t, "Occlusion") ) colormap(&pbr->ao, t, 0); -- } -- -- return true; --} -- --void pbr_material_destroy(pbr_material_t *m) { -- if( m->name ) FREE(m->name), m->name = NULL; -- if( m->diffuse.texture) texture_destroy( m->diffuse.texture ); -- if( m->normals.texture) texture_destroy( m->normals.texture ); -- if( m->specular.texture) texture_destroy( m->specular.texture ); -- if( m->albedo.texture) texture_destroy( m->albedo.texture ); -- if( m->roughness.texture) texture_destroy( m->roughness.texture ); -- if( m->metallic.texture) texture_destroy( m->metallic.texture ); -- if( m->ao.texture ) texture_destroy( m->ao.texture ); -- if( m->ambient.texture ) texture_destroy( m->ambient.texture ); -- *m = (pbr_material_t){0}; --} -- - // ---------------------------------------------------------------------------- - // shadertoys - // -@@ -3376,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; -@@ -3450,16 +3393,11 @@ bool model_load_textures(iqm_t *q, const struct iqmheader *hdr, model_t *model, - material_t mt = {0}; - mt.name = STRDUP(&str[m->material]); - -- // initialise basic texture layer first -+ // initialise basic texture layer - mt.layer[MATERIAL_CHANNEL_DIFFUSE].map.color = material_color_hex ? material_color : vec4(1,1,1,1); - mt.layer[MATERIAL_CHANNEL_DIFFUSE].map.texture = CALLOC(1, sizeof(texture_t)); - mt.layer[MATERIAL_CHANNEL_DIFFUSE].map.texture->id = *out++; - -- // initialise PBR material workflow -- if (_flags & MODEL_PBR) { -- model_load_pbr(&mt); -- } -- - array_push(model->materials, mt); - } - -@@ -3871,7 +3809,9 @@ void model_shading(model_t *m, int shading) { - } - - // rebind shader -- // @fixme: destroy old shader program -+ // @fixme: app crashes rn -+ // glUseProgram(0); -+ // glDeleteProgram(m->program); - const char *symbols[] = { "{{include-shadowmap}}", vfs_read("shaders/fs_0_0_shadowmap_lit.glsl") }; // #define RIM - int shaderprog = shader(strlerp(1,symbols,vfs_read("shaders/vs_323444143_16_3322_model.glsl")), strlerp(1,symbols,vfs_read("shaders/fs_32_4_model.glsl")), //fs, - "att_position,att_texcoord,att_normal,att_tangent,att_instanced_matrix,,,,att_indexes,att_weights,att_vertexindex,att_color,att_bitangent,att_texcoord2","fragColor", -diff --git a/engine/split/fwk_render.h b/engine/split/fwk_render.h -index 834c80e..29f341e 100644 ---- a/engine/split/fwk_render.h -+++ b/engine/split/fwk_render.h -@@ -150,32 +150,14 @@ API void texture_rec_end(texture_t *t); // texture_rec - API texture_t brdf_lut(); - - // ----------------------------------------------------------------------------- --// pbr materials -+// colormap - - typedef struct colormap_t { - vec4 color; - texture_t *texture; - } colormap_t; - --API bool colormap( colormap_t *cm, const char *pbr_material_type, bool load_as_srgb ); -- --typedef struct pbr_material_t { -- char* name; -- colormap_t diffuse; -- colormap_t normals; -- colormap_t specular; -- colormap_t albedo; -- colormap_t roughness; -- colormap_t metallic; -- colormap_t ao; -- colormap_t ambient; -- colormap_t emissive; -- -- float specular_shininess; --} pbr_material_t; -- --API bool pbr_material(pbr_material_t *pbr, const char *material); --API void pbr_material_destroy(pbr_material_t *m); -+API bool colormap( colormap_t *cm, const char *texture_name, bool load_as_srgb ); - - // ----------------------------------------------------------------------------- - // fullscreen quads -@@ -472,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 { -diff --git a/engine/split/fwk_scene.c b/engine/split/fwk_scene.c -index 8dd9029..0a63c51 100644 ---- a/engine/split/fwk_scene.c -+++ b/engine/split/fwk_scene.c -@@ -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); -diff --git a/engine/fwk.c b/engine/fwk.c -index 80e0939..33d2579 100644 ---- a/engine/fwk.c -+++ b/engine/fwk.c -@@ -10518,7 +10518,7 @@ void font_face_from_mem(const char *tag, const void *ttf_data, unsigned ttf_len, - glEnableVertexAttribArray(1); - glVertexAttribPointer(1,4,GL_FLOAT,GL_FALSE,0,(void*)0); - glVertexAttribDivisor(1, 1); -- //glEnable(GL_FRAMEBUFFER_SRGB); -+ // glEnable(GL_FRAMEBUFFER_SRGB); - - // setup and upload font bitmap texture - glGenTextures(1, &f->texture_fontdata); -@@ -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); -@@ -19746,8 +19746,8 @@ texture_t brdf_lut() { - // ----------------------------------------------------------------------------- - // materials - --bool colormap( colormap_t *cm, const char *material_file, bool load_as_srgb ) { -- if( !material_file ) return false; -+bool colormap( colormap_t *cm, const char *texture_name, bool load_as_srgb ) { -+ if( !texture_name ) return false; - - if( cm->texture ) { - texture_destroy(cm->texture); -@@ -19755,8 +19755,8 @@ bool colormap( colormap_t *cm, const char *material_file, bool load_as_srgb ) { - } - - int srgb = load_as_srgb ? TEXTURE_SRGB : 0; -- int hdr = strendi(material_file, ".hdr") ? TEXTURE_FLOAT | TEXTURE_RGBA : 0; -- texture_t t = texture_compressed(material_file, TEXTURE_LINEAR | TEXTURE_MIPMAPS | TEXTURE_REPEAT | hdr | srgb); -+ int hdr = strendi(texture_name, ".hdr") ? TEXTURE_FLOAT | TEXTURE_RGBA : 0; -+ texture_t t = texture_compressed(texture_name, TEXTURE_LINEAR | TEXTURE_MIPMAPS | TEXTURE_REPEAT | hdr | srgb); - - if( t.id == texture_checker().id ) { - cm->texture = NULL; -@@ -19767,63 +19767,6 @@ bool colormap( colormap_t *cm, const char *material_file, bool load_as_srgb ) { - return true; - } - --bool pbr_material(pbr_material_t *pbr, const char *material) { -- if( !material || !pbr ) return false; -- -- //pbr_material_destroy(pbr); -- *pbr = (pbr_material_t){0}; -- -- pbr->name = STRDUP(material); -- -- pbr->specular_shininess = 1.0f; -- /* -- if( const float *f = aiGetMaterialFloat(scn_material[i], aiMaterialTypeString(MATERIAL_SHININESS)) ) { -- pbr->specular_shininess = *f; -- } -- */ -- -- pbr->diffuse.color = vec4(0.5,0.5,0.5,0.5); -- pbr->normals.color = vec4(0,0,0,0); -- pbr->specular.color = vec4(0,0,0,0); -- pbr->albedo.color = vec4(0.5,0.5,0.5,1.0); -- pbr->roughness.color = vec4(1,1,1,1); -- pbr->metallic.color = vec4(0,0,0,0); -- pbr->ao.color = vec4(1,1,1,1); -- pbr->ambient.color = vec4(0,0,0,1); -- pbr->emissive.color = vec4(0,0,0,0); -- -- array(char*) tokens = strsplit(material, "+"); -- for( int j = 0, end = array_count(tokens); j < end; ++j ) { -- char *t = tokens[j]; -- if( strstri(t, "_D.") || strstri(t, "Diffuse") || strstri(t, "BaseColor") || strstri(t, "Base_Color") ) colormap(&pbr->diffuse, t, 1); -- if( strstri(t, "_N.") || strstri(t, "Normal") ) colormap(&pbr->normals, t, 0); -- if( strstri(t, "_S.") || strstri(t, "Specular") ) colormap(&pbr->specular, t, 0); -- if( strstri(t, "_A.") || strstri(t, "Albedo") ) colormap(&pbr->albedo, t, 1); // 0? -- if( strstri(t, "_MR.")|| strstri(t, "Roughness") || strstri(t, "MetallicRoughness") ) colormap(&pbr->roughness, t, 0); -- else -- if( strstri(t, "_M.") || strstri(t, "Metallic") ) colormap(&pbr->metallic, t, 0); -- //if( strstri(t, "_S.") || strstri(t, "Shininess") ) colormap(&pbr->roughness, t, 0); -- //if( strstri(t, "_A.") || strstri(t, "Ambient") ) colormap(&pbr->ambient, t, 0); -- if( strstri(t, "_E.") || strstri(t, "Emissive") ) colormap(&pbr->emissive, t, 1); -- if( strstri(t, "_AO.") || strstri(t, "AO") || strstri(t, "Occlusion") ) colormap(&pbr->ao, t, 0); -- } -- -- return true; --} -- --void pbr_material_destroy(pbr_material_t *m) { -- if( m->name ) FREE(m->name), m->name = NULL; -- if( m->diffuse.texture) texture_destroy( m->diffuse.texture ); -- if( m->normals.texture) texture_destroy( m->normals.texture ); -- if( m->specular.texture) texture_destroy( m->specular.texture ); -- if( m->albedo.texture) texture_destroy( m->albedo.texture ); -- if( m->roughness.texture) texture_destroy( m->roughness.texture ); -- if( m->metallic.texture) texture_destroy( m->metallic.texture ); -- if( m->ao.texture ) texture_destroy( m->ao.texture ); -- if( m->ambient.texture ) texture_destroy( m->ambient.texture ); -- *m = (pbr_material_t){0}; --} -- - // ---------------------------------------------------------------------------- - // shadertoys - // -@@ -20550,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; -@@ -20624,16 +20567,11 @@ bool model_load_textures(iqm_t *q, const struct iqmheader *hdr, model_t *model, - material_t mt = {0}; - mt.name = STRDUP(&str[m->material]); - -- // initialise basic texture layer first -+ // initialise basic texture layer - mt.layer[MATERIAL_CHANNEL_DIFFUSE].map.color = material_color_hex ? material_color : vec4(1,1,1,1); - mt.layer[MATERIAL_CHANNEL_DIFFUSE].map.texture = CALLOC(1, sizeof(texture_t)); - mt.layer[MATERIAL_CHANNEL_DIFFUSE].map.texture->id = *out++; - -- // initialise PBR material workflow -- if (_flags & MODEL_PBR) { -- model_load_pbr(&mt); -- } -- - array_push(model->materials, mt); - } - -@@ -21045,7 +20983,9 @@ void model_shading(model_t *m, int shading) { - } - - // rebind shader -- // @fixme: destroy old shader program -+ // @fixme: app crashes rn -+ // glUseProgram(0); -+ // glDeleteProgram(m->program); - const char *symbols[] = { "{{include-shadowmap}}", vfs_read("shaders/fs_0_0_shadowmap_lit.glsl") }; // #define RIM - int shaderprog = shader(strlerp(1,symbols,vfs_read("shaders/vs_323444143_16_3322_model.glsl")), strlerp(1,symbols,vfs_read("shaders/fs_32_4_model.glsl")), //fs, - "att_position,att_texcoord,att_normal,att_tangent,att_instanced_matrix,,,,att_indexes,att_weights,att_vertexindex,att_color,att_bitangent,att_texcoord2","fragColor", -@@ -22632,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); -diff --git a/engine/fwk.h b/engine/fwk.h -index e2de2b8..57d7ba6 100644 ---- a/engine/fwk.h -+++ b/engine/fwk.h -@@ -3239,32 +3239,14 @@ API void texture_rec_end(texture_t *t); // texture_rec - API texture_t brdf_lut(); - - // ----------------------------------------------------------------------------- --// pbr materials -+// colormap - - typedef struct colormap_t { - vec4 color; - texture_t *texture; - } colormap_t; - --API bool colormap( colormap_t *cm, const char *pbr_material_type, bool load_as_srgb ); -- --typedef struct pbr_material_t { -- char* name; -- colormap_t diffuse; -- colormap_t normals; -- colormap_t specular; -- colormap_t albedo; -- colormap_t roughness; -- colormap_t metallic; -- colormap_t ao; -- colormap_t ambient; -- colormap_t emissive; -- -- float specular_shininess; --} pbr_material_t; -- --API bool pbr_material(pbr_material_t *pbr, const char *material); --API void pbr_material_destroy(pbr_material_t *m); -+API bool colormap( colormap_t *cm, const char *texture_name, bool load_as_srgb ); - - // ----------------------------------------------------------------------------- - // fullscreen quads -@@ -3561,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 {