Skip to content

Commit

Permalink
Updates to align with proposed spec changes.
Browse files Browse the repository at this point in the history
anisotropyFactor -> anisotropyStrength
anisotropyDirection now expressed as a radian rotation from the tangent direction
  • Loading branch information
abwood committed Mar 10, 2023
1 parent ba0d506 commit 111178c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
16 changes: 9 additions & 7 deletions cgltf.h
Original file line number Diff line number Diff line change
Expand Up @@ -507,8 +507,8 @@ typedef struct cgltf_iridescence

typedef struct cgltf_anisotropy
{
cgltf_float anisotropy_factor;
cgltf_float anisotropy_direction[2];
cgltf_float anisotropy_strength;
cgltf_float anisotropy_direction;
cgltf_texture_view anisotropy_texture;
} cgltf_anisotropy;

Expand Down Expand Up @@ -4043,22 +4043,24 @@ static int cgltf_parse_json_anisotropy(cgltf_options* options, jsmntok_t const*
++i;

// Default
out_anisotropy->anisotropy_factor = 0.f;
cgltf_fill_float_array(out_anisotropy->anisotropy_direction, 2, 1.0f);
out_anisotropy->anisotropy_strength = 0.f;
out_anisotropy->anisotropy_direction = 0.f;

for (int j = 0; j < size; ++j)
{
CGLTF_CHECK_KEY(tokens[i]);

if (cgltf_json_strcmp(tokens + i, json_chunk, "anisotropyFactor") == 0)
if (cgltf_json_strcmp(tokens + i, json_chunk, "anisotropyStrength") == 0)
{
++i;
out_anisotropy->anisotropy_factor = cgltf_json_to_float(tokens + i, json_chunk);
out_anisotropy->anisotropy_strength = cgltf_json_to_float(tokens + i, json_chunk);
++i;
}
else if (cgltf_json_strcmp(tokens + i, json_chunk, "anisotropyDirection") == 0)
{
i = cgltf_parse_json_float_array(tokens, i + 1, json_chunk, out_anisotropy->anisotropy_direction, 2);
++i;
out_anisotropy->anisotropy_direction = cgltf_json_to_float(tokens + i, json_chunk);
++i;
}
else if (cgltf_json_strcmp(tokens + i, json_chunk, "anisotropyTexture") == 0)
{
Expand Down
7 changes: 2 additions & 5 deletions cgltf_write.h
Original file line number Diff line number Diff line change
Expand Up @@ -738,11 +738,8 @@ static void cgltf_write_material(cgltf_write_context* context, const cgltf_mater
{
cgltf_write_line(context, "\"KHR_materials_anisotropy\": {");
const cgltf_anisotropy* params = &material->anisotropy;
cgltf_write_floatprop(context, "anisotropyFactor", params->anisotropy_factor, 0.f);
if (!params->anisotropy_texture->texture)
{
cgltf_write_floatarrayprop(context, "anisotropyDirection", params->anisotropy_direction, 2);
}
cgltf_write_floatprop(context, "anisotropyFactor", params->anisotropy_strength, 0.f);
cgltf_write_floatprop(context, "anisotropyDirection", params->anisotropy_direction, 0.f);
CGLTF_WRITE_TEXTURE_INFO("anisotropyTexture", params->anisotropy_texture);
cgltf_write_line(context, "}");
}
Expand Down

0 comments on commit 111178c

Please sign in to comment.