Browse Source

Pack bitangent sign into painting system's tangent calculation

master
C. J. Howard 4 years ago
parent
commit
af364f598a
2 changed files with 7 additions and 18 deletions
  1. +7
    -9
      src/game/systems/painting-system.cpp
  2. +0
    -9
      src/resources/model-loader.cpp

+ 7
- 9
src/game/systems/painting-system.cpp View File

@ -180,8 +180,7 @@ void painting_system::update(double t, double dt)
/// @TODO: smooth normals in middle of segment /// @TODO: smooth normals in middle of segment
float3 tangents[12];
float3 bitangents[12];
float4 tangents[12];
for (int i = 0; i < 4; ++i) for (int i = 0; i < 4; ++i)
{ {
const float3& a = tangent_positions[i * 3]; const float3& a = tangent_positions[i * 3];
@ -204,13 +203,12 @@ void painting_system::update(double t, double dt)
tangent = math::normalize(tangent_rotation * tangent); tangent = math::normalize(tangent_rotation * tangent);
bitangent = math::normalize(tangent_rotation * bitangent); bitangent = math::normalize(tangent_rotation * bitangent);
tangents[i * 3] = tangent;
tangents[i * 3 + 1] = tangent;
tangents[i * 3 + 2] = tangent;
// Calculate sign of bitangent
float bitangent_sign = (math::dot(math::cross(surface_normal, tangent), bitangent) < 0.0f) ? -1.0f : 1.0f;
bitangents[i * 3] = bitangent;
bitangents[i * 3 + 1] = bitangent;
bitangents[i * 3 + 2] = bitangent;
tangents[i * 3] = {tangent.x, tangent.y, tangent.z, bitangent_sign};
tangents[i * 3 + 1] = {tangent.x, tangent.y, tangent.z, bitangent_sign};
tangents[i * 3 + 2] = {tangent.x, tangent.y, tangent.z, bitangent_sign};
} }
float vertex_data[13 * 12]; float vertex_data[13 * 12];
@ -232,7 +230,7 @@ void painting_system::update(double t, double dt)
*(v++) = tangents[i].x; *(v++) = tangents[i].x;
*(v++) = tangents[i].y; *(v++) = tangents[i].y;
*(v++) = tangents[i].z; *(v++) = tangents[i].z;
*(v++) = 0.0f;
*(v++) = tangents[i].w;
} }
std::size_t segment_size = sizeof(float) * vertex_size * 6; std::size_t segment_size = sizeof(float) * vertex_size * 6;

+ 0
- 9
src/resources/model-loader.cpp View File

@ -356,13 +356,6 @@ model* resource_loader::load(resource_manager* resource_manager, PHYSFS_F
} }
*/ */
static struct attribute_data
{
std::string type;
std::size_t size;
std::vector<float> data;
};
template <> template <>
model* resource_loader<model>::load(resource_manager* resource_manager, PHYSFS_File* file) model* resource_loader<model>::load(resource_manager* resource_manager, PHYSFS_File* file)
{ {
@ -519,8 +512,6 @@ model* resource_loader::load(resource_manager* resource_manager, PHYSFS_F
if (auto size_node = material_node.value().find("size"); size_node != material_node.value().end()) if (auto size_node = material_node.value().find("size"); size_node != material_node.value().end())
group_size = size_node.value().get<std::size_t>(); group_size = size_node.value().get<std::size_t>();
std::cout << "MATERIAL: " << group_name << std::endl;
group_material = resource_manager->load<material>(group_name + ".mtl"); group_material = resource_manager->load<material>(group_name + ".mtl");
model_group* model_group = model->add_group(group_name); model_group* model_group = model->add_group(group_name);

Loading…
Cancel
Save