Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions SandboxRendering/SandboxRendering/Res/Models/Primitives/Cube.mtl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Blender MTL File: 'None'
# Material Count: 1

newmtl Material.001
Ns 96.078431
Ka 1.000000 1.000000 1.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2
49 changes: 49 additions & 0 deletions SandboxRendering/SandboxRendering/Res/Models/Primitives/Cube.obj
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Blender v2.79 (sub 0) OBJ File: ''
# www.blender.org
mtllib Cube.mtl
o Cube
v -0.500000 0.000000 0.500000
v -0.500000 1.000000 0.500000
v -0.500000 0.000000 -0.500000
v -0.500000 1.000000 -0.500000
v 0.500000 0.000000 0.500000
v 0.500000 1.000000 0.500000
v 0.500000 0.000000 -0.500000
v 0.500000 1.000000 -0.500000
vt 0.666667 0.333333
vt 0.333333 0.333333
vt 0.333333 0.000000
vt 0.666667 0.000000
vt 0.000000 0.666667
vt 0.000000 0.333333
vt 0.333333 0.333333
vt 0.333333 0.666667
vt 0.333333 0.000000
vt 0.000000 0.333333
vt 0.000000 0.000000
vt 0.333333 0.666667
vt 0.333333 0.333333
vt 0.666667 0.333333
vt 0.666667 0.666667
vt 0.666667 0.333333
vt 0.666667 0.000000
vt 1.000000 0.000000
vt 1.000000 0.333333
vt 0.333333 0.666667
vt 0.333333 1.000000
vt 0.000000 1.000000
vt 0.000000 0.666667
vn -1.0000 0.0000 0.0000
vn 0.0000 0.0000 -1.0000
vn 1.0000 0.0000 0.0000
vn 0.0000 0.0000 1.0000
vn 0.0000 -1.0000 0.0000
vn 0.0000 1.0000 0.0000
usemtl Material.001
s off
f 1/1/1 2/2/1 4/3/1 3/4/1
f 3/5/2 4/6/2 8/7/2 7/8/2
f 7/9/3 8/7/3 6/10/3 5/11/3
f 5/12/4 6/13/4 2/14/4 1/15/4
f 3/16/5 7/17/5 5/18/5 1/19/5
f 8/20/6 4/21/6 2/22/6 6/23/6
175 changes: 133 additions & 42 deletions SandboxRendering/SandboxRendering/Src/GameManagerSystem.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "GameManagerSystem.hpp"

#include <algorithm> // std::min

#include "GameManagerWorldComponent.hpp"

#include <Math/Random.hpp>
Expand Down Expand Up @@ -35,28 +37,22 @@ void GameManagerSystem::CreateScene(Scene* scene)
DeferredTaskSystem::AddWorldComponentImmediate<SkyboxWorldComponent>(scene, "HDR/HDR.hdr", eResourceSource::GAME);

// gameMgrCmp->Model = CreateModel(scene, "Models/leather_shoes/Leather_Shoes.obj");
// gameMgrCmp->Model->GetTransform().SetGlobalTranslation(Vector(500.0f, 0.0f, 0.0f));

// gameMgrCmp->Model = CreateModel(scene, "Models/kv-2-heavy-tank-1940/model.obj");
// gameMgrCmp->Model->GetTransform().SetGlobalScale(Vector(5.0f, 5.0f, 5.0f));
// gameMgrCmp->Model->GetTransform().SetGlobalTranslation(Vector(0.0f, 10.0f, 0.0f));

// gameMgrCmp->Model = CreateModel(scene, "Models/1972-datsun-240k-gt/model.obj");
// gameMgrCmp->Model->GetTransform().SetGlobalScale(Vector::ONE * 20.0f);
// gameMgrCmp->Model->GetTransform().SetGlobalTranslation(Vector(300.0f, 0.0f, 0.0f));

