diff --git a/README.md b/README.md index 1dbfd3dc..4858ea63 100644 --- a/README.md +++ b/README.md @@ -13,11 +13,11 @@ sudo apt install build-essential cmake libsdl2-dev libglew-dev libglm-dev libass ``` ### Arch ```bash -sudo pacman -S base-devel cmake sdl2 glew glm +sudo pacman -S base-devel cmake sdl2 glew glm assimp ``` ### Redhat/Fedora ```bash -sudo dnf install kernel-devel cmake sdl +sudo dnf install kernel-devel cmake sdl // TODO ``` ## Build Instructions ```bash @@ -78,24 +78,82 @@ Pull requests are welcome. For major changes, please open an issue first to disc - [ ] Mesh Importing - [ ] Full UV mapping support - [ ] Full vertex color support - - [ ] Multiple texture materials + - [ ] Multi-texture materials - [ ] Normals - [ ] Normal maps + - [ ] Matcaps (SArpnt will do this) + - [ ] Simple object classes (combine assets and automatically manage render commands) + - [ ] Depth manipulation - [ ] Skybox + - [x] Render triangle strips + - [ ] GL lines + - [ ] Sprites (i think you can do GL_POINTS and draw the images in a frag shader) + - [ ] Supersampling and subsampling + - [ ] Antialiasing + - [ ] MSAA + - [ ] FXAA + - [ ] MSAA with FXAA + - [ ] Mipmaps + - [ ] Anisotropic filtering + - [ ] Texture filtering + - [ ] Nearest + - [ ] Linear + - [ ] Bilinear + - [ ] Trilinear + - [ ] Supersampling / subsampling Interpolation + - [ ] Nearest + - [ ] Bilinear + - [ ] Bicubic + - [ ] Trilinear + - [ ] Lanczos - [ ] Lights - - [ ] Input System - - [ ] Events System - - [ ] Collision - - [ ] Gravity - [ ] Text - - [ ] Layers - [ ] GUI + - [ ] Portals + - [ ] VR Support + - [ ] Test on Windowsbetter + - [ ] Port to Emscripten + +### Physics engine (make a seperate project) + + - [ ] Shapes + - [ ] Point + - [ ] Line segment + - [ ] Rectangular prism + - [ ] Sphere + - [ ] Cylinder + - [ ] Capsule + - [ ] Cone + - [ ] Ngon prism + - [ ] Elipsoid + - [ ] Mesh + - [ ] Shape collision + - [ ] Shape advanced collision (Get information like position, speeds, collision normals, etc. so that physics can be done) + - [ ] Physics + - [ ] Air resistance + - [ ] Friction + - [ ] Bounciness + - [ ] Buoyancy + - [ ] Fake fluid (fluid in small comtainers like bottles, get water level) + - [ ] Soft body + - [ ] Fluid + - [ ] Portals + - [ ] Test on Windows + - [ ] Port to Emscripten + + - [ ] VR Support + - [ ] Input System + +SceneGraph (make a seperate project) - [ ] States + - [ ] Scene Graph - [ ] Map management + - [ ] XML based scene graph import +### Misc + - [ ] Events System - [ ] Make an Actual Game + # Networking (make a seperate project) - [ ] Networking - - [ ] VR Support - - [ ] Scene Graph - - [ ] XML based scene graph import - - [ ] Test ON Windows - - [ ] Port to Emscripten \ No newline at end of file + # Platforms + - [ ] Test on Windows + - [ ] Port to Emscripten diff --git a/dep/CMakeLists.txt b/dep/CMakeLists.txt index e0837233..3ca26469 100644 --- a/dep/CMakeLists.txt +++ b/dep/CMakeLists.txt @@ -35,7 +35,7 @@ find_package(glm REQUIRED) include_directories(${GLM_INCLUDE_DIRS}) message(NOTICE "GLM_INCLUDE_DIRS " ${GLM_INCLUDE_DIRS}) -# ASIMP +# ASSIMP find_package(assimp REQUIRED) message(NOTICE "ASSIMP_LIBRARY " ${OPENGL_LIBRARY}) message(NOTICE "ASSIMP_LIBRARIES " ${OPENGL_LIBRARIES}) @@ -54,7 +54,7 @@ set(CE_LIBS PARENT_SCOPE ) -#Include +# Include set(CE_INCLUDES ${OPENGL_INCLUDE_DIR} ${GLEW_INCLUDE_DIRS} @@ -62,4 +62,4 @@ set(CE_INCLUDES ${GLM_INCLUDE_DIRS} ${ASSIMP_INCLUDE_DIR} PARENT_SCOPE -) +) \ No newline at end of file diff --git a/engine/CMakeLists.txt b/engine/CMakeLists.txt index 9961cb85..4e9d0f6c 100644 --- a/engine/CMakeLists.txt +++ b/engine/CMakeLists.txt @@ -38,17 +38,15 @@ add_test( set(LIBNAME ce_module) + add_library(${LIBNAME} -SHARED -"./ce_module_api.cpp" + SHARED + "./ce_module_api.cpp" ) - target_link_libraries(${LIBNAME} ${CE_LIBS} ) - include_directories(${LIBNAME} ${CMAKE_CURRENT_SOURCE_DIR} ${CE_INCLUDES} -) - +) \ No newline at end of file diff --git a/engine/ce_assets.h b/engine/ce_assets.h index 125161e3..6a23315d 100644 --- a/engine/ce_assets.h +++ b/engine/ce_assets.h @@ -1,28 +1,32 @@ #pragma once -#include #include + #include "rendering/vertex.h" +#include #include namespace ce { struct File { std::string name = ""; }; - struct ShaderFile :public File { + struct ShaderFile : public File { std::string + vertName = "", + geomName = "", + fragName = "", vertex = "", - fragment = "", - geometry = ""; + geometry = "", + fragment = ""; }; - struct TextureFile :public File { + struct TextureFile : public File { unsigned char* data = NULL; int width = 0, height = 0, channelCount = 0; }; - struct MaterialFile :public File { + struct MaterialFile : public File { glm::vec4 ambient = glm::vec4(0.0f), diffuse = glm::vec4(0.0f), @@ -30,12 +34,12 @@ namespace ce { std::string diffuseTex = "missing.png", specularTex = "missing.png", - shader = ""; + shader = NULL; }; - - struct MeshFile:public File { - std::vector vertices; - std::vector indices; - std::vector textures; + + struct MeshFile : public File { + std::vector vertices; + std::vector indices; + std::vector textures; }; } diff --git a/engine/ce_module_api.cpp b/engine/ce_module_api.cpp index 21f1b102..85df827a 100644 --- a/engine/ce_module_api.cpp +++ b/engine/ce_module_api.cpp @@ -6,4 +6,4 @@ * */ -#include "core/module.h" +#include "core/module.h" \ No newline at end of file diff --git a/engine/core/module.h b/engine/core/module.h index 2e614c33..5c0fcbd7 100644 --- a/engine/core/module.h +++ b/engine/core/module.h @@ -2,20 +2,17 @@ * API FOR CREATING MODULES FOR CINNABAR ENGINE */ -#ifndef _CE_MODULE_H_ -#define _CE_MODULE_H_ +#pragma once namespace ce { class Module { - private: - public: - virtual void tick(float deltaTime)=0; + private: + public: + virtual void tick(float deltaTime) = 0; }; - typedef Module* init_module_t(); typedef void delete_module_t(Module*); - } -#define CE_MODULE(X) extern "C" ce::Module* init_module() { return new X;} extern "C" void delete_module(ce::Module* m) { delete m;} - -#endif //_CE_MODULE_H_ +#define CE_MODULE(X) \ + extern "C" ce::Module* init_module() { return new X; } \ + extern "C" void delete_module(ce::Module* m) { delete m; } \ No newline at end of file diff --git a/engine/core/tpnt_log.h b/engine/core/tpnt_log.h index bcefc5b5..0aabbeb2 100644 --- a/engine/core/tpnt_log.h +++ b/engine/core/tpnt_log.h @@ -16,6 +16,7 @@ */ #pragma once +#include #include #include #include diff --git a/engine/main.cpp b/engine/main.cpp index b39e3400..b8e3e1dc 100644 --- a/engine/main.cpp +++ b/engine/main.cpp @@ -1,5 +1,5 @@ // Debugging -#include +#include "core/tpnt_log.h" #include // Core @@ -7,13 +7,13 @@ #include "core/window.h" // Assets -#include "managers/module_manager.h" #include "managers/asset_manager.h" +#include "managers/module_manager.h" #include "stb_image.h" // Maths -#include "math/transform.h" #include "ce_math.h" +#include "math/transform.h" // Rendering #include "ce_render_fundementals.h" @@ -27,61 +27,50 @@ // clang-format off ce::Vertex cubeVerts[] = { // Position Color Texture coord - glm::vec3( 0.5f, 0.5f, -0.5f), glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), glm::vec2(1.0f, 1.0f),// 0 - glm::vec3( 0.5f, -0.5f, -0.5f), glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), glm::vec2(1.0f, 0.0f),// 1 - glm::vec3(-0.5f, -0.5f, -0.5f), glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), glm::vec2(0.0f, 0.0f),// 2 - glm::vec3(-0.5f, 0.5f, -0.5f), glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), glm::vec2(0.0f, 1.0f),// 3 + glm::vec3(-0.5f, -0.5f, -0.5f), glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), glm::vec2(1.0f, 1.0f),// 0 + glm::vec3(-0.5f, 0.5f, -0.5f), glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), glm::vec2(1.0f, 0.0f),// 1 + glm::vec3( 0.5f, -0.5f, -0.5f), glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), glm::vec2(0.0f, 1.0f),// 2 + glm::vec3( 0.5f, 0.5f, -0.5f), glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), glm::vec2(0.0f, 0.0f),// 3 - glm::vec3( 0.5f, 0.5f, 0.5f), glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), glm::vec2(1.0f, 1.0f),// 4 - glm::vec3( 0.5f, -0.5f, 0.5f), glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), glm::vec2(1.0f, 0.0f),// 5 - glm::vec3(-0.5f, -0.5f, 0.5f), glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), glm::vec2(0.0f, 0.0f),// 6 - glm::vec3(-0.5f, 0.5f, 0.5f), glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), glm::vec2(0.0f, 1.0f),// 7 + glm::vec3(-0.5f, -0.5f, 0.5f), glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), glm::vec2(0.0f, 1.0f),// 4 + glm::vec3(-0.5f, 0.5f, 0.5f), glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), glm::vec2(0.0f, 0.0f),// 5 + glm::vec3( 0.5f, -0.5f, 0.5f), glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), glm::vec2(1.0f, 1.0f),// 6 + glm::vec3( 0.5f, 0.5f, 0.5f), glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), glm::vec2(1.0f, 0.0f),// 7 }; ce::Vertex planeVerts[] = { - // Position Color Texture coord - glm::vec3( 1.0f, 0.0f, 1.0f), glm::vec4(0.0f, 1.0f, 0.0f, 1.0f), glm::vec2(1.0f, 1.0f),// 0 - glm::vec3( 1.0f, 0.0f, -1.0f), glm::vec4(0.0f, 1.0f, 0.0f, 1.0f), glm::vec2(1.0f, 0.0f),// 1 - glm::vec3(-1.0f, 0.0f, -1.0f), glm::vec4(0.0f, 1.0f, 0.0f, 1.0f), glm::vec2(0.0f, 0.0f),// 2 - glm::vec3(-1.0f, 0.0f, 1.0f), glm::vec4(0.0f, 1.0f, 0.0f, 1.0f), glm::vec2(0.0f, 1.0f),// 3 + // Position Color Texture coord + glm::vec3(-1.0f, 0.0f, -1.0f), glm::vec4(0.0f, 1.0f, 0.0f, 1.0f), glm::vec2(0.0f, 0.0f),// 0 + glm::vec3(-1.0f, 0.0f, 1.0f), glm::vec4(0.0f, 1.0f, 0.0f, 1.0f), glm::vec2(0.0f, 1.0f),// 1 + glm::vec3( 1.0f, 0.0f, -1.0f), glm::vec4(0.0f, 1.0f, 0.0f, 1.0f), glm::vec2(1.0f, 0.0f),// 2 + glm::vec3( 1.0f, 0.0f, 1.0f), glm::vec4(0.0f, 1.0f, 0.0f, 1.0f), glm::vec2(1.0f, 1.0f),// 3 }; /* * this is a cube - /7-4 - / 6-5 - 3-0 / - 2-1/ + /1-3 + / 0-2 + 5-7 / + 4-6/ + viewed from the front, bottom face here is front */ // clang-format on unsigned cubeVertCount = sizeof(cubeVerts) / sizeof(ce::Vertex); unsigned planeVertCount = sizeof(planeVerts) / sizeof(ce::Vertex); // 7<=>5 // clang-format off -GLuint cubeIndices [] = { - // F - 0, 1, 3, - 1, 2, 3, - // U - 4, 0, 7, - 0, 3, 7, - // L - 3, 2, 7, - 2, 6, 7, - // R - 4, 5, 0, - 5, 1, 0, - // D - 1, 5, 2, - 5, 6, 2, - // B - 7, 6, 4, - 6, 5, 4, +GLuint cubeIndices[] = { + 0, 1, 2, 3, // back, right, front + 6, 7, + 4, 5, + 5, 7, // reset + 7, 3, 5, 1, // top, left, bottom + 4, 0, + 6, 2, }; GLuint planeIndices[] = { - 0, 1, 3, - 1, 2, 3, + 0, 1, 2, 3, }; // clang-format on unsigned cubeIndexCount = sizeof(cubeIndices) / sizeof(GLuint); @@ -89,7 +78,7 @@ unsigned planeIndexCount = sizeof(planeIndices) / sizeof(GLuint); int main(int argc, char* argv[]) { LOG_INFO("Hello World"); - + ce::ModuleManger* moduleManager = new ce::ModuleManger(); ce::Time* time = new ce::Time(); @@ -105,12 +94,12 @@ int main(int argc, char* argv[]) { ce::Mesh* cubeMesh = new ce::Mesh(cubeVerts, cubeVertCount, cubeIndices, cubeIndexCount); ce::Transform* cubePos = new ce::Transform(); ce::Material* cubeMaterial = new ce::Material("basic"); - cubeMaterial->setTexture("hfdshfdshfdkshfdks"); + cubeMaterial->setTexture("uv-map.png"); // Plane ce::Mesh* planeMesh = new ce::Mesh(planeVerts, planeIndexCount, planeIndices, planeVertCount); ce::Transform* planePos = new ce::Transform(); - ce::Material* planeMaterial = new ce::Material("color"); + ce::Material* planeMaterial = new ce::Material("vertColor"); planePos->setPosition(0.0f, -1.0f, 0.0f); planePos->scale(10.0f, 1.0f, 10.0f); @@ -185,9 +174,9 @@ int main(int argc, char* argv[]) { } } } - + moduleManager->tickModules(time->getDeltaTime()); - + // Rotate cube cubePos->roll(25.0f * time->getDeltaTime()); cubePos->yaw(50.0f * time->getDeltaTime()); @@ -217,4 +206,4 @@ int main(int argc, char* argv[]) { delete renderEngine; delete window; return 0; -} +} \ No newline at end of file diff --git a/engine/managers/asset_manager.cpp b/engine/managers/asset_manager.cpp index 0042beca..7027ac8d 100644 --- a/engine/managers/asset_manager.cpp +++ b/engine/managers/asset_manager.cpp @@ -35,22 +35,30 @@ std::string ce::AssetManager::load_text_file(std::string path) { return text; } -ce::ShaderFile ce::AssetManager::getShaderFile(std::string filename) { - std::string path = SHADER_FOLDER + "/" + filename; +ce::ShaderFile ce::AssetManager::getShaderFiles(std::string vert, std::string geom, std::string frag) { ShaderFile shaderFile; - shaderFile.name = filename; + shaderFile.vertName = vert; + shaderFile.geomName = geom; + shaderFile.fragName = frag; - shaderFile.vertex = load_text_file(path + ".vert"); + shaderFile.vertex = load_text_file(SHADER_FOLDER + "/" + vert + ".vert"); if (shaderFile.vertex == "") - shaderFile.vertex = load_text_file(path + ".vs"); + shaderFile.vertex = load_text_file(SHADER_FOLDER + "/" + vert + ".vs"); - shaderFile.fragment = load_text_file(path + ".frag"); + shaderFile.geometry = load_text_file(SHADER_FOLDER + "/" + geom + ".geom"); + if (shaderFile.geometry == "") + shaderFile.geometry = load_text_file(SHADER_FOLDER + "/" + geom + ".gs"); + + shaderFile.fragment = load_text_file(SHADER_FOLDER + "/" + frag + ".frag"); if (shaderFile.fragment == "") - shaderFile.fragment = load_text_file(path + ".fs"); + shaderFile.fragment = load_text_file(SHADER_FOLDER + "/" + frag + ".fs"); - shaderFile.geometry = load_text_file(path + ".geom"); - if (shaderFile.geometry == "") - shaderFile.geometry = load_text_file(path + ".gs"); + if (frag != "") + shaderFile.name = frag; + else if (vert != "") + shaderFile.name = vert; + else + shaderFile.name = geom; return shaderFile; } diff --git a/engine/managers/asset_manager.h b/engine/managers/asset_manager.h index b8218572..72edaac3 100644 --- a/engine/managers/asset_manager.h +++ b/engine/managers/asset_manager.h @@ -15,9 +15,10 @@ namespace ce { static std::string load_text_file(std::string file); public: - static ShaderFile getShaderFile(std::string filename); + static ShaderFile getShaderFile(std::string name) { return getShaderFiles(name, name, name); }; + static ShaderFile getShaderFiles(std::string vert, std::string geom, std::string frag); static TextureFile getTextureFile(std::string filename); - static void freeTextureFile(ce::TextureFile textureFile); + static void freeTextureFile(TextureFile textureFile); static MeshFile getMeshFile(std::string filename); }; diff --git a/engine/managers/module_manager.cpp b/engine/managers/module_manager.cpp index 75650a6d..1a12d1bf 100644 --- a/engine/managers/module_manager.cpp +++ b/engine/managers/module_manager.cpp @@ -1,21 +1,20 @@ #include "module_manager.h" +#include #include -#include #include -#include #include +#include #define LIB_EXT so -void ce::ModuleManger::loadModules() -{ +void ce::ModuleManger::loadModules() { std::string path = "./" + MODULE_FOLDER; - for(const auto & entry : std::filesystem::directory_iterator(path)) { + for (const auto& entry : std::filesystem::directory_iterator(path)) { const char* path = entry.path().c_str(); LOG_INFO(path); - void * lib = dlopen(path,RTLD_LAZY); - if(!lib) { + void* lib = dlopen(path, RTLD_LAZY); + if (!lib) { LOG_ERROR(dlerror()); continue; } @@ -23,46 +22,42 @@ void ce::ModuleManger::loadModules() dlerror(); const char* error; LOG_ERROR("Loading Symbols for: " + path); - //Get a function called "Hello" - init_module_t* init_module = (init_module_t*) dlsym(lib,"init_module"); - //Handle any errors + // Get a function called "Hello" + init_module_t* init_module = (init_module_t*)dlsym(lib, "init_module"); + // Handle any errors error = dlerror(); - if(error) { + if (error) { LOG_ERROR(dlerror()); dlclose(lib); continue; } - delete_module_t* delete_module = (delete_module_t*) dlsym(lib,"delete_module"); + delete_module_t* delete_module = (delete_module_t*)dlsym(lib, "delete_module"); error = dlerror(); - if(error) { + if (error) { LOG_ERROR(dlerror()); dlclose(lib); continue; } Module* module = init_module(); - m_modules.push_back({module,lib,init_module,delete_module}); + m_modules.push_back({module, lib, init_module, delete_module}); //delete_module(module); - ///dlclose(lib); + //dlclose(lib); } } -ce::ModuleManger::ModuleManger() -{ +ce::ModuleManger::ModuleManger() { loadModules(); } -ce::ModuleManger::~ModuleManger() -{ - for(int i=0;itick(deltaTime); -} - - +void ce::ModuleManger::tickModules(float deltaTime) { + for (int i = 0; i < m_modules.size(); i++) + m_modules[i].module->tick(deltaTime); +} \ No newline at end of file diff --git a/engine/managers/module_manager.h b/engine/managers/module_manager.h index c84b2863..1ec6d43d 100644 --- a/engine/managers/module_manager.h +++ b/engine/managers/module_manager.h @@ -1,5 +1,4 @@ -#ifndef _MODULE_MANAGER_H_ -#define _MODULE_MANAGER_H_ +#pragma once #include #include @@ -7,27 +6,25 @@ #include namespace ce { - class ModuleManger { - private: + private: struct ModuleRef { Module* module; void* lib; init_module_t* inti_module; delete_module_t* delete_module; }; - + inline static const std::string MODULE_FOLDER = "modules"; - + std::vector m_modules; - + void loadModules(); - public: + + public: ModuleManger(); ~ModuleManger(); - + void tickModules(float deltaTime); }; -} - -#endif // _MODULE_MANAGER_H_ +} \ No newline at end of file diff --git a/engine/rendering/material.h b/engine/rendering/material.h index 0c03f49f..c6ba2dd6 100644 --- a/engine/rendering/material.h +++ b/engine/rendering/material.h @@ -15,13 +15,18 @@ namespace ce { Texture* m_texture; public: - Material(const char* shader):Material(new Shader(shader)){} + Material(const char* name, std::map options = {}) + : Material(new Shader(name, options)) {} + Material(const char* vertName, const char* fragName, std::map options = {}) + : Material(new Shader(vertName, fragName, options)) {} + Material(const char* vertName, const char* geomName, const char* fragName, std::map options = {}) + : Material(new Shader(vertName, geomName, fragName, options)) {} Material(Shader* shader); ~Material(); void update(); Shader* getShader() { return m_shader; } - void setTexture(const char* texture) {setTexture(new Texture(texture));} + void setTexture(const char* texture) { setTexture(new Texture(texture)); } void setTexture(Texture* texture) { m_texture = texture; } void bind(); diff --git a/engine/rendering/render_engine.cpp b/engine/rendering/render_engine.cpp index 9e427ae7..924aa59b 100644 --- a/engine/rendering/render_engine.cpp +++ b/engine/rendering/render_engine.cpp @@ -6,7 +6,7 @@ void ce::RenderEngine::clear() { } void ce::RenderEngine::render(unsigned count) { - glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_INT, 0); + glDrawElements(GL_TRIANGLE_STRIP, count, GL_UNSIGNED_INT, 0); } void ce::RenderEngine::bind(RenderCommand command) { diff --git a/engine/rendering/shader.cpp b/engine/rendering/shader.cpp index 4b26ae39..35261e84 100644 --- a/engine/rendering/shader.cpp +++ b/engine/rendering/shader.cpp @@ -1,7 +1,9 @@ #include "shader.h" + #include #include #include +#include void checkCompileErrors(GLuint shader, GLint shaderType) { std::string type; @@ -51,6 +53,24 @@ int createShader(GLenum type, std::string source) { return shader; } +std::string setupShaderDefs(std::string source, std::map options) { + std::string shader = source; + for (std::pair option : options) { + size_t defPos = shader.find("#define " + option.first); + if (defPos == std::string::npos) { + LOG_ERROR("Invalid Option: " + option.first); + continue; + } + size_t defValuePos = defPos + option.first.length() + 9; // 8 is length of "#define " and space after name + size_t lineEnd = shader.find('\n', defValuePos); + if (lineEnd == std::string::npos) + lineEnd = shader.length(); + + shader = shader.replace(defValuePos, lineEnd - defValuePos, option.second); + } + return shader; +} + void ce::Shader::linkProgram( int vertexShader, int fragmentShader, int geometryShader) { if (vertexShader != 0) @@ -85,20 +105,20 @@ int ce::Shader::registerUniform(std::string name) { return location; } -ce::Shader::Shader(const char* name) +ce::Shader::Shader(const char* vertName, const char* geomName, const char* fragName, std::map options) : m_program(glCreateProgram()) { - ShaderFile shaderFile = ce::AssetManager::getShaderFile(name); + ShaderFile shaderFile = ce::AssetManager::getShaderFiles(vertName, geomName, fragName); int vertexShader = 0; int fragmentShader = 0; int geometryShader = 0; if (shaderFile.vertex != "") - vertexShader = createShader(GL_VERTEX_SHADER, shaderFile.vertex); + vertexShader = createShader(GL_VERTEX_SHADER, setupShaderDefs(shaderFile.vertex, options)); if (shaderFile.fragment != "") - fragmentShader = createShader(GL_FRAGMENT_SHADER, shaderFile.fragment); + fragmentShader = createShader(GL_FRAGMENT_SHADER, setupShaderDefs(shaderFile.fragment, options)); if (shaderFile.geometry != "") - geometryShader = createShader(GL_GEOMETRY_SHADER, shaderFile.geometry); + geometryShader = createShader(GL_GEOMETRY_SHADER, setupShaderDefs(shaderFile.geometry, options)); linkProgram(vertexShader, fragmentShader, vertexShader); int attrCount = 0, uniformCount = 0; diff --git a/engine/rendering/shader.h b/engine/rendering/shader.h index 4d1a6d80..b59f529d 100644 --- a/engine/rendering/shader.h +++ b/engine/rendering/shader.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include @@ -25,7 +26,11 @@ namespace ce { registerUniform(std::string name); public: - Shader(const char* name); + Shader(const char* name, std::map options = {}) + : Shader(name, name, name, options) {}; + Shader(const char* vertName, const char* fragName, std::map options = {}) + : Shader(vertName, NULL, fragName, options) {}; + Shader(const char* vertName, const char* geoName, const char* fragName, std::map options = {}); ~Shader(); void bind(), unbind(); diff --git a/res/shaders/affine.frag b/res/shaders/affine.frag new file mode 100644 index 00000000..b429b7ac --- /dev/null +++ b/res/shaders/affine.frag @@ -0,0 +1,18 @@ +#version 330 core + +uniform sampler2D uTex; + +struct Material { + sampler2D texture; +}; + +uniform Material material; + +in vec4 vColor; +in vec2 vTexCoord; + +out vec4 fColor; + +void main() { + fColor = texture(material.texture, vTexCoord) * vColor; +} \ No newline at end of file diff --git a/res/shaders/affine.vert b/res/shaders/affine.vert new file mode 100644 index 00000000..82c77dab --- /dev/null +++ b/res/shaders/affine.vert @@ -0,0 +1,25 @@ +#version 330 core + +struct Transform { + mat4 model; + mat4 view; + mat4 proj; +}; + +uniform Transform transform; + +in vec3 aPos; +in vec4 aColor; +in vec2 aTexCoord; + +out vec4 vColor; +out vec2 vTexCoord; + + +void main() { + vColor = aColor; + vTexCoord = aTexCoord; + + gl_Position = transform.proj * transform.view * transform.model * vec4(aPos, 1.); + gl_Position /= gl_Position.w; +} \ No newline at end of file diff --git a/res/shaders/basic.frag b/res/shaders/basic.frag index f3276e35..5c5cc877 100644 --- a/res/shaders/basic.frag +++ b/res/shaders/basic.frag @@ -13,5 +13,5 @@ in vec2 vTexCoord; out vec4 fColor; void main() { - fColor = texture(material.texture,vTexCoord) * vColor; + fColor = texture(material.texture, vTexCoord) * vColor; } \ No newline at end of file diff --git a/res/shaders/basic.vert b/res/shaders/basic.vert index d36a6900..f1947418 100644 --- a/res/shaders/basic.vert +++ b/res/shaders/basic.vert @@ -20,5 +20,5 @@ void main() { vColor = aColor; vTexCoord = aTexCoord; - gl_Position = transform.proj * transform.view * transform.model * vec4(aPos, 1.0f); + gl_Position = transform.proj * transform.view * transform.model * vec4(aPos, 1.); } \ No newline at end of file diff --git a/res/shaders/color.frag b/res/shaders/vertColor.frag similarity index 100% rename from res/shaders/color.frag rename to res/shaders/vertColor.frag diff --git a/res/shaders/color.vert b/res/shaders/vertColor.vert similarity index 87% rename from res/shaders/color.vert rename to res/shaders/vertColor.vert index d36a6900..f1947418 100644 --- a/res/shaders/color.vert +++ b/res/shaders/vertColor.vert @@ -20,5 +20,5 @@ void main() { vColor = aColor; vTexCoord = aTexCoord; - gl_Position = transform.proj * transform.view * transform.model * vec4(aPos, 1.0f); + gl_Position = transform.proj * transform.view * transform.model * vec4(aPos, 1.); } \ No newline at end of file diff --git a/res/textures/wall.png b/res/textures/floor.png similarity index 100% rename from res/textures/wall.png rename to res/textures/floor.png