Fixed volumetric fog, added transform system
This commit is contained in:
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -7,3 +7,6 @@
|
||||
[submodule "Nuake/dependencies/bullet3"]
|
||||
path = Nuake/dependencies/bullet3
|
||||
url = https://github.com/bulletphysics/bullet3.git
|
||||
[submodule "Nuake/dependencies/glew"]
|
||||
path = Nuake/dependencies/glew
|
||||
url = https://github.com/nigels-com/glew.git
|
||||
|
||||
@@ -271,7 +271,7 @@ float ComputeScattering(float lightDotView)
|
||||
}
|
||||
|
||||
uniform float u_FogStepCount;
|
||||
vec3 ComputeVolumetric(vec3 FragPos, mat4 LightTransform, vec3 LightColor, sampler2D shadowMap, vec3 LightDirection)
|
||||
vec3 ComputeVolumetric(vec3 FragPos, Light light)
|
||||
{
|
||||
// world space frag position.
|
||||
vec3 startPosition = u_EyePosition; // Camera Position
|
||||
@@ -289,7 +289,7 @@ vec3 ComputeVolumetric(vec3 FragPos, mat4 LightTransform, vec3 LightColor, sampl
|
||||
// Raymarching
|
||||
for (int i = 0; i < u_FogStepCount; i++)
|
||||
{
|
||||
vec4 fragPosLightSpace = LightTransform * vec4(currentPosition, 1.0f);
|
||||
vec4 fragPosLightSpace = light.LightTransforms[0] * vec4(currentPosition, 1.0f);
|
||||
// perform perspective divide
|
||||
vec3 projCoords = fragPosLightSpace.xyz / fragPosLightSpace.w;
|
||||
// transform to [0,1] range
|
||||
@@ -298,12 +298,12 @@ vec3 ComputeVolumetric(vec3 FragPos, mat4 LightTransform, vec3 LightColor, sampl
|
||||
float currentDepth = projCoords.z;
|
||||
|
||||
// get closest depth value from light's perspective (using [0,1] range fragPosLight as coords)
|
||||
vec2 texelSize = 1.0 / textureSize(shadowMap, 0);
|
||||
vec2 texelSize = 1.0 / textureSize(light.ShadowMaps[0], 0);
|
||||
|
||||
float closestDepth = texture(shadowMap, projCoords.xy).r;
|
||||
float closestDepth = texture(light.ShadowMaps[0], projCoords.xy).r;
|
||||
|
||||
if (closestDepth > currentDepth)
|
||||
accumFog += (ComputeScattering(dot(rayDirection, LightDirection)).xxx * LightColor);
|
||||
accumFog += (ComputeScattering(dot(rayDirection, light.Direction)).xxx * light.Color);
|
||||
|
||||
currentPosition += step;
|
||||
}
|
||||
@@ -370,9 +370,9 @@ void main()
|
||||
L = normalize(Lights[i].Direction);
|
||||
attenuation = 1.0f;
|
||||
if (Lights[i].Volumetric == 1)
|
||||
Fog += ComputeVolumetric(v_FragPos, Lights[i].LightTransform, Lights[i].Color, Lights[i].ShadowMap, Lights[i].Direction);
|
||||
Fog += ComputeVolumetric(v_FragPos, Lights[i]);
|
||||
|
||||
shadow += ShadowCalculation(Lights[i], v_FragPos, N);
|
||||
//shadow += ShadowCalculation(Lights[i].LightTransform * vec4(v_FragPos, 1.0f), Lights[i].ShadowMap, N, Lights[i].Direction);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -104,6 +104,19 @@ bool Project::Deserialize(const std::string& str)
|
||||
Name = j["Name"];
|
||||
Description = j["Description"];
|
||||
|
||||
if (j.contains("EntityDefinition"))
|
||||
{
|
||||
std::string path = j["EntityDefinition"];
|
||||
EntityDefinitionsFile = CreateRef<FGDFile>(path);
|
||||
std::string content = FileSystem::ReadFile(path, false);
|
||||
EntityDefinitionsFile->Deserialize(content);
|
||||
}
|
||||
|
||||
if (j.contains("TrenchbroomPath"))
|
||||
{
|
||||
this->TrenchbroomPath = j["TrenchbroomPath"];
|
||||
}
|
||||
|
||||
DefaultScene = Scene::New();
|
||||
|
||||
// Load default scene, a project can have no default scene set.
|
||||
@@ -121,19 +134,6 @@ bool Project::Deserialize(const std::string& str)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (j.contains("EntityDefinition"))
|
||||
{
|
||||
std::string path = j["EntityDefinition"];
|
||||
EntityDefinitionsFile = CreateRef<FGDFile>(path);
|
||||
std::string content = FileSystem::ReadFile(path, false);
|
||||
EntityDefinitionsFile->Deserialize(content);
|
||||
}
|
||||
|
||||
if (j.contains("TrenchbroomPath"))
|
||||
{
|
||||
this->TrenchbroomPath = j["TrenchbroomPath"];
|
||||
}
|
||||
|
||||
DefaultScene->Path = scenePath;
|
||||
Logger::Log("Successfully loaded scene: " + scenePath);
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "../Rendering/Mesh/Mesh.h"
|
||||
#include "../Resource/TrenchbroomMap.h"
|
||||
#include "../Resource/Serializable.h"
|
||||
#include <src/Scene/Systems/QuakeMapBuilder.h>
|
||||
|
||||
class QuakeMapComponent {
|
||||
private:
|
||||
@@ -31,6 +32,7 @@ public:
|
||||
BEGIN_DESERIALIZE();
|
||||
this->Path = j["Path"];
|
||||
this->HasCollisions = j["HasCollisions"];
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include <src/Scene/Systems/ScriptingSystem.h>
|
||||
#include <src/Scene/Systems/PhysicsSystem.h>
|
||||
|
||||
#include <src/Scene/Systems/TransformSystem.h>
|
||||
|
||||
#include <src/Scene/Systems/QuakeMapBuilder.h>
|
||||
#include <src/Scene/Components/BSPBrushComponent.h>
|
||||
@@ -41,8 +41,10 @@ Scene::Scene()
|
||||
m_Interfaces = std::vector<Ref<UI::UserInterface>>();
|
||||
|
||||
// Adding systems
|
||||
m_Systems.push_back(CreateRef<TransformSystem>(this));
|
||||
m_Systems.push_back(CreateRef<ScriptingSystem>(this));
|
||||
m_Systems.push_back(CreateRef<PhysicsSystem>(this));
|
||||
|
||||
}
|
||||
|
||||
Scene::~Scene() {}
|
||||
@@ -96,8 +98,6 @@ void Scene::OnExit()
|
||||
|
||||
void Scene::Update(Timestep ts)
|
||||
{
|
||||
UpdatePositions();
|
||||
|
||||
for (auto& system : m_Systems)
|
||||
system->Update(ts);
|
||||
}
|
||||
@@ -549,12 +549,13 @@ bool Scene::Deserialize(const std::string& str)
|
||||
}
|
||||
|
||||
auto view = m_Registry.view<ParentComponent>();
|
||||
for (auto e : view) {
|
||||
for (auto e : view)
|
||||
{
|
||||
auto parentC = view.get<ParentComponent>(e);
|
||||
if (!parentC.HasParent)
|
||||
continue;
|
||||
|
||||
auto& p = Entity{ e, this };
|
||||
|
||||
auto parent = GetEntityByID(parentC.ParentID);
|
||||
parent.AddChild(p);
|
||||
}
|
||||
@@ -566,7 +567,6 @@ bool Scene::Deserialize(const std::string& str)
|
||||
|
||||
void Scene::Snapshot()
|
||||
{
|
||||
const auto view = m_Registry.view<TransformComponent>();
|
||||
|
||||
}
|
||||
|
||||
|
||||
54
Nuake/src/Scene/Systems/TransformSystem.cpp
Normal file
54
Nuake/src/Scene/Systems/TransformSystem.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
#include "TransformSystem.h"
|
||||
#include "src/Scene/Scene.h"
|
||||
#include <src/Scene/Components/TransformComponent.h>
|
||||
#include <src/Scene/Components/ParentComponent.h>
|
||||
|
||||
TransformSystem::TransformSystem(Scene* scene)
|
||||
{
|
||||
m_Scene = scene;
|
||||
}
|
||||
|
||||
bool TransformSystem::Init()
|
||||
{
|
||||
UpdateTransform();
|
||||
return true;
|
||||
}
|
||||
|
||||
void TransformSystem::Update(Timestep ts)
|
||||
{
|
||||
UpdateTransform();
|
||||
}
|
||||
|
||||
void TransformSystem::FixedUpdate(Timestep ts)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void TransformSystem::Exit()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void TransformSystem::UpdateTransform()
|
||||
{
|
||||
auto transformView = m_Scene->m_Registry.view<ParentComponent, TransformComponent>();
|
||||
for (auto e : transformView) {
|
||||
auto [parent, transform] = transformView.get<ParentComponent, TransformComponent>(e);
|
||||
Entity currentParent = Entity((entt::entity)e, m_Scene);
|
||||
Vector3 globalPos = Vector3();
|
||||
if (parent.HasParent)
|
||||
{
|
||||
while (currentParent.GetComponent<ParentComponent>().HasParent)
|
||||
{
|
||||
currentParent = currentParent.GetComponent<ParentComponent>().Parent;
|
||||
globalPos += currentParent.GetComponent<TransformComponent>().Translation;
|
||||
}
|
||||
|
||||
transform.GlobalTranslation = globalPos + transform.Translation;
|
||||
}
|
||||
else
|
||||
{
|
||||
transform.GlobalTranslation = transform.Translation;
|
||||
}
|
||||
}
|
||||
}
|
||||
15
Nuake/src/Scene/Systems/TransformSystem.h
Normal file
15
Nuake/src/Scene/Systems/TransformSystem.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
#include "System.h"
|
||||
|
||||
class Scene;
|
||||
class TransformSystem : public System {
|
||||
public:
|
||||
TransformSystem(Scene* scene);
|
||||
bool Init() override;
|
||||
void Update(Timestep ts) override;
|
||||
void Draw() override {}
|
||||
void FixedUpdate(Timestep ts) override;
|
||||
void Exit() override;
|
||||
|
||||
void UpdateTransform();
|
||||
};
|
||||
@@ -10,9 +10,7 @@
|
||||
|
||||
WrenVM* ScriptingEngine::m_WrenVM;
|
||||
|
||||
|
||||
std::map<std::string, Ref<WrenScript>> ScriptingEngine::m_Scripts;
|
||||
|
||||
std::map<std::string, Ref<ScriptModule>> ScriptingEngine::Modules;
|
||||
|
||||
void errorFn(WrenVM* vm, WrenErrorType errorType,
|
||||
@@ -38,25 +36,25 @@ void errorFn(WrenVM* vm, WrenErrorType errorType,
|
||||
Logger::Log(t, WARNING);
|
||||
} break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void writeFn(WrenVM* vm, const char* text) {
|
||||
void writeFn(WrenVM* vm, const char* text)
|
||||
{
|
||||
printf("%s", text);
|
||||
}
|
||||
|
||||
bool hasEnding(std::string const& fullString, std::string const& ending) {
|
||||
if (fullString.length() >= ending.length()) {
|
||||
bool hasEnding(std::string const& fullString, std::string const& ending)
|
||||
{
|
||||
if (fullString.length() >= ending.length())
|
||||
{
|
||||
return (0 == fullString.compare(fullString.length() - ending.length(), ending.length(), ending));
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const std::string NuakeModulePrefix = "Nuake:";
|
||||
WrenLoadModuleResult myLoadModule(WrenVM* vm, const char* name)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user