Compare commits
2 commits
ff7eb827fe
...
7e9596d77f
| Author | SHA1 | Date | |
|---|---|---|---|
| 7e9596d77f | |||
| 156a58a59a |
2 changed files with 42 additions and 25 deletions
|
|
@ -228,39 +228,43 @@ namespace psemek::gfx
|
|||
|
||||
target.name = material["name"].GetString();
|
||||
|
||||
target.two_sided = false;
|
||||
if (material.HasMember("doubleSided"))
|
||||
target.two_sided = material["doubleSided"].GetBool();
|
||||
else
|
||||
target.two_sided = false;
|
||||
|
||||
auto const & pbr = material["pbrMetallicRoughness"];
|
||||
|
||||
if (pbr.HasMember("baseColorFactor"))
|
||||
// Material can omit pbrMetallicRoughness entry if
|
||||
// all the values are defaulted
|
||||
if (material.HasMember("pbrMetallicRoughness"))
|
||||
{
|
||||
auto const & color = pbr["baseColorFactor"].GetArray();
|
||||
gfx::color_4f & target_color = target.albedo.emplace();
|
||||
for (std::size_t i = 0; i < 4; ++i)
|
||||
target_color[i] = color[i].GetFloat();
|
||||
}
|
||||
auto const & pbr = material["pbrMetallicRoughness"];
|
||||
|
||||
if (pbr.HasMember("baseColorTexture"))
|
||||
{
|
||||
target.texture = document["textures"].GetArray()[pbr["baseColorTexture"]["index"].GetUint64()]["source"].GetInt64();
|
||||
}
|
||||
if (pbr.HasMember("baseColorFactor"))
|
||||
{
|
||||
auto const & color = pbr["baseColorFactor"].GetArray();
|
||||
gfx::color_4f & target_color = target.albedo.emplace();
|
||||
for (std::size_t i = 0; i < 4; ++i)
|
||||
target_color[i] = color[i].GetFloat();
|
||||
}
|
||||
|
||||
if (pbr.HasMember("metallicFactor"))
|
||||
{
|
||||
target.metallic = pbr["metallicFactor"].GetFloat();
|
||||
}
|
||||
if (pbr.HasMember("baseColorTexture"))
|
||||
{
|
||||
target.texture = document["textures"].GetArray()[pbr["baseColorTexture"]["index"].GetUint64()]["source"].GetInt64();
|
||||
}
|
||||
|
||||
if (pbr.HasMember("roughnessFactor"))
|
||||
{
|
||||
target.roughness = pbr["roughnessFactor"].GetFloat();
|
||||
}
|
||||
if (pbr.HasMember("metallicFactor"))
|
||||
{
|
||||
target.metallic = pbr["metallicFactor"].GetFloat();
|
||||
}
|
||||
|
||||
if (pbr.HasMember("metallicRoughnessTexture"))
|
||||
{
|
||||
target.material_texture = document["textures"].GetArray()[pbr["metallicRoughnessTexture"]["index"].GetUint64()]["source"].GetInt64();
|
||||
if (pbr.HasMember("roughnessFactor"))
|
||||
{
|
||||
target.roughness = pbr["roughnessFactor"].GetFloat();
|
||||
}
|
||||
|
||||
if (pbr.HasMember("metallicRoughnessTexture"))
|
||||
{
|
||||
target.material_texture = document["textures"].GetArray()[pbr["metallicRoughnessTexture"]["index"].GetUint64()]["source"].GetInt64();
|
||||
}
|
||||
}
|
||||
|
||||
if (material.HasMember("emissiveFactor"))
|
||||
|
|
|
|||
|
|
@ -235,4 +235,17 @@ namespace psemek::math
|
|||
return T{1} / T{2} - std::sin(std::asin(T{1} - T{2} * x) / T{3});
|
||||
}
|
||||
|
||||
// Stateless piecewise-quadratic spline acceleration
|
||||
// based on current velocity, current distance to target,
|
||||
// and max acceleration
|
||||
template <typename T>
|
||||
T quadratic_spline_acceleration(T velocity, T distance, T max_acceleration)
|
||||
{
|
||||
T max_velocity = std::sqrt(2.f * std::abs(distance) * max_acceleration);
|
||||
return max_acceleration
|
||||
* (distance < 0.f ? -1.f : 1.f)
|
||||
* ((std::abs(velocity) < max_velocity || (distance > 0.f) != (velocity > 0.f))? 1.f : -1.f)
|
||||
;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue