Skip to content

Commit

Permalink
Added demo environments for light casters
Browse files Browse the repository at this point in the history
  • Loading branch information
denyskryvytskyi committed Mar 4, 2024
1 parent 9f96261 commit 3fbe73e
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 9 deletions.
File renamed without changes
Binary file added .github/demo/light_casters_demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ Firstly you need to install [cmake](https://cmake.org/) 3.10+ version (3.21+ for
+ [x] Just cool stuff
- [x] Orthographic camera controller (OrthographicCameraController), that can be used if needed
- [x] Fly(FPS-like) 3D camera support (CameraController)
+ [ ] 3D Renderer
+ [ ] 3D Renderer (IN PROGRESS)
- [x] Lighting: spotlight, directional and point light
- [ ] Mesh/Model system
- [ ] Primitives: cube, sphere, plane
- [ ] Model loading (Assimp)
- [ ] Lighting support
+ [ ] In-engine editor (based on ImGui)
- [ ] Scene hierarchy
- [ ] Properties: entity components
Expand All @@ -74,20 +74,21 @@ Firstly you need to install [cmake](https://cmake.org/) 3.10+ version (3.21+ for
- [ ] Thread pool

## Demo
#### Space Invaders full demo
### 2D Rendering
**Space Invaders full demo**

https://github.com/denyskryvytskyi/ElvenEngine/assets/25298585/f0d32c8b-1ed2-44e3-9c93-a781f3da4203

| 2D Rendering | |
| --- | --- |
| Space Invades | TRON |
| --- | --- |
| <img src=".github/demo/invaders.gif"> | <img src=".github/demo/tron.gif"> |
| Ping Pong | Quad and texture batch rendering (20000 wizards) |
| <img src=".github/demo/pong.gif"> | <img src=".github/demo/wizards.gif"> |

#### 3D rendering
| Simple lighting | Textures |
### 3D rendering
| Lighting environments with spotlight, directional, and point lights | Cube transformation and simple light |
| --- | --- |
| <img src=".github/demo/lighting_demo.gif"> | <img src=".github/demo/cubes.gif"> |
| <img src=".github/demo/light_casters_demo.gif"> | <img src=".github/demo/cube_light_demo.gif"> |

## Third-party libraries
| Lib | |
Expand Down
155 changes: 155 additions & 0 deletions Sandbox3D/src/LightCastersSandbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#endif

const int kCubesAmount = 10;
const int kEnvironments = 4;

const lia::vec3 kPointLightPositions[] = {
lia::vec3(0.0f, 0.8f, 1.2f),
Expand All @@ -29,6 +30,121 @@ const lia::vec3 kCubePositions[] = {
lia::vec3(-1.3f, 1.0f, -1.5f)
};

struct SpotLightEnvironmentSetting {
lia::vec3 ambient;
lia::vec3 diffuse;
lia::vec3 specular;
};

struct EnvironmentMaterials {
lia::vec4 clearColor;

elv::DirectionalLight dirLight;
SpotLightEnvironmentSetting spotLight;

lia::vec3 pointLightColors[kPointLightsAmount];
};

const EnvironmentMaterials kEnvironmenMaterials[kEnvironments] = {
// ============== DESERT ================
{

// clear color
{ 0.75f, 0.52f, 0.3f, 1.0f },
// dir light
{
{ -0.2f, -1.0f, -0.3f }, // direction
{ 0.3f, 0.24f, 0.14f }, // ambient
{ 0.7f, 0.42f, 0.26f }, // deffuse
{ 0.5f, 0.5f, 0.5f }, // specular
},
// spot light
{
{ 0.0f, 0.0f, 0.0f }, // ambient
{ 0.8f, 0.8f, 0.0f }, // deffuse
{ 0.8f, 0.8f, 0.0f }, // specular
},
// point lights
{
{ 1.0f, 0.6f, 0.0f },
{ 1.0f, 0.0f, 0.0f },
{ 1.0f, 1.0f, 0.0f },
{ 0.2f, 0.2f, 1.0f } } },
// ============== FACTORY ================
{

// clear color
{ 0.1f, 0.1f, 0.1f, 1.0f },
// dir light
{
{ -0.2f, -1.0f, -0.3f }, // direction
{ 0.05f, 0.05f, 0.1f }, // ambient
{ 0.2f, 0.2f, 0.7f }, // deffuse
{ 0.7f, 0.7f, 0.7f }, // specular
},
// spot light
{
{ 0.0f, 0.0f, 0.0f }, // ambient
{ 1.0f, 1.0f, 1.0f }, // deffuse
{ 1.0f, 1.0f, 1.0f }, // specular
},
// point lights
{
{ 0.2f, 0.2f, 0.6f },
{ 0.3f, 0.3f, 0.7f },
{ 0.0f, 0.0f, 0.3f },
{ 0.4f, 0.4f, 0.4f } } },
// ============== HORROR ================
{

// clear color
{ 0.0f, 0.0f, 0.0f, 1.0f },
// dir light
{
{ -0.2f, -1.0f, -0.3f }, // direction
{ 0.0f, 0.0f, 0.0f }, // ambient
{ 0.05f, 0.05f, 0.05f }, // deffuse
{ 0.2f, 0.2f, 0.2f }, // specular
},
// spot light
{
{ 0.0f, 0.0f, 0.0f }, // ambient
{ 1.0f, 1.0f, 1.0f }, // deffuse
{ 1.0f, 1.0f, 1.0f }, // specular
},
// point lights
{

{ 0.1f, 0.1f, 0.1f },
{ 0.1f, 0.1f, 0.1f },
{ 0.1f, 0.1f, 0.1f },
{ 0.3f, 0.1f, 0.1f } } },
// ============== BIOCHEMICAL LAB ================
{

// clear color
{ 0.9f, 0.9f, 0.9f, 1.0f },
// dir light
{
{ -0.2f, -1.0f, -0.3f }, // direction
{ 0.5f, 0.5f, 0.5f }, // ambient
{ 1.0f, 1.0f, 1.0f }, // deffuse
{ 1.0f, 1.0f, 1.0f }, // specular
},
// spot light
{
{ 0.0f, 0.0f, 0.0f }, // ambient
{ 0.0f, 1.0f, 0.0f }, // deffuse
{ 0.0f, 1.0f, 0.0f }, // specular
},
// point lights
{
{ 0.4f, 0.7f, 0.1f },
{ 0.4f, 0.7f, 0.1f },
{ 0.4f, 0.7f, 0.1f },
{ 0.4f, 0.7f, 0.1f } } }
};

LightCastersSandbox::LightCastersSandbox()
: m_cameraController(45.0f, 1280.0f / 720.0f, 0.1f, 100.0f)
, m_vao(elv::VertexArray::Create())
Expand Down Expand Up @@ -165,6 +281,9 @@ LightCastersSandbox::LightCastersSandbox()
for (size_t i = 0; i < kPointLightsAmount; i++) {
m_pointLights[i].position = kPointLightPositions[i];
}

// default environment
SetEnvironment(0);
}

void LightCastersSandbox::OnCreate()
Expand Down Expand Up @@ -279,6 +398,25 @@ void LightCastersSandbox::OnImguiRender()

if (ImGui::CollapsingHeader("Scene properties")) {
elv::editor::DrawRGBAColorControl("Clear color", m_clearColor);

// environment materials combo
const char* items[] = { "Desert", "Factory", "Horror", "Biochemical lab" };
static int currentEnvironmentIndex = 0;
const char* combo_label = items[currentEnvironmentIndex];
if (ImGui::BeginCombo("Environment ", combo_label)) {
for (int i = 0; i < IM_ARRAYSIZE(items); ++i) {
const bool is_selected = (currentEnvironmentIndex == i);
if (ImGui::Selectable(items[i], is_selected)) {
currentEnvironmentIndex = i;
SetEnvironment(currentEnvironmentIndex);
}

// Set the initial focus when opening the combo (scrolling + keyboard navigation focus)
if (is_selected)
ImGui::SetItemDefaultFocus();
}
ImGui::EndCombo();
}
}

if (ImGui::CollapsingHeader("Cube")) {
Expand Down Expand Up @@ -352,3 +490,20 @@ void LightCastersSandbox::OnTextureLoaded(const elv::events::TextureLoadedEvent&
m_texturesIsReady = true;
}
}

void LightCastersSandbox::SetEnvironment(const int envIndex)
{
const auto& env = kEnvironmenMaterials[envIndex];

m_clearColor = env.clearColor;
m_dirLight = env.dirLight;
m_flashlight.ambient = env.spotLight.ambient;
m_flashlight.diffuse = env.spotLight.diffuse;
m_flashlight.specular = env.spotLight.specular;

for (size_t i = 0; i < kPointLightsAmount; ++i) {
m_pointLights[i].ambient = env.pointLightColors[i] * 0.1f;
m_pointLights[i].diffuse = env.pointLightColors[i];
m_pointLights[i].specular = env.pointLightColors[i];
}
}
2 changes: 2 additions & 0 deletions Sandbox3D/src/LightCastersSandbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class LightCastersSandbox : public elv::Application {
private:
void OnTextureLoaded(const elv::events::TextureLoadedEvent& e);

void SetEnvironment(const int envIndex);

private:
elv::EditorCameraController m_cameraController;
elv::events::EventHandler<elv::events::TextureLoadedEvent> m_textureLoadedCallback;
Expand Down
2 changes: 1 addition & 1 deletion Sandbox3D/src/SandboxApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

elv::Application* elv::CreateApplication()
{
return new SimpleLightSandbox();
return new LightCastersSandbox();
}

0 comments on commit 3fbe73e

Please sign in to comment.