improved lighting, enabled shadows
This commit is contained in:
parent
1b673127fe
commit
d476878b9c
BIN
assets/model/monitor_graphics.glb (Stored with Git LFS)
BIN
assets/model/monitor_graphics.glb (Stored with Git LFS)
Binary file not shown.
BIN
assets/model/monitor_graphics.stl (Stored with Git LFS)
BIN
assets/model/monitor_graphics.stl (Stored with Git LFS)
Binary file not shown.
BIN
assets/model/monitor_turbine.stl (Stored with Git LFS)
BIN
assets/model/monitor_turbine.stl (Stored with Git LFS)
Binary file not shown.
BIN
assets/model/pump_switch_1.glb (Stored with Git LFS)
BIN
assets/model/pump_switch_1.glb (Stored with Git LFS)
Binary file not shown.
BIN
assets/model/pump_switch_2.glb (Stored with Git LFS)
BIN
assets/model/pump_switch_2.glb (Stored with Git LFS)
Binary file not shown.
BIN
assets/model/pump_switch_3.glb (Stored with Git LFS)
BIN
assets/model/pump_switch_3.glb (Stored with Git LFS)
Binary file not shown.
BIN
assets/model/pump_switch_click_1.stl (Stored with Git LFS)
BIN
assets/model/pump_switch_click_1.stl (Stored with Git LFS)
Binary file not shown.
BIN
assets/model/pump_switch_click_2.stl (Stored with Git LFS)
BIN
assets/model/pump_switch_click_2.stl (Stored with Git LFS)
Binary file not shown.
BIN
assets/model/pump_switch_click_3.stl (Stored with Git LFS)
BIN
assets/model/pump_switch_click_3.stl (Stored with Git LFS)
Binary file not shown.
BIN
assets/model/reactor_core_button1.stl (Stored with Git LFS)
BIN
assets/model/reactor_core_button1.stl (Stored with Git LFS)
Binary file not shown.
BIN
assets/model/reactor_core_button2.stl (Stored with Git LFS)
BIN
assets/model/reactor_core_button2.stl (Stored with Git LFS)
Binary file not shown.
BIN
assets/model/reactor_core_button3.stl (Stored with Git LFS)
BIN
assets/model/reactor_core_button3.stl (Stored with Git LFS)
Binary file not shown.
BIN
assets/model/reactor_core_button4.stl (Stored with Git LFS)
BIN
assets/model/reactor_core_button4.stl (Stored with Git LFS)
Binary file not shown.
BIN
assets/model/reactor_core_button5.stl (Stored with Git LFS)
BIN
assets/model/reactor_core_button5.stl (Stored with Git LFS)
Binary file not shown.
BIN
assets/model/reactor_core_button6.stl (Stored with Git LFS)
BIN
assets/model/reactor_core_button6.stl (Stored with Git LFS)
Binary file not shown.
BIN
assets/model/reactor_core_button7.stl (Stored with Git LFS)
BIN
assets/model/reactor_core_button7.stl (Stored with Git LFS)
Binary file not shown.
BIN
assets/model/reactor_core_button8.stl (Stored with Git LFS)
BIN
assets/model/reactor_core_button8.stl (Stored with Git LFS)
Binary file not shown.
BIN
assets/model/reactor_core_button9.stl (Stored with Git LFS)
BIN
assets/model/reactor_core_button9.stl (Stored with Git LFS)
Binary file not shown.
BIN
assets/model/reactor_core_input.stl (Stored with Git LFS)
BIN
assets/model/reactor_core_input.stl (Stored with Git LFS)
Binary file not shown.
BIN
assets/model/reactor_core_interface_cell.stl (Stored with Git LFS)
BIN
assets/model/reactor_core_interface_cell.stl (Stored with Git LFS)
Binary file not shown.
BIN
assets/model/reactor_core_interface_circle.stl (Stored with Git LFS)
BIN
assets/model/reactor_core_interface_circle.stl (Stored with Git LFS)
Binary file not shown.
BIN
assets/model/reactor_core_joystick.stl (Stored with Git LFS)
BIN
assets/model/reactor_core_joystick.stl (Stored with Git LFS)
Binary file not shown.
BIN
assets/model/reactor_core_scram.stl (Stored with Git LFS)
BIN
assets/model/reactor_core_scram.stl (Stored with Git LFS)
Binary file not shown.
BIN
assets/model/resistor_bank_switch.glb (Stored with Git LFS)
BIN
assets/model/resistor_bank_switch.glb (Stored with Git LFS)
Binary file not shown.
BIN
assets/model/resistor_bank_switch_click.stl (Stored with Git LFS)
BIN
assets/model/resistor_bank_switch_click.stl (Stored with Git LFS)
Binary file not shown.
BIN
assets/model/scene_collisions.stl (Stored with Git LFS)
BIN
assets/model/scene_collisions.stl (Stored with Git LFS)
Binary file not shown.
BIN
assets/model/synchroscope_dial.glb (Stored with Git LFS)
BIN
assets/model/synchroscope_dial.glb (Stored with Git LFS)
Binary file not shown.
BIN
assets/model/synchroscope_dial.stl (Stored with Git LFS)
BIN
assets/model/synchroscope_dial.stl (Stored with Git LFS)
Binary file not shown.
BIN
assets/model/turbine_breaker_switch.glb (Stored with Git LFS)
BIN
assets/model/turbine_breaker_switch.glb (Stored with Git LFS)
Binary file not shown.
BIN
assets/model/turbine_breaker_switch_click.stl (Stored with Git LFS)
BIN
assets/model/turbine_breaker_switch_click.stl (Stored with Git LFS)
Binary file not shown.
BIN
assets/model/turbine_valve_bypass_joystick.stl (Stored with Git LFS)
BIN
assets/model/turbine_valve_bypass_joystick.stl (Stored with Git LFS)
Binary file not shown.
BIN
assets/model/turbine_valve_bypass_switch.glb (Stored with Git LFS)
BIN
assets/model/turbine_valve_bypass_switch.glb (Stored with Git LFS)
Binary file not shown.
BIN
assets/model/turbine_valve_bypass_switch_click.stl (Stored with Git LFS)
BIN
assets/model/turbine_valve_bypass_switch_click.stl (Stored with Git LFS)
Binary file not shown.
BIN
assets/model/turbine_valve_inlet_joystick.stl (Stored with Git LFS)
BIN
assets/model/turbine_valve_inlet_joystick.stl (Stored with Git LFS)
Binary file not shown.
BIN
assets/model/turbine_valve_inlet_switch.glb (Stored with Git LFS)
BIN
assets/model/turbine_valve_inlet_switch.glb (Stored with Git LFS)
Binary file not shown.
BIN
assets/model/turbine_valve_inlet_switch_click.stl (Stored with Git LFS)
BIN
assets/model/turbine_valve_inlet_switch_click.stl (Stored with Git LFS)
Binary file not shown.
BIN
assets/scene.blend (Stored with Git LFS)
BIN
assets/scene.blend (Stored with Git LFS)
Binary file not shown.
BIN
assets/scene.glb (Stored with Git LFS)
BIN
assets/scene.glb (Stored with Git LFS)
Binary file not shown.
|
@ -8,6 +8,6 @@ uniform float far_plane;
|
|||
void main()
|
||||
{
|
||||
float distance = length(frag_pos);
|
||||
gl_FragDepth = distance / far_plane + 1e-4f;
|
||||
gl_FragDepth = distance / far_plane;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,11 +7,12 @@ layout (triangle_strip, max_vertices=18) out;
|
|||
uniform mat4 shadow_mats[6];
|
||||
|
||||
in float emissive[];
|
||||
in float base_transparency[];
|
||||
out vec3 frag_pos;
|
||||
|
||||
void main()
|
||||
{
|
||||
if(emissive[0] > 0) return;
|
||||
if(emissive[0] > 0 || base_transparency[0] > 0) return;
|
||||
|
||||
for(int i = 0; i < 6; i++)
|
||||
{
|
||||
|
|
|
@ -2,16 +2,19 @@
|
|||
#version 460 core
|
||||
|
||||
layout (location = 2) in vec4 aPos;
|
||||
layout (location = 4) in vec4 aColour;
|
||||
layout (location = 5) in vec3 aMaterial;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 camera;
|
||||
|
||||
out float emissive;
|
||||
out float base_transparency;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = camera * model * aPos;
|
||||
base_transparency = 1.f - aColour.a;
|
||||
emissive = aMaterial[2];
|
||||
}
|
||||
|
||||
|
|
|
@ -2,23 +2,7 @@
|
|||
#version 460 core
|
||||
#extension GL_ARB_bindless_texture : require
|
||||
|
||||
const float PI = 3.141592;
|
||||
const float Epsilon = 0.00001;
|
||||
|
||||
// Constant normal incidence Fresnel factor for all dielectrics.
|
||||
const vec3 Fdielectric = vec3(0.04);
|
||||
|
||||
const int SampleOffsetsLen = 8;
|
||||
const vec3 SampleOffsets[SampleOffsetsLen] = {
|
||||
vec3(-1.f,-1.f,-1.f),
|
||||
vec3(-1.f,-1.f, 1.f),
|
||||
vec3(-1.f, 1.f,-1.f),
|
||||
vec3(-1.f, 1.f, 1.f),
|
||||
vec3( 1.f,-1.f,-1.f),
|
||||
vec3( 1.f,-1.f, 1.f),
|
||||
vec3( 1.f, 1.f,-1.f),
|
||||
vec3( 1.f, 1.f, 1.f),
|
||||
};
|
||||
const float PI = 3.141592f;
|
||||
|
||||
in VS_OUT {
|
||||
vec3 normal;
|
||||
|
@ -55,18 +39,18 @@ uniform bool shadows_enabled;
|
|||
|
||||
vec3 FresnelSchlick(float cosTheta, vec3 F0)
|
||||
{
|
||||
return F0 + (1.0 - F0) * pow(clamp(1.0 - cosTheta, 0.0, 1.0), 5.0);
|
||||
return F0 + (1.f - F0) * pow(clamp(1.f - cosTheta, 0.f, 1.f), 5.f);
|
||||
}
|
||||
|
||||
float DistributionGGX(vec3 N, vec3 H, float roughness)
|
||||
{
|
||||
float a = roughness*roughness;
|
||||
float a2 = a*a;
|
||||
float NdotH = max(dot(N, H), 0.0);
|
||||
float NdotH = max(dot(N, H), 0.f);
|
||||
float NdotH2 = NdotH*NdotH;
|
||||
|
||||
float num = a2;
|
||||
float denom = (NdotH2 * (a2 - 1.0) + 1.0);
|
||||
float denom = (NdotH2 * (a2 - 1.f) + 1.f);
|
||||
denom = PI * denom * denom;
|
||||
|
||||
return num / denom;
|
||||
|
@ -74,19 +58,19 @@ float DistributionGGX(vec3 N, vec3 H, float roughness)
|
|||
|
||||
float GeometrySchlickGGX(float NdotV, float roughness)
|
||||
{
|
||||
float r = (roughness + 1.0);
|
||||
float k = (r*r) / 8.0;
|
||||
float r = (roughness + 1.f);
|
||||
float k = (r*r) / 8.f;
|
||||
|
||||
float num = NdotV;
|
||||
float denom = NdotV * (1.0 - k) + k;
|
||||
float denom = NdotV * (1.f - k) + k;
|
||||
|
||||
return num / denom;
|
||||
}
|
||||
|
||||
float GeometrySmith(vec3 N, vec3 V, vec3 L, float roughness)
|
||||
{
|
||||
float NdotV = max(dot(N, V), 0.0);
|
||||
float NdotL = max(dot(N, L), 0.0);
|
||||
float NdotV = max(dot(N, V), 0.f);
|
||||
float NdotL = max(dot(N, L), 0.f);
|
||||
float ggx2 = GeometrySchlickGGX(NdotV, roughness);
|
||||
float ggx1 = GeometrySchlickGGX(NdotL, roughness);
|
||||
|
||||
|
@ -114,6 +98,8 @@ vec3 sRGB_To_LinRGB(vec3 c)
|
|||
void main()
|
||||
{
|
||||
vec4 albedo = texture2D(frag_tex, vin.tex_pos) * vin.colour;
|
||||
if(albedo.a == 0.f) discard;
|
||||
|
||||
vec3 albedo_lin = sRGB_To_LinRGB(albedo.rgb);
|
||||
|
||||
float roughness = vin.material[0];
|
||||
|
@ -123,10 +109,10 @@ void main()
|
|||
vec3 N = normalize(vin.normal);
|
||||
vec3 V = normalize(camera_pos - vin.pos.xyz);
|
||||
|
||||
vec3 F0 = vec3(0.04);
|
||||
vec3 F0 = vec3(0.04f);
|
||||
F0 = mix(F0, albedo_lin, metalness);
|
||||
|
||||
vec3 Lo = vec3(0.0);
|
||||
vec3 Lo = vec3(0.0f);
|
||||
for(int i = 0; i < lights_count; i++)
|
||||
{
|
||||
Light l = lights[i];
|
||||
|
@ -141,38 +127,35 @@ void main()
|
|||
// cook-torrance brdf
|
||||
float NDF = DistributionGGX(N, H, roughness);
|
||||
float G = GeometrySmith(N, V, L, roughness);
|
||||
vec3 F = FresnelSchlick(max(dot(H, V), 0.0), F0);
|
||||
vec3 F = FresnelSchlick(max(dot(H, V), 0.f), F0);
|
||||
|
||||
vec3 kS = F;
|
||||
vec3 kD = vec3(1.0) - kS;
|
||||
kD *= 1.0 - metalness;
|
||||
vec3 kD = vec3(1.f) - kS;
|
||||
kD *= 1.f - metalness;
|
||||
|
||||
vec3 numerator = NDF * G * F;
|
||||
float denominator = 4.0 * max(dot(N, V), 0.0) * max(dot(N, L), 0.0) + 0.0001;
|
||||
float denominator = 4.f * max(dot(N, V), 0.f) * max(dot(N, L), 0.f) + 1e-4f;
|
||||
vec3 specular = numerator / denominator;
|
||||
|
||||
float amount = 0;
|
||||
float light_m;
|
||||
float spec_m;
|
||||
|
||||
if(shadows_enabled)
|
||||
{
|
||||
float texel_size = 1.f / textureSize(shadow_maps[i], 0)[0];
|
||||
|
||||
for(int j = 0; j < SampleOffsetsLen; j++)
|
||||
{
|
||||
amount += ((texture(shadow_maps[i], -L + SampleOffsets[j] * texel_size).r * far_plane > d) ? 1.f : 0.5f);
|
||||
}
|
||||
|
||||
amount /= SampleOffsetsLen;
|
||||
float max_d = texture(shadow_maps[i], -L).r * far_plane + 1e-2f;
|
||||
spec_m = max_d > d ? 1.f : 0.f;
|
||||
light_m = spec_m * 0.25f + 0.75f;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
amount = 1.f;
|
||||
light_m = 1.f;
|
||||
spec_m = 1.f;
|
||||
}
|
||||
|
||||
// add to outgoing radiance Lo
|
||||
float NdotL = max(dot(N, L), 0.0);
|
||||
Lo += (kD * albedo_lin / PI + specular) * radiance * NdotL * amount;
|
||||
float NdotL = max(dot(N, L), 0.f);
|
||||
Lo += (kD * albedo_lin / PI + specular * spec_m) * radiance * NdotL * light_m;
|
||||
}
|
||||
|
||||
vec3 ambient = vec3(0.03f) * albedo_lin * brightness;
|
||||
|
@ -181,6 +164,5 @@ void main()
|
|||
light = mix(light, albedo.rgb, luminance);
|
||||
frag_colour = vec4(light, albedo.a);
|
||||
|
||||
if(frag_colour.a == 0.f) discard;
|
||||
}
|
||||
|
||||
|
|
|
@ -79,9 +79,9 @@ glm::vec<3, double> Camera::get_pos()
|
|||
return pos;
|
||||
}
|
||||
|
||||
void Camera::init()
|
||||
void Camera::init(const Model& model)
|
||||
{
|
||||
collision_scene.load_model("../assets/model", "scene_collisions.stl");
|
||||
collision_scene = model.load("collision");
|
||||
}
|
||||
|
||||
void Camera::update(double dt)
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <json/json.h>
|
||||
|
||||
#include "../system.hpp"
|
||||
#include "mesh/model.hpp"
|
||||
|
||||
namespace Sim::Graphics::Camera
|
||||
{
|
||||
|
@ -18,7 +19,7 @@ double get_yaw();
|
|||
Json::Value serialize();
|
||||
void load(const Json::Value& node);
|
||||
|
||||
void init();
|
||||
void init(const Model& model);
|
||||
void rotate(double pitch, double yaw);
|
||||
void move(double x, double y, double z);
|
||||
void update(double dt);
|
||||
|
|
|
@ -14,7 +14,7 @@ using namespace Sim::Graphics;
|
|||
|
||||
static glm::mat4 shadow_mats[6];
|
||||
|
||||
GLLight::GLLight(Light light) : light(light), size(4096)
|
||||
GLLight::GLLight(Light light) : light(light), size(1024)
|
||||
{
|
||||
glGenTextures(1, &id);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, id);
|
||||
|
@ -53,8 +53,6 @@ GLLight::GLLight(GLLight&& o) : light(o.light), size(o.size)
|
|||
|
||||
GLLight::~GLLight()
|
||||
{
|
||||
std::cout << "Destructor called for " << fbo << ":" << id << ":" << handle << "\n";
|
||||
|
||||
if(fbo)
|
||||
glDeleteFramebuffers(1, &fbo);
|
||||
if(id)
|
||||
|
|
|
@ -17,17 +17,13 @@ namespace Sim::Graphics
|
|||
|
||||
struct Mesh
|
||||
{
|
||||
std::unordered_map<std::string, glm::mat4> mat_nodes;
|
||||
std::vector<Arrays::Vertex> vertices;
|
||||
std::vector<unsigned int> indices;
|
||||
std::vector<Light> lights;
|
||||
|
||||
Mesh();
|
||||
|
||||
void set_vertices(const Arrays::Vertex* data, size_t size);
|
||||
void set_indices(const unsigned int* data, size_t size);
|
||||
void load_model(std::string base, std::string path);
|
||||
void load_model(std::string path);
|
||||
void load_text(const char* text, double size);
|
||||
void load_text(const char* text, double size, glm::vec2 align);
|
||||
void add(const Mesh& o, glm::mat4 mat);
|
||||
|
|
|
@ -2,10 +2,6 @@
|
|||
#include <GL/glew.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <assimp/Importer.hpp>
|
||||
#include <assimp/scene.h>
|
||||
#include <assimp/postprocess.h>
|
||||
#include <assimp/material.h>
|
||||
#include <glm/matrix.hpp>
|
||||
|
||||
#include <unordered_map>
|
||||
|
@ -15,6 +11,7 @@
|
|||
#include "mesh.hpp"
|
||||
#include "arrays.hpp"
|
||||
#include "texture.hpp"
|
||||
#include "model.hpp"
|
||||
#include "../../util/streams.hpp"
|
||||
|
||||
using namespace Sim::Graphics;
|
||||
|
@ -24,11 +21,9 @@ struct ProcState
|
|||
unsigned int offset = 0;
|
||||
|
||||
std::string base;
|
||||
std::vector<Light> lights;
|
||||
std::vector<Arrays::Vertex> vertices;
|
||||
std::vector<unsigned int> indices;
|
||||
std::unordered_map<const aiTexture*, unsigned int> handles;
|
||||
std::unordered_map<std::string, glm::mat4> mat_nodes;
|
||||
};
|
||||
|
||||
static unsigned int proc_texture(const ProcState& state, aiMaterial* mat, const aiScene* scene, aiTextureType type, int index)
|
||||
|
@ -177,7 +172,7 @@ static void proc_mesh(ProcState& state, glm::mat4 mat, aiMesh* mesh, const aiSce
|
|||
state.offset += mesh->mNumVertices;
|
||||
}
|
||||
|
||||
glm::mat4 get_mat(aiMatrix4x4 m)
|
||||
glm::mat4 convert_mat(aiMatrix4x4 m)
|
||||
{
|
||||
return {
|
||||
m.a1, m.a2, m.a3, m.a4,
|
||||
|
@ -187,21 +182,38 @@ glm::mat4 get_mat(aiMatrix4x4 m)
|
|||
};
|
||||
}
|
||||
|
||||
static void proc_node(ProcState& state, glm::mat4 mat, aiNode* node, const aiScene* scene)
|
||||
bool starts_with(const char* base, const char* check)
|
||||
{
|
||||
mat = get_mat(node->mTransformation) * mat;
|
||||
std::string name(node->mName.C_Str());
|
||||
state.mat_nodes[name] = mat;
|
||||
|
||||
for(size_t i = 0; i < node->mNumMeshes; i++)
|
||||
while(base[0] != '\0' && check[0] != '\0')
|
||||
{
|
||||
aiMesh* mesh = scene->mMeshes[node->mMeshes[i]];
|
||||
proc_mesh(state, mat, mesh, scene);
|
||||
if(base[0] != check[0])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
base++;
|
||||
check++;
|
||||
}
|
||||
|
||||
return (check[0] == '\0');
|
||||
}
|
||||
|
||||
static void proc_node(ProcState& state, glm::mat4 mat, aiNode* node, const aiScene* scene, const char* search)
|
||||
{
|
||||
mat = convert_mat(node->mTransformation) * mat;
|
||||
|
||||
if(starts_with(node->mName.C_Str(), search))
|
||||
{
|
||||
for(size_t i = 0; i < node->mNumMeshes; i++)
|
||||
{
|
||||
aiMesh* mesh = scene->mMeshes[node->mMeshes[i]];
|
||||
proc_mesh(state, mat, mesh, scene);
|
||||
}
|
||||
}
|
||||
|
||||
for(size_t i = 0; i < node->mNumChildren; i++)
|
||||
{
|
||||
proc_node(state, mat, node->mChildren[i], scene);
|
||||
proc_node(state, mat, node->mChildren[i], scene, search);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -214,65 +226,92 @@ static unsigned int proc_embedded_texture(aiTexture* tex)
|
|||
return Texture::load_mem((unsigned char*)tex->pcData, tex->mWidth);
|
||||
}
|
||||
|
||||
// swizzle each pixel to get RGBA
|
||||
std::vector<glm::vec<4, unsigned char>> pixels;
|
||||
pixels.reserve(tex->mWidth * tex->mHeight);
|
||||
|
||||
// convert image to get RGBA
|
||||
for(int i = 0; i < tex->mWidth * tex->mHeight; i++)
|
||||
{
|
||||
aiTexel t = tex->pcData[i];
|
||||
tex->pcData[i] = {t.r, t.g, t.b, t.a};
|
||||
pixels.push_back({t.r, t.g, t.b, t.a});
|
||||
}
|
||||
|
||||
return Texture::load_mem((unsigned char*)tex->pcData, tex->mWidth, tex->mHeight, 4);
|
||||
return Texture::load_mem(&pixels[0][0], tex->mWidth, tex->mHeight, 4);
|
||||
}
|
||||
|
||||
void Mesh::load_model(std::string path)
|
||||
glm::mat4 get_transforms(const aiNode* node)
|
||||
{
|
||||
load_model(".", path);
|
||||
}
|
||||
glm::mat4 mat(1);
|
||||
|
||||
void Mesh::load_model(std::string base, std::string filename)
|
||||
{
|
||||
ProcState state {.base = base};
|
||||
std::string path = base + "/" + filename;
|
||||
Assimp::Importer importer;
|
||||
|
||||
const aiScene *scene = importer.ReadFile(path.c_str(), aiProcess_Triangulate | aiProcess_FlipUVs);
|
||||
|
||||
std::cout << "Loaded model: " << path << "\n";
|
||||
|
||||
if(scene == nullptr)
|
||||
while(node->mParent != nullptr)
|
||||
{
|
||||
std::cerr << "AssImp: Error loading model\n";
|
||||
return;
|
||||
mat = mat * convert_mat(node->mTransformation);
|
||||
node = node->mParent;
|
||||
}
|
||||
|
||||
return mat;
|
||||
}
|
||||
|
||||
glm::mat4 Model::get_matrix(const char* name) const
|
||||
{
|
||||
return get_transforms(scene->mRootNode->FindNode(name));
|
||||
}
|
||||
|
||||
Model::Model(std::string base, std::string filename) : base(base)
|
||||
{
|
||||
std::string path = base + "/" + filename;
|
||||
scene = importer.ReadFile(path.c_str(), aiProcess_Triangulate | aiProcess_FlipUVs);
|
||||
|
||||
textures.reserve(scene->mNumTextures);
|
||||
|
||||
for(int i = 0; i < scene->mNumTextures; i++)
|
||||
{
|
||||
aiTexture* tex = scene->mTextures[i];
|
||||
unsigned int handle = proc_embedded_texture(tex);
|
||||
state.handles[tex] = handle;
|
||||
textures.push_back(handle);
|
||||
}
|
||||
|
||||
proc_node(state, glm::mat4(1), scene->mRootNode, scene);
|
||||
|
||||
for(int i = 0; i < scene->mNumLights; i++)
|
||||
{
|
||||
aiLight* light = scene->mLights[i];
|
||||
glm::mat4 mat = state.mat_nodes[light->mName.C_Str()];
|
||||
glm::mat4 mat = get_matrix(light->mName.C_Str());
|
||||
|
||||
auto [x, y, z] = light->mPosition;
|
||||
auto [r, g, b] = light->mColorDiffuse;
|
||||
|
||||
glm::vec4 pos = glm::vec4(x, y, z, 1) * mat;
|
||||
|
||||
state.lights.push_back({
|
||||
lights.push_back({
|
||||
glm::vec3(pos),
|
||||
{r, g, b},
|
||||
});
|
||||
}
|
||||
|
||||
mat_nodes = std::move(state.mat_nodes);
|
||||
vertices = std::move(state.vertices);
|
||||
indices = std::move(state.indices);
|
||||
lights = std::move(state.lights);
|
||||
}
|
||||
|
||||
Mesh Model::load(const char* name, glm::mat4 mat) const
|
||||
{
|
||||
Mesh mesh;
|
||||
ProcState state {.base = base};
|
||||
proc_node(state, mat, scene->mRootNode, scene, name);
|
||||
|
||||
mesh.vertices = std::move(state.vertices);
|
||||
mesh.indices = std::move(state.indices);
|
||||
|
||||
return mesh;
|
||||
}
|
||||
|
||||
Mesh Model::load_root(glm::mat4 mat) const
|
||||
{
|
||||
return load("", mat);
|
||||
}
|
||||
|
||||
Mesh Model::load(const char* name) const
|
||||
{
|
||||
return load(name, glm::mat4(1));
|
||||
}
|
||||
|
||||
Mesh Model::load_root() const
|
||||
{
|
||||
return load("", glm::mat4(1));
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "mesh.hpp"
|
||||
#include "light.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <glm/matrix.hpp>
|
||||
|
||||
#include <assimp/Importer.hpp>
|
||||
#include <assimp/scene.h>
|
||||
#include <assimp/material.h>
|
||||
#include <assimp/postprocess.h>
|
||||
|
||||
namespace Sim::Graphics
|
||||
{
|
||||
|
||||
class Model
|
||||
{
|
||||
std::string base;
|
||||
Assimp::Importer importer;
|
||||
const aiScene* scene;
|
||||
|
||||
public:
|
||||
|
||||
std::vector<uint64_t> textures;
|
||||
std::vector<Light> lights;
|
||||
|
||||
Model(std::string base, std::string filename);
|
||||
Model(const Model&) = delete;
|
||||
|
||||
Mesh load_root() const;
|
||||
Mesh load_root(glm::mat4 mat) const;
|
||||
Mesh load(const char* name) const;
|
||||
Mesh load(const char* name, glm::mat4 mat) const;
|
||||
glm::mat4 get_matrix(const char* name) const;
|
||||
};
|
||||
|
||||
};
|
||||
|
|
@ -120,26 +120,26 @@ Core::Core()
|
|||
{
|
||||
}
|
||||
|
||||
void Core::init(Mesh& rmesh)
|
||||
void Core::init(const Model& model, Mesh& rmesh)
|
||||
{
|
||||
Mesh mesh;
|
||||
Mesh mesh = model.load("translation_monitor_3");
|
||||
mat = Locations::monitors[2];
|
||||
|
||||
mesh.load_text("Reactor Core", 0.04);
|
||||
rmesh.add(mesh, mat);
|
||||
|
||||
m_buttons[0].load_model("../assets/model/", "reactor_core_button1.stl");
|
||||
m_buttons[1].load_model("../assets/model/", "reactor_core_button2.stl");
|
||||
m_buttons[2].load_model("../assets/model/", "reactor_core_button3.stl");
|
||||
m_buttons[3].load_model("../assets/model/", "reactor_core_button4.stl");
|
||||
m_buttons[4].load_model("../assets/model/", "reactor_core_button5.stl");
|
||||
m_buttons[5].load_model("../assets/model/", "reactor_core_button6.stl");
|
||||
m_buttons[6].load_model("../assets/model/", "reactor_core_button7.stl");
|
||||
m_buttons[7].load_model("../assets/model/", "reactor_core_button8.stl");
|
||||
m_buttons[8].load_model("../assets/model/", "reactor_core_button9.stl");
|
||||
m_joystick.load_model("../assets/model/", "reactor_core_joystick.stl");
|
||||
m_monitor.load_model("../assets/model/", "reactor_core_input.stl");
|
||||
m_scram.load_model("../assets/model/", "reactor_core_scram.stl");
|
||||
m_buttons[0] = model.load("click_numpad_1");
|
||||
m_buttons[1] = model.load("click_numpad_2");
|
||||
m_buttons[2] = model.load("click_numpad_3");
|
||||
m_buttons[3] = model.load("click_numpad_4");
|
||||
m_buttons[4] = model.load("click_numpad_5");
|
||||
m_buttons[5] = model.load("click_numpad_6");
|
||||
m_buttons[6] = model.load("click_numpad_7");
|
||||
m_buttons[7] = model.load("click_numpad_8");
|
||||
m_buttons[8] = model.load("click_numpad_9");
|
||||
m_joystick = model.load("click_reactor_joystick");
|
||||
m_monitor = model.load("translation_monitor_3");
|
||||
m_scram = model.load("click_scram");
|
||||
}
|
||||
|
||||
static Mesh add_dot(glm::mat4 model_mat, glm::vec4 colour)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "../mesh/glmesh.hpp"
|
||||
#include "../mesh/model.hpp"
|
||||
|
||||
namespace Sim::Graphics::Monitor
|
||||
{
|
||||
|
@ -17,7 +17,7 @@ class Core
|
|||
public:
|
||||
|
||||
Core();
|
||||
void init(Mesh& rmesh);
|
||||
void init(const Model& model, Mesh& rmesh);
|
||||
void update(double dt);
|
||||
void remesh_slow(Mesh& rmesh);
|
||||
void remesh_fast(Mesh& rmesh);
|
||||
|
|
|
@ -55,7 +55,7 @@ PrimaryLoop::PrimaryLoop()
|
|||
|
||||
}
|
||||
|
||||
void PrimaryLoop::init(Mesh& rmesh)
|
||||
void PrimaryLoop::init(const Model& model, Mesh& rmesh)
|
||||
{
|
||||
mat = Locations::monitors[3];
|
||||
|
||||
|
@ -77,15 +77,15 @@ void PrimaryLoop::init(Mesh& rmesh)
|
|||
mesh.load_text(ss.str().c_str(), 0.04);
|
||||
rmesh.add(mesh, mat);
|
||||
|
||||
g_switch_pump.load_model("../assets/model", "pump_switch_1.glb");
|
||||
g_switch_bypass.load_model("../assets/model", "turbine_valve_bypass_switch.glb");
|
||||
g_switch_inlet.load_model("../assets/model", "turbine_valve_inlet_switch.glb");
|
||||
g_switch_pump = model.load("visual_pump_switch_1");
|
||||
g_switch_bypass = model.load("visual_bypass_switch");
|
||||
g_switch_inlet = model.load("visual_inlet_switch");
|
||||
|
||||
m_joystick_turbine_bypass.load_model("../assets/model", "turbine_valve_bypass_joystick.stl");
|
||||
m_joystick_turbine_inlet.load_model("../assets/model", "turbine_valve_inlet_joystick.stl");
|
||||
m_switch_pump.load_model("../assets/model", "pump_switch_click_1.stl");
|
||||
m_switch_bypass.load_model("../assets/model", "turbine_valve_bypass_switch_click.stl");
|
||||
m_switch_inlet.load_model("../assets/model", "turbine_valve_inlet_switch_click.stl");
|
||||
m_joystick_turbine_bypass = model.load("click_bypass_joystick");
|
||||
m_joystick_turbine_inlet = model.load("click_inlet_joystick");
|
||||
m_switch_pump = model.load("click_pump_switch_1");
|
||||
m_switch_bypass = model.load("click_bypass_switch");
|
||||
m_switch_inlet = model.load("click_inlet_switch");
|
||||
}
|
||||
|
||||
void PrimaryLoop::update(double dt)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "../mesh/glmesh.hpp"
|
||||
#include "../mesh/model.hpp"
|
||||
|
||||
namespace Sim::Graphics::Monitor
|
||||
{
|
||||
|
@ -24,7 +24,7 @@ class PrimaryLoop
|
|||
public:
|
||||
|
||||
PrimaryLoop();
|
||||
void init(Mesh& rmesh);
|
||||
void init(const Model& model, Mesh& rmesh);
|
||||
void update(double dt);
|
||||
void remesh_slow(Mesh& rmesh);
|
||||
void remesh_fast(Mesh& rmesh);
|
||||
|
|
|
@ -21,7 +21,7 @@ SecondaryLoop::SecondaryLoop()
|
|||
|
||||
}
|
||||
|
||||
void SecondaryLoop::init(Mesh& rmesh)
|
||||
void SecondaryLoop::init(const Model& model, Mesh& rmesh)
|
||||
{
|
||||
mat = Locations::monitors[5];
|
||||
|
||||
|
@ -38,13 +38,13 @@ void SecondaryLoop::init(Mesh& rmesh)
|
|||
mesh.load_text(ss.str().c_str(), 0.04);
|
||||
rmesh.add(mesh, mat);
|
||||
|
||||
g_switch_2.load_model("../assets/model", "pump_switch_2.glb");
|
||||
g_switch_3.load_model("../assets/model", "pump_switch_3.glb");
|
||||
g_switch_2 = model.load("visual_pump_switch_2");
|
||||
g_switch_3 = model.load("visual_pump_switch_3");
|
||||
|
||||
m_joystick_turbine_bypass.load_model("../assets/model", "turbine_valve_bypass_joystick.stl");
|
||||
m_joystick_turbine_inlet.load_model("../assets/model", "turbine_valve_inlet_joystick.stl");
|
||||
m_switch_2.load_model("../assets/model", "pump_switch_click_2.stl");
|
||||
m_switch_3.load_model("../assets/model", "pump_switch_click_3.stl");
|
||||
m_joystick_turbine_bypass = model.load("click_bypass_joystick");
|
||||
m_joystick_turbine_inlet = model.load("click_inlet_joystick");
|
||||
m_switch_2 = model.load("click_pump_switch_2");
|
||||
m_switch_3 = model.load("click_pump_switch_3");
|
||||
}
|
||||
|
||||
void SecondaryLoop::update(double dt)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "../mesh/glmesh.hpp"
|
||||
#include "../mesh/model.hpp"
|
||||
|
||||
namespace Sim::Graphics::Monitor
|
||||
{
|
||||
|
@ -21,7 +21,7 @@ class SecondaryLoop
|
|||
public:
|
||||
|
||||
SecondaryLoop();
|
||||
void init(Mesh& rmesh);
|
||||
void init(const Model& model, Mesh& rmesh);
|
||||
void update(double dt);
|
||||
void remesh_slow(Mesh& rmesh);
|
||||
void remesh_fast(Mesh& rmesh);
|
||||
|
|
|
@ -21,7 +21,7 @@ Turbine::Turbine()
|
|||
|
||||
}
|
||||
|
||||
void Turbine::init(Mesh& rmesh)
|
||||
void Turbine::init(const Model& model, Mesh& rmesh)
|
||||
{
|
||||
mat = Locations::monitors[4];
|
||||
|
||||
|
@ -37,12 +37,12 @@ void Turbine::init(Mesh& rmesh)
|
|||
mesh.load_text("Synchroscope", 0.04);
|
||||
rmesh.add(mesh, glm::translate(mat, glm::vec3(0, 0.6, 0)));
|
||||
|
||||
mesh.load_model("../assets/model", "synchroscope_dial.glb");
|
||||
mesh = model.load("visual_synchroscope_dial");
|
||||
gm_synchroscope_dial.bind();
|
||||
gm_synchroscope_dial.set(mesh, GL_STATIC_DRAW);
|
||||
|
||||
g_switch_breaker.load_model("../assets/model", "turbine_breaker_switch.glb");
|
||||
m_switch_breaker.load_model("../assets/model", "turbine_breaker_switch_click.stl");
|
||||
g_switch_breaker = model.load("visual_breaker_switch");
|
||||
m_switch_breaker = model.load("click_breaker_switch");
|
||||
}
|
||||
|
||||
void Turbine::update(double dt)
|
||||
|
@ -61,7 +61,6 @@ void Turbine::update(double dt)
|
|||
|
||||
if(m_switch_breaker.check_focus())
|
||||
sys.loop.generator.breaker_closed = !sys.loop.generator.breaker_closed;
|
||||
|
||||
}
|
||||
|
||||
void Turbine::remesh_slow(Mesh& rmesh)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "../mesh/model.hpp"
|
||||
#include "../mesh/glmesh.hpp"
|
||||
|
||||
namespace Sim::Graphics::Monitor
|
||||
|
@ -17,7 +18,7 @@ class Turbine
|
|||
public:
|
||||
|
||||
Turbine();
|
||||
void init(Mesh& rmesh);
|
||||
void init(const Model& model, Mesh& rmesh);
|
||||
void update(double dt);
|
||||
void remesh_slow(Mesh& rmesh);
|
||||
void remesh_fast(Mesh& rmesh);
|
||||
|
|
|
@ -20,7 +20,7 @@ Vessel::Vessel()
|
|||
|
||||
}
|
||||
|
||||
void Vessel::init(Mesh& rmesh)
|
||||
void Vessel::init(const Model& model, Mesh& rmesh)
|
||||
{
|
||||
mat = Locations::monitors[1];
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "../mesh/glmesh.hpp"
|
||||
#include "../mesh/model.hpp"
|
||||
|
||||
namespace Sim::Graphics::Monitor
|
||||
{
|
||||
|
@ -13,7 +13,7 @@ class Vessel
|
|||
public:
|
||||
|
||||
Vessel();
|
||||
void init(Mesh& rmesh);
|
||||
void init(const Model& model, Mesh& rmesh);
|
||||
void update(double dt);
|
||||
void remesh_slow(Mesh& rmesh);
|
||||
void remesh_fast(Mesh& rmesh);
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "monitor/secondary_loop.hpp"
|
||||
#include "monitor/turbine.hpp"
|
||||
#include "mesh/texture.hpp"
|
||||
#include "mesh/model.hpp"
|
||||
#include "mesh/gllight.hpp"
|
||||
#include "../system.hpp"
|
||||
#include "../util/streams.hpp"
|
||||
|
@ -124,7 +125,6 @@ void Window::create()
|
|||
Mouse::init();
|
||||
Resize::init();
|
||||
Texture::init();
|
||||
Camera::init();
|
||||
Font::init();
|
||||
UI::init();
|
||||
|
||||
|
@ -134,45 +134,30 @@ void Window::create()
|
|||
Sim::System& sys = *System::active;
|
||||
Mesh m_scene;
|
||||
|
||||
m_scene.load_model("../assets", "scene.glb");
|
||||
Model model("../assets", "scene.glb");
|
||||
m_scene = model.load("scene");
|
||||
|
||||
m_scene.lights[0].pos.x = 6;
|
||||
m_scene.lights[1].pos.x = 0;
|
||||
|
||||
// find the floor parts of the model and set them slightly transparent
|
||||
for(int i = 0; i < m_scene.indices.size(); i += 3)
|
||||
{
|
||||
Arrays::Vertex& v1 = m_scene.vertices[m_scene.indices[i]];
|
||||
Arrays::Vertex& v2 = m_scene.vertices[m_scene.indices[i + 1]];
|
||||
Arrays::Vertex& v3 = m_scene.vertices[m_scene.indices[i + 2]];
|
||||
|
||||
if(v1.pos.z <= 0 && v2.pos.z <= 0 && v3.pos.z <= 0)
|
||||
{
|
||||
v1.colour.w = 0.95;
|
||||
v2.colour.w = 0.95;
|
||||
v3.colour.w = 0.95;
|
||||
}
|
||||
}
|
||||
Camera::init(model);
|
||||
|
||||
// send all the light data
|
||||
glGenBuffers(1, &ssbo_lights);
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssbo_lights);
|
||||
glBufferData(GL_SHADER_STORAGE_BUFFER, m_scene.lights.size() * sizeof(m_scene.lights[0]), &m_scene.lights[0], GL_STATIC_DRAW);
|
||||
glBufferData(GL_SHADER_STORAGE_BUFFER, model.lights.size() * sizeof(model.lights[0]), &model.lights[0], GL_STATIC_DRAW);
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, ssbo_lights);
|
||||
|
||||
glUniform1i(Shader::MAIN["lights_count"], m_scene.lights.size());
|
||||
glUniform1i(Shader::MAIN["lights_count"], model.lights.size());
|
||||
|
||||
monitor_core.init(m_scene);
|
||||
monitor_vessel.init(m_scene);
|
||||
monitor_primary_loop.init(m_scene);
|
||||
monitor_secondary_loop.init(m_scene);
|
||||
monitor_turbine.init(m_scene);
|
||||
monitor_core.init(model, m_scene);
|
||||
monitor_vessel.init(model, m_scene);
|
||||
monitor_primary_loop.init(model, m_scene);
|
||||
monitor_secondary_loop.init(model, m_scene);
|
||||
monitor_turbine.init(model, m_scene);
|
||||
|
||||
gm_scene.bind();
|
||||
gm_scene.set(m_scene, GL_STATIC_DRAW);
|
||||
|
||||
glfwShowWindow(win);
|
||||
/*
|
||||
|
||||
// setup lighting and prerender shadows
|
||||
Shader::LIGHT.load("../assets/shader", "light.vsh", "light.gsh", "light.fsh");
|
||||
glUniform1f(Shader::LIGHT["far_plane"], 100.0f);
|
||||
|
@ -180,28 +165,24 @@ void Window::create()
|
|||
|
||||
std::vector<unsigned long> light_handles;
|
||||
|
||||
for(int i = 0; i < m_scene.lights.size(); i++)
|
||||
for(int i = 0; i < model.lights.size(); i++)
|
||||
{
|
||||
GLLight light(m_scene.lights[i]);
|
||||
GLLight light(model.lights[i]);
|
||||
light.render();
|
||||
|
||||
light_handles.push_back(light.handle);
|
||||
lights.push_back(std::move(light));
|
||||
}
|
||||
|
||||
for(int i = 0; i < lights.size(); i++)
|
||||
{
|
||||
std::cout << "handle " << i << ": " << light_handles[i] << "\n";
|
||||
}
|
||||
|
||||
Shader::MAIN.use();*/
|
||||
Shader::MAIN.use();
|
||||
glUniform1f(Shader::MAIN["far_plane"], 100.0f);
|
||||
glUniform1i(Shader::MAIN["shadows_enabled"], 1);
|
||||
|
||||
/* // send all the light shadow map handles
|
||||
// send all the light shadow map handles
|
||||
glGenBuffers(1, &ssbo_shadow_maps);
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssbo_shadow_maps);
|
||||
glBufferData(GL_SHADER_STORAGE_BUFFER, light_handles.size() * sizeof(light_handles[0]), &light_handles[0], GL_STATIC_DRAW);
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, ssbo_shadow_maps);*/
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, ssbo_shadow_maps);
|
||||
}
|
||||
|
||||
void update_slow()
|
||||
|
@ -287,32 +268,19 @@ void Window::render()
|
|||
|
||||
glm::vec3 camera_pos = Camera::get_pos();
|
||||
glm::mat4 mat_camera = Camera::get_matrix();
|
||||
mat_camera = glm::scale(mat_camera, {1, 1, -1});
|
||||
camera_pos.z *= -1;
|
||||
|
||||
Shader::MAIN.use();
|
||||
|
||||
glm::vec3 brightness = glm::vec3(System::active->grid.get_light_intensity());
|
||||
glm::mat4 mat_projection = glm::perspective(glm::radians(90.0f), Resize::get_aspect(), 0.01f, 20.f);
|
||||
glm::mat4 mat_projection = glm::perspective(glm::radians(90.0f), Resize::get_aspect(), 0.01f, 50.f);
|
||||
glUniformMatrix4fv(Shader::MAIN["projection"], 1, false, &mat_projection[0][0]);
|
||||
glUniformMatrix4fv(Shader::MAIN["camera"], 1, false, &mat_camera[0][0]);
|
||||
glUniform3fv(Shader::MAIN["brightness"], 1, &brightness[0]);
|
||||
glUniform3fv(Shader::MAIN["camera_pos"], 1, &camera_pos[0]);
|
||||
projection_matrix = mat_projection;
|
||||
glUniform3fv(Shader::MAIN["brightness"], 1, &brightness[0]);
|
||||
|
||||
glFrontFace(GL_CCW);
|
||||
glClearColor(0, 0, 0, 1.0f);
|
||||
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
|
||||
glCullFace(GL_BACK);
|
||||
glFrontFace(GL_CW);
|
||||
|
||||
render_scene();
|
||||
|
||||
camera_pos.z *= -1;
|
||||
mat_camera = Camera::get_matrix();
|
||||
glUniformMatrix4fv(Shader::MAIN["camera"], 1, false, &mat_camera[0][0]);
|
||||
glUniform3fv(Shader::MAIN["camera_pos"], 1, &camera_pos[0]);
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
glFrontFace(GL_CCW);
|
||||
|
||||
render_scene();
|
||||
|
||||
|
|
Loading…
Reference in New Issue