diff --git a/assets/model/monitor_graphics.fbx b/assets/model/monitor_graphics.fbx deleted file mode 100644 index 922e836..0000000 --- a/assets/model/monitor_graphics.fbx +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:6ace8732e2bc0c4bea4f0586f181b528128dcec35ced129ebade356b0203ef86 -size 42268 diff --git a/assets/model/pump_switch_1.fbx b/assets/model/pump_switch_1.fbx deleted file mode 100644 index 7dc1142..0000000 --- a/assets/model/pump_switch_1.fbx +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:51fdc2455d2ef9ae46f6ac45ae32bd68d024a6250aa3895b5800f8afaef87bad -size 31724 diff --git a/assets/model/pump_switch_2.fbx b/assets/model/pump_switch_2.fbx deleted file mode 100644 index 4068732..0000000 --- a/assets/model/pump_switch_2.fbx +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:4f91df7bc962adc9fe7aff4cde58b4610ee0be9ada26e1e24cae12e842fd64e2 -size 31724 diff --git a/assets/model/pump_switch_3.fbx b/assets/model/pump_switch_3.fbx deleted file mode 100644 index 9220cd7..0000000 --- a/assets/model/pump_switch_3.fbx +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:c5103e5d3c2d48fe8f21c51d92ec7f1daf38529dd38e103d59a6bbc88abceecc -size 31724 diff --git a/assets/model/reactor_core_interface_cell.scad b/assets/model/reactor_core_interface_cell.scad deleted file mode 100644 index 317d259..0000000 --- a/assets/model/reactor_core_interface_cell.scad +++ /dev/null @@ -1,3 +0,0 @@ - -linear_extrude(0.0001) -square([1, 1], center = true); diff --git a/assets/model/reactor_core_interface_circle.scad b/assets/model/reactor_core_interface_circle.scad deleted file mode 100644 index 4bdc405..0000000 --- a/assets/model/reactor_core_interface_circle.scad +++ /dev/null @@ -1,10 +0,0 @@ - -$fn = 256; - -linear_extrude(0.0001) -translate([0.5, 0.5]) -difference() -{ - circle(d = 0.81); - circle(d = 0.8); -} diff --git a/assets/model/resistor_bank_switch.fbx b/assets/model/resistor_bank_switch.fbx deleted file mode 100644 index 4b8dda1..0000000 --- a/assets/model/resistor_bank_switch.fbx +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:43649e014384d821d81dfd6df6fa903c6b1345b3da76f4ffc325d60fa049e646 -size 31724 diff --git a/assets/model/synchroscope_dial.fbx b/assets/model/synchroscope_dial.fbx deleted file mode 100644 index 0d263b2..0000000 --- a/assets/model/synchroscope_dial.fbx +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:032a5c320e87afe6bc994b74dadc9dc2bbb27040f58ffe8c3b9bf190d54b9874 -size 31500 diff --git a/assets/model/turbine_breaker_switch.fbx b/assets/model/turbine_breaker_switch.fbx deleted file mode 100644 index 0f6a765..0000000 --- a/assets/model/turbine_breaker_switch.fbx +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:5d7bc022f495d34009a78d9c5e4e932c31d7570d352eb5e57efc9bc705dcd9b8 -size 31740 diff --git a/assets/model/turbine_valve_bypass_switch.fbx b/assets/model/turbine_valve_bypass_switch.fbx deleted file mode 100644 index 78828c7..0000000 --- a/assets/model/turbine_valve_bypass_switch.fbx +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:ce3c7ad6594ed7a902276fb6fea0820d6ce1a4394db5d5c6aca5b3ac31a2e7f1 -size 26220 diff --git a/assets/model/turbine_valve_inlet_switch.fbx b/assets/model/turbine_valve_inlet_switch.fbx deleted file mode 100644 index c8df4b2..0000000 --- a/assets/model/turbine_valve_inlet_switch.fbx +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:1234cbecb0a231a4205b6f8fcc2d8ba1b6efe6d40cb279446e81751dfe941158 -size 3027260 diff --git a/assets/scene.bin b/assets/scene.bin deleted file mode 100644 index 637316e..0000000 --- a/assets/scene.bin +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:37c206c103088402c4074a25888f7b61f4890a3614b4bcabcb3ff8793f8c7448 -size 3318000 diff --git a/assets/scene.fbx b/assets/scene.fbx deleted file mode 100644 index c5bc137..0000000 --- a/assets/scene.fbx +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:d03ebaa76e68a97f909cab312abbc9c22897d77f80eee6542172d53afde6c70f -size 3025052 diff --git a/assets/shader/light.fsh b/assets/shader/light.fsh new file mode 100644 index 0000000..7d36ad3 --- /dev/null +++ b/assets/shader/light.fsh @@ -0,0 +1,13 @@ + +#version 460 core + +in vec4 frag_pos; +out vec4 frag_colour; + +void main() +{ + float distance = length(frag_pos); + frag_colour = vec4(vec3(distance / 50.0f), 1); + gl_FragDepth = distance / 50.0f; +} + diff --git a/assets/shader/light.gsh b/assets/shader/light.gsh new file mode 100644 index 0000000..6c57360 --- /dev/null +++ b/assets/shader/light.gsh @@ -0,0 +1,28 @@ + +#version 460 core + +layout (triangles) in; +layout (triangle_strip, max_vertices=18) out; + +uniform mat4 shadow_mats[6]; + +out vec4 frag_pos; + +void main() +{ + for(int i = 0; i < 6; i++) + { + gl_Layer = i; + + for(int j = 0; j < 3; j++) + { + frag_pos = gl_in[j].gl_Position; + gl_Position = shadow_mats[i] * frag_pos; + + EmitVertex(); + } + + EndPrimitive(); + } +} + diff --git a/assets/shader/light.vsh b/assets/shader/light.vsh new file mode 100644 index 0000000..991ba7f --- /dev/null +++ b/assets/shader/light.vsh @@ -0,0 +1,13 @@ + +#version 460 core + +layout (location = 2) in vec4 aPos; + +uniform mat4 model; +uniform mat4 camera; + +void main() +{ + gl_Position = camera * model * aPos; +} + diff --git a/assets/test.bin b/assets/test.bin deleted file mode 100644 index a5181ed..0000000 --- a/assets/test.bin +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:e357caf37d9510a004b35c2bc9e73eb92a5f16e65a1a6a7f7969add40c3ba6f6 -size 25320 diff --git a/assets/test.fbx b/assets/test.fbx deleted file mode 100644 index b74dc41..0000000 --- a/assets/test.fbx +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:0c222b009a0f14c0d8c1bfea3a449c45f34b758aee73282baf149e05c9dfd0ff -size 31500 diff --git a/assets/test.glb b/assets/test.glb deleted file mode 100644 index 9a42769..0000000 --- a/assets/test.glb +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:f83c9f4a59566dcb497c60c7470a92979eb610d09171f8f4471d5b284230d19c -size 29164 diff --git a/assets/test.gltf b/assets/test.gltf deleted file mode 100644 index 09cb0bd..0000000 --- a/assets/test.gltf +++ /dev/null @@ -1,382 +0,0 @@ -{ - "asset":{ - "generator":"Khronos glTF Blender I/O v4.0.44", - "version":"2.0" - }, - "scene":0, - "scenes":[ - { - "extras":{ - "SimpleBake_Props":{}, - "bake_to_vertex_color_props":{} - }, - "name":"Scene", - "nodes":[ - 0, - 1, - 2, - 3 - ] - } - ], - "nodes":[ - { - "mesh":0, - "name":"Cylinder", - "translation":[ - 0, - 0, - 0.5 - ] - }, - { - "mesh":1, - "name":"Cylinder.001", - "translation":[ - 1, - 0, - 0.5 - ] - }, - { - "mesh":2, - "name":"Cylinder.002", - "translation":[ - 3, - 0, - 0.5 - ] - }, - { - "mesh":3, - "name":"Cylinder.003", - "translation":[ - 2, - 0, - 0.5 - ] - } - ], - "materials":[ - { - "doubleSided":true, - "name":"Material.006", - "pbrMetallicRoughness":{ - "baseColorFactor":[ - 0.800000011920929, - 0.800000011920929, - 0.800000011920929, - 1 - ], - "metallicFactor":0, - "roughnessFactor":0.75 - } - }, - { - "doubleSided":true, - "name":"Material.005", - "pbrMetallicRoughness":{ - "baseColorFactor":[ - 0.800000011920929, - 0.800000011920929, - 0.800000011920929, - 1 - ], - "metallicFactor":0, - "roughnessFactor":0.5 - } - }, - { - "doubleSided":true, - "name":"Material.003", - "pbrMetallicRoughness":{ - "baseColorFactor":[ - 0.800000011920929, - 0.800000011920929, - 0.800000011920929, - 1 - ], - "metallicFactor":0, - "roughnessFactor":0.125 - } - }, - { - "doubleSided":true, - "name":"Material.004", - "pbrMetallicRoughness":{ - "baseColorFactor":[ - 0.800000011920929, - 0.800000011920929, - 0.800000011920929, - 1 - ], - "metallicFactor":0, - "roughnessFactor":0.25 - } - } - ], - "meshes":[ - { - "name":"Cylinder", - "primitives":[ - { - "attributes":{ - "POSITION":0, - "NORMAL":1, - "TEXCOORD_0":2 - }, - "indices":3, - "material":0 - } - ] - }, - { - "name":"Cylinder.001", - "primitives":[ - { - "attributes":{ - "POSITION":4, - "NORMAL":5, - "TEXCOORD_0":6 - }, - "indices":3, - "material":1 - } - ] - }, - { - "name":"Cylinder.002", - "primitives":[ - { - "attributes":{ - "POSITION":7, - "NORMAL":8, - "TEXCOORD_0":9 - }, - "indices":3, - "material":2 - } - ] - }, - { - "name":"Cylinder.003", - "primitives":[ - { - "attributes":{ - "POSITION":10, - "NORMAL":11, - "TEXCOORD_0":12 - }, - "indices":3, - "material":3 - } - ] - } - ], - "accessors":[ - { - "bufferView":0, - "componentType":5126, - "count":192, - "max":[ - 0.20000000298023224, - 0.20000000298023224, - 0.5 - ], - "min":[ - -0.20000000298023224, - -0.20000000298023224, - -0.5 - ], - "type":"VEC3" - }, - { - "bufferView":1, - "componentType":5126, - "count":192, - "type":"VEC3" - }, - { - "bufferView":2, - "componentType":5126, - "count":192, - "type":"VEC2" - }, - { - "bufferView":3, - "componentType":5123, - "count":372, - "type":"SCALAR" - }, - { - "bufferView":4, - "componentType":5126, - "count":192, - "max":[ - 0.20000000298023224, - 0.20000000298023224, - 0.5 - ], - "min":[ - -0.20000000298023224, - -0.20000000298023224, - -0.5 - ], - "type":"VEC3" - }, - { - "bufferView":5, - "componentType":5126, - "count":192, - "type":"VEC3" - }, - { - "bufferView":6, - "componentType":5126, - "count":192, - "type":"VEC2" - }, - { - "bufferView":7, - "componentType":5126, - "count":192, - "max":[ - 0.20000000298023224, - 0.20000000298023224, - 0.5 - ], - "min":[ - -0.20000000298023224, - -0.20000000298023224, - -0.5 - ], - "type":"VEC3" - }, - { - "bufferView":8, - "componentType":5126, - "count":192, - "type":"VEC3" - }, - { - "bufferView":9, - "componentType":5126, - "count":192, - "type":"VEC2" - }, - { - "bufferView":10, - "componentType":5126, - "count":192, - "max":[ - 0.20000000298023224, - 0.20000000298023224, - 0.5 - ], - "min":[ - -0.20000000298023224, - -0.20000000298023224, - -0.5 - ], - "type":"VEC3" - }, - { - "bufferView":11, - "componentType":5126, - "count":192, - "type":"VEC3" - }, - { - "bufferView":12, - "componentType":5126, - "count":192, - "type":"VEC2" - } - ], - "bufferViews":[ - { - "buffer":0, - "byteLength":2304, - "byteOffset":0, - "target":34962 - }, - { - "buffer":0, - "byteLength":2304, - "byteOffset":2304, - "target":34962 - }, - { - "buffer":0, - "byteLength":1536, - "byteOffset":4608, - "target":34962 - }, - { - "buffer":0, - "byteLength":744, - "byteOffset":6144, - "target":34963 - }, - { - "buffer":0, - "byteLength":2304, - "byteOffset":6888, - "target":34962 - }, - { - "buffer":0, - "byteLength":2304, - "byteOffset":9192, - "target":34962 - }, - { - "buffer":0, - "byteLength":1536, - "byteOffset":11496, - "target":34962 - }, - { - "buffer":0, - "byteLength":2304, - "byteOffset":13032, - "target":34962 - }, - { - "buffer":0, - "byteLength":2304, - "byteOffset":15336, - "target":34962 - }, - { - "buffer":0, - "byteLength":1536, - "byteOffset":17640, - "target":34962 - }, - { - "buffer":0, - "byteLength":2304, - "byteOffset":19176, - "target":34962 - }, - { - "buffer":0, - "byteLength":2304, - "byteOffset":21480, - "target":34962 - }, - { - "buffer":0, - "byteLength":1536, - "byteOffset":23784, - "target":34962 - } - ], - "buffers":[ - { - "byteLength":25320, - "uri":"test.bin" - } - ] -} diff --git a/src/graphics/shader.cpp b/src/graphics/shader.cpp index d98c282..5612fe1 100644 --- a/src/graphics/shader.cpp +++ b/src/graphics/shader.cpp @@ -13,6 +13,7 @@ using namespace Sim::Graphics; Shader Shader::MAIN; Shader Shader::BLUR; +Shader Shader::LIGHT; static int load_shader(const char* src, int type) { @@ -39,6 +40,12 @@ static std::string read_shader(const char* path) return ss.str(); } +static std::string read_shader(const char* base, const char* file) +{ + std::string path = std::string(base) + "/" + std::string(file); + return read_shader(path.c_str()); +} + Shader::Shader() { @@ -60,18 +67,29 @@ Shader::~Shader() void Shader::load(const char* path, const char* file_vsh, const char* file_fsh) { - std::string path_vsh = std::string(path) + "/" + std::string(file_vsh); - std::string path_fsh = std::string(path) + "/" + std::string(file_fsh); - std::string shader_vsh = read_shader(path_vsh.c_str()); - std::string shader_fsh = read_shader(path_fsh.c_str()); + load(path, file_vsh, nullptr, file_fsh); +} + +void Shader::load(const char* path, const char* file_vsh, const char* file_gsh, const char* file_fsh) +{ + std::string shader_vsh = file_vsh ? read_shader(path, file_vsh) : ""; + std::string shader_gsh = file_gsh ? read_shader(path, file_gsh) : ""; + std::string shader_fsh = file_fsh ? read_shader(path, file_fsh) : ""; int success; - int vsh_id = load_shader(shader_vsh.c_str(), GL_VERTEX_SHADER); - int fsh_id = load_shader(shader_fsh.c_str(), GL_FRAGMENT_SHADER); + int vsh_id = file_vsh ? load_shader(shader_vsh.c_str(), GL_VERTEX_SHADER) : 0; + int gsh_id = file_gsh ? load_shader(shader_gsh.c_str(), GL_GEOMETRY_SHADER) : 0; + int fsh_id = file_fsh ? load_shader(shader_fsh.c_str(), GL_FRAGMENT_SHADER) : 0; + prog_id = glCreateProgram(); - glAttachShader(prog_id, vsh_id); - glAttachShader(prog_id, fsh_id); + if(file_vsh) + glAttachShader(prog_id, vsh_id); + if(file_gsh) + glAttachShader(prog_id, gsh_id); + if(file_fsh) + glAttachShader(prog_id, fsh_id); + glLinkProgram(prog_id); glGetProgramiv(prog_id, GL_LINK_STATUS, &success); @@ -85,8 +103,13 @@ void Shader::load(const char* path, const char* file_vsh, const char* file_fsh) } glUseProgram(prog_id); - glDeleteShader(vsh_id); - glDeleteShader(fsh_id); + + if(file_vsh) + glDeleteShader(vsh_id); + if(file_gsh) + glDeleteShader(gsh_id); + if(file_fsh) + glDeleteShader(fsh_id); } void Shader::use() diff --git a/src/graphics/shader.hpp b/src/graphics/shader.hpp index af12c7e..ef53da4 100644 --- a/src/graphics/shader.hpp +++ b/src/graphics/shader.hpp @@ -16,12 +16,14 @@ public: static Shader MAIN; static Shader BLUR; + static Shader LIGHT; Shader(); Shader(const Shader& o) = delete; Shader(Shader&& o); ~Shader(); + void load(const char* path, const char* file_vsh, const char* file_gsh, const char* file_fsh); void load(const char* path, const char* file_vsh, const char* file_fsh); void use(); diff --git a/src/graphics/window.cpp b/src/graphics/window.cpp index b6b5912..8bb27b2 100644 --- a/src/graphics/window.cpp +++ b/src/graphics/window.cpp @@ -119,6 +119,7 @@ void Window::create() Font::init(); UI::init(); + Shader::LIGHT.load("../assets/shader", "light.vsh", "light.gsh", "light.fsh"); Shader::MAIN.load("../assets/shader", "main.vsh", "main.fsh"); glBindFramebuffer(GL_FRAMEBUFFER, 0); @@ -255,7 +256,7 @@ void Window::render() projection_matrix = mat_projection; glClearColor(0, 0, 0, 1.0f); - glClear(GL_DEPTH_BUFFER_BIT); + glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); glFrontFace(GL_CW); render_scene();