Add engine resources to store core shaders, create core shader class
This commit is contained in:
parent
a507e2f169
commit
db94d85168
|
@ -19,11 +19,22 @@ add_library(simpleengine STATIC ${source_list})
|
||||||
# Link headers
|
# Link headers
|
||||||
target_include_directories(simpleengine PUBLIC include PRIVATE include/simpleengine)
|
target_include_directories(simpleengine PUBLIC include PRIVATE include/simpleengine)
|
||||||
|
|
||||||
|
# Embed shaders
|
||||||
|
file(GLOB_RECURSE simpleeng_resources_list resources/**)
|
||||||
|
cmrc_add_resource_library(
|
||||||
|
simpleengine_resources# ALIAS simpleengine::res::shaders
|
||||||
|
#NAMESPACE simpleengine__res
|
||||||
|
#WHENCE resources/shaders
|
||||||
|
#PREFIX resources/shaders
|
||||||
|
${simpleeng_resources_list}
|
||||||
|
)
|
||||||
|
|
||||||
# Link dependencies
|
# Link dependencies
|
||||||
target_link_libraries(simpleengine PUBLIC GLEW::GLEW)
|
target_link_libraries(simpleengine PUBLIC GLEW::GLEW)
|
||||||
target_link_libraries(simpleengine PUBLIC glfw)
|
target_link_libraries(simpleengine PUBLIC glfw)
|
||||||
target_link_libraries(simpleengine PUBLIC glm::glm)
|
target_link_libraries(simpleengine PUBLIC glm::glm)
|
||||||
target_link_libraries(simpleengine PUBLIC soil2)
|
target_link_libraries(simpleengine PUBLIC soil2)
|
||||||
|
target_link_libraries(simpleengine PRIVATE simpleengine_resources)
|
||||||
|
|
||||||
include_directories(${GLM_INCLUDE_DIRS})
|
include_directories(${GLM_INCLUDE_DIRS})
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include <simpleengine/game.h>
|
#include <simpleengine/game.h>
|
||||||
#include <simpleengine/vertex.h>
|
#include <simpleengine/vertex.h>
|
||||||
#include <simpleengine/objects/3d/obj_model.h>
|
#include <simpleengine/objects/3d/obj_model.h>
|
||||||
|
#include <simpleengine/gfx/shaders/core_3d_shader.h>
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
@ -23,6 +24,8 @@ CMRC_DECLARE(resource_shaders);
|
||||||
|
|
||||||
#include <SOIL2/SOIL2.h>
|
#include <SOIL2/SOIL2.h>
|
||||||
|
|
||||||
|
namespace se = simpleengine;
|
||||||
|
|
||||||
std::string read_resource_shader(const std::string& path) {
|
std::string read_resource_shader(const std::string& path) {
|
||||||
auto fs = cmrc::resource_shaders::get_filesystem();
|
auto fs = cmrc::resource_shaders::get_filesystem();
|
||||||
cmrc::file vertex_file = fs.open(path);
|
cmrc::file vertex_file = fs.open(path);
|
||||||
|
@ -31,43 +34,34 @@ std::string read_resource_shader(const std::string& path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
simpleengine::Game game(640, 480, "SimpleEngine 3D OpenGL - Developer Testing", GLFW_OPENGL_CORE_PROFILE, 4, 4, false);
|
se::Game game(640, 480, "SimpleEngine 3D OpenGL - Developer Testing", GLFW_OPENGL_CORE_PROFILE, 4, 4, false);
|
||||||
|
|
||||||
// Load shaders
|
/* se::gfx::Texture wall_texture("resources/wall.jpg");
|
||||||
std::string vertex_core = read_resource_shader("shaders/vertex_core.glsl");
|
se::gfx::Texture crate_texture("resources/container.jpg", true, true); */
|
||||||
std::string fragment_core = read_resource_shader("shaders/fragment_core.glsl");
|
|
||||||
|
|
||||||
// Compile shader program
|
// Load core shaders from simpleengine resources
|
||||||
simpleengine::ShaderProgram shader_prog;
|
se::gfx::shaders::Core3dShader core_shader;
|
||||||
shader_prog.add_shader_from_source(simpleengine::gfx::ShaderType::ST_Vertex, vertex_core);
|
|
||||||
shader_prog.add_shader_from_source(simpleengine::gfx::ShaderType::ST_Fragment, fragment_core);
|
|
||||||
shader_prog.link();
|
|
||||||
simpleengine::gfx::Shader core_shader = shader_prog.shaders.front();
|
|
||||||
|
|
||||||
/* simpleengine::gfx::Texture wall_texture("resources/wall.jpg");
|
auto light = std::make_shared<se::gfx::Light>(core_shader, glm::vec3(0.f, 0.f, -20.f), glm::vec3(1.f, 1.f, 1.f));
|
||||||
simpleengine::gfx::Texture crate_texture("resources/container.jpg", true, true); */
|
|
||||||
|
|
||||||
|
|
||||||
auto light = std::make_shared<simpleengine::gfx::Light>(core_shader, glm::vec3(0.f, 0.f, -20.f), glm::vec3(1.f, 1.f, 1.f));
|
|
||||||
game.add_event(light);
|
game.add_event(light);
|
||||||
|
|
||||||
simpleengine::gfx::Texture white_texture("resources/white_texture.png");
|
se::gfx::Texture white_texture("examples/dev_testing/resources/white_texture.png");
|
||||||
/* white_texture.shine_damper = 10;
|
/* white_texture.shine_damper = 10;
|
||||||
white_texture.reflectivity = 1; */
|
white_texture.reflectivity = 1; */
|
||||||
auto dragon = std::make_shared<simpleengine::objects_3d::ObjModel>(game.get_window(), core_shader, white_texture, "resources/dragon.obj");
|
auto dragon = std::make_shared<se::objects_3d::ObjModel>(game.get_window(), core_shader, white_texture, "examples/dev_testing/resources/dragon.obj");
|
||||||
dragon->translate(0.f, -5.f, -25.f);
|
dragon->translate(0.f, -5.f, -25.f);
|
||||||
game.add_event(dragon);
|
game.add_event(dragon);
|
||||||
|
|
||||||
/* simpleengine::gfx::Texture stall_texture("resources/stallTexture.png");
|
/* se::gfx::Texture stall_texture("resources/stallTexture.png");
|
||||||
auto stall = std::make_shared<simpleengine::objects_3d::ObjModel>(game.get_window(), core_shader, stall_texture, "resources/stall.obj");
|
auto stall = std::make_shared<se::objects_3d::ObjModel>(game.get_window(), core_shader, stall_texture, "resources/stall.obj");
|
||||||
stall->translate(0.f, -4.f, -25.f);
|
stall->translate(0.f, -4.f, -25.f);
|
||||||
game.add_event(stall); */
|
game.add_event(stall); */
|
||||||
|
|
||||||
/* std::vector<simpleengine::Vertex> square_vertices = {
|
/* std::vector<se::Vertex> square_vertices = {
|
||||||
{ simpleengine::Vectorf(0.5f, 0.5f, -1.f), glm::vec3(1.f, 0.f, 0.f), glm::vec2(0.f, 0.f) }, // top right
|
{ se::Vectorf(0.5f, 0.5f, -1.f), glm::vec3(1.f, 0.f, 0.f), glm::vec2(0.f, 0.f) }, // top right
|
||||||
{ simpleengine::Vectorf(0.5f, -0.5f, -1.f), glm::vec3(0.f, 1.f, 0.f), glm::vec2(1.f, 0.f) }, // bottom right
|
{ se::Vectorf(0.5f, -0.5f, -1.f), glm::vec3(0.f, 1.f, 0.f), glm::vec2(1.f, 0.f) }, // bottom right
|
||||||
{ simpleengine::Vectorf(-0.5f, -0.5f, -1.f), glm::vec3(0.f, 0.f, 1.f), glm::vec2(0.5f, 1.0f) }, // bottom left
|
{ se::Vectorf(-0.5f, -0.5f, -1.f), glm::vec3(0.f, 0.f, 1.f), glm::vec2(0.5f, 1.0f) }, // bottom left
|
||||||
{ simpleengine::Vectorf(-0.5f, 0.5f, -1.f), glm::vec3(.5f, 0.5f, 0.f), glm::vec2(0.5f, 1.0f) }, // top left
|
{ se::Vectorf(-0.5f, 0.5f, -1.f), glm::vec3(.5f, 0.5f, 0.f), glm::vec2(0.5f, 1.0f) }, // top left
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<GLuint> indicies = {
|
std::vector<GLuint> indicies = {
|
||||||
|
@ -75,52 +69,52 @@ int main(int argc, char *argv[]) {
|
||||||
1, 2, 3
|
1, 2, 3
|
||||||
};
|
};
|
||||||
|
|
||||||
auto square = std::make_shared<simpleengine::gfx::Model>(game.get_window(), core_shader, square_vertices, indicies);
|
auto square = std::make_shared<se::gfx::Model>(game.get_window(), core_shader, square_vertices, indicies);
|
||||||
square->translate(1.25f, 0.f, -1.f);
|
square->translate(1.25f, 0.f, -1.f);
|
||||||
square->scale(.75f);
|
square->scale(.75f);
|
||||||
game.add_event(square);
|
game.add_event(square);
|
||||||
|
|
||||||
std::vector<simpleengine::Vertex> tri_vertices = {
|
std::vector<se::Vertex> tri_vertices = {
|
||||||
{ simpleengine::Vectorf(-0.5f, -0.5f, -1.f), glm::vec3(1.f, 0.f, 0.f), glm::vec2(0.f, 0.f) }, // top right
|
{ se::Vectorf(-0.5f, -0.5f, -1.f), glm::vec3(1.f, 0.f, 0.f), glm::vec2(0.f, 0.f) }, // top right
|
||||||
{ simpleengine::Vectorf(0.5f, -0.5f, -1.f), glm::vec3(0.f, 1.f, 0.f), glm::vec2(1.f, 0.f) }, // bottom right
|
{ se::Vectorf(0.5f, -0.5f, -1.f), glm::vec3(0.f, 1.f, 0.f), glm::vec2(1.f, 0.f) }, // bottom right
|
||||||
{ simpleengine::Vectorf(0.f, 0.5f, -1.f), glm::vec3(0.f, 0.f, 1.f), glm::vec2(0.5f, 1.0f) }, // bottom left
|
{ se::Vectorf(0.f, 0.5f, -1.f), glm::vec3(0.f, 0.f, 1.f), glm::vec2(0.5f, 1.0f) }, // bottom left
|
||||||
};
|
};
|
||||||
|
|
||||||
auto tri = std::make_shared<simpleengine::gfx::Model>(game.get_window(), core_shader, tri_vertices);
|
auto tri = std::make_shared<se::gfx::Model>(game.get_window(), core_shader, tri_vertices);
|
||||||
tri->translate(-1.25f, 0.f, -1.f);
|
tri->translate(-1.25f, 0.f, -1.f);
|
||||||
tri->scale(.75f);
|
tri->scale(.75f);
|
||||||
game.add_event(tri); */
|
game.add_event(tri); */
|
||||||
|
|
||||||
/* std::vector<simpleengine::Vertex> cube_vertices = {
|
/* std::vector<se::Vertex> cube_vertices = {
|
||||||
{ simpleengine::Vectorf(-0.5f,0.5f,-0.5f), glm::vec3(1.f, 0.f, 0.f), glm::vec2(1.f, 1.f) },
|
{ se::Vectorf(-0.5f,0.5f,-0.5f), glm::vec3(1.f, 0.f, 0.f), glm::vec2(1.f, 1.f) },
|
||||||
{ simpleengine::Vectorf(-0.5f,-0.5f,-0.5f), glm::vec3(0.f, 1.f, 0.f), glm::vec2(1.f, 0.f) },
|
{ se::Vectorf(-0.5f,-0.5f,-0.5f), glm::vec3(0.f, 1.f, 0.f), glm::vec2(1.f, 0.f) },
|
||||||
{ simpleengine::Vectorf(0.5f,-0.5f,-0.5f), glm::vec3(0.f, 0.f, 1.f), glm::vec2(0.f, 0.f) },
|
{ se::Vectorf(0.5f,-0.5f,-0.5f), glm::vec3(0.f, 0.f, 1.f), glm::vec2(0.f, 0.f) },
|
||||||
{ simpleengine::Vectorf(0.5f,0.5f,-0.5f), glm::vec3(1.f, 1.f, 0.f), glm::vec2(0.f, 1.f) },
|
{ se::Vectorf(0.5f,0.5f,-0.5f), glm::vec3(1.f, 1.f, 0.f), glm::vec2(0.f, 1.f) },
|
||||||
|
|
||||||
{ simpleengine::Vectorf(-0.5f,0.5f,0.5f), glm::vec3(1.f, 0.f, 0.f), glm::vec2(1.f, 1.f) },
|
{ se::Vectorf(-0.5f,0.5f,0.5f), glm::vec3(1.f, 0.f, 0.f), glm::vec2(1.f, 1.f) },
|
||||||
{ simpleengine::Vectorf(-0.5f,-0.5f,0.5f), glm::vec3(0.f, 1.f, 0.f), glm::vec2(1.f, 0.f) },
|
{ se::Vectorf(-0.5f,-0.5f,0.5f), glm::vec3(0.f, 1.f, 0.f), glm::vec2(1.f, 0.f) },
|
||||||
{ simpleengine::Vectorf(0.5f,-0.5f,0.5f), glm::vec3(0.f, 0.f, 1.f), glm::vec2(0.f, 0.f) },
|
{ se::Vectorf(0.5f,-0.5f,0.5f), glm::vec3(0.f, 0.f, 1.f), glm::vec2(0.f, 0.f) },
|
||||||
{ simpleengine::Vectorf(0.5f,0.5f,0.5f), glm::vec3(1.f, 1.f, 0.f), glm::vec2(0.f, 1.f) },
|
{ se::Vectorf(0.5f,0.5f,0.5f), glm::vec3(1.f, 1.f, 0.f), glm::vec2(0.f, 1.f) },
|
||||||
|
|
||||||
{ simpleengine::Vectorf(0.5f,0.5f,-0.5f), glm::vec3(1.f, 0.f, 0.f), glm::vec2(1.f, 1.f) },
|
{ se::Vectorf(0.5f,0.5f,-0.5f), glm::vec3(1.f, 0.f, 0.f), glm::vec2(1.f, 1.f) },
|
||||||
{ simpleengine::Vectorf(0.5f,-0.5f,-0.5f), glm::vec3(0.f, 1.f, 0.f), glm::vec2(1.f, 0.f) },
|
{ se::Vectorf(0.5f,-0.5f,-0.5f), glm::vec3(0.f, 1.f, 0.f), glm::vec2(1.f, 0.f) },
|
||||||
{ simpleengine::Vectorf(0.5f,-0.5f,0.5f), glm::vec3(0.f, 0.f, 1.f), glm::vec2(0.f, 0.f) },
|
{ se::Vectorf(0.5f,-0.5f,0.5f), glm::vec3(0.f, 0.f, 1.f), glm::vec2(0.f, 0.f) },
|
||||||
{ simpleengine::Vectorf(0.5f,0.5f,0.5f), glm::vec3(1.f, 1.f, 0.f), glm::vec2(0.f, 1.f) },
|
{ se::Vectorf(0.5f,0.5f,0.5f), glm::vec3(1.f, 1.f, 0.f), glm::vec2(0.f, 1.f) },
|
||||||
|
|
||||||
{ simpleengine::Vectorf(-0.5f,0.5f,-0.5f), glm::vec3(1.f, 0.f, 0.f), glm::vec2(1.f, 1.f) },
|
{ se::Vectorf(-0.5f,0.5f,-0.5f), glm::vec3(1.f, 0.f, 0.f), glm::vec2(1.f, 1.f) },
|
||||||
{ simpleengine::Vectorf(-0.5f,-0.5f,-0.5f), glm::vec3(0.f, 1.f, 0.f), glm::vec2(1.f, 0.f) },
|
{ se::Vectorf(-0.5f,-0.5f,-0.5f), glm::vec3(0.f, 1.f, 0.f), glm::vec2(1.f, 0.f) },
|
||||||
{ simpleengine::Vectorf(-0.5f,-0.5f,0.5f), glm::vec3(0.f, 0.f, 1.f), glm::vec2(0.f, 0.f) },
|
{ se::Vectorf(-0.5f,-0.5f,0.5f), glm::vec3(0.f, 0.f, 1.f), glm::vec2(0.f, 0.f) },
|
||||||
{ simpleengine::Vectorf(-0.5f,0.5f,0.5f), glm::vec3(1.f, 1.f, 0.f), glm::vec2(0.f, 1.f) },
|
{ se::Vectorf(-0.5f,0.5f,0.5f), glm::vec3(1.f, 1.f, 0.f), glm::vec2(0.f, 1.f) },
|
||||||
|
|
||||||
{ simpleengine::Vectorf(-0.5f,0.5f,0.5f), glm::vec3(1.f, 0.f, 0.f), glm::vec2(1.f, 1.f) },
|
{ se::Vectorf(-0.5f,0.5f,0.5f), glm::vec3(1.f, 0.f, 0.f), glm::vec2(1.f, 1.f) },
|
||||||
{ simpleengine::Vectorf(-0.5f,0.5f,-0.5f), glm::vec3(0.f, 1.f, 0.f), glm::vec2(1.f, 0.f) },
|
{ se::Vectorf(-0.5f,0.5f,-0.5f), glm::vec3(0.f, 1.f, 0.f), glm::vec2(1.f, 0.f) },
|
||||||
{ simpleengine::Vectorf(0.5f,0.5f,-0.5f), glm::vec3(0.f, 0.f, 1.f), glm::vec2(0.f, 0.f) },
|
{ se::Vectorf(0.5f,0.5f,-0.5f), glm::vec3(0.f, 0.f, 1.f), glm::vec2(0.f, 0.f) },
|
||||||
{ simpleengine::Vectorf(0.5f,0.5f,0.5f), glm::vec3(1.f, 1.f, 0.f), glm::vec2(0.f, 1.f) },
|
{ se::Vectorf(0.5f,0.5f,0.5f), glm::vec3(1.f, 1.f, 0.f), glm::vec2(0.f, 1.f) },
|
||||||
|
|
||||||
{ simpleengine::Vectorf(-0.5f,-0.5f,0.5f), glm::vec3(1.f, 0.f, 0.f), glm::vec2(1.f, 1.f) },
|
{ se::Vectorf(-0.5f,-0.5f,0.5f), glm::vec3(1.f, 0.f, 0.f), glm::vec2(1.f, 1.f) },
|
||||||
{ simpleengine::Vectorf(-0.5f,-0.5f,-0.5f), glm::vec3(0.f, 1.f, 0.f), glm::vec2(1.f, 0.f) },
|
{ se::Vectorf(-0.5f,-0.5f,-0.5f), glm::vec3(0.f, 1.f, 0.f), glm::vec2(1.f, 0.f) },
|
||||||
{ simpleengine::Vectorf(0.5f,-0.5f,-0.5f), glm::vec3(0.f, 0.f, 1.f), glm::vec2(0.f, 0.f) },
|
{ se::Vectorf(0.5f,-0.5f,-0.5f), glm::vec3(0.f, 0.f, 1.f), glm::vec2(0.f, 0.f) },
|
||||||
{ simpleengine::Vectorf(0.5f,-0.5f,0.5f), glm::vec3(1.f, 1.f, 0.f), glm::vec2(0.f, 1.f) },
|
{ se::Vectorf(0.5f,-0.5f,0.5f), glm::vec3(1.f, 1.f, 0.f), glm::vec2(0.f, 1.f) },
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<GLuint> cube_indicies = {
|
std::vector<GLuint> cube_indicies = {
|
||||||
|
@ -138,10 +132,10 @@ int main(int argc, char *argv[]) {
|
||||||
23,21,22
|
23,21,22
|
||||||
};
|
};
|
||||||
|
|
||||||
auto cube = std::make_shared<simpleengine::gfx::Model>(game.get_window(), core_shader, cube_vertices, cube_indicies);
|
auto cube = std::make_shared<se::gfx::Model>(game.get_window(), core_shader, cube_vertices, cube_indicies);
|
||||||
game.add_event(cube); */
|
game.add_event(cube); */
|
||||||
|
|
||||||
auto camera = std::make_shared<simpleengine::Camera>(game.get_window(), core_shader, 70, glm::vec3(0, 0, -10));
|
auto camera = std::make_shared<se::Camera>(game.get_window(), core_shader, 70, glm::vec3(0, 0, -10));
|
||||||
game.add_event(camera);
|
game.add_event(camera);
|
||||||
|
|
||||||
return game.run();
|
return game.run();
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "../shader.h"
|
||||||
|
|
||||||
|
#include <cmrc/cmrc.hpp>
|
||||||
|
CMRC_DECLARE(simpleengine_resources);
|
||||||
|
|
||||||
|
namespace simpleengine::gfx::shaders {
|
||||||
|
class Core3dShader : public simpleengine::gfx::Shader {
|
||||||
|
private:
|
||||||
|
gfx::Shader fragment_shader;
|
||||||
|
public:
|
||||||
|
Core3dShader() {
|
||||||
|
this->program = glCreateProgram();
|
||||||
|
|
||||||
|
auto vertex_fs = cmrc::simpleengine_resources::get_filesystem();
|
||||||
|
cmrc::file vertex_file = vertex_fs.open("resources/shaders/vertex_core.glsl");
|
||||||
|
std::string vertex_source(vertex_file.begin());
|
||||||
|
Shader vertex = gfx::Shader::from_source(program, ShaderType::ST_Vertex, vertex_source);
|
||||||
|
this->shader = vertex.shader;
|
||||||
|
|
||||||
|
auto fragment_fs = cmrc::simpleengine_resources::get_filesystem();
|
||||||
|
cmrc::file fragment_file = fragment_fs.open("resources/shaders/fragment_core.glsl");
|
||||||
|
std::string fragment_source(fragment_file.begin());
|
||||||
|
fragment_shader = gfx::Shader::from_source(program, ShaderType::ST_Fragment, fragment_source);
|
||||||
|
|
||||||
|
link();
|
||||||
|
delete_shader();
|
||||||
|
fragment_shader.delete_shader();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
|
@ -0,0 +1,46 @@
|
||||||
|
#version 440
|
||||||
|
|
||||||
|
in vec3 vs_position;
|
||||||
|
in mat4 vs_transform;
|
||||||
|
in vec2 vs_texcoord;
|
||||||
|
in vec3 vs_normal;
|
||||||
|
in vec3 vs_to_light;
|
||||||
|
in vec3 vs_to_camera;
|
||||||
|
|
||||||
|
uniform bool texture_is_set;
|
||||||
|
uniform sampler2D vs_texture;
|
||||||
|
uniform vec3 light_color;
|
||||||
|
uniform float shine_damper;
|
||||||
|
uniform float reflectivity;
|
||||||
|
|
||||||
|
out vec4 fs_color;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
// Lighting
|
||||||
|
vec3 unit_normal = normalize(vs_normal);
|
||||||
|
vec3 unit_light_vector = normalize(vs_to_light);
|
||||||
|
|
||||||
|
float dot_prod = dot(unit_normal, unit_light_vector);
|
||||||
|
float brightness = max(dot_prod, 0.f);
|
||||||
|
vec3 diffuse = brightness * light_color;
|
||||||
|
|
||||||
|
// Specular lighting
|
||||||
|
// only do all this math is reflectivity is > 0
|
||||||
|
vec3 final_specular = vec3(0.f);
|
||||||
|
if (reflectivity > 0) {
|
||||||
|
vec3 unit_vector_to_camera = normalize(vs_to_camera);
|
||||||
|
vec3 light_direction = -unit_vector_to_camera;
|
||||||
|
vec3 reflected_light_dir = reflect(light_direction, unit_normal);
|
||||||
|
float specular_factor = dot(reflected_light_dir, unit_vector_to_camera);
|
||||||
|
specular_factor = max(specular_factor, 0.f);
|
||||||
|
float damped_specular = pow(specular_factor, shine_damper);
|
||||||
|
final_specular = damped_specular * reflectivity * light_color;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (texture_is_set) {
|
||||||
|
//fs_color = vec4(0.5 * unit_normal + vec3(0.5), 1.f); // Visualize normals
|
||||||
|
fs_color = vec4(diffuse, 1.f) * texture(vs_texture, vs_texcoord) + vec4(final_specular, 1.f);
|
||||||
|
} else {
|
||||||
|
fs_color = vec4(diffuse, 1.f) + vec4(final_specular, 1.f);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
#version 440
|
||||||
|
|
||||||
|
layout (location = 0) in vec3 vertex_position;
|
||||||
|
layout (location = 1) in vec2 vertex_texcoord;
|
||||||
|
layout (location = 2) in vec3 vertex_normal;
|
||||||
|
|
||||||
|
out vec3 vs_position;
|
||||||
|
out vec2 vs_texcoord;
|
||||||
|
out mat4 vs_transform;
|
||||||
|
out vec3 vs_normal;
|
||||||
|
out vec3 vs_to_light;
|
||||||
|
out vec3 vs_to_camera;
|
||||||
|
|
||||||
|
uniform mat4 transform_matrix;
|
||||||
|
uniform mat4 view_matrix;
|
||||||
|
uniform mat4 projection_matrix;
|
||||||
|
uniform vec3 light_position;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
vec4 world_pos = (transform_matrix * vec4(vertex_position, 1.f));
|
||||||
|
|
||||||
|
vs_position = world_pos.xyz;
|
||||||
|
vs_transform = transform_matrix;
|
||||||
|
vs_texcoord = vertex_texcoord;
|
||||||
|
|
||||||
|
gl_Position = projection_matrix * view_matrix * world_pos;
|
||||||
|
|
||||||
|
vs_normal = (transform_matrix * vec4(vertex_normal, 0.f)).xyz;
|
||||||
|
vs_to_light = light_position - world_pos.xyz;
|
||||||
|
vs_to_camera = (inverse(view_matrix) * vec4(0.f, 0.f, 0.f, 1.f)).xyz - world_pos.xyz;
|
||||||
|
}
|
|
@ -115,6 +115,6 @@ namespace simpleengine::objects_3d {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjModel::update(const float& delta_time) {
|
void ObjModel::update(const float& delta_time) {
|
||||||
this->rotate_y(0.5f); // Slowly rotate (for debugging)
|
this->rotate_y(0.05f); // Slowly rotate (for debugging)
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue