From 0fe50aa1c75271a0f896d1731df9de37c03f268c Mon Sep 17 00:00:00 2001 From: SArpnt <36542932+SArpnt@users.noreply.github.com> Date: Wed, 17 Feb 2021 22:36:19 -0500 Subject: [PATCH 01/13] another new TODO proposal --- README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1dbfd3dc..eef0cb3a 100644 --- a/README.md +++ b/README.md @@ -78,16 +78,19 @@ 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) - [ ] Skybox + - [ ] Sprites (i think you can do GL_POINTS and draw the images in a frag shader) - [ ] Lights + - [ ] Text - [ ] Input System - [ ] Events System - [ ] Collision - [ ] Gravity - - [ ] Text - [ ] Layers - [ ] GUI - [ ] States @@ -97,5 +100,5 @@ Pull requests are welcome. For major changes, please open an issue first to disc - [ ] VR Support - [ ] Scene Graph - [ ] XML based scene graph import - - [ ] Test ON Windows + - [ ] Test on Windows - [ ] Port to Emscripten \ No newline at end of file From d2b35c770e431bd1b395765aa94c6c9be4b9a8cd Mon Sep 17 00:00:00 2001 From: SArpnt <36542932+SArpnt@users.noreply.github.com> Date: Wed, 17 Feb 2021 22:37:04 -0500 Subject: [PATCH 02/13] shader improvements --- engine/ce_assets.h | 17 ++++++++++------- engine/main.cpp | 2 +- engine/managers/asset_manager.cpp | 28 ++++++++++++++++++---------- engine/managers/asset_manager.h | 3 ++- engine/rendering/material.h | 9 +++++++-- engine/rendering/shader.cpp | 16 ++++++++++++++-- engine/rendering/shader.h | 7 ++++++- res/shaders/vertColor.frag | 17 +++++++++++++++++ res/shaders/vertColor.vert | 24 ++++++++++++++++++++++++ 9 files changed, 99 insertions(+), 24 deletions(-) create mode 100644 res/shaders/vertColor.frag create mode 100644 res/shaders/vertColor.vert diff --git a/engine/ce_assets.h b/engine/ce_assets.h index 3b33619d..f498ca8c 100644 --- a/engine/ce_assets.h +++ b/engine/ce_assets.h @@ -1,26 +1,29 @@ #pragma once -#include #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), @@ -28,6 +31,6 @@ namespace ce { std::string diffuseTex = "missing.png", specularTex = "missing.png", - shader = ""; + shader = NULL; }; } \ No newline at end of file diff --git a/engine/main.cpp b/engine/main.cpp index 29ec71e4..55f6e728 100644 --- a/engine/main.cpp +++ b/engine/main.cpp @@ -107,7 +107,7 @@ int main(int argc, char* argv[]) { // 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); diff --git a/engine/managers/asset_manager.cpp b/engine/managers/asset_manager.cpp index 69f8bdeb..5c380cde 100644 --- a/engine/managers/asset_manager.cpp +++ b/engine/managers/asset_manager.cpp @@ -30,22 +30,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 0638cfb2..b4c6685f 100644 --- a/engine/managers/asset_manager.h +++ b/engine/managers/asset_manager.h @@ -14,7 +14,8 @@ 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 ce::TextureFile getTextureFile(std::string filename); static void freeTextureFile(ce::TextureFile textureFile); }; 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/shader.cpp b/engine/rendering/shader.cpp index 4b26ae39..9ea034c6 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; @@ -85,14 +87,24 @@ 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; + /** + * TODO: shader #defines done from options, so that changes can be made to the shader with the preprocessor + * just dump defines at the start of the file like: + * {"F_SIDED", "both"} + * {"V_JITTER", "3"} + * #define F_SIDED both + * #define V_JITTER 3 + * seperate options for each file shouldn't be needed, just prefix with V, G, F + */ + if (shaderFile.vertex != "") vertexShader = createShader(GL_VERTEX_SHADER, shaderFile.vertex); if (shaderFile.fragment != "") 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/vertColor.frag b/res/shaders/vertColor.frag new file mode 100644 index 00000000..ece60953 --- /dev/null +++ b/res/shaders/vertColor.frag @@ -0,0 +1,17 @@ +#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 = vColor; +} \ No newline at end of file diff --git a/res/shaders/vertColor.vert b/res/shaders/vertColor.vert new file mode 100644 index 00000000..d36a6900 --- /dev/null +++ b/res/shaders/vertColor.vert @@ -0,0 +1,24 @@ +#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.0f); +} \ No newline at end of file From 9d0946cecaa346d1250e02998a7e4c2874fb5e71 Mon Sep 17 00:00:00 2001 From: SArpnt <36542932+SArpnt@users.noreply.github.com> Date: Wed, 17 Feb 2021 22:37:15 -0500 Subject: [PATCH 03/13] rename texture --- res/textures/{wall.png => floor.png} | Bin 1 file changed, 0 insertions(+), 0 deletions(-) rename res/textures/{wall.png => floor.png} (100%) 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 From 7786106e4b9508547b54725092c715592a7af670 Mon Sep 17 00:00:00 2001 From: SArpnt <36542932+SArpnt@users.noreply.github.com> Date: Thu, 18 Feb 2021 08:08:13 -0500 Subject: [PATCH 04/13] not sure why these didn't commit before --- res/shaders/color.frag | 17 ----------------- res/shaders/color.vert | 24 ------------------------ 2 files changed, 41 deletions(-) delete mode 100644 res/shaders/color.frag delete mode 100644 res/shaders/color.vert diff --git a/res/shaders/color.frag b/res/shaders/color.frag deleted file mode 100644 index ece60953..00000000 --- a/res/shaders/color.frag +++ /dev/null @@ -1,17 +0,0 @@ -#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 = vColor; -} \ No newline at end of file diff --git a/res/shaders/color.vert b/res/shaders/color.vert deleted file mode 100644 index d36a6900..00000000 --- a/res/shaders/color.vert +++ /dev/null @@ -1,24 +0,0 @@ -#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.0f); -} \ No newline at end of file From 8b541cd2354e065ebc8448455e5220e2ca8467ec Mon Sep 17 00:00:00 2001 From: SArpnt <36542932+SArpnt@users.noreply.github.com> Date: Thu, 18 Feb 2021 09:50:16 -0500 Subject: [PATCH 05/13] small cleanup --- dep/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 From 24133fa937cb8a06b804774287b30b0110de19f2 Mon Sep 17 00:00:00 2001 From: SArpnt <36542932+SArpnt@users.noreply.github.com> Date: Thu, 18 Feb 2021 09:50:20 -0500 Subject: [PATCH 06/13] TODO proposal again --- README.md | 62 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 56 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index eef0cb3a..5f7f61f0 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 @@ -83,16 +83,66 @@ Pull requests are welcome. For major changes, please open an issue first to disc - [ ] Normal maps - [ ] Matcaps (SArpnt will do this) - [ ] Simple object classes (combine assets and automatically manage render commands) + - [ ] Depth manipulation - [ ] Skybox - [ ] 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 - [ ] Text + - [ ] 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 + +### Game engine (make a seperate project) + - [ ] Input System - [ ] Events System - - [ ] Collision - - [ ] Gravity - - [ ] Layers - - [ ] GUI - [ ] States - [ ] Map management - [ ] Make an Actual Game From 2241142b75a9985df73765946f13354a922f69ad Mon Sep 17 00:00:00 2001 From: SArpnt <36542932+SArpnt@users.noreply.github.com> Date: Thu, 18 Feb 2021 10:58:42 -0500 Subject: [PATCH 07/13] removed unneccecary lines --- engine/CMakeLists.txt | 2 +- engine/main.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/engine/CMakeLists.txt b/engine/CMakeLists.txt index ca74b50d..41b09782 100644 --- a/engine/CMakeLists.txt +++ b/engine/CMakeLists.txt @@ -34,4 +34,4 @@ add_test( NAME run COMMAND ${NAME} WORKING_DIRECTORY "$" -) +) \ No newline at end of file diff --git a/engine/main.cpp b/engine/main.cpp index facf7fb8..4016bcc2 100644 --- a/engine/main.cpp +++ b/engine/main.cpp @@ -214,4 +214,4 @@ int main(int argc, char* argv[]) { delete renderEngine; delete window; return 0; -} +} \ No newline at end of file From a9d82dbcbb3b9f23f2f908e0b005fd10fc3bf9ee Mon Sep 17 00:00:00 2001 From: SArpnt <36542932+SArpnt@users.noreply.github.com> Date: Thu, 18 Feb 2021 11:12:09 -0500 Subject: [PATCH 08/13] more readme TODO --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 5f7f61f0..993c80e9 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,8 @@ Pull requests are welcome. For major changes, please open an issue first to disc - [ ] Simple object classes (combine assets and automatically manage render commands) - [ ] Depth manipulation - [ ] Skybox + - [ ] 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 From d197474cc3a6f3811ea5b26ca7a78317bd2e4bb6 Mon Sep 17 00:00:00 2001 From: SArpnt <36542932+SArpnt@users.noreply.github.com> Date: Thu, 18 Feb 2021 11:35:22 -0500 Subject: [PATCH 09/13] affine texture mapping shader and small bugfixes --- engine/core/tpnt_log.h | 1 + engine/main.cpp | 12 ++++++------ res/shaders/affine.frag | 20 ++++++++++++++++++++ res/shaders/affine.vert | 25 +++++++++++++++++++++++++ res/shaders/basic.frag | 2 +- res/shaders/basic.vert | 2 +- res/shaders/vertColor.vert | 2 +- 7 files changed, 55 insertions(+), 9 deletions(-) create mode 100644 res/shaders/affine.frag create mode 100644 res/shaders/affine.vert 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 4016bcc2..1a11ed13 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" @@ -89,7 +89,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(); @@ -104,8 +104,8 @@ int main(int argc, char* argv[]) { // Cube 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"); + ce::Material* cubeMaterial = new ce::Material("affine"); + cubeMaterial->setTexture("uv-map.png"); // Plane ce::Mesh* planeMesh = new ce::Mesh(planeVerts, planeIndexCount, planeIndices, planeVertCount); diff --git a/res/shaders/affine.frag b/res/shaders/affine.frag new file mode 100644 index 00000000..372e691b --- /dev/null +++ b/res/shaders/affine.frag @@ -0,0 +1,20 @@ +#version 330 core +#define F_DEFTEST 1 +//===PLACE_OPTIONS=== + +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 + .5 * F_DEFTEST) * 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/vertColor.vert b/res/shaders/vertColor.vert index d36a6900..f1947418 100644 --- a/res/shaders/vertColor.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 From b0f994156eb7c6be9905cc57d94061c3e2f00f09 Mon Sep 17 00:00:00 2001 From: SArpnt <36542932+SArpnt@users.noreply.github.com> Date: Thu, 18 Feb 2021 16:34:53 -0500 Subject: [PATCH 10/13] shader options with #define --- engine/main.cpp | 2 +- engine/rendering/shader.cpp | 36 +++++++++++++++++++++++------------- res/shaders/affine.frag | 4 +--- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/engine/main.cpp b/engine/main.cpp index 1a11ed13..3f3a8d77 100644 --- a/engine/main.cpp +++ b/engine/main.cpp @@ -104,7 +104,7 @@ int main(int argc, char* argv[]) { // Cube ce::Mesh* cubeMesh = new ce::Mesh(cubeVerts, cubeVertCount, cubeIndices, cubeIndexCount); ce::Transform* cubePos = new ce::Transform(); - ce::Material* cubeMaterial = new ce::Material("affine"); + ce::Material* cubeMaterial = new ce::Material("basic"); cubeMaterial->setTexture("uv-map.png"); // Plane diff --git a/engine/rendering/shader.cpp b/engine/rendering/shader.cpp index 9ea034c6..aa28c809 100644 --- a/engine/rendering/shader.cpp +++ b/engine/rendering/shader.cpp @@ -53,6 +53,26 @@ 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); + } + + std::cout << shader << std::endl; + return shader; +} + void ce::Shader::linkProgram( int vertexShader, int fragmentShader, int geometryShader) { if (vertexShader != 0) @@ -95,22 +115,12 @@ ce::Shader::Shader(const char* vertName, const char* geomName, const char* fragN int fragmentShader = 0; int geometryShader = 0; - /** - * TODO: shader #defines done from options, so that changes can be made to the shader with the preprocessor - * just dump defines at the start of the file like: - * {"F_SIDED", "both"} - * {"V_JITTER", "3"} - * #define F_SIDED both - * #define V_JITTER 3 - * seperate options for each file shouldn't be needed, just prefix with V, G, F - */ - 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/res/shaders/affine.frag b/res/shaders/affine.frag index 372e691b..b429b7ac 100644 --- a/res/shaders/affine.frag +++ b/res/shaders/affine.frag @@ -1,6 +1,4 @@ #version 330 core -#define F_DEFTEST 1 -//===PLACE_OPTIONS=== uniform sampler2D uTex; @@ -16,5 +14,5 @@ in vec2 vTexCoord; out vec4 fColor; void main() { - fColor = texture(material.texture,vTexCoord + .5 * F_DEFTEST) * vColor; + fColor = texture(material.texture, vTexCoord) * vColor; } \ No newline at end of file From dbdd2df513b199b13661313d2243aa3b2f686714 Mon Sep 17 00:00:00 2001 From: SArpnt <36542932+SArpnt@users.noreply.github.com> Date: Thu, 18 Feb 2021 17:02:40 -0500 Subject: [PATCH 11/13] triangle strips --- README.md | 2 +- engine/main.cpp | 65 +++++++++++++----------------- engine/rendering/render_engine.cpp | 2 +- 3 files changed, 29 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index 993c80e9..cf43e881 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ Pull requests are welcome. For major changes, please open an issue first to disc - [ ] Simple object classes (combine assets and automatically manage render commands) - [ ] Depth manipulation - [ ] Skybox - - [ ] Render triangle strips + - [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 diff --git a/engine/main.cpp b/engine/main.cpp index 3f3a8d77..151f31bf 100644 --- a/engine/main.cpp +++ b/engine/main.cpp @@ -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); 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) { From c4592d1954a3629a0557d9b38ba97db3e72ca63a Mon Sep 17 00:00:00 2001 From: SArpnt <36542932+SArpnt@users.noreply.github.com> Date: Thu, 18 Feb 2021 17:03:07 -0500 Subject: [PATCH 12/13] removed debug line i forgot about --- engine/rendering/shader.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/engine/rendering/shader.cpp b/engine/rendering/shader.cpp index aa28c809..35261e84 100644 --- a/engine/rendering/shader.cpp +++ b/engine/rendering/shader.cpp @@ -68,8 +68,6 @@ std::string setupShaderDefs(std::string source, std::map Date: Thu, 18 Feb 2021 22:24:39 +0000 Subject: [PATCH 13/13] Update README.md --- README.md | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index cf43e881..4858ea63 100644 --- a/README.md +++ b/README.md @@ -141,16 +141,19 @@ Pull requests are welcome. For major changes, please open an issue first to disc - [ ] Test on Windows - [ ] Port to Emscripten -### Game engine (make a seperate project) - + - [ ] VR Support - [ ] Input System - - [ ] Events 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 + # Platforms - [ ] Test on Windows - - [ ] Port to Emscripten \ No newline at end of file + - [ ] Port to Emscripten