CreateModel(scene, "Models/Primitives/Cube.obj")->GetTransform().SetGlobalScale(Vector(4000.0f, 1.0f, 4000.0f));
CreateRandomCubes(scene, 100, Vector(0.0f, 0.0f, 0.0f), Vector(2000.0f, 100.0f, 2000.0f));

CreatePBRShpereGrid(scene, Vector(0.0f, 0.0f, 0.0f), Color(0.0f, 0.0f, 0.0f, 1.0f));
CreatePBRShpereGrid(scene, Vector(-300.0f, 0.0f, 0.0f), Color(0.5f, 0.5f, 0.5f, 1.0f));
CreatePBRShpereGrid(scene, Vector(-600.0f, 0.0f, 0.0f), Color(1.0f, 1.0f, 1.0f, 1.0f));
// CreatePBRShpereGrid(scene, Vector(0.0f, 0.0f, 0.0f), Color(0.0f, 0.0f, 0.0f, 1.0f));
// CreatePBRShpereGrid(scene, Vector(-300.0f, 0.0f, 0.0f), Color(0.5f, 0.5f, 0.5f, 1.0f));
// CreatePBRShpereGrid(scene, Vector(-600.0f, 0.0f, 0.0f), Color(1.0f, 1.0f, 1.0f, 1.0f));

// CreateSponza(scene);

CreateTextUI(scene);
// CreateTextUI(scene);

// CreateTranslucent(scene);
// CreatePointLights(scene, 64);

CreatePointLights(scene, 128);

CreateParticles(scene);
// CreateParticles(scene);
}

void GameManagerSystem::CreateTextUI(Scene* scene)
Expand Down Expand Up @@ -86,27 +82,79 @@ void GameManagerSystem::CreateCamera(Scene* scene)
GameManagerWorldComponent* gameMgrCmp = scene->GetWorldComponent<GameManagerWorldComponent>();

Entity* camera = DeferredTaskSystem::SpawnEntityImmediate(scene);
DeferredTaskSystem::AddComponentImmediate<CameraComponent>(scene, camera, 35_deg, 1.0f, 5000.f);
CameraComponent* cameraCmp = DeferredTaskSystem::AddComponentImmediate<CameraComponent>(scene, camera, 35_deg, 1.0f, 5000.f);
cameraCmp->SetRenderingMode(eRenderingModeType::IMMEDIATE_DEBUG);

DeferredTaskSystem::AddComponentImmediate<FreeFloatMovementComponent>(scene, camera, 100.0f, 0.003f, 10.0f);
gameMgrCmp->PostCmp = DeferredTaskSystem::AddComponentImmediate<PostprocessSettingsComponent>(scene, camera);
gameMgrCmp->PostCmp->Exposure = 1.0f;
gameMgrCmp->PostCmp->DOFSize = 1.0f;
gameMgrCmp->PostCmp->DOFPoint = 300.0f;
gameMgrCmp->PostCmp->DOFRange = 200.0f;
// gameMgrCmp->PostCmp->DOFShow = 1.0f;
gameMgrCmp->PostCmp->BloomScale = 1.0f;

EntityTransform& cameraTrans = camera->GetTransform();
cameraTrans.SetGlobalTranslation(Vector(-550.0f, 180.0f, 0.0f));
cameraTrans.SetGlobalRotation(Quaternion(Vector::UNIT_Y, -90.0_deg) * Quaternion(Vector::UNIT_X, -10.0_deg));
// PostFancy(gameMgrCmp->PostCmp);
// PostReset(gameMgrCmp->PostCmp);
PostMinimal(gameMgrCmp->PostCmp);

