Vivid
Loading...
Searching...
No Matches
depth_map.cpp
1#include "Vivid.h"
2
4{
5private:
6 Vivid::Mesh lightMesh;
7 Ref<Vivid::Shader> lightShader;
8 Ref<Vivid::Entity> plane;
9 Ref<Vivid::Entity> light;
10 Ref<Vivid::ModelComponent> planeModelComponent;
11 Ref<Vivid::TransformComponent> planeTransformComponent;
12 Vivid::Mesh* planeMesh;
13
14 Ref<Vivid::DirectionalLightComponent> directionalLightComponent;
15 Ref<Vivid::Shader> shader;
16
17public:
18 void Setup() override
19 {
20
21 Ref<Vivid::Entity> plane = Vivid::ECS::CreateEntity("Plane");
22 Ref<Vivid::Entity> light = Vivid::ECS::CreateEntity("DirectionalLight");
23 planeModelComponent = Vivid::ECS::CreateComponent<Vivid::ModelComponent>();
24 planeTransformComponent = Vivid::ECS::CreateComponent<Vivid::TransformComponent>();
25 // Can write custom opengl confs here
26 OPENGL_CONFS
27
28 shader = MakeRef<Vivid::Shader>("./../assets/shaders/phong.vertexShader.glsl",
29 "./../assets/shaders/phong.pixelShader.glsl");
30
31 planeMesh = new Vivid::Mesh("./../assets/obj/plane.obj");
32 planeMesh->BindShader(shader);
33
34 planeModelComponent->AddMesh(planeMesh);
35
36 directionalLightComponent = Vivid::ECS::CreateComponent<Vivid::DirectionalLightComponent>();
37 directionalLightComponent->SetDirection(Vivid::Maths::Vec3(0.0f, -1.0f, 0.0f));
38
39 planeTransformComponent->SetScale(Vivid::Maths::Vec3(50.0f, 50.0f, 50.0f));
40 planeTransformComponent->SetRotation(Vivid::Maths::Vec3(90, 0, 0));
41
42 Vivid::ECS::AddComponent(planeModelComponent->GetComponentID(), plane->GetEntityID());
43 Vivid::ECS::AddComponent(planeTransformComponent->GetComponentID(), plane->GetEntityID());
44
45 Vivid::ECS::AddComponent(directionalLightComponent->GetComponentID(), light->GetEntityID());
46
47 MovableCamera* cam = static_cast<MovableCamera*>(Application::GetInstance()->GetCamera());
48 cam->SetPosition({ 0.0f, 0.0f, 100.0f });
49 cam->MoveBackward();
50
51 planeMesh->AddTexture("./../assets/textures/brick_wall/diffuse.jpg");
52 planeMesh->AddTexture("./../assets/textures/brick_wall/displacement.jpg");
53 planeMesh->AddTexture("./../assets/textures/brick_wall/normal.jpg");
54 planeMesh->GetTexture(0)->SetName("DiffuseTexture");
55 planeMesh->GetTexture(1)->SetName("DepthMap");
56 planeMesh->GetTexture(2)->SetName("NormalMap");
57 }
58
59 void Draw() override
60 {
61 Vector<Vivid::DirectionalLightComponent*> directionalLights;
62 Vivid::ECS::GetAllComponents(Vivid::ComponentType::DirectionalLightComponent, directionalLights);
63 Vivid::Maths::Vec3 lightColor = directionalLights[0]->GetLightColor();
64 float intensity = directionalLights[0]->GetIntensity();
65 Vivid::Maths::Vec3 lightDir = directionalLights[0]->GetDirection();
66
67 planeMesh->BindShader(shader);
68 shader->Bind();
69 shader->SetUniform3f("LightDir", lightDir);
70 shader->SetUniform1f("LightIntensity", intensity);
71 shader->SetUniform3f("LightColor", lightColor);
72 }
73
74 void ImGuiRender() override
75 {
76 ImGui::Begin("Debug");
77
78 ImGui::Text("Application average %.3f ms/frame (%.1f FPS)",
79 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
80
81 ImGui::End();
82 }
83};
84
85Application* Vivid::CreateApplication()
86{
87 Application* app = Application::GetInstance(1920, 1080, "Vivid: Bump Map Example");
88
89 app->SetRenderingInterface(new ExampleInterface);
90
91 return app;
92}
93
94int main()
95{
96 return Vivid::main(0, nullptr);
97}
Application class.
Definition: Application.h:19
void Setup() override
Setup function.
Definition: depth_map.cpp:18
void ImGuiRender() override
ImGuiRender function.
Definition: depth_map.cpp:74
void Draw() override
Draw function.
Definition: depth_map.cpp:59
A class for the MovableCamera's.
Definition: MovableCamera.h:15
RenderingInterface class.
Contains a Mesh.
Definition: Mesh.h:32
Contains a 3D vector.
Definition: Vec.h:51