diff --git a/SandboxRendering/SandboxRendering/Res/Models/Primitives/Cube.mtl b/SandboxRendering/SandboxRendering/Res/Models/Primitives/Cube.mtl new file mode 100644 index 0000000..8ec060d --- /dev/null +++ b/SandboxRendering/SandboxRendering/Res/Models/Primitives/Cube.mtl @@ -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 diff --git a/SandboxRendering/SandboxRendering/Res/Models/Primitives/Cube.obj b/SandboxRendering/SandboxRendering/Res/Models/Primitives/Cube.obj new file mode 100644 index 0000000..c3bef44 --- /dev/null +++ b/SandboxRendering/SandboxRendering/Res/Models/Primitives/Cube.obj @@ -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 diff --git a/SandboxRendering/SandboxRendering/Src/GameManagerSystem.cpp b/SandboxRendering/SandboxRendering/Src/GameManagerSystem.cpp index 1d79a39..8b2bec9 100644 --- a/SandboxRendering/SandboxRendering/Src/GameManagerSystem.cpp +++ b/SandboxRendering/SandboxRendering/Src/GameManagerSystem.cpp @@ -1,5 +1,7 @@ #include "GameManagerSystem.hpp" +#include // std::min + #include "GameManagerWorldComponent.hpp" #include @@ -35,28 +37,22 @@ void GameManagerSystem::CreateScene(Scene* scene) DeferredTaskSystem::AddWorldComponentImmediate(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) @@ -86,27 +82,79 @@ void GameManagerSystem::CreateCamera(Scene* scene) GameManagerWorldComponent* gameMgrCmp = scene->GetWorldComponent(); Entity* camera = DeferredTaskSystem::SpawnEntityImmediate(scene); - DeferredTaskSystem::AddComponentImmediate(scene, camera, 35_deg, 1.0f, 5000.f); + CameraComponent* cameraCmp = DeferredTaskSystem::AddComponentImmediate(scene, camera, 35_deg, 1.0f, 5000.f); + cameraCmp->SetRenderingMode(eRenderingModeType::IMMEDIATE_DEBUG); + DeferredTaskSystem::AddComponentImmediate(scene, camera, 100.0f, 0.003f, 10.0f); gameMgrCmp->PostCmp = DeferredTaskSystem::AddComponentImmediate(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()->SetCamera(0, scene->GetComponent(camera)); + scene->GetWorldComponent()->SetCamera(0, cameraCmp); gameMgrCmp->Camera = camera; - // Entity* keyDirLight = DeferredTaskSystem::SpawnEntityImmediate(scene); - // DeferredTaskSystem::AddComponentImmediate(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(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(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(); + // viewportCmp->AddViewport(AARect(Vector2f(0.0f, 0.0f), Vector2f(1.0f, 1.0f))); + // scene->GetWorldComponent()->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) @@ -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(scene, sphere, "Models/Primitives/Sphere_HighPoly.obj", eResourceSource::GAME); - MeshRenderingComponent* meshCmp = DeferredTaskSystem::AddComponentImmediate(scene, sphere, "Models/Primitives/Sphere_LowPoly.obj", eResourceSource::GAME); + MeshRenderingComponent* meshCmp = DeferredTaskSystem::AddComponentImmediate(scene, sphere, "Models/Primitives/Sphere_HighPoly.obj", eResourceSource::GAME); size_t materialsNum = meshCmp->GetMesh()->GetSubMeshes().GetSize(); for (size_t i = 0; i < materialsNum; ++i) { @@ -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(); + + for (int i = 0; i < size; ++i) + { + Entity* cube = DeferredTaskSystem::SpawnEntityImmediate(scene); + MeshRenderingComponent* meshCmp = DeferredTaskSystem::AddComponentImmediate(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(); @@ -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()->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(); + gameMgrCmp->KeyDirLight->GetTransform().SetGlobalRotation(Quaternion(Vector::UNIT_X, animDeg)); } void GameManagerSystem::UpdatePostProcess(Scene* scene) @@ -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); @@ -424,10 +515,10 @@ void GameManagerSystem::CreateParticles(Scene* scene) GameManagerWorldComponent* gameMgrCmp = scene->GetWorldComponent(); 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); } diff --git a/SandboxRendering/SandboxRendering/Src/GameManagerSystem.hpp b/SandboxRendering/SandboxRendering/Src/GameManagerSystem.hpp index aa2800e..42c93cf 100644 --- a/SandboxRendering/SandboxRendering/Src/GameManagerSystem.hpp +++ b/SandboxRendering/SandboxRendering/Src/GameManagerSystem.hpp @@ -9,48 +9,54 @@ using namespace Poly; namespace GameManagerSystem { - void CreateScene(Scene* world); + void CreateScene(Scene* scene); - Entity* CreateModel(Scene* world, String path); + Entity* CreateModel(Scene* scene, String path); - void CreateTextUI(Scene* world); - void CreateCamera(Scene* world); - void CreatePBRShpereGrid(Scene* world, Vector pos, Color albedo); - void CreateTranslucent(Scene* world); - void CreateSponza(Scene* world); - void CreateSponzaSample(Scene* world); + void CreateTextUI(Scene* scene); + void CreateCamera(Scene* scene); + void CreateRandomCubes(Scene* scene, int size, Vector pos, Vector originScatter); + void CreatePBRShpereGrid(Scene* scene, Vector pos, Color albedo); + void CreateTranslucent(Scene* scene); + void CreateSponza(Scene* scene); + void CreateSponzaSample(Scene* scene); + + void PostFancy(PostprocessSettingsComponent* postCmp); + void PostReset(PostprocessSettingsComponent* postCmp); + void PostMinimal(PostprocessSettingsComponent* postCmp); - void CreatePointLights(Scene* world, int quota); - Entity* CreatePointLight(Scene* world, Vector& position, float Range); - void CreateSpotLight(Scene* world, float Range); - void CreateParticles(Scene* world); - void SpawnSpritesSheets(Scene* world); - void SpawnShaderball(Scene* world); - - void SpawnSpritesheet11(Scene* world, Vector pos); - void SpawnSpritesheet22(Scene* world, Vector pos); - void SpawnSpritesheet44(Scene* world, Vector pos); - void SpawnSpritesheet42(Scene* world, Vector pos); - void SpawnSpritesheet41(Scene* world, Vector pos); - void SpawnSpritesheet44Random(Scene* world, Vector pos); - void SpawnSpritesheetGandalf(Scene* world, Vector pos); - - ParticleComponent* SpawnEmitterDefault(Scene* world, Vector pos); - ParticleComponent* SpawnEmitterWorldSpace(Scene* world, Vector pos); - ParticleComponent* SpawnEmitterLocalSpace(Scene* world, Vector pos); - ParticleComponent* SpawnEmitterAmbient(Scene* world, Vector pos); - ParticleComponent* SpawnEmitterAmbientWind(Scene* world, Vector pos); - ParticleComponent* SpawnEmitterHeart(Scene* world, Vector pos); - ParticleComponent* SpawnEmitterHeartImpact(Scene* world, Vector pos); - ParticleComponent* SpawnEmitterHeartImpact2(Scene* world, Vector pos); - void SpawnHeartSystem(Scene* world); - - void Update(Scene* world); - void UpdateParticles(Scene* world); - void UpdateLights(Scene* world); - void UpdateModel(Scene* world); - void UpdatePostProcess(Scene* world); + void CreatePointLights(Scene* scene, int quota); + Entity* CreatePointLight(Scene* scene, Vector& position, float Range); + void CreateSpotLight(Scene* scene, float Range); + void CreateParticles(Scene* scene); + void SpawnSpritesSheets(Scene* scene); + void SpawnShaderball(Scene* scene); + + void SpawnSpritesheet11(Scene* scene, Vector pos); + void SpawnSpritesheet22(Scene* scene, Vector pos); + void SpawnSpritesheet44(Scene* scene, Vector pos); + void SpawnSpritesheet42(Scene* scene, Vector pos); + void SpawnSpritesheet41(Scene* scene, Vector pos); + void SpawnSpritesheet44Random(Scene* scene, Vector pos); + void SpawnSpritesheetGandalf(Scene* scene, Vector pos); + + ParticleComponent* SpawnEmitterDefault(Scene* scene, Vector pos); + ParticleComponent* SpawnEmitterWorldSpace(Scene* scene, Vector pos); + ParticleComponent* SpawnEmitterLocalSpace(Scene* scene, Vector pos); + ParticleComponent* SpawnEmitterAmbient(Scene* scene, Vector pos); + ParticleComponent* SpawnEmitterAmbientWind(Scene* scene, Vector pos); + ParticleComponent* SpawnEmitterHeart(Scene* scene, Vector pos); + ParticleComponent* SpawnEmitterHeartImpact(Scene* scene, Vector pos); + ParticleComponent* SpawnEmitterHeartImpact2(Scene* scene, Vector pos); + void SpawnHeartSystem(Scene* scene); + + void Update(Scene* scene); + void UpdateDirLight(Poly::Scene * scene); + void UpdateParticles(Scene* scene); + void UpdateLights(Scene* scene); + void UpdateModel(Scene* scene); + void UpdatePostProcess(Scene* scene); - void Deinit(Scene* world); + void Deinit(Scene* scene); } diff --git a/SandboxRendering/SandboxRendering/Src/GameManagerWorldComponent.hpp b/SandboxRendering/SandboxRendering/Src/GameManagerWorldComponent.hpp index 33c47f7..47c92a8 100644 --- a/SandboxRendering/SandboxRendering/Src/GameManagerWorldComponent.hpp +++ b/SandboxRendering/SandboxRendering/Src/GameManagerWorldComponent.hpp @@ -18,6 +18,8 @@ class GameManagerWorldComponent : public ComponentBase } public: SafePtr Camera; + CameraComponent* CameraStaticCmp; + SafePtr KeyDirLight; PostprocessSettingsComponent* PostCmp; SafePtr Model; bool IsDrawingDebugMeshes = true;