Browse Source

Add painting system

master
C. J. Howard 4 years ago
parent
commit
6aa655f3f1
14 changed files with 459 additions and 31 deletions
  1. +1
    -1
      CMakeLists.txt
  2. +6
    -0
      src/game/bootloader.cpp
  3. +32
    -0
      src/game/components/brush-component.hpp
  4. +2
    -0
      src/game/game-context.hpp
  5. +2
    -2
      src/game/states/play-state.cpp
  6. +272
    -0
      src/game/systems/painting-system.cpp
  7. +84
    -0
      src/game/systems/painting-system.hpp
  8. +0
    -17
      src/game/systems/tracking-system.cpp
  9. +1
    -5
      src/game/systems/tracking-system.hpp
  10. +2
    -0
      src/renderer/material-flags.hpp
  11. +36
    -1
      src/renderer/passes/material-pass.cpp
  12. +3
    -4
      src/renderer/passes/outline-pass.cpp
  13. +16
    -0
      src/resources/entity-archetype-loader.cpp
  14. +2
    -1
      src/scene/model-instance.hpp

+ 1
- 1
CMakeLists.txt View File

@ -14,6 +14,7 @@ find_package(SDL2 REQUIRED COMPONENTS SDL2::SDL2-static SDL2::SDL2main CONFIG)
find_package(OpenAL REQUIRED CONFIG) find_package(OpenAL REQUIRED CONFIG)
find_library(physfs REQUIRED NAMES physfs-static PATHS "${CMAKE_PREFIX_PATH}/lib") find_library(physfs REQUIRED NAMES physfs-static PATHS "${CMAKE_PREFIX_PATH}/lib")
# Determine dependencies # Determine dependencies
set(STATIC_LIBS set(STATIC_LIBS
dr_wav dr_wav
@ -27,7 +28,6 @@ set(STATIC_LIBS
set(SHARED_LIBS set(SHARED_LIBS
${OPENGL_gl_LIBRARY}) ${OPENGL_gl_LIBRARY})
# Generate configuration header file # Generate configuration header file
configure_file(${PROJECT_SOURCE_DIR}/src/configuration.hpp.in configure_file(${PROJECT_SOURCE_DIR}/src/configuration.hpp.in
${PROJECT_BINARY_DIR}/src/configuration.hpp) ${PROJECT_BINARY_DIR}/src/configuration.hpp)

+ 6
- 0
src/game/bootloader.cpp View File

@ -77,6 +77,7 @@
#include "game/systems/vegetation-system.hpp" #include "game/systems/vegetation-system.hpp"
#include "game/systems/spatial-system.hpp" #include "game/systems/spatial-system.hpp"
#include "game/systems/tracking-system.hpp" #include "game/systems/tracking-system.hpp"
#include "game/systems/painting-system.hpp"
#include "game/components/marker-component.hpp" #include "game/components/marker-component.hpp"
#include "game/entity-commands.hpp" #include "game/entity-commands.hpp"
#include "utility/paths.hpp" #include "utility/paths.hpp"
@ -841,6 +842,10 @@ void setup_systems(game_context* ctx)
ctx->tracking_system = new tracking_system(*ctx->ecs_registry, event_dispatcher, ctx->resource_manager); ctx->tracking_system = new tracking_system(*ctx->ecs_registry, event_dispatcher, ctx->resource_manager);
ctx->tracking_system->set_scene(ctx->overworld_scene); ctx->tracking_system->set_scene(ctx->overworld_scene);
// Setup painting system
ctx->painting_system = new painting_system(*ctx->ecs_registry, event_dispatcher, ctx->resource_manager);
ctx->painting_system->set_scene(ctx->overworld_scene);
// Setup render system // Setup render system
ctx->render_system = new ::render_system(*ctx->ecs_registry); ctx->render_system = new ::render_system(*ctx->ecs_registry);
ctx->render_system->add_layer(ctx->overworld_scene); ctx->render_system->add_layer(ctx->overworld_scene);
@ -1189,6 +1194,7 @@ void setup_callbacks(game_context* ctx)
ctx->spatial_system->update(t, dt); ctx->spatial_system->update(t, dt);
ctx->constraint_system->update(t, dt); ctx->constraint_system->update(t, dt);
ctx->tracking_system->update(t, dt); ctx->tracking_system->update(t, dt);
ctx->painting_system->update(t, dt);
//(*ctx->focal_point_tween)[1] = ctx->orbit_cam->get_focal_point(); //(*ctx->focal_point_tween)[1] = ctx->orbit_cam->get_focal_point();

+ 32
- 0
src/game/components/brush-component.hpp View File

@ -0,0 +1,32 @@
/*
* Copyright (C) 2020 Christopher J. Howard
*
* This file is part of Antkeeper source code.
*
* Antkeeper source code is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Antkeeper source code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_BRUSH_COMPONENT_HPP
#define ANTKEEPER_ECS_BRUSH_COMPONENT_HPP
namespace ecs {
struct brush_component
{
float radius;
};
} // namespace ecs
#endif // ANTKEEPER_ECS_BRUSH_COMPONENT_HPP

+ 2
- 0
src/game/game-context.hpp View File

@ -85,6 +85,7 @@ class input_mapper;
class cli; class cli;
class outline_pass; class outline_pass;
class tracking_system; class tracking_system;
class painting_system;
template <typename T> class animation; template <typename T> class animation;
template <typename T> class material_property; template <typename T> class material_property;
template <typename T> class tween; template <typename T> class tween;
@ -237,6 +238,7 @@ struct game_context
vegetation_system* vegetation_system; vegetation_system* vegetation_system;
spatial_system* spatial_system; spatial_system* spatial_system;
tracking_system* tracking_system; tracking_system* tracking_system;
painting_system* painting_system;
// Debug // Debug
cli* cli; cli* cli;

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

@ -125,8 +125,8 @@ void play_state_enter(game_context* ctx)
ec::assign_render_layers(ecs_registry, ctx->container_entity, 0); ec::assign_render_layers(ecs_registry, ctx->container_entity, 0);
ec::assign_render_layers(ecs_registry, ctx->twig_entity, 0); ec::assign_render_layers(ecs_registry, ctx->twig_entity, 0);
// Activate lens tool
ctx->tool_system->set_active_tool(ctx->lens_entity);
// Activate brush tool
ctx->tool_system->set_active_tool(ctx->brush_entity);
// Create ant-hill // Create ant-hill
auto ant_hill_entity = ant_hill_archetype->create(ecs_registry); auto ant_hill_entity = ant_hill_archetype->create(ecs_registry);

+ 272
- 0
src/game/systems/painting-system.cpp View File

@ -0,0 +1,272 @@
/*
* Copyright (C) 2020 Christopher J. Howard
*
* This file is part of Antkeeper source code.
*
* Antkeeper source code is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Antkeeper source code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "painting-system.hpp"
#include "game/components/transform-component.hpp"
#include "game/components/brush-component.hpp"
#include "event/event-dispatcher.hpp"
#include "resources/resource-manager.hpp"
#include "scene/scene.hpp"
#include "scene/model-instance.hpp"
#include "math/math.hpp"
#include "renderer/material.hpp"
#include "renderer/model.hpp"
#include "utility/fundamental-types.hpp"
#include "game/entity-commands.hpp"
#include "game/components/collision-component.hpp"
#include "game/components/transform-component.hpp"
#include "rasterizer/vertex-buffer.hpp"
#include "rasterizer/vertex-attribute-type.hpp"
#include "renderer/vertex-attributes.hpp"
#include <limits>
using namespace ecs;
painting_system::painting_system(entt::registry& registry, ::event_dispatcher* event_dispatcher, ::resource_manager* resource_manager):
entity_system(registry),
event_dispatcher(event_dispatcher),
resource_manager(resource_manager),
scene(nullptr),
painting(false)
{
event_dispatcher->subscribe<tool_pressed_event>(this);
event_dispatcher->subscribe<tool_released_event>(this);
max_miter_angle = math::radians(135.0f);
stroke_width = 1.0f;
min_stroke_length = 1.0f;
min_stroke_length_squared = min_stroke_length * min_stroke_length;
max_stroke_segments = 4096;
current_stroke_segment = 0;
std::size_t vertex_size = 4;
std::size_t vertex_stride = sizeof(float) * vertex_size;
std::size_t vertex_count = max_stroke_segments * 6;
// Create stroke model
stroke_model = new model();
stroke_model_group = stroke_model->add_group();
stroke_model_group->set_material(resource_manager->load<material>("brushstroke.mtl"));
// Setup stroke vbo and vao
stroke_vbo = stroke_model->get_vertex_buffer();
stroke_vbo->repurpose(sizeof(float) * vertex_size * vertex_count, nullptr, buffer_usage::dynamic_draw);
stroke_model->get_vertex_array()->bind_attribute(VERTEX_POSITION_LOCATION, *stroke_vbo, 4, vertex_attribute_type::float_32, vertex_stride, 0);
// Create stroke model instance
stroke_model_instance = new model_instance();
stroke_model_instance->set_model(stroke_model);
stroke_model_instance->update_tweens();
stroke_bounds_min.x = std::numeric_limits<float>::infinity();
stroke_bounds_min.y = std::numeric_limits<float>::infinity();
stroke_bounds_min.z = std::numeric_limits<float>::infinity();
stroke_bounds_max.x = -std::numeric_limits<float>::infinity();
stroke_bounds_max.y = -std::numeric_limits<float>::infinity();
stroke_bounds_max.z = -std::numeric_limits<float>::infinity();
midstroke = false;
}
painting_system::~painting_system()
{
event_dispatcher->unsubscribe<tool_pressed_event>(this);
event_dispatcher->unsubscribe<tool_released_event>(this);
}
void painting_system::update(double t, double dt)
{
if (painting)
{
auto cast_result = cast_ray(ec::get_world_transform(registry, brush_entity).translation);
if (cast_result.has_value())
{
float3 p2 =
stroke_end = cast_result.value();
float3 segment_difference = stroke_end - stroke_start;
float segment_length_squared = math::dot(segment_difference, segment_difference);
if (segment_length_squared >= min_stroke_length_squared)
{
float segment_length = std::sqrt(segment_length_squared);
float3 segment_forward = segment_difference / segment_length;
float3 segment_right = math::normalize(math::cross(segment_forward, float3{0, 1, 0}));
float3 segment_up = math::cross(segment_right, segment_forward);
float3 segment_center = (stroke_start + stroke_end) * 0.5f;
float3 p1 = stroke_start;
float3 p2 = stroke_end;
// Find miter
float3 tangent = math::normalize(math::normalize(p2 - p1) + math::normalize(p1 - p0));
float2 miter = float2{-tangent.z, tangent.x};
float2 normal = float2{segment_right.x, segment_right.z};
float miter_length = stroke_width / math::dot(miter, normal);
float3 a = p0a;
float3 b = p0b;
float3 c = p1 - segment_right * stroke_width * 0.5f;
float3 d = p1 + segment_right * stroke_width * 0.5f;
float3 e = p2 - segment_right * stroke_width * 0.5f;
float3 f = p2 + segment_right * stroke_width * 0.5f;
// Adjust c and d
bool mitered = false;
if (midstroke)
{
float angle = std::acos(math::dot(math::normalize(p2 - p1), math::normalize(p1 - p0)));
if (angle < max_miter_angle)
{
mitered = true;
c = p1 - float3{miter.x, 0.0f, miter.y} * miter_length * 0.5f;
d = p1 + float3{miter.x, 0.0f, miter.y} * miter_length * 0.5f;
}
}
float4 segment_vertices[12];
float w = static_cast<float>(t);
segment_vertices[0] = {a.x, a.y, a.z, w};
segment_vertices[1] = {b.x, b.y, b.z, w};
segment_vertices[2] = {c.x, c.y, c.z, w};
segment_vertices[3] = {c.x, c.y, c.z, w};
segment_vertices[4] = {b.x, b.y, b.z, w};
segment_vertices[5] = {d.x, d.y, d.z, w};
segment_vertices[6] = {c.x, c.y, c.z, w};
segment_vertices[7] = {d.x, d.y, d.z, w};
segment_vertices[8] = {e.x, e.y, e.z, w};
segment_vertices[9] = {e.x, e.y, e.z, w};
segment_vertices[10] = {d.x, d.y, d.z, w};
segment_vertices[11] = {f.x, f.y, f.z, w};
std::size_t segment_size = sizeof(float) * 4 * 6;
if (mitered)
{
stroke_vbo->update((current_stroke_segment - 1) * segment_size, segment_size * 2, &segment_vertices[0][0]);
}
else
{
stroke_vbo->update(current_stroke_segment * segment_size, segment_size, &segment_vertices[6][0]);
}
++current_stroke_segment;
stroke_model_group->set_index_count(current_stroke_segment * 6);
// Update stroke bounds
stroke_bounds_min.x = std::min<float>(stroke_bounds_min.x, std::min<float>(c.x, std::min<float>(d.x, std::min<float>(e.x, f.x))));
stroke_bounds_min.y = std::min<float>(stroke_bounds_min.y, std::min<float>(c.y, std::min<float>(d.y, std::min<float>(e.y, f.y))));
stroke_bounds_min.z = std::min<float>(stroke_bounds_min.z, std::min<float>(c.z, std::min<float>(d.z, std::min<float>(e.z, f.z))));
stroke_bounds_max.x = std::max<float>(stroke_bounds_max.x, std::max<float>(c.x, std::max<float>(d.x, std::max<float>(e.x, f.x))));
stroke_bounds_max.y = std::max<float>(stroke_bounds_max.y, std::max<float>(c.y, std::max<float>(d.y, std::max<float>(e.y, f.y))));
stroke_bounds_max.z = std::max<float>(stroke_bounds_max.z, std::max<float>(c.z, std::max<float>(d.z, std::max<float>(e.z, f.z))));
stroke_model->set_bounds(aabb<float>{stroke_bounds_min, stroke_bounds_max});
stroke_model_instance->update_bounds();
p0 = stroke_start;
p0a = c;
p0b = d;
stroke_start = stroke_end;
midstroke = true;
}
}
}
}
void painting_system::set_scene(::scene* scene)
{
this->scene = scene;
scene->add_object(stroke_model_instance);
}
void painting_system::handle_event(const tool_pressed_event& event)
{
if (registry.has<brush_component>(event.entity))
{
auto cast_result = cast_ray(ec::get_world_transform(registry, event.entity).translation);
if (cast_result.has_value())
{
brush_entity = event.entity;
painting = true;
stroke_start = cast_result.value();
stroke_end = stroke_start;
p0 = stroke_start;
p0a = p0;
p0b = p0;
midstroke = false;
}
}
}
void painting_system::handle_event(const tool_released_event& event)
{
if (registry.has<brush_component>(event.entity))
{
auto cast_result = cast_ray(ec::get_world_transform(registry, event.entity).translation);
if (cast_result.has_value())
{
stroke_end = cast_result.value();
}
brush_entity = entt::null;
painting = false;
}
}
std::optional<float3> painting_system::cast_ray(const float3& position) const
{
std::optional<float3> result;
ray<float> untransformed_ray = {position + float3{0.0f, 10000.0f, 0.0f}, {0, -1, 0}};
float min_distance = std::numeric_limits<float>::infinity();
registry.view<transform_component, collision_component>().each(
[&](auto entity, auto& collision_transform, auto& collision)
{
// Transform ray into local space of collision component
math::transform<float> inverse_transform = math::inverse(collision_transform.local);
float3 origin = inverse_transform * untransformed_ray.origin;
float3 direction = math::normalize(math::conjugate(collision_transform.local.rotation) * untransformed_ray.direction);
ray<float> transformed_ray = {origin, direction};
// Broad phase AABB test
auto aabb_result = ray_aabb_intersection(transformed_ray, collision.bounds);
if (!std::get<0>(aabb_result))
{
return;
}
// Narrow phase mesh test
auto mesh_result = collision.mesh_accelerator.query_nearest(transformed_ray);
if (mesh_result)
{
if (mesh_result->t < min_distance)
{
min_distance = mesh_result->t;
result = untransformed_ray.extrapolate(min_distance);
}
}
});
return result;
}

+ 84
- 0
src/game/systems/painting-system.hpp View File

@ -0,0 +1,84 @@
/*
* Copyright (C) 2020 Christopher J. Howard
*
* This file is part of Antkeeper source code.
*
* Antkeeper source code is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Antkeeper source code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_PAINTING_SYSTEM_HPP
#define ANTKEEPER_PAINTING_SYSTEM_HPP
#include "entity-system.hpp"
#include "event/event-handler.hpp"
#include "game/events/tool-events.hpp"
#include "utility/fundamental-types.hpp"
#include <vector>
#include <optional>
class material;
class event_dispatcher;
class resource_manager;
class scene;
class model;
class model_instance;
class model_group;
class vertex_buffer;
class painting_system: public entity_system,
public event_handler<tool_pressed_event>,
public event_handler<tool_released_event>
{
public:
painting_system(entt::registry& registry, event_dispatcher* event_dispatcher, resource_manager* resource_manager);
virtual ~painting_system();
virtual void update(double t, double dt);
void set_scene(scene* scene);
private:
virtual void handle_event(const tool_pressed_event& event);
virtual void handle_event(const tool_released_event& event);
std::optional<float3> cast_ray(const float3& position) const;
event_dispatcher* event_dispatcher;
resource_manager* resource_manager;
scene* scene;
bool painting;
entt::entity brush_entity;
float3 stroke_start;
float3 stroke_end;
float min_stroke_length;
float min_stroke_length_squared;
float stroke_width;
int max_stroke_segments;
int current_stroke_segment;
float max_miter_angle;
float3 stroke_bounds_min;
float3 stroke_bounds_max;
float3 p0;
float3 p0a;
float3 p0b;
model* stroke_model;
model_group* stroke_model_group;
vertex_buffer* stroke_vbo;
bool midstroke;
model_instance* stroke_model_instance;
};
#endif // ANTKEEPER_PAINTING_SYSTEM_HPP

+ 0
- 17
src/game/systems/tracking-system.cpp View File

@ -22,18 +22,13 @@
#include "game/components/marker-component.hpp" #include "game/components/marker-component.hpp"
#include "event/event-dispatcher.hpp" #include "event/event-dispatcher.hpp"
#include "resources/resource-manager.hpp" #include "resources/resource-manager.hpp"
#include "scene/billboard.hpp"
#include "scene/scene.hpp" #include "scene/scene.hpp"
#include "scene/model-instance.hpp" #include "scene/model-instance.hpp"
#include "math/math.hpp" #include "math/math.hpp"
#include "renderer/material.hpp" #include "renderer/material.hpp"
#include "renderer/material-flags.hpp"
#include "renderer/model.hpp" #include "renderer/model.hpp"
#include "rasterizer/texture-2d.hpp"
#include "rasterizer/shader-program.hpp"
#include "utility/fundamental-types.hpp" #include "utility/fundamental-types.hpp"
#include "game/entity-commands.hpp" #include "game/entity-commands.hpp"
#include <iostream>
using namespace ecs; using namespace ecs;
@ -64,14 +59,12 @@ tracking_system::tracking_system(entt::registry& registry, ::event_dispatcher* e
event_dispatcher->subscribe<tool_pressed_event>(this); event_dispatcher->subscribe<tool_pressed_event>(this);
event_dispatcher->subscribe<tool_released_event>(this); event_dispatcher->subscribe<tool_released_event>(this);
event_dispatcher->subscribe<window_resized_event>(this);
} }
tracking_system::~tracking_system() tracking_system::~tracking_system()
{ {
event_dispatcher->unsubscribe<tool_pressed_event>(this); event_dispatcher->unsubscribe<tool_pressed_event>(this);
event_dispatcher->unsubscribe<tool_released_event>(this); event_dispatcher->unsubscribe<tool_released_event>(this);
event_dispatcher->unsubscribe<window_resized_event>(this);
for (auto it = trackers.begin(); it != trackers.end(); ++it) for (auto it = trackers.begin(); it != trackers.end(); ++it)
{ {
@ -104,11 +97,6 @@ void tracking_system::set_scene(::scene* scene)
this->scene = scene; this->scene = scene;
} }
void tracking_system::set_viewport(const float4& viewport)
{
this->viewport = viewport;
}
void tracking_system::on_component_construct(entt::registry& registry, entt::entity entity, trackable_component& component) void tracking_system::on_component_construct(entt::registry& registry, entt::entity entity, trackable_component& component)
{ {
@ -167,8 +155,3 @@ void tracking_system::handle_event(const tool_released_event& event)
{ {
} }
void tracking_system::handle_event(const window_resized_event& event)
{
set_viewport({0.0f, 0.0f, static_cast<float>(event.w), static_cast<float>(event.h)});
}

+ 1
- 5
src/game/systems/tracking-system.hpp View File

@ -23,7 +23,6 @@
#include "entity-system.hpp" #include "entity-system.hpp"
#include "game/components/trackable-component.hpp" #include "game/components/trackable-component.hpp"
#include "event/event-handler.hpp" #include "event/event-handler.hpp"
#include "event/window-events.hpp"
#include "game/events/tool-events.hpp" #include "game/events/tool-events.hpp"
#include <unordered_map> #include <unordered_map>
@ -36,8 +35,7 @@ class model_instance;
class tracking_system: public entity_system, class tracking_system: public entity_system,
public event_handler<tool_pressed_event>, public event_handler<tool_pressed_event>,
public event_handler<tool_released_event>,
public event_handler<window_resized_event>
public event_handler<tool_released_event>
{ {
public: public:
tracking_system(entt::registry& registry, event_dispatcher* event_dispatcher, resource_manager* resource_manager); tracking_system(entt::registry& registry, event_dispatcher* event_dispatcher, resource_manager* resource_manager);
@ -52,12 +50,10 @@ private:
void on_component_destroy(entt::registry& registry, entt::entity entity); void on_component_destroy(entt::registry& registry, entt::entity entity);
virtual void handle_event(const tool_pressed_event& event); virtual void handle_event(const tool_pressed_event& event);
virtual void handle_event(const tool_released_event& event); virtual void handle_event(const tool_released_event& event);
virtual void handle_event(const window_resized_event& event);
event_dispatcher* event_dispatcher; event_dispatcher* event_dispatcher;
resource_manager* resource_manager; resource_manager* resource_manager;
scene* scene; scene* scene;
float4 viewport;
model* tracker_model; model* tracker_model;
model* paint_ball_model; model* paint_ball_model;
material** paint_ball_materials; material** paint_ball_materials;

+ 2
- 0
src/renderer/material-flags.hpp View File

@ -31,6 +31,8 @@
#define MATERIAL_FLAG_OUTLINE 0x20 #define MATERIAL_FLAG_OUTLINE 0x20
#define MATERIAL_FLAG_VEGETATION 0x40 #define MATERIAL_FLAG_VEGETATION 0x40
#define MATERIAL_FLAG_REFRACTIVE 0x80 #define MATERIAL_FLAG_REFRACTIVE 0x80
#define MATERIAL_FLAG_DECAL 0x100
#define MATERIAL_FLAG_DECAL_SURFACE 0x200
#define MATERIAL_FLAG_WIREFRAME 0x80000000 #define MATERIAL_FLAG_WIREFRAME 0x80000000
#endif // ANTKEEPER_MATERIAL_FLAGS_HPP #endif // ANTKEEPER_MATERIAL_FLAGS_HPP

+ 36
- 1
src/renderer/passes/material-pass.cpp View File

@ -327,6 +327,39 @@ void material_pass::render(render_context* context) const
} }
} }
if ((material_flags & MATERIAL_FLAG_DECAL_SURFACE) != (active_material_flags & MATERIAL_FLAG_DECAL_SURFACE))
{
if (material_flags & MATERIAL_FLAG_DECAL_SURFACE)
{
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_ALWAYS, 1, ~0);
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
glStencilMask(~0);
}
else
{
glDisable(GL_STENCIL_TEST);
glStencilMask(0);
}
}
if ((material_flags & MATERIAL_FLAG_DECAL) != (active_material_flags & MATERIAL_FLAG_DECAL))
{
if (material_flags & MATERIAL_FLAG_DECAL)
{
glDisable(GL_DEPTH_TEST);
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_EQUAL, 1, ~0);
glStencilMask(0);
}
else
{
glEnable(GL_DEPTH_TEST);
glDisable(GL_STENCIL_TEST);
glStencilMask(0);
}
}
/* /*
if ((material_flags & MATERIAL_FLAG_OUTLINE) != (active_material_flags & MATERIAL_FLAG_OUTLINE)) if ((material_flags & MATERIAL_FLAG_OUTLINE) != (active_material_flags & MATERIAL_FLAG_OUTLINE))
{ {
@ -334,7 +367,7 @@ void material_pass::render(render_context* context) const
{ {
glEnable(GL_STENCIL_TEST); glEnable(GL_STENCIL_TEST);
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
glStencilFunc(GL_ALWAYS, 1, 0xFF);
glStencilFunc(GL_ALWAYS, 2, 0xFF);
glStencilMask(0xFF); glStencilMask(0xFF);
} }
else else
@ -514,6 +547,8 @@ bool operation_compare(const render_operation& a, const render_operation& b)
else if (!b.material) else if (!b.material)
return true; return true;
bool xray_a = a.material->get_flags() & MATERIAL_FLAG_X_RAY; bool xray_a = a.material->get_flags() & MATERIAL_FLAG_X_RAY;
bool xray_b = b.material->get_flags() & MATERIAL_FLAG_X_RAY; bool xray_b = b.material->get_flags() & MATERIAL_FLAG_X_RAY;

+ 3
- 4
src/renderer/passes/outline-pass.cpp View File

@ -72,13 +72,13 @@ void outline_pass::render(render_context* context) const
glEnable(GL_CULL_FACE); glEnable(GL_CULL_FACE);
glCullFace(GL_BACK); glCullFace(GL_BACK);
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
glEnable(GL_STENCIL_TEST);
// Render fill // Render fill
{ {
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
glEnable(GL_STENCIL_TEST);
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
glStencilFunc(GL_ALWAYS, 1, 0xFF);
glStencilFunc(GL_ALWAYS, 2, 0xFF);
glStencilMask(0xFF); glStencilMask(0xFF);
glDisable(GL_BLEND); glDisable(GL_BLEND);
@ -113,8 +113,7 @@ void outline_pass::render(render_context* context) const
glDisable(GL_BLEND); glDisable(GL_BLEND);
} }
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_NOTEQUAL, 1, 0xFF);
glStencilFunc(GL_NOTEQUAL, 2, 0xFF);
glStencilMask(0x00); glStencilMask(0x00);
// Setup stroke shader // Setup stroke shader

+ 16
- 0
src/resources/entity-archetype-loader.cpp View File

@ -29,6 +29,7 @@
#include "game/components/nest-component.hpp" #include "game/components/nest-component.hpp"
#include "game/components/tool-component.hpp" #include "game/components/tool-component.hpp"
#include "game/components/marker-component.hpp" #include "game/components/marker-component.hpp"
#include "game/components/brush-component.hpp"
#include "entity/archetype.hpp" #include "entity/archetype.hpp"
#include "game/behavior/ebt.hpp" #include "game/behavior/ebt.hpp"
#include <sstream> #include <sstream>
@ -123,6 +124,20 @@ static bool load_marker_component(archetype& archetype, const std::vector
return true; return true;
} }
static bool load_brush_component(archetype& archetype, const std::vector<std::string>& parameters)
{
if (parameters.size() != 2)
{
throw std::runtime_error("load_brush_component(): Invalid parameter count.");
}
brush_component component;
component.radius = std::stof(parameters[1]);
archetype.set<brush_component>(component);
return true;
}
static bool load_terrain_component(archetype& archetype, const std::vector<std::string>& parameters) static bool load_terrain_component(archetype& archetype, const std::vector<std::string>& parameters)
{ {
if (parameters.size() != 4) if (parameters.size() != 4)
@ -199,6 +214,7 @@ static bool load_component(archetype& archetype, resource_manager& resource_mana
if (parameters[0] == "tool") return load_tool_component(archetype, parameters); if (parameters[0] == "tool") return load_tool_component(archetype, parameters);
if (parameters[0] == "transform") return load_transform_component(archetype, parameters); if (parameters[0] == "transform") return load_transform_component(archetype, parameters);
if (parameters[0] == "marker") return load_marker_component(archetype, parameters); if (parameters[0] == "marker") return load_marker_component(archetype, parameters);
if (parameters[0] == "brush") return load_brush_component(archetype, parameters);
std::string message = std::string("load_component(): Unknown component type \"") + parameters[0] + std::string("\""); std::string message = std::string("load_component(): Unknown component type \"") + parameters[0] + std::string("\"");
throw std::runtime_error(message); throw std::runtime_error(message);

+ 2
- 1
src/scene/model-instance.hpp View File

@ -76,8 +76,9 @@ public:
virtual void update_tweens(); virtual void update_tweens();
private:
void update_bounds(); void update_bounds();
private:
virtual void transformed(); virtual void transformed();
model* model; model* model;

Loading…
Cancel
Save