-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
First draft of KHR_materials_diffuse_transmission. #179
Draft
abwood
wants to merge
2
commits into
jkuhlmann:master
Choose a base branch
from
abwood:diffuse-transmission
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -505,6 +505,14 @@ typedef struct cgltf_iridescence | |
cgltf_texture_view iridescence_thickness_texture; | ||
} cgltf_iridescence; | ||
|
||
typedef struct cgltf_diffuse_transmission | ||
{ | ||
cgltf_texture_view diffuse_transmission_texture; | ||
cgltf_float diffuse_transmission_factor; | ||
cgltf_float diffuse_transmission_color_factor[3]; | ||
cgltf_texture_view diffuse_transmission_color_texture; | ||
} cgltf_diffuse_transmission; | ||
|
||
typedef struct cgltf_material | ||
{ | ||
char* name; | ||
|
@@ -518,6 +526,7 @@ typedef struct cgltf_material | |
cgltf_bool has_sheen; | ||
cgltf_bool has_emissive_strength; | ||
cgltf_bool has_iridescence; | ||
cgltf_bool has_diffuse_transmission; | ||
cgltf_pbr_metallic_roughness pbr_metallic_roughness; | ||
cgltf_pbr_specular_glossiness pbr_specular_glossiness; | ||
cgltf_clearcoat clearcoat; | ||
|
@@ -528,6 +537,7 @@ typedef struct cgltf_material | |
cgltf_volume volume; | ||
cgltf_emissive_strength emissive_strength; | ||
cgltf_iridescence iridescence; | ||
cgltf_diffuse_transmission diffuse_transmission; | ||
cgltf_texture_view normal_texture; | ||
cgltf_texture_view occlusion_texture; | ||
cgltf_texture_view emissive_texture; | ||
|
@@ -1897,7 +1907,7 @@ void cgltf_free(cgltf_data* data) | |
{ | ||
cgltf_free_extensions(data, data->materials[i].transmission.transmission_texture.extensions, data->materials[i].transmission.transmission_texture.extensions_count); | ||
} | ||
if (data->materials[i].has_volume) | ||
if(data->materials[i].has_volume) | ||
{ | ||
cgltf_free_extensions(data, data->materials[i].volume.thickness_texture.extensions, data->materials[i].volume.thickness_texture.extensions_count); | ||
} | ||
|
@@ -1911,6 +1921,11 @@ void cgltf_free(cgltf_data* data) | |
cgltf_free_extensions(data, data->materials[i].iridescence.iridescence_texture.extensions, data->materials[i].iridescence.iridescence_texture.extensions_count); | ||
cgltf_free_extensions(data, data->materials[i].iridescence.iridescence_thickness_texture.extensions, data->materials[i].iridescence.iridescence_thickness_texture.extensions_count); | ||
} | ||
if (data->materials[i].has_diffuse_transmission) | ||
{ | ||
cgltf_free_extensions(data, data->materials[i].diffuse_transmission.diffuse_transmission_texture.extensions, data->materials[i].diffuse_transmission.diffuse_transmission_texture.extensions_count); | ||
cgltf_free_extensions(data, data->materials[i].diffuse_transmission.diffuse_transmission_color_texture.extensions, data->materials[i].diffuse_transmission.diffuse_transmission_color_texture.extensions_count); | ||
} | ||
|
||
cgltf_free_extensions(data, data->materials[i].normal_texture.extensions, data->materials[i].normal_texture.extensions_count); | ||
cgltf_free_extensions(data, data->materials[i].occlusion_texture.extensions, data->materials[i].occlusion_texture.extensions_count); | ||
|
@@ -4027,6 +4042,52 @@ static int cgltf_parse_json_iridescence(cgltf_options* options, jsmntok_t const* | |
return i; | ||
} | ||
|
||
static int cgltf_parse_json_diffuse_transmission(cgltf_options* options, jsmntok_t const* tokens, int i, const uint8_t* json_chunk, cgltf_diffuse_transmission* out_diff_transmission) | ||
{ | ||
CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT); | ||
int size = tokens[i].size; | ||
++i; | ||
|
||
// Defaults | ||
cgltf_fill_float_array(out_diff_transmission->diffuse_transmission_color_factor, 3, 1.0f); | ||
out_diff_transmission->diffuse_transmission_factor = 0.f; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit, 0.f will be assigned automatically as we zero out all fields by default |
||
|
||
for (int j = 0; j < size; ++j) | ||
{ | ||
CGLTF_CHECK_KEY(tokens[i]); | ||
|
||
if (cgltf_json_strcmp(tokens + i, json_chunk, "diffuseTransmissionFactor") == 0) | ||
{ | ||
++i; | ||
out_diff_transmission->diffuse_transmission_factor = cgltf_json_to_float(tokens + i, json_chunk); | ||
++i; | ||
} | ||
else if (cgltf_json_strcmp(tokens + i, json_chunk, "diffuseTransmissionTexture") == 0) | ||
{ | ||
i = cgltf_parse_json_texture_view(options, tokens, i + 1, json_chunk, &out_diff_transmission->diffuse_transmission_texture); | ||
} | ||
else if (cgltf_json_strcmp(tokens + i, json_chunk, "diffuseTransmissionColorFactor") == 0) | ||
{ | ||
i = cgltf_parse_json_float_array(tokens, i + 1, json_chunk, out_diff_transmission->diffuse_transmission_color_factor, 3); | ||
} | ||
else if (cgltf_json_strcmp(tokens + i, json_chunk, "diffuseTransmissionColorTexture") == 0) | ||
{ | ||
i = cgltf_parse_json_texture_view(options, tokens, i + 1, json_chunk, &out_diff_transmission->diffuse_transmission_color_texture); | ||
} | ||
else | ||
{ | ||
i = cgltf_skip_json(tokens, i + 1); | ||
} | ||
|
||
if (i < 0) | ||
{ | ||
return i; | ||
} | ||
} | ||
|
||
return i; | ||
} | ||
|
||
static int cgltf_parse_json_image(cgltf_options* options, jsmntok_t const* tokens, int i, const uint8_t* json_chunk, cgltf_image* out_image) | ||
{ | ||
CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT); | ||
|
@@ -4415,6 +4476,11 @@ static int cgltf_parse_json_material(cgltf_options* options, jsmntok_t const* to | |
out_material->has_iridescence = 1; | ||
i = cgltf_parse_json_iridescence(options, tokens, i + 1, json_chunk, &out_material->iridescence); | ||
} | ||
else if (cgltf_json_strcmp(tokens + i, json_chunk, "KHR_materials_diffuse_transmission") == 0) | ||
{ | ||
out_material->has_diffuse_transmission = 1; | ||
i = cgltf_parse_json_diffuse_transmission(options, tokens, i + 1, json_chunk, &out_material->diffuse_transmission); | ||
} | ||
else | ||
{ | ||
i = cgltf_parse_json_unprocessed_extension(options, tokens, i, json_chunk, &(out_material->extensions[out_material->extensions_count++])); | ||
|
@@ -6269,6 +6335,9 @@ static int cgltf_fixup_pointers(cgltf_data* data) | |
|
||
CGLTF_PTRFIXUP(data->materials[i].iridescence.iridescence_texture.texture, data->textures, data->textures_count); | ||
CGLTF_PTRFIXUP(data->materials[i].iridescence.iridescence_thickness_texture.texture, data->textures, data->textures_count); | ||
|
||
CGLTF_PTRFIXUP(data->materials[i].diffuse_transmission.diffuse_transmission_texture.texture, data->textures, data->textures_count); | ||
CGLTF_PTRFIXUP(data->materials[i].diffuse_transmission.diffuse_transmission_color_texture.texture, data->textures, data->textures_count); | ||
} | ||
|
||
for (cgltf_size i = 0; i < data->buffer_views_count; ++i) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two calls should use cgltf_free_texture_view for now (and the PR needs to be rebased to latest master) to take care of extras. This will keep the code correct for now, although once I get to #118 this will become unnecessary as the code will just get deleted.