Adding a really basic ambient light component
This commit is contained in:
parent
adf2331ab1
commit
f0984b6117
@ -35,10 +35,8 @@ void GUIManager::Render()
|
||||
|
||||
ImGui::NewFrame();
|
||||
|
||||
ImGui::Begin("##App");
|
||||
|
||||
ImmediateGraphicsDraw();
|
||||
ImGui::End();
|
||||
|
||||
ImGui::Render();
|
||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||
|
@ -48,16 +48,20 @@ void BarinkEngine::Renderer::Prepare(Scene& scene ) {
|
||||
void BarinkEngine::Renderer::Render(Scene& scene)
|
||||
{
|
||||
auto group = scene.getReg().view<TransformComponent, Render3DComponent>();
|
||||
group.each([](auto entity , TransformComponent& trans, Render3DComponent& renderComponent)
|
||||
group.each([&](auto entity , TransformComponent& trans, Render3DComponent& renderComponent)
|
||||
{
|
||||
|
||||
glBindVertexArray(renderComponent.VAO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, renderComponent.IBO);
|
||||
|
||||
renderComponent.shader.Use();
|
||||
|
||||
renderComponent.shader.setUniformVec3("Color", renderComponent.color);
|
||||
auto lights = scene.getReg().view<LightComponent>();
|
||||
lights.each([&](auto entity, LightComponent& light) {
|
||||
renderComponent.shader.setUniformVec3("lighting.color", light.Color);
|
||||
renderComponent.shader.setUniformFloat("lighting.strength", light.Strength);
|
||||
});
|
||||
|
||||
renderComponent.shader.setUniformVec3("Color", renderComponent.color);
|
||||
renderComponent.shader.setUniformMat4("M", trans.transform);
|
||||
renderComponent.shader.setUniformMat4("V", cam.GetViewMatrix());
|
||||
renderComponent.shader.setUniformMat4("P", projection);
|
||||
|
@ -39,7 +39,7 @@ inline void SamplePerformance(void) {
|
||||
|
||||
|
||||
inline void ShowStats() {
|
||||
ImGui::Begin("Statistics", false, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove);
|
||||
ImGui::Begin("Statistics", false, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize );
|
||||
|
||||
ImGui::Text("FPS: %i", ES.FPS);
|
||||
ImGui::Text("Frame Time: %f", ES.frameTime);
|
||||
|
@ -12,6 +12,12 @@ namespace BarinkEngine {
|
||||
|
||||
};
|
||||
|
||||
struct LightComponent {
|
||||
float Strength = 1.0f;
|
||||
glm::vec3 Color = glm::vec3(1.0f, 1.0f, 1.0f);
|
||||
|
||||
};
|
||||
|
||||
|
||||
struct CameraComponent {
|
||||
glm::mat4 view;
|
||||
@ -22,7 +28,6 @@ namespace BarinkEngine {
|
||||
unsigned int VAO = 0;
|
||||
unsigned int IBO = 0;
|
||||
Mesh mesh;
|
||||
|
||||
// TODO: becomes a material
|
||||
glm::vec3 color;
|
||||
Shader shader;
|
||||
|
@ -8,11 +8,12 @@ Scene::Scene()
|
||||
Scene::~Scene()
|
||||
{}
|
||||
|
||||
Entity Scene::AddEntity(std::string& name)
|
||||
Entity Scene::AddEntity(std::string name)
|
||||
{
|
||||
Entity entity = { m_registry.create(), this };
|
||||
|
||||
entity.AddComponent<BarinkEngine::IdentifierComponent>();
|
||||
auto& ident = entity.AddComponent<BarinkEngine::IdentifierComponent>();
|
||||
ident.name = name;
|
||||
entity.AddComponent<BarinkEngine::TransformComponent>();
|
||||
|
||||
|
||||
|
@ -9,7 +9,7 @@ public:
|
||||
Scene();
|
||||
~Scene();
|
||||
|
||||
Entity AddEntity(std::string& name);
|
||||
Entity AddEntity(std::string name);
|
||||
|
||||
entt::registry& getReg() { return m_registry; }
|
||||
|
||||
|
@ -21,28 +21,36 @@ Entity cube;
|
||||
* - USe to initialize the game/sandbox/demo
|
||||
*/
|
||||
void Start() {
|
||||
|
||||
cube = scene.AddEntity((std::string&)"cube");
|
||||
auto& render3DComponent = cube.AddComponent<BarinkEngine::Render3DComponent>();
|
||||
auto importer = BarinkEngine::ModelImporter();
|
||||
|
||||
// Load in asset(S)
|
||||
object = importer.Import("build/Debug/Models/Cube.obj");
|
||||
renderable = object->renderable;
|
||||
|
||||
|
||||
// Add Entities to the scene
|
||||
cube = scene.AddEntity("cube");
|
||||
auto& render3DComponent = cube.AddComponent<BarinkEngine::Render3DComponent>();
|
||||
render3DComponent.mesh = *renderable->mesh;
|
||||
cube.GetComponent<BarinkEngine::TransformComponent>()
|
||||
.transform = glm::rotate(glm::mat4(1.0f), 32.0f, glm::vec3(0.5f,1.0f,0.0f));
|
||||
|
||||
|
||||
// Create a second cube
|
||||
|
||||
auto cube2 = scene.AddEntity((std::string&)"Cube2");
|
||||
auto cube2 = scene.AddEntity("Cube2");
|
||||
auto& cube2Render = cube2.AddComponent<BarinkEngine::Render3DComponent>();
|
||||
cube2Render.mesh = *renderable->mesh;
|
||||
cube2Render.color = glm::vec3(0.0f, 1.0f, 0.0f);
|
||||
auto& cube2Trans = cube2.GetComponent<BarinkEngine::TransformComponent>();
|
||||
cube2Trans.transform = glm::translate( glm::mat4(1.0f), glm::vec3(1.0f,0.0f, 5.0f));
|
||||
|
||||
|
||||
// Create a light
|
||||
auto AmbientLight = scene.AddEntity("AmbientLight");
|
||||
AmbientLight.AddComponent<BarinkEngine::LightComponent>();
|
||||
|
||||
|
||||
|
||||
renderer.Prepare(scene);
|
||||
|
||||
|
||||
@ -53,6 +61,7 @@ void Start() {
|
||||
|
||||
|
||||
|
||||
bool showImGuiMetrics = false;
|
||||
/*
|
||||
* Runs every frame
|
||||
* - Use to draw Immediate mode graphics (Not meant for HUD's )
|
||||
@ -62,16 +71,47 @@ void ImmediateGraphicsDraw()
|
||||
// Show internal BarinkEngine stats
|
||||
ShowStats();
|
||||
|
||||
ImGui::Begin("Render edit");
|
||||
ImGui::Begin("Scene view");
|
||||
auto group = scene.getReg().view<BarinkEngine::IdentifierComponent>();
|
||||
group.each([](auto entity, BarinkEngine::IdentifierComponent& identifier) {
|
||||
|
||||
auto& a = cube.GetComponent<BarinkEngine::Render3DComponent>();
|
||||
ImGui::Text("%s", identifier.name.c_str());
|
||||
|
||||
});
|
||||
ImGui::End();
|
||||
|
||||
ImGui::DragFloat3("Color", &a.color[0], 0.01f, 0.0f, 1.0f);
|
||||
|
||||
ImGui::Begin("Settings");
|
||||
|
||||
|
||||
if (ImGui::Button("ImGui Debug"))
|
||||
{
|
||||
std::cout << "Click!" << std::endl;
|
||||
showImGuiMetrics = true;
|
||||
}
|
||||
ImGui::ShowMetricsWindow(&showImGuiMetrics);
|
||||
|
||||
auto& a = cube.GetComponent<BarinkEngine::Render3DComponent>();
|
||||
|
||||
auto& b = cube.GetComponent<BarinkEngine::TransformComponent>();
|
||||
|
||||
ImGui::DragFloat3("Color", &a.color[0], 0.01f, 0.0f, 1.0f);
|
||||
|
||||
ImGui::DragFloat3("Position", &b.transform[3][0], 0.01f, 0.0f, 16.0f);
|
||||
|
||||
auto l = scene.getReg().view<BarinkEngine::LightComponent>();
|
||||
l.each([](auto entity, BarinkEngine::LightComponent& light) {
|
||||
ImGui::Text("Lighting");
|
||||
ImGui::SliderFloat("Intensity", &light.Strength, 0.0f, 1.0f);
|
||||
ImGui::SliderFloat3("l-Color", &light.Color[0], 0.0f, 1.0f);
|
||||
|
||||
});
|
||||
|
||||
|
||||
ImGui::End();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user