Can move around scene again .. working on Rendering engine still
This commit is contained in:
parent
7448017701
commit
89f5b1497f
@ -18,6 +18,7 @@ void Viewport::Draw() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
cam.Update();
|
cam.Update();
|
||||||
|
renderer.SetMainCamera(cam);
|
||||||
renderer.Render(scene);
|
renderer.Render(scene);
|
||||||
|
|
||||||
ImVec2 WinPos = ImGui::GetWindowPos();
|
ImVec2 WinPos = ImGui::GetWindowPos();
|
||||||
@ -37,6 +38,7 @@ void Viewport::Draw() {
|
|||||||
ImGuizmo::SetRect(ScreenSpaceMin.x, ScreenSpaceMin.y, ContentRegionMax.x, ContentRegionMax.y);
|
ImGuizmo::SetRect(ScreenSpaceMin.x, ScreenSpaceMin.y, ContentRegionMax.x, ContentRegionMax.y);
|
||||||
|
|
||||||
glm::mat4 transposed_view = glm::transpose(cam.ViewMatrix);
|
glm::mat4 transposed_view = glm::transpose(cam.ViewMatrix);
|
||||||
|
isFocused = ImGui::IsWindowFocused();
|
||||||
|
|
||||||
//ImGuizmo::DrawGrid(glm::value_ptr(cam.ViewMatrix), glm::value_ptr(cam.ProjectionMatrix), glm::value_ptr(worldOrigin), 100.0f);
|
//ImGuizmo::DrawGrid(glm::value_ptr(cam.ViewMatrix), glm::value_ptr(cam.ProjectionMatrix), glm::value_ptr(worldOrigin), 100.0f);
|
||||||
//ImGuizmo::ViewManipulate(glm::value_ptr(cam.ViewMatrix), 1, { ScreenSpaceMin.x,ScreenSpaceMin.y }, { 90,90 }, 0x22CCCCCC);
|
//ImGuizmo::ViewManipulate(glm::value_ptr(cam.ViewMatrix), 1, { ScreenSpaceMin.x,ScreenSpaceMin.y }, { 90,90 }, 0x22CCCCCC);
|
||||||
@ -44,12 +46,4 @@ void Viewport::Draw() {
|
|||||||
// Matrix is the model matrix we would want to manipulate
|
// Matrix is the model matrix we would want to manipulate
|
||||||
//ImGuizmo::Manipulate(glm::value_ptr(cam.ViewMatrix), glm::value_ptr(cam.ProjectionMatrix), ImGuizmo::TRANSLATE, ImGuizmo::WORLD, glm::value_ptr(cam.ViewMatrix));
|
//ImGuizmo::Manipulate(glm::value_ptr(cam.ViewMatrix), glm::value_ptr(cam.ProjectionMatrix), ImGuizmo::TRANSLATE, ImGuizmo::WORLD, glm::value_ptr(cam.ViewMatrix));
|
||||||
|
|
||||||
if (ImGui::IsWindowFocused())
|
|
||||||
{
|
|
||||||
isFocused = true;
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
isFocused = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -55,67 +55,15 @@ public:
|
|||||||
|
|
||||||
scene.Update();
|
scene.Update();
|
||||||
|
|
||||||
if (sceneview.isFocused)
|
if (sceneview.isFocused) {
|
||||||
{
|
UpdateSceneCamera(sceneview);
|
||||||
const float movement_speed = 0.1f;
|
|
||||||
static float lastX = 400, lastY = 300;
|
|
||||||
const float sensitivity = 0.1;
|
|
||||||
static bool firstMouse = true;
|
|
||||||
|
|
||||||
if (MouseButtonPressed(YOGGIE_MOUSE_BUTTON_RIGHT)) {
|
|
||||||
|
|
||||||
glfwSetInputMode((GLFWwindow*)appWindow->GetHandle(), GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
|
|
||||||
auto newX = getCursorPosX(appWindow);
|
|
||||||
auto newY = getCursorPosY(appWindow);
|
|
||||||
|
|
||||||
if (firstMouse)
|
|
||||||
{
|
|
||||||
lastX = newX;
|
|
||||||
lastY = newY;
|
|
||||||
firstMouse = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
float xoffset = newX - lastX;
|
|
||||||
float yoffset = newY - lastY;
|
|
||||||
|
|
||||||
lastX = newX;
|
|
||||||
lastY = newY;
|
|
||||||
|
|
||||||
xoffset *= sensitivity;
|
|
||||||
yoffset *= sensitivity;
|
|
||||||
|
|
||||||
sceneview.cam.yaw += xoffset;
|
|
||||||
sceneview.cam.pitch += yoffset;
|
|
||||||
|
|
||||||
if (sceneview.cam.pitch > 89.0f)
|
|
||||||
sceneview.cam.pitch = 89.0f;
|
|
||||||
if (sceneview.cam.pitch < -89.0f)
|
|
||||||
sceneview.cam.pitch = -89.0f;
|
|
||||||
|
|
||||||
}
|
|
||||||
else if (firstMouse == false)
|
|
||||||
{
|
|
||||||
glfwSetInputMode((GLFWwindow*)appWindow->GetHandle(), GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
|
||||||
firstMouse = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for Camara movement input here!
|
|
||||||
if (keyIsPressed(YOGGIE_KEY_W))
|
|
||||||
sceneview.cam.Position += sceneview.cam.Front * movement_speed;
|
|
||||||
|
|
||||||
if (keyIsPressed(YOGGIE_KEY_A))
|
|
||||||
sceneview.cam.Position -= sceneview.cam.Right * movement_speed;
|
|
||||||
|
|
||||||
if (keyIsPressed(YOGGIE_KEY_S))
|
|
||||||
sceneview.cam.Position -= sceneview.cam.Front * movement_speed;
|
|
||||||
|
|
||||||
if (keyIsPressed(YOGGIE_KEY_D))
|
|
||||||
sceneview.cam.Position += sceneview.cam.Right * movement_speed;
|
|
||||||
|
|
||||||
|
std::cout << "Scene view in Focus!\r" ;
|
||||||
}
|
}
|
||||||
|
|
||||||
GuiBegin();
|
GuiBegin();
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
MainMenuBar menuBar = MainMenuBar();
|
MainMenuBar menuBar = MainMenuBar();
|
||||||
|
|
||||||
@ -181,10 +129,70 @@ public:
|
|||||||
private:
|
private:
|
||||||
bool SimulatePhysics = true;
|
bool SimulatePhysics = true;
|
||||||
YoggieEngine::Entity Selected;
|
YoggieEngine::Entity Selected;
|
||||||
|
|
||||||
Project project;
|
Project project;
|
||||||
Scene scene;
|
Scene scene;
|
||||||
|
|
||||||
|
|
||||||
|
void UpdateSceneCamera(Viewport& sceneview) {
|
||||||
|
const float movement_speed = 0.1f;
|
||||||
|
static float lastX = 400, lastY = 300;
|
||||||
|
const float sensitivity = 0.1;
|
||||||
|
static bool firstMouse = true;
|
||||||
|
|
||||||
|
if (MouseButtonPressed(YOGGIE_MOUSE_BUTTON_RIGHT)) {
|
||||||
|
|
||||||
|
glfwSetInputMode((GLFWwindow*)appWindow->GetHandle(), GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
|
||||||
|
auto newX = getCursorPosX(appWindow);
|
||||||
|
auto newY = getCursorPosY(appWindow);
|
||||||
|
|
||||||
|
if (firstMouse)
|
||||||
|
{
|
||||||
|
lastX = newX;
|
||||||
|
lastY = newY;
|
||||||
|
firstMouse = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
float xoffset = newX - lastX;
|
||||||
|
float yoffset = newY - lastY;
|
||||||
|
|
||||||
|
lastX = newX;
|
||||||
|
lastY = newY;
|
||||||
|
|
||||||
|
xoffset *= sensitivity;
|
||||||
|
yoffset *= sensitivity;
|
||||||
|
|
||||||
|
sceneview.cam.yaw += xoffset;
|
||||||
|
sceneview.cam.pitch += yoffset;
|
||||||
|
|
||||||
|
if (sceneview.cam.pitch > 89.0f)
|
||||||
|
sceneview.cam.pitch = 89.0f;
|
||||||
|
if (sceneview.cam.pitch < -89.0f)
|
||||||
|
sceneview.cam.pitch = -89.0f;
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (firstMouse == false)
|
||||||
|
{
|
||||||
|
glfwSetInputMode((GLFWwindow*)appWindow->GetHandle(), GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||||
|
firstMouse = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for Camara movement input here!
|
||||||
|
if (keyIsPressed(YOGGIE_KEY_W)) {
|
||||||
|
sceneview.cam.Position += sceneview.cam.Front * movement_speed;
|
||||||
|
std::cout << "Pressed W !" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (keyIsPressed(YOGGIE_KEY_A))
|
||||||
|
sceneview.cam.Position -= sceneview.cam.Right * movement_speed;
|
||||||
|
|
||||||
|
if (keyIsPressed(YOGGIE_KEY_S))
|
||||||
|
sceneview.cam.Position -= sceneview.cam.Front * movement_speed;
|
||||||
|
|
||||||
|
if (keyIsPressed(YOGGIE_KEY_D))
|
||||||
|
sceneview.cam.Position += sceneview.cam.Right * movement_speed;
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
YoggieEngine::Application* CreateApplication() {
|
YoggieEngine::Application* CreateApplication() {
|
||||||
@ -192,3 +200,5 @@ YoggieEngine::Application* CreateApplication() {
|
|||||||
return new Editor();
|
return new Editor();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -71,14 +71,14 @@ Renderer::Renderer(RendererConfig& config)
|
|||||||
lightingPassShader("build/Debug/Shaders/deferred/lightPass.vert", "build/Debug/Shaders/deferred/lightPass.frag"),
|
lightingPassShader("build/Debug/Shaders/deferred/lightPass.vert", "build/Debug/Shaders/deferred/lightPass.frag"),
|
||||||
SkyboxShader("build/Debug/Shaders/Cubemaps/Skybox.vert", "build/Debug/Shaders/Cubemaps/Skybox.frag"),
|
SkyboxShader("build/Debug/Shaders/Cubemaps/Skybox.vert", "build/Debug/Shaders/Cubemaps/Skybox.frag"),
|
||||||
BlendingShader("build/Debug/Shaders/forward/Blending.vert", "build/Debug/Shaders/forward/Blending.frag"),
|
BlendingShader("build/Debug/Shaders/forward/Blending.vert", "build/Debug/Shaders/forward/Blending.frag"),
|
||||||
forwardShader("build/Debug/Shaders/forward/geometry.vert", "build/Debug/Shaders/forward/geometry.frag")
|
forwardShader("build/Debug/Shaders/forward/geometry.vert", "build/Debug/Shaders/forward/geometry.frag"),
|
||||||
|
postProcessingShader("build/Debug/Shaders/forward/postprocessing.vert", "build/Debug/Shaders/forward/postprocessing.frag")
|
||||||
{
|
{
|
||||||
width = config.ScreenWidth;
|
width = config.ScreenWidth;
|
||||||
height = config.ScreenHeight;
|
height = config.ScreenHeight;
|
||||||
|
|
||||||
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
// Deferred Rendering
|
// Deferred Rendering
|
||||||
glGenFramebuffers(1, &gBuffer);
|
glGenFramebuffers(1, &gBuffer);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, gBuffer);
|
glBindFramebuffer(GL_FRAMEBUFFER, gBuffer);
|
||||||
@ -151,9 +151,6 @@ Renderer::Renderer(RendererConfig& config)
|
|||||||
grassTexture = Texture("build/Debug/Texture/grass.png", true);
|
grassTexture = Texture("build/Debug/Texture/grass.png", true);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Renderer::~Renderer(){}
|
Renderer::~Renderer(){}
|
||||||
@ -257,6 +254,32 @@ void Renderer::GeometryPass() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Renderer::ForwardGeometryPass()
|
||||||
|
{
|
||||||
|
for (const DrawCommand& command : commands)
|
||||||
|
{
|
||||||
|
if (command.isDynamic == false)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
glBindVertexArray(command.VAO_identifier);
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, command.IBO_identifier);
|
||||||
|
|
||||||
|
forwardShader.Use();
|
||||||
|
|
||||||
|
forwardShader.setUniformVec3("Color", command.color);
|
||||||
|
forwardShader.setUniformMat4("M", command.transform.LocalTransform);
|
||||||
|
forwardShader.setUniformMat4("V", MainCamera.ViewMatrix);
|
||||||
|
forwardShader.setUniformMat4("P", MainCamera.ProjectionMatrix);
|
||||||
|
|
||||||
|
glDrawElements(GL_TRIANGLES, static_cast<unsigned int>(command.num_elements),
|
||||||
|
GL_UNSIGNED_INT, NULL);
|
||||||
|
|
||||||
|
glBindVertexArray(0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void Renderer::SkyboxPass() {
|
void Renderer::SkyboxPass() {
|
||||||
// Render skybox
|
// Render skybox
|
||||||
glDepthMask(GL_FALSE);
|
glDepthMask(GL_FALSE);
|
||||||
@ -267,7 +290,6 @@ void Renderer::SkyboxPass() {
|
|||||||
glBindTexture(GL_TEXTURE_CUBE_MAP, sky.getID());
|
glBindTexture(GL_TEXTURE_CUBE_MAP, sky.getID());
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 36);
|
glDrawArrays(GL_TRIANGLES, 0, 36);
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
|
|
||||||
glDepthMask(GL_TRUE);
|
glDepthMask(GL_TRUE);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -361,12 +383,38 @@ void Renderer::BlendingPass() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glBindVertexArray(0);
|
||||||
|
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Renderer::PostProcessing()
|
||||||
|
{
|
||||||
|
postProcessingShader.Use();
|
||||||
|
postProcessingShader.setUniformInt("screen", 0);
|
||||||
|
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, m_framebuffer.GetColourAttachment());
|
||||||
|
|
||||||
|
|
||||||
|
glBindVertexArray(quadVAO);
|
||||||
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||||
|
glBindVertexArray(0);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer::CopyGBuffer() {
|
||||||
|
glBindFramebuffer(GL_READ_FRAMEBUFFER, gBuffer);
|
||||||
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_framebuffer.GetId());
|
||||||
|
glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, GL_DEPTH_BUFFER_BIT, GL_NEAREST);
|
||||||
|
|
||||||
|
glBindFramebuffer(GL_FRAMEBUFFER, m_framebuffer.GetId());
|
||||||
|
}
|
||||||
|
|
||||||
void Renderer::Render(Scene& scene)
|
void Renderer::Render(Scene& scene)
|
||||||
{
|
{
|
||||||
SubmitVegetationDemo();
|
SubmitVegetationDemo();
|
||||||
@ -380,37 +428,13 @@ void Renderer::Render(Scene& scene)
|
|||||||
|
|
||||||
lightingPass(scene);
|
lightingPass(scene);
|
||||||
|
|
||||||
|
CopyGBuffer();
|
||||||
|
|
||||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, gBuffer);
|
ForwardGeometryPass();
|
||||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_framebuffer.GetId());
|
|
||||||
glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, GL_DEPTH_BUFFER_BIT, GL_NEAREST);
|
|
||||||
|
|
||||||
// Forward rendering approach
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, m_framebuffer.GetId());
|
|
||||||
|
|
||||||
for (const DrawCommand& command : commands)
|
|
||||||
{
|
|
||||||
if (command.isDynamic == false)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
glBindVertexArray(command.VAO_identifier);
|
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, command.IBO_identifier);
|
|
||||||
|
|
||||||
forwardShader.Use();
|
|
||||||
|
|
||||||
forwardShader.setUniformVec3("Color", command.color);
|
|
||||||
forwardShader.setUniformMat4("M", command.transform.LocalTransform);
|
|
||||||
forwardShader.setUniformMat4("V", MainCamera.ViewMatrix);
|
|
||||||
forwardShader.setUniformMat4("P", MainCamera.ProjectionMatrix);
|
|
||||||
|
|
||||||
glDrawElements(GL_TRIANGLES, static_cast<unsigned int>(command.num_elements),
|
|
||||||
GL_UNSIGNED_INT, NULL);
|
|
||||||
|
|
||||||
glBindVertexArray(0);
|
|
||||||
|
|
||||||
}
|
|
||||||
BlendingPass();
|
BlendingPass();
|
||||||
|
|
||||||
|
//PostProcessing();
|
||||||
|
|
||||||
|
|
||||||
// Lighting pass
|
// Lighting pass
|
||||||
|
@ -35,10 +35,12 @@ namespace YoggieEngine {
|
|||||||
Framebuffer& getCurrentFrameBuffer() { return m_framebuffer; }
|
Framebuffer& getCurrentFrameBuffer() { return m_framebuffer; }
|
||||||
private:
|
private:
|
||||||
void GeometryPass();
|
void GeometryPass();
|
||||||
|
void ForwardGeometryPass();
|
||||||
void SkyboxPass();
|
void SkyboxPass();
|
||||||
void lightingPass(Scene& scene);
|
void lightingPass(Scene& scene);
|
||||||
void BlendingPass();
|
void BlendingPass();
|
||||||
|
void PostProcessing();
|
||||||
|
void CopyGBuffer();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -59,6 +61,8 @@ namespace YoggieEngine {
|
|||||||
Shader lightingPassShader;
|
Shader lightingPassShader;
|
||||||
Shader gBufferShader;
|
Shader gBufferShader;
|
||||||
Shader SkyboxShader;
|
Shader SkyboxShader;
|
||||||
|
Shader postProcessingShader;
|
||||||
|
|
||||||
|
|
||||||
// blending
|
// blending
|
||||||
Shader BlendingShader;
|
Shader BlendingShader;
|
||||||
|
Loading…
Reference in New Issue
Block a user