GLTF 2.0 support, Updated Scripting, Fixed point light shadowing, Added editor focus camera

This commit is contained in:
antopilo
2021-09-06 22:28:54 -04:00
parent a6823ba2fa
commit 61e54c5a46
12 changed files with 184 additions and 78 deletions

View File

@@ -85,55 +85,55 @@ int main()
Ref<Nuake::Scene> currentScene = Nuake::Engine::GetCurrentScene();
if (currentScene && !Nuake::Engine::IsPlayMode)
{
GuizmoShader->Bind();
glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
auto camView = currentScene->m_Registry.view<Nuake::TransformComponent, Nuake::CameraComponent>();
for (auto e : camView) {
auto [transformComponent, cam] = camView.get<Nuake::TransformComponent, Nuake::CameraComponent>(e);
GuizmoShader->SetUniformMat4f("model", transformComponent.GetGlobalTransform());
GuizmoShader->SetUniformMat4f("view", currentScene->m_EditorCamera->GetTransform());
GuizmoShader->SetUniformMat4f("projection", currentScene->m_EditorCamera->GetPerspective());
camTexture->Bind(2);
GuizmoShader->SetUniform1i("gizmo_texture", 2);
Nuake::Renderer::DrawQuad(transformComponent.GetGlobalTransform());
}
auto view = currentScene->m_Registry.view<Nuake::TransformComponent, Nuake::LightComponent>();
for (auto e : view) {
auto [transformComponent, light] = view.get<Nuake::TransformComponent, Nuake::LightComponent>(e);
GuizmoShader->SetUniformMat4f("model", transformComponent.GetGlobalTransform());
GuizmoShader->SetUniformMat4f("view", currentScene->m_EditorCamera->GetTransform());
GuizmoShader->SetUniformMat4f("projection", currentScene->m_EditorCamera->GetPerspective());
lightTexture->Bind(2);
GuizmoShader->SetUniform1i("gizmo_texture", 2);
Nuake::Renderer::DrawQuad(transformComponent.GetGlobalTransform());
}
glEnable(GL_CULL_FACE);
GuizmoShader->Unbind();
ditherShader->Bind();
ditherShader->SetUniformMat4f("u_View", Nuake::Engine::GetCurrentScene()->m_EditorCamera->GetTransform());
ditherShader->SetUniformMat4f("u_Projection", Nuake::Engine::GetCurrentScene()->m_EditorCamera->GetPerspective());
ditherShader->SetUniform1f("u_Time", Nuake::Engine::GetTime());
ditherShader->SetUniform4f("u_Color", 252.0 / 255.0, 3.0 / 255.0, 65.0 / 255.0, 1.0);
if (editor.m_IsEntitySelected && editor.m_SelectedEntity.HasComponent<Nuake::BSPBrushComponent>())
{
for (auto& m : editor.m_SelectedEntity.GetComponent<Nuake::BSPBrushComponent>().Meshes)
Nuake::Renderer::SubmitMesh(m, editor.m_SelectedEntity.GetComponent<Nuake::TransformComponent>().GetGlobalTransform());
Nuake::Renderer::Flush(ditherShader, true);
}
//GuizmoShader->Bind();
//
//glDisable(GL_CULL_FACE);
//glDisable(GL_DEPTH_TEST);
//auto camView = currentScene->m_Registry.view<Nuake::TransformComponent, Nuake::CameraComponent>();
//for (auto e : camView) {
// auto [transformComponent, cam] = camView.get<Nuake::TransformComponent, Nuake::CameraComponent>(e);
//
// GuizmoShader->SetUniformMat4f("model", transformComponent.GetGlobalTransform());
// GuizmoShader->SetUniformMat4f("view", currentScene->m_EditorCamera->GetTransform());
// GuizmoShader->SetUniformMat4f("projection", currentScene->m_EditorCamera->GetPerspective());
//
// camTexture->Bind(2);
// GuizmoShader->SetUniform1i("gizmo_texture", 2);
//
// Nuake::Renderer::DrawQuad(transformComponent.GetGlobalTransform());
//}
//
//auto view = currentScene->m_Registry.view<Nuake::TransformComponent, Nuake::LightComponent>();
//for (auto e : view) {
// auto [transformComponent, light] = view.get<Nuake::TransformComponent, Nuake::LightComponent>(e);
//
// GuizmoShader->SetUniformMat4f("model", transformComponent.GetGlobalTransform());
// GuizmoShader->SetUniformMat4f("view", currentScene->m_EditorCamera->GetTransform());
// GuizmoShader->SetUniformMat4f("projection", currentScene->m_EditorCamera->GetPerspective());
//
// lightTexture->Bind(2);
// GuizmoShader->SetUniform1i("gizmo_texture", 2);
//
// Nuake::Renderer::DrawQuad(transformComponent.GetGlobalTransform());
//}
//
//glEnable(GL_CULL_FACE);
//
//GuizmoShader->Unbind();
//
//ditherShader->Bind();
//ditherShader->SetUniformMat4f("u_View", Nuake::Engine::GetCurrentScene()->m_EditorCamera->GetTransform());
//ditherShader->SetUniformMat4f("u_Projection", Nuake::Engine::GetCurrentScene()->m_EditorCamera->GetPerspective());
//ditherShader->SetUniform1f("u_Time", Nuake::Engine::GetTime());
//ditherShader->SetUniform4f("u_Color", 252.0 / 255.0, 3.0 / 255.0, 65.0 / 255.0, 1.0);
//
//if (editor.m_IsEntitySelected && editor.m_SelectedEntity.HasComponent<Nuake::BSPBrushComponent>())
//{
// for (auto& m : editor.m_SelectedEntity.GetComponent<Nuake::BSPBrushComponent>().Meshes)
// Nuake::Renderer::SubmitMesh(m, editor.m_SelectedEntity.GetComponent<Nuake::TransformComponent>().GetGlobalTransform());
//
// Nuake::Renderer::Flush(ditherShader, true);
//}
glEnable(GL_DEPTH_TEST);
}
sceneFramebuffer->Unbind();

