demos: fix 99-pbr

main
Dominik Madarász 2024-03-26 15:34:25 +01:00
parent d2582796a8
commit 253b931093
7 changed files with 95 additions and 306 deletions

View File

@ -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 );

View File

@ -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();
// 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 );
// 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_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();
}
// ui_panel_end();
// }
if( ui_panel("Help", 0)) {
if( fps_mode ) {

View File

@ -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
@ -372606,8 +372588,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 +372597,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 +372609,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
//

View File

@ -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
//

View File

@ -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

View File

@ -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
//

View File

@ -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