Skip to content

Commit

Permalink
ogt_vox: support material property _media_type jpaver#64
Browse files Browse the repository at this point in the history
  • Loading branch information
mgerhardy committed Mar 6, 2024
1 parent a45c00f commit d4051c8
Showing 1 changed file with 39 additions and 16 deletions.
55 changes: 39 additions & 16 deletions src/ogt_vox.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,25 +291,34 @@
static const uint32_t k_ogt_vox_matl_have_g = 1 << 12;
static const uint32_t k_ogt_vox_matl_have_media = 1 << 13;

// media type for blend, glass and cloud materials
enum ogt_media_type {
ogt_media_type_absorb, // Absorb media
ogt_media_type_scatter, // Scatter media
ogt_media_type_emit, // Emissive media
ogt_media_type_sss, // Subsurface scattering media
};

// Extended Material Chunk MATL information
typedef struct ogt_vox_matl
{
uint32_t content_flags; // set of k_ogt_vox_matl_* OR together to denote contents available
ogt_matl_type type;
float metal;
float rough;
float spec;
float ior;
float att;
float flux;
float emit;
float ldr;
float trans;
float alpha;
float d;
float sp;
float g;
float media;
uint32_t content_flags; // set of k_ogt_vox_matl_* OR together to denote contents available
ogt_media_type media_type; // media type for blend, glass and cloud materials
ogt_matl_type type;
float metal;
float rough; // roughness
float spec; // specular
float ior; // index of refraction
float att; // attenuation
float flux; // radiant flux (power)
float emit; // emissive
float ldr; // low dynamic range
float trans; // transparency
float alpha;
float d; // density
float sp;
float g;
float media;
} ogt_vox_matl;

// Extended Material Chunk MATL array of materials
Expand Down Expand Up @@ -1677,6 +1686,20 @@
materials.matl[material_id].type = ogt_matl_type_media;
}
}
materials.matl[material_id].media_type = ogt_media_type_absorb;
const char* media_type_string = _vox_dict_get_value_as_string(&dict, "_media_type", NULL);
if (media_type_string) {
if (0 == _vox_strcmp(media_type_string,"_scatter") {
materials.matl[material_id].media_type = ogt_media_type_scatter;
}
else if (0 == _vox_strcmp(media_type_string,"_emit") {
materials.matl[material_id].media_type = ogt_media_type_emit;
}
else if (0 == _vox_strcmp(media_type_string,"_sss") {
materials.matl[material_id].media_type = ogt_media_type_sss;
}
}

const char* metal_string = _vox_dict_get_value_as_string(&dict, "_metal", NULL);
if (metal_string) {
materials.matl[material_id].content_flags |= k_ogt_vox_matl_have_metal;
Expand Down

0 comments on commit d4051c8

Please sign in to comment.