Skip to content

Commit

Permalink
Merge branch '2021_updates_part1'
Browse files Browse the repository at this point in the history
  • Loading branch information
pierremoreau committed Sep 1, 2021
2 parents 8a3f4cb + f3e1c99 commit 8cdadaf
Show file tree
Hide file tree
Showing 62 changed files with 15,905 additions and 5,449 deletions.
43 changes: 28 additions & 15 deletions CMake/InstallSTB.cmake
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
FetchContent_Declare (
stb
GIT_REPOSITORY [[https://github.com/nothings/stb]]
GIT_TAG [[b42009b3b9d4ca35bc703f5310eedc74f584be58]]
)
find_package (Stb QUIET)
if (NOT Stb_FOUND)
FetchContent_Declare (
stb
GIT_REPOSITORY [[https://github.com/nothings/stb]]
GIT_TAG [[c0c982601f40183e74d84a61237e968dca08380e]]
)

FetchContent_GetProperties (stb)
if (NOT stb_POPULATED)
message (STATUS "Cloning stb…")
FetchContent_Populate (stb)
endif ()
FetchContent_GetProperties (stb)
if (NOT stb_POPULATED)
message (STATUS "Cloning stb…")
FetchContent_Populate (stb)
endif ()

add_library( stb::stb INTERFACE IMPORTED)
set_target_properties(stb::stb PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${stb_SOURCE_DIR}"
INTERFACE_SOURCES "${CMAKE_SOURCE_DIR}/src/core/stb_impl.c"
)
add_library (stb::stb INTERFACE IMPORTED)
set_target_properties (stb::stb PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${stb_SOURCE_DIR}"
INTERFACE_SOURCES "${CMAKE_SOURCE_DIR}/src/core/stb_impl.c"
)
else ()
# vcpkg has its own FindStb.cmake which defines `Stb_FOUND` and
# `Stb_INCLUDE_DIR`, but not library which can be readily linked
# against. So wrap an interface library around those sources, similar
# to when we retrieve the library sources ourselves.
add_library (stb::stb INTERFACE IMPORTED)
set_target_properties (stb::stb PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${Stb_INCLUDE_DIR}"
INTERFACE_SOURCES "${CMAKE_SOURCE_DIR}/src/core/stb_impl.c"
)
endif ()
33 changes: 18 additions & 15 deletions CMake/InstallTinyFileDialogs.cmake
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
FetchContent_Declare (
tinyfiledialogs
GIT_REPOSITORY [[https://git.code.sf.net/p/tinyfiledialogs/code]]
GIT_TAG [[fb228c5bcd7d0574d08b71b4fae84676328addaf]]
)
find_package (tinyfiledialogs QUIET)
if (NOT tinyfiledialogs_FOUND)
FetchContent_Declare (
tinyfiledialogs
GIT_REPOSITORY [[https://git.code.sf.net/p/tinyfiledialogs/code]]
GIT_TAG [[e11f94cd7887b101d64f74892d769f0139b5e166]]
)

FetchContent_GetProperties (tinyfiledialogs)
if (NOT tinyfiledialogs_POPULATED)
message (STATUS "Cloning tinyfiledialogs…")
FetchContent_Populate (tinyfiledialogs)
endif ()
FetchContent_GetProperties (tinyfiledialogs)
if (NOT tinyfiledialogs_POPULATED)
message (STATUS "Cloning tinyfiledialogs…")
FetchContent_Populate (tinyfiledialogs)
endif ()

add_library( tinyfiledialogs::tinyfiledialogs INTERFACE IMPORTED)
set_target_properties(tinyfiledialogs::tinyfiledialogs PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${tinyfiledialogs_SOURCE_DIR}"
INTERFACE_SOURCES "${tinyfiledialogs_SOURCE_DIR}/tinyfiledialogs.c"
)
add_library( tinyfiledialogs::tinyfiledialogs INTERFACE IMPORTED)
set_target_properties(tinyfiledialogs::tinyfiledialogs PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${tinyfiledialogs_SOURCE_DIR}"
INTERFACE_SOURCES "${tinyfiledialogs_SOURCE_DIR}/tinyfiledialogs.c"
)
endif ()
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ CG_Labs uses the following dependencies:

* assimp_ (>= 5.0.0): to load OBJ models;
* CMake_ (>= 3.13): to generate project files and handle dependencies;
* `Dear ImGui`_ (1.78): to display information on screen, such as logs;
* `Dear ImGui`_ (1.84.2): to display information on screen, such as logs;
* Git_: to clone missing dependencies;
* GLAD_ (0.1.33): to load OpenGL extensions;
* GLFW_ (>= 3.2.0): to create a window and an OpenGL context, as well as handle inputs;
* GLM_ (0.9.9.5): for linear algebra operations;
* stb_: to load image files;
* tinyfiledialogs_: to display dialogue windows to the user, in case of errors
for example.
* tinyfiledialogs_ (>= 3.1.2): to display dialogue windows to the user, in case
of errors for example.

The project contains the needed files for GLAD and Dear ImGui, and it will
download assimp, GLM, GLFW, stb and tinyfiledialogs if they are not found on
Expand Down
3 changes: 0 additions & 3 deletions shaders/EDAF80/binormal.vert
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,3 @@ void main()

gl_Position = vertex_world_to_clip * vertex_model_to_world * vec4(vertex, 1.0);
}



14 changes: 0 additions & 14 deletions shaders/EDAF80/fallback.vert

This file was deleted.

9 changes: 9 additions & 0 deletions shaders/EDAN35/fill_shadowmap.frag
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
#version 410

uniform bool has_opacity_texture;
uniform sampler2D opacity_texture;

in VS_OUT {
vec2 texcoord;
} fs_in;

void main()
{
if (has_opacity_texture && texture(opacity_texture, fs_in.texcoord).r < 1.0)
discard;
}
7 changes: 7 additions & 0 deletions shaders/EDAN35/fill_shadowmap.vert
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@ uniform mat4 vertex_model_to_world;
uniform mat4 vertex_world_to_clip;

layout (location = 0) in vec3 vertex;
layout (location = 2) in vec3 texcoord;

out VS_OUT {
vec2 texcoord;
} vs_out;

void main()
{
vs_out.texcoord = texcoord.xy;

gl_Position = vertex_world_to_clip * vertex_model_to_world * vec4(vertex, 1.0);
}
26 changes: 26 additions & 0 deletions shaders/common/basis.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#version 410

in VS_OUT {
flat uint axis_index;
} vs_out;

out vec4 frag_color;

void main()
{
switch (vs_out.axis_index)
{
case 0:
frag_color = vec4(0.8f, 0.2f, 0.2f, 1.0f);
break;
case 1:
frag_color = vec4(0.2f, 0.8f, 0.2f, 1.0f);
break;
case 2:
frag_color = vec4(0.2f, 0.2f, 0.8f, 1.0f);
break;
default:
frag_color = vec4(1.0f);
break;
}
}
46 changes: 46 additions & 0 deletions shaders/common/basis.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#version 410

layout (location = 0) in vec3 vertex;

uniform mat4 vertex_model_to_world;
uniform mat4 vertex_world_to_clip;
uniform float thickness_scale;
uniform float length_scale;

out VS_OUT {
flat uint axis_index;
} vs_out;


void main()
{
vs_out.axis_index = gl_InstanceID;
vec3 local_vertex = vertex;

// One arrow is instanced three times, to provide all three axes. That
// arrow represents a (1 0 0) vector.

// Scale the arrow before it is transformed to represent an axis other
// than x.
local_vertex.yz *= thickness_scale;
local_vertex.x *= length_scale;

// The first instance is for the x axis, so no additional
// transformation is needed.
//
// The second instance is for the y axis, so swap the x and y
// components.
if (vs_out.axis_index == 1)
{
local_vertex.xy = local_vertex.yx;
}
// The third instance is for the z axis, so set x to -z, and z to x.
else if (vs_out.axis_index == 2)
{
float tmpX = local_vertex.x;
local_vertex.x = -local_vertex.z;
local_vertex.z = tmpX;
}

gl_Position = vertex_world_to_clip * vertex_model_to_world * vec4(local_vertex, 1.0);
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 0 additions & 8 deletions shaders/fallback.frag

This file was deleted.

3 changes: 2 additions & 1 deletion src/EDAF80/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ target_sources (
EDAF80_Assignment1
PRIVATE
[[assignment1.cpp]]
[[assignment1.hpp]]
[[CelestialBody.cpp]]
[[CelestialBody.hpp]]
)
target_link_libraries (
EDAF80_Assignment1
Expand Down
89 changes: 89 additions & 0 deletions src/EDAF80/CelestialBody.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#include "CelestialBody.hpp"

#include <glm/gtc/matrix_transform.hpp>
#include <glm/trigonometric.hpp>

#include "core/helpers.hpp"
#include "core/Log.h"

CelestialBody::CelestialBody(bonobo::mesh_data const& shape,
GLuint const* program,
GLuint diffuse_texture_id)
{
_body.node.set_geometry(shape);
_body.node.add_texture("diffuse_texture", diffuse_texture_id, GL_TEXTURE_2D);
_body.node.set_program(program);
}

glm::mat4 CelestialBody::render(std::chrono::microseconds elapsed_time,
glm::mat4 const& view_projection,
glm::mat4 const& parent_transform,
bool show_basis)
{
// Convert the duration from microseconds to seconds.
auto const elapsed_time_s = std::chrono::duration<float>(elapsed_time).count();
// If a different ratio was needed, for example a duration in
// milliseconds, the following would have been used:
// auto const elapsed_time_ms = std::chrono::duration<float, std::milli>(elapsed_time).count();

_body.spin.rotation_angle = -glm::half_pi<float>() / 2.0f;

glm::mat4 world = parent_transform;

if (show_basis)
{
bonobo::renderBasis(1.0f, 2.0f, view_projection, world);
}

// Note: The second argument of `node::render()` is supposed to be the
// parent transform of the node, not the whole world matrix, as the
// node internally manages its local transforms. However in our case we
// manage all the local transforms ourselves, so the internal transform
// of the node is just the identity matrix and we can forward the whole
// world matrix.
_body.node.render(view_projection, world);

return parent_transform;
}

void CelestialBody::add_child(CelestialBody* child)
{
_children.push_back(child);
}

std::vector<CelestialBody*> const& CelestialBody::get_children() const
{
return _children;
}

void CelestialBody::set_orbit(OrbitConfiguration const& configuration)
{
_body.orbit.radius = configuration.radius;
_body.orbit.inclination = configuration.inclination;
_body.orbit.speed = configuration.speed;
_body.orbit.rotation_angle = 0.0f;
}

void CelestialBody::set_scale(glm::vec3 const& scale)
{
_body.scale = scale;
}

void CelestialBody::set_spin(SpinConfiguration const& configuration)
{
_body.spin.axial_tilt = configuration.axial_tilt;
_body.spin.speed = configuration.speed;
_body.spin.rotation_angle = 0.0f;
}

void CelestialBody::set_ring(bonobo::mesh_data const& shape,
GLuint const* program,
GLuint diffuse_texture_id,
glm::vec2 const& scale)
{
_ring.node.set_geometry(shape);
_ring.node.add_texture("diffuse_texture", diffuse_texture_id, GL_TEXTURE_2D);
_ring.node.set_program(program);

_ring.scale = scale;
}
Loading

0 comments on commit 8cdadaf

Please sign in to comment.