View File

@@ -43,7 +43,8 @@ class Scene {
foreign static GetScript_(e)
foreign static GetTranslation_(e)
foreign static SetTranslation_(e, x, y, z)
//foreign static SetRotation_(e, x, y, z)
foreign static SetRotation_(e, x, y, z)
foreign static GetRotation_(e)
//foreign static SetScale_(e, x, y, z)
// Light
@@ -101,6 +102,15 @@ class TransformComponent {
Scene.SetTranslation_(_entityId, t.x, t.y, t.z)
}
GetRotation() {
var result = Scene.GetRotation_(_entityId)
return Vector3.new(result[0], result[1], result[2])
}
SetRotation(t) {
Scene.SetRotation_(_entityId, t.x, t.y, t.z)
}
}
class Light {

View File

@@ -265,13 +265,17 @@ void main()
if (Lights[i].Volumetric == 1)
fog += ComputeVolumetric(worldPos, Lights[i]);
shadow = ShadowCalculation(Lights[i], worldPos, N);
shadow += ShadowCalculation(Lights[i], worldPos, N);
}
vec3 H = normalize(V + L);
vec3 radiance = Lights[i].Color * attenuation * (1.0f - shadow);
vec3 radiance = Lights[i].Color * attenuation ;
if (Lights[i].Type == 0) {
radiance *= 1.0f - shadow;
}
// Cook-Torrance BRDF
vec3 H = normalize(V + L);
float NDF = DistributionGGX(N, H, roughness);
float G = GeometrySmith(N, V, L, roughness);
vec3 F = fresnelSchlick(max(dot(H, V), 0.0), F0);

View File