camera->GetTransform().SetGlobalTranslation(Vector(-550.0f, 180.0f, 0.0f));
camera->GetTransform().SetGlobalRotation(Quaternion(Vector::UNIT_Y, -90.0_deg) * Quaternion(Vector::UNIT_X, -10.0_deg));
// cameraTrans.SetGlobalRotation(Quaternion(Matrix(cameraTrans.GetGlobalTranslation(), Vector(0.0f, 0.0f, 0.0f))));
scene->GetWorldComponent<ViewportWorldComponent>()->SetCamera(0, scene->GetComponent<CameraComponent>(camera));
scene->GetWorldComponent<ViewportWorldComponent>()->SetCamera(0, cameraCmp);
gameMgrCmp->Camera = camera;

// Entity* keyDirLight = DeferredTaskSystem::SpawnEntityImmediate(scene);
// DeferredTaskSystem::AddComponentImmediate<DirectionalLightComponent>(scene, keyDirLight, Color(1.0f, 1.0f, 1.0f), 5.0f);
// keyDirLight->GetTransform().SetGlobalRotation(Quaternion(Vector::UNIT_Y, -45_deg) * Quaternion(Vector::UNIT_X, 65_deg));
// gameMgrCmp->GameEntities.PushBack(keyDirLight);
Entity* keyDirLight = DeferredTaskSystem::SpawnEntityImmediate(scene);
DeferredTaskSystem::AddComponentImmediate<DirectionalLightComponent>(scene, keyDirLight, Color(1.0f, 1.0f, 1.0f), 1.0f);
keyDirLight->GetTransform().SetGlobalRotation(Quaternion(Vector::UNIT_Y, -45_deg) * Quaternion(Vector::UNIT_X, 75_deg));
gameMgrCmp->KeyDirLight = keyDirLight;
gameMgrCmp->GameEntities.PushBack(keyDirLight);

Entity* cameraStatic = DeferredTaskSystem::SpawnEntityImmediate(scene);
CameraComponent* cameraStaticCmp = DeferredTaskSystem::AddComponentImmediate<CameraComponent>(scene, cameraStatic, 35_deg, 1.0f, 100.f);
//cameraStatic->GetTransform().SetGlobalTranslation(Vector(-550.0f, 180.0f, 0.0f));
//cameraStatic->GetTransform().SetGlobalRotation(Quaternion(Vector::UNIT_Y, -90.0_deg) * Quaternion(Vector::UNIT_X, -10.0_deg));
gameMgrCmp->CameraStaticCmp = cameraStaticCmp;
gameMgrCmp->GameEntities.PushBack(cameraStatic);

// ViewportWorldComponent* viewportCmp = scene->GetWorldComponent<ViewportWorldComponent>();
// viewportCmp->AddViewport(AARect(Vector2f(0.0f, 0.0f), Vector2f(1.0f, 1.0f)));
// scene->GetWorldComponent<ViewportWorldComponent>()->SetCamera(1, cameraStaticCmp);
}

void GameManagerSystem::PostFancy(PostprocessSettingsComponent* postCmp)
{
postCmp->Exposure = 1.0f;
postCmp->DOFSize = 0.1f;
postCmp->DOFPoint = 700.0f;
postCmp->DOFRange = 800.0f;
// postCmp->DOFShow = 1.0f;
postCmp->BloomScale = 0.5f;
postCmp->AbberationScale = 0.5f;
postCmp->GrainScale = 0.1f;
postCmp->VignetteScale = 0.5f;
postCmp->MotionBlurScale = 0.5f;
}

void GameManagerSystem::PostReset(PostprocessSettingsComponent* postCmp)
{
postCmp->Exposure = 1.0f;
postCmp->DOFSize = 0.1f;
postCmp->DOFPoint = 500.0f;
postCmp->DOFRange = 10000.0f;
// postCmp->DOFShow = 1.0f;
postCmp->BloomScale = 0.0f;
postCmp->AbberationScale = 0.0f;
postCmp->GrainScale = 0.0f;
postCmp->VignetteScale = 0.0f;
postCmp->MotionBlurScale = 0.0f;
}

