Browse Source

Pack bitangent sign into tangent attribute

master
C. J. Howard 3 years ago
parent
commit
4b6ed04a74
2 changed files with 11 additions and 17 deletions
  1. +6
    -7
      src/game/states/play-state.cpp
  2. +5
    -10
      src/resources/model-loader.cpp

+ 6
- 7
src/game/states/play-state.cpp View File

@ -88,7 +88,7 @@ void play_state_enter(game_context* ctx)
ecs::archetype* flashlight_archetype = resource_manager->load<ecs::archetype>("flashlight.ent");
ecs::archetype* flashlight_light_cone_archetype = resource_manager->load<ecs::archetype>("flashlight-light-cone.ent");
ecs::archetype* lens_light_cone_archetype = resource_manager->load<ecs::archetype>("lens-light-cone.ent");
ecs::archetype* round_eye_archetype = resource_manager->load<ecs::archetype>("round-eye.ent");
ecs::archetype* ant_head_archetype = resource_manager->load<ecs::archetype>("ant-head.ent");
// Create tools
forceps_archetype->assign(ecs_registry, ctx->forceps_entity);
@ -211,12 +211,11 @@ void play_state_enter(game_context* ctx)
ctx->overworld_camera->look_at({0, 0, 1}, {0, 0, 0}, {0, 1, 0});
ctx->camera_system->set_camera(ctx->overworld_camera);
auto round_eye = round_eye_archetype->create(ecs_registry);
math::transform<float> eye_xf;
eye_xf.translation = {50, 0, 0};
eye_xf.rotation = math::angle_axis(-math::half_pi<float>, {1, 0, 0});
eye_xf.scale = float3{1, 1, 1} * 50.0f;
ec::set_transform(ecs_registry, round_eye, eye_xf, true);
auto ant_head = ant_head_archetype->create(ecs_registry);
math::transform<float> head_xf = math::identity_transform<float>;
head_xf.translation = {50, 0, 0};
head_xf.scale = float3{1, 1, 1} * 1.0f;
ec::set_transform(ecs_registry, ant_head, head_xf, true);
ctx->overworld_scene->update_tweens();

+ 5
- 10
src/resources/model-loader.cpp View File

@ -253,7 +253,7 @@ model* resource_loader::load(resource_manager* resource_manager, PHYSFS_F
if (has_normals)
vertex_size += 3;
if (has_tangents)
vertex_size += 6;
vertex_size += 4;
if (has_barycentric)
vertex_size += 3;
@ -297,15 +297,12 @@ model* resource_loader::load(resource_manager* resource_manager, PHYSFS_F
// Gram-Schmidt orthogonalize tangent and bitangent
float3 tangent = math::normalize(t - n * dot(n, t));
tangent = (math::dot(math::cross(n, t), b) < 0.0f) ? -tangent : tangent;
float3 bitangent = math::cross(n, tangent);
float bitangent_sign = (math::dot(math::cross(n, t), b) < 0.0f) ? -1.0f : 1.0f;
*(v++) = tangent.x;
*(v++) = tangent.y;
*(v++) = tangent.z;
*(v++) = bitangent.x;
*(v++) = bitangent.y;
*(v++) = bitangent.z;
*(v++) = bitangent_sign;
}
if (has_barycentric)
@ -338,10 +335,8 @@ model* resource_loader::load(resource_manager* resource_manager, PHYSFS_F
}
if (has_tangents)
{
vao->bind_attribute(VERTEX_TANGENT_LOCATION, *vbo, 3, vertex_attribute_type::float_32, vertex_stride, sizeof(float) * offset);
offset += 3;
vao->bind_attribute(VERTEX_BITANGENT_LOCATION, *vbo, 3, vertex_attribute_type::float_32, vertex_stride, sizeof(float) * offset);
offset += 3;
vao->bind_attribute(VERTEX_TANGENT_LOCATION, *vbo, 4, vertex_attribute_type::float_32, vertex_stride, sizeof(float) * offset);
offset += 4;
}
if (has_barycentric)
{

Loading…
Cancel
Save