@@ -279,11 +279,22 @@ namespace Nuake {
if (ImGui::BeginPopupContextItem())
{
if (m_SelectedEntity.HasComponent<CameraComponent>())
{
if (ImGui::Selectable("Focus camera"))
{
Engine::GetCurrentScene()->m_EditorCamera->Translation = m_SelectedEntity.GetComponent<TransformComponent>().Translation;
Engine::GetCurrentScene()->m_EditorCamera->SetDirection(m_SelectedEntity.GetComponent<CameraComponent>().CameraInstance->GetDirection());
}
ImGui::Separator();
}
if (ImGui::Selectable("Remove"))
{
QueueDeletion = e;
}
if (ImGui::Selectable("Move to root"))
{
auto& p = m_SelectedEntity.GetComponent<ParentComponent>();
@@ -1051,8 +1062,7 @@ namespace Nuake {
if (ImGui::CollapsingHeader("Albedo", ImGuiTreeNodeFlags_DefaultOpen))
{
unsigned int textureID = 0;
if (material->HasAlbedo())
textureID = material->m_Albedo->GetID();
textureID = material->m_Albedo->GetID();
ImGui::ColorEdit3("Color", &material->data.m_AlbedoColor.r);

View File

@@ -37,8 +37,9 @@ project 'assimp'
-- 'assimp/code/Blender/**', 'assimp/contrib/poly2tri/poly2tri/**',
'assimp/code/AssetLib/FBX/**',
'../src/Vendors/pugixml/**',
-- 'assimp/code/glTF2/**',
'assimp/code/glTF2/**',
'assimp/code/AssetLib/glTF/**',
'assimp/code/AssetLib/glTF2/**',
'assimp/code/AssetLib/MDL/**',
'assimp/code/AssetLib/MD2/**',
'assimp/code/AssetLib/MD3/**',
@@ -63,7 +64,7 @@ project 'assimp'
'ASSIMP_BUILD_NO_CSM_IMPORTER',
'ASSIMP_BUILD_NO_DXF_IMPORTER',
-- 'ASSIMP_BUILD_NO_FBX_IMPORTER',
'ASSIMP_BUILD_NO_GLTF_IMPORTER',
-- 'ASSIMP_BUILD_NO_GLTF_IMPORTER',
'ASSIMP_BUILD_NO_HMP_IMPORTER',
'ASSIMP_BUILD_NO_IFC_IMPORTER',
'ASSIMP_BUILD_NO_IRR_IMPORTER',

View File

@@ -86,8 +86,8 @@ namespace Nuake
void Material::Bind(Ref<Shader> shader)
{
if (MaterialManager::Get()->CurrentlyBoundedMaterial == m_Name)
return;
//if (MaterialManager::Get()->CurrentlyBoundedMaterial == m_Name)
// return;
MaterialManager::Get()->CurrentlyBoundedMaterial = m_Name;
glBindBuffer(GL_UNIFORM_BUFFER, UBO);

View File

@@ -38,6 +38,7 @@ namespace Nuake
Texture::Texture(glm::vec2 size, GLenum format)
{
m_RendererId = 0;
m_Format = format;
m_Width = size.x;
@@ -51,8 +52,35 @@ namespace Nuake
//glGenerateMipmap(GL_TEXTURE_2D);
}
Texture::Texture(Vector2 size, unsigned char* data, int len)
{
m_RendererId = 0;
m_Width = size.x;
m_Height = size.y;
int channels = 0;
m_LocalBuffer = stbi_load_from_memory(data, len, &m_Width, &m_Height, &channels, 0);
glGenTextures(1, &m_RendererId);
glBindTexture(GL_TEXTURE_2D, m_RendererId);
glGenerateMipmap(GL_TEXTURE_2D);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_LOD_BIAS, -1.0f);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, m_Width, m_Height, 0, GL_RGB, GL_UNSIGNED_BYTE, m_LocalBuffer);
glGenerateMipmap(GL_TEXTURE_2D);
if (m_LocalBuffer)
stbi_image_free(m_LocalBuffer);
else
std::cout << "Error: failed to load texture buffer " << std::endl;
}
Texture::Texture(glm::vec2 size, msdfgen::BitmapConstRef<unsigned char, 4>& bitmap, bool t)
{
m_RendererId = 0;
m_Width = size.x;
m_Height = size.y;
@@ -69,6 +97,7 @@ namespace Nuake
void Texture::Resize(glm::vec2 size)
{
glDeleteTextures(1, &m_RendererId);
m_Width = size.x;
m_Height = size.y;

View File

@@ -1,4 +1,5 @@
#pragma once
#include "stb_image/stb_image.h"
#include <string>
#include "src/Core/Maths.h"
@@ -24,7 +25,7 @@ namespace Nuake
Texture(const std::string& path);
Texture(glm::vec2 size, msdfgen::BitmapConstRef<unsigned char, 4>& bitmap, bool t);
Texture(glm::vec2 size, GLenum format);
Texture(Vector2 size, unsigned char* data, int len);
~Texture();
void Resize(glm::vec2 size);

View File

@@ -10,8 +10,15 @@ namespace Nuake {
this->meshes.clear();
Assimp::Importer import;
import.SetPropertyFloat("PP_GSN_MAX_SMOOTHING_ANGLE", 90);
const aiScene* scene = import.ReadFile(FileSystem::Root + ModelPath, aiProcess_Triangulate |aiProcess_FixInfacingNormals | aiProcess_CalcTangentSpace);
const aiScene* scene = import.ReadFile(FileSystem::Root + ModelPath, aiProcess_Triangulate | aiProcess_GenSmoothNormals | aiProcess_FixInfacingNormals | aiProcess_CalcTangentSpace);
if (scene->HasTextures())
{
int textureCount = scene->mNumTextures;
for (unsigned int i = 0; i < textureCount; i++)
{
scene->mTextures[i];
}
}
if (!scene || scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode)
{
Logger::Log("ASSIMP! Failed to load model" + std::string(import.GetErrorString()), CRITICAL);
@@ -92,10 +99,23 @@ namespace Nuake {
if (mesh->mMaterialIndex >= 0)
{
aiMaterial* material = scene->mMaterials[mesh->mMaterialIndex];
Ref<Material> newMaterial = MaterialManager::Get()->GetMaterial(material->GetName().C_Str());
aiString str;
std::string directory = FileSystem::Root + "/textures/d3b_concrt02a.png";
unsigned int textureCount = material->GetTextureCount(aiTextureType_DIFFUSE);
material->GetTexture(aiTextureType_DIFFUSE, 0, &str);
Ref<Material> newMaterial = MaterialManager::Get()->GetMaterial(directory);
// Embedded texture
if (String::BeginsWith(str.C_Str(), "*"))
{
int textureIndex = std::atoi(String::Split(str.C_Str(), '*')[1].c_str());
const aiTexture* texture = scene->GetEmbeddedTexture(str.C_Str());
Ref<Texture> newTexture = CreateRef<Texture>(Vector2(texture->mWidth, texture->mHeight), (unsigned char*)texture->pcData, texture->mWidth);
newMaterial->SetAlbedo(newTexture);
}
//material->GetTexture(aiTextureType_NORMALS, 0, &str);
//newMaterial->SetNormal(TextureManager::Get()->GetTexture(directory + str.C_Str()));

View File

@@ -42,8 +42,8 @@ namespace Nuake {
m_Interfaces = std::vector<Ref<UI::UserInterface>>();
// Adding systems - Order is important
m_Systems.push_back(CreateRef<TransformSystem>(this));
m_Systems.push_back(CreateRef<ScriptingSystem>(this));
m_Systems.push_back(CreateRef<TransformSystem>(this));
m_Systems.push_back(CreateRef<PhysicsSystem>(this));
}
@@ -156,21 +156,22 @@ namespace Nuake {
void Scene::DrawShadows()
{
glEnable(GL_DEPTH_TEST);
auto meshView = m_Registry.view<TransformComponent, MeshComponent>();
auto quakeView = m_Registry.view<TransformComponent, BSPBrushComponent>();
auto view = m_Registry.view<TransformComponent, LightComponent>();
Ref<Camera> cam = m_EditorCamera;
if (Engine::IsPlayMode)
{
auto view = m_Registry.view<TransformComponent, CameraComponent>();
for (auto e : view)
{
auto [transform, camera] = view.get<TransformComponent, CameraComponent>(e);
cam = camera.CameraInstance;
break;
}
}
//if (Engine::IsPlayMode)
//{
// auto view = m_Registry.view<TransformComponent, CameraComponent>();
// for (auto e : view)
// {
// auto [transform, camera] = view.get<TransformComponent, CameraComponent>(e);
// cam = camera.CameraInstance;
// break;
// }
//}
Ref<Shader> shadowShader = ShaderManager::GetShader("resources/Shaders/shadowMap.shader");
shadowShader->Bind();
@@ -186,7 +187,6 @@ namespace Nuake {
light.CalculateViewProjection(cam->GetTransform(), cam->GetPerspective());
for (int i = 0; i < CSM_AMOUNT; i++)
{
light.m_Framebuffers[i]->Bind();
@@ -224,7 +224,6 @@ namespace Nuake {
Renderer::Flush(shadowShader, true);
light.m_Framebuffers[i]->Unbind();
}
}
}

View File

@@ -33,6 +33,8 @@ namespace Nuake {
RegisterMethod("GetTranslation_(_)", (void*)GetTranslation);
RegisterMethod("SetTranslation_(_,_,_,_)", (void*)SetTranslation);
RegisterMethod("GetRotation_(_)", (void*)GetRotation);
RegisterMethod("SetRotation_(_,_,_,_)", (void*)SetRotation);
RegisterMethod("SetLightIntensity_(_,_)", (void*)SetLightIntensity);
RegisterMethod("GetLightIntensity_(_)", (void*)GetLightIntensity);
@@ -234,6 +236,36 @@ namespace Nuake {
wrenInsertInList(vm, 0, 2, 3);
}
static void GetRotation(WrenVM* vm)
{
int handle = wrenGetSlotDouble(vm, 1);
Entity ent = Entity((entt::entity)handle, Engine::GetCurrentScene().get());
auto& transform = ent.GetComponent<TransformComponent>();
// set the slots
wrenSetSlotDouble(vm, 1, transform.Rotation.x);
wrenSetSlotDouble(vm, 2, transform.Rotation.y);
wrenSetSlotDouble(vm, 3, transform.Rotation.z);
// Fill the list
wrenSetSlotNewList(vm, 0);
wrenInsertInList(vm, 0, 0, 1);
wrenInsertInList(vm, 0, 1, 2);
wrenInsertInList(vm, 0, 2, 3);
}
static void SetRotation(WrenVM* vm)
{
int handle = wrenGetSlotDouble(vm, 1);
Entity ent = Entity((entt::entity)handle, Engine::GetCurrentScene().get());
auto& transform = ent.GetComponent<TransformComponent>();
// set the slots
float x = wrenGetSlotDouble(vm, 2);
float y = wrenGetSlotDouble(vm, 3);
float z = wrenGetSlotDouble(vm, 4);
transform.Rotation = Vector3(x, y, z);
}
static void SetTranslation(WrenVM* vm)
{
int handle = wrenGetSlotDouble(vm, 1);

View File

@@ -315,7 +315,7 @@ namespace Nuake {
Renderer::DrawQuad(Matrix4());
}
m_DeferredBuffer->Unbind();
glEnable(GL_DEPTH_TEST);
Renderer::EndDraw();
}