void GameManagerSystem::PostMinimal(PostprocessSettingsComponent* postCmp)
{
postCmp->Exposure = 1.0f;
postCmp->DOFSize = 0.1f;
postCmp->DOFPoint = 700.0f;
postCmp->DOFRange = 2000.0f;
// postCmp->DOFShow = 1.0f;
postCmp->BloomScale = 0.5f;
postCmp->AbberationScale = 0.2f;
postCmp->GrainScale = 0.1f;
postCmp->VignetteScale = 0.5f;
postCmp->MotionBlurScale = 0.5f;
}

void GameManagerSystem::CreatePBRShpereGrid(Scene* scene, Vector pos, Color albedo)
Expand Down Expand Up @@ -153,7 +201,7 @@ void GameManagerSystem::CreatePBRShpereGrid(Scene* scene, Vector pos, Color albe
sphereTrans.SetLocalScale(Vector(1.0f, 1.0f, 1.0f) * 20.0f);
sphereTrans.SetLocalRotation(Quaternion(Vector::UNIT_Z, 90.0_deg));
// MeshRenderingComponent* meshCmp = DeferredTaskSystem::AddComponentImmediate<MeshRenderingComponent>(scene, sphere, "Models/Primitives/Sphere_HighPoly.obj", eResourceSource::GAME);
MeshRenderingComponent* meshCmp = DeferredTaskSystem::AddComponentImmediate<MeshRenderingComponent>(scene, sphere, "Models/Primitives/Sphere_LowPoly.obj", eResourceSource::GAME);
MeshRenderingComponent* meshCmp = DeferredTaskSystem::AddComponentImmediate<MeshRenderingComponent>(scene, sphere, "Models/Primitives/Sphere_HighPoly.obj", eResourceSource::GAME);
size_t materialsNum = meshCmp->GetMesh()->GetSubMeshes().GetSize();
for (size_t i = 0; i < materialsNum; ++i)
{
Expand All @@ -174,6 +222,39 @@ void GameManagerSystem::CreatePBRShpereGrid(Scene* scene, Vector pos, Color albe
}
}

void GameManagerSystem::CreateRandomCubes(Scene* scene, int size, Vector pos, Vector originScatter)
{
GameManagerWorldComponent* gameMgrCmp = scene->GetWorldComponent<GameManagerWorldComponent>();

for (int i = 0; i < size; ++i)
{
Entity* cube = DeferredTaskSystem::SpawnEntityImmediate(scene);
MeshRenderingComponent* meshCmp = DeferredTaskSystem::AddComponentImmediate<MeshRenderingComponent>(scene, cube, "Models/Primitives/Cube.obj", eResourceSource::GAME);
meshCmp->SetMaterial(0, Material(Color::BLACK, Color::WHITE * 0.5f, 0.1f, 0.75f, 0.5f));

EntityTransform& cubeTrans = cube->GetTransform();

Vector rndRot = RandomVectorRange(-1.0f, 1.0f);
cubeTrans.SetLocalRotation(
Quaternion(Vector::UNIT_X, 180.0_deg * rndRot.X)
* Quaternion(Vector::UNIT_Y, 180.0_deg * rndRot.Y)
* Quaternion(Vector::UNIT_Z, 180.0_deg * rndRot.Z)
);

Vector rndPos = RandomVectorRange(-1.0f, 1.0f);
Vector offsetPos = Vector(
rndPos.X * originScatter.X,
rndPos.Y * originScatter.Y,
rndPos.Z * originScatter.Z
);
cubeTrans.SetGlobalTranslation(pos + offsetPos + Vector::UNIT_Y * 200.0f);

cubeTrans.SetLocalScale(Vector::ONE * 100.0f);

gameMgrCmp->GameEntities.PushBack(cube);
}
}

void GameManagerSystem::CreateTranslucent(Scene* scene)
{
GameManagerWorldComponent* gameMgrCmp = scene->GetWorldComponent<GameManagerWorldComponent>();
Expand Down Expand Up @@ -255,17 +336,27 @@ void GameManagerSystem::CreateSponzaSample(Scene* scene)

void GameManagerSystem::Update(Scene* scene)
{
// UpdateDirLight(scene);

UpdateParticles(scene);

UpdateLights(scene);

// UpdateModel(scene);

// Vector offset = Vector(800.0f, 0.0f, 0.0f);
// Vector offset = Vector(0.0f, 0.0f, 0.0f);
// DebugDrawSystem::DrawLine(scene, offset, offset + Vector::UNIT_Y * 1000.0f, Color::RED);
// DebugDrawSystem::DrawBox(scene, offset + Vector(-100.0f, 0.0f, -100.0f), offset + Vector(100.0f, 200.0f, 100.0f), Color::RED);
}

Vector offset = Vector(800.0f, 0.0f, 0.0f);
DebugDrawSystem::DrawLine(scene, offset, offset + Vector::UNIT_Y * 1000.0f, Color::RED);
DebugDrawSystem::DrawBox(scene, offset + Vector(-100.0f, 0.0f, -100.0f), offset + Vector(100.0f, 200.0f, 100.0f), Color::RED);

// UpdatePostProcess(scene);
void GameManagerSystem::UpdateDirLight(Poly::Scene * scene)
{
float time = (float)(scene->GetWorldComponent<TimeWorldComponent>()->GetGameplayTime());
float anim = SmoothStep(-0.8f, 0.8f, Sin(0.2_rad * time));
Angle animDeg = Lerp(0_deg, 90_deg, anim);
GameManagerWorldComponent* gameMgrCmp = scene->GetWorldComponent<GameManagerWorldComponent>();
gameMgrCmp->KeyDirLight->GetTransform().SetGlobalRotation(Quaternion(Vector::UNIT_X, animDeg));
}

void GameManagerSystem::UpdatePostProcess(Scene* scene)
Expand Down Expand Up @@ -293,7 +384,7 @@ void GameManagerSystem::CreatePointLights(Scene* scene, int quota)
{
Vector position = Vector(RandomRange(-1.0f, 1.0f)*1000.0f, RandomRange(0.0f, 800.0f), RandomRange(-1.0f, 1.0f)*500.0f);
float rangeRnd = pow(RandomRange(0.0f, 1.0f), 8.0f);
float range = 100.0f + rangeRnd * 2000.0f;
float range = 100.0f + rangeRnd * 100.0f;
Entity* lightEntity = CreatePointLight(scene, position, range);

gameMgrCmp->LightsStartPositions.PushBack(position);
Expand Down Expand Up @@ -424,10 +515,10 @@ void GameManagerSystem::CreateParticles(Scene* scene)
GameManagerWorldComponent* gameMgrCmp = scene->GetWorldComponent<GameManagerWorldComponent>();
Vector particlesPosition = Vector(0.0f, 0.0f, 0.0f);
// gameMgrCmp->particleDefault = SpawnEmitterDefault(scene, particlesPosition);
gameMgrCmp->particleWorldSpace = SpawnEmitterWorldSpace(scene, particlesPosition);
gameMgrCmp->particleLocalSpace = SpawnEmitterLocalSpace(scene, particlesPosition);
// gameMgrCmp->particleWorldSpace = SpawnEmitterWorldSpace(scene, particlesPosition);
// gameMgrCmp->particleLocalSpace = SpawnEmitterLocalSpace(scene, particlesPosition);
gameMgrCmp->particleAmbient = SpawnEmitterAmbient(scene, particlesPosition);
gameMgrCmp->particleAmbientWind = SpawnEmitterAmbientWind(scene, particlesPosition);
// gameMgrCmp->particleAmbientWind = SpawnEmitterAmbientWind(scene, particlesPosition);

// SpawnHeartSystem(scene);
}
Expand Down
Loading