deferred rendering can be enabled for certain meshes
This commit is contained in:
parent
13f67a7cdb
commit
79b68fbff1
@ -82,6 +82,8 @@ public:
|
|||||||
auto& render3d = selected.GetComponent<Render3DComponent>();
|
auto& render3d = selected.GetComponent<Render3DComponent>();
|
||||||
if (ImGui::CollapsingHeader("Render3D", ImGuiTreeNodeFlags_DefaultOpen)) {
|
if (ImGui::CollapsingHeader("Render3D", ImGuiTreeNodeFlags_DefaultOpen)) {
|
||||||
ImGui::ColorEdit3("Colour", glm::value_ptr(render3d.color));
|
ImGui::ColorEdit3("Colour", glm::value_ptr(render3d.color));
|
||||||
|
|
||||||
|
ImGui::Checkbox("Use static rendering:", &render3d.isStatic);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static bool deferred = true;
|
static bool deferred = true;
|
||||||
|
@ -81,14 +81,12 @@ public:
|
|||||||
const float sensitivity = 0.1;
|
const float sensitivity = 0.1;
|
||||||
static bool firstMouse = true;
|
static bool firstMouse = true;
|
||||||
|
|
||||||
|
if (MouseButtonPressed(YOGGIE_MOUSE_BUTTON_RIGHT) ){
|
||||||
|
|
||||||
if (MouseButtonPressed(YOGGIE_MOUSE_BUTTON_MIDDLE) ){
|
glfwSetInputMode(AppWindow.GetGLFWHandle(), GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
|
||||||
|
|
||||||
|
|
||||||
auto newX = getCursorPosX(&AppWindow);
|
auto newX = getCursorPosX(&AppWindow);
|
||||||
auto newY = getCursorPosY(&AppWindow);
|
auto newY = getCursorPosY(&AppWindow);
|
||||||
|
|
||||||
|
|
||||||
if (firstMouse)
|
if (firstMouse)
|
||||||
{
|
{
|
||||||
lastX = newX;
|
lastX = newX;
|
||||||
@ -115,31 +113,25 @@ public:
|
|||||||
cam.pitch = -89.0f;
|
cam.pitch = -89.0f;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
else if (firstMouse == false)
|
||||||
|
{
|
||||||
|
glfwSetInputMode(AppWindow.GetGLFWHandle(), GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||||
|
firstMouse = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Check for Camara movement input here!
|
// Check for Camara movement input here!
|
||||||
if (keyIsPressed(YOGGIE_KEY_W)) {
|
if (keyIsPressed(YOGGIE_KEY_W))
|
||||||
cam.Position += cam.Front * movement_speed;
|
cam.Position += cam.Front * movement_speed;
|
||||||
}
|
|
||||||
|
|
||||||
if (keyIsPressed(YOGGIE_KEY_A))
|
if (keyIsPressed(YOGGIE_KEY_A))
|
||||||
{
|
|
||||||
cam.Position -= cam.Right * movement_speed;
|
cam.Position -= cam.Right * movement_speed;
|
||||||
|
|
||||||
}
|
if (keyIsPressed(YOGGIE_KEY_S))
|
||||||
|
|
||||||
if (keyIsPressed(YOGGIE_KEY_S)) {
|
|
||||||
cam.Position -= cam.Front * movement_speed;
|
cam.Position -= cam.Front * movement_speed;
|
||||||
|
|
||||||
}
|
if (keyIsPressed(YOGGIE_KEY_D))
|
||||||
|
|
||||||
if (keyIsPressed(YOGGIE_KEY_D)) {
|
|
||||||
cam.Position += cam.Right * movement_speed;
|
cam.Position += cam.Right * movement_speed;
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,14 @@
|
|||||||
#include "Scene/Components.h"
|
#include "Scene/Components.h"
|
||||||
namespace YoggieEngine {
|
namespace YoggieEngine {
|
||||||
struct DrawCommand {
|
struct DrawCommand {
|
||||||
|
bool isDynamic;
|
||||||
unsigned int VAO_identifier;
|
unsigned int VAO_identifier;
|
||||||
unsigned int num_elements;
|
unsigned int num_elements;
|
||||||
unsigned int IBO_identifier;
|
unsigned int IBO_identifier;
|
||||||
TransformComponent& transform;
|
TransformComponent& transform;
|
||||||
Shader& shader;
|
|
||||||
glm::vec3& color;
|
glm::vec3& color;
|
||||||
|
|
||||||
|
|
||||||
// Material
|
// Material
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -21,7 +21,6 @@ std::vector<glm::vec3> vegetation = {
|
|||||||
unsigned int transparentVAO, transparentVBO;
|
unsigned int transparentVAO, transparentVBO;
|
||||||
Texture grassTexture;
|
Texture grassTexture;
|
||||||
|
|
||||||
|
|
||||||
float skyboxVertices[]{
|
float skyboxVertices[]{
|
||||||
// positions
|
// positions
|
||||||
-1.0f, 1.0f, -1.0f,
|
-1.0f, 1.0f, -1.0f,
|
||||||
@ -72,7 +71,8 @@ Renderer::Renderer(RendererConfig& config)
|
|||||||
gBufferShader("build/Debug/Shaders/deferred/geometry.vert", "build/Debug/Shaders/deferred/geometry.frag"),
|
gBufferShader("build/Debug/Shaders/deferred/geometry.vert", "build/Debug/Shaders/deferred/geometry.frag"),
|
||||||
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")
|
||||||
{
|
{
|
||||||
width = config.ScreenWidth;
|
width = config.ScreenWidth;
|
||||||
height = config.ScreenHeight;
|
height = config.ScreenHeight;
|
||||||
@ -231,7 +231,7 @@ void Renderer::Submit( Render3DComponent& renderComponent, TransformComponent& t
|
|||||||
renderComponent.IBO = elementBuffer.getBufferID();
|
renderComponent.IBO = elementBuffer.getBufferID();
|
||||||
}
|
}
|
||||||
|
|
||||||
DrawCommand dc = { renderComponent.VAO, renderComponent.mesh.elements.size(), renderComponent.IBO, transform, renderComponent.shader, renderComponent.color };
|
DrawCommand dc = { renderComponent.isStatic , renderComponent.VAO, renderComponent.mesh.elements.size(), renderComponent.IBO, transform, renderComponent.color };
|
||||||
commands.push_back(dc);
|
commands.push_back(dc);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -242,6 +242,9 @@ void Renderer::GeometryPass() {
|
|||||||
|
|
||||||
for (const DrawCommand& command : commands)
|
for (const DrawCommand& command : commands)
|
||||||
{
|
{
|
||||||
|
if (command.isDynamic == true)
|
||||||
|
continue;
|
||||||
|
|
||||||
glBindVertexArray(command.VAO_identifier);
|
glBindVertexArray(command.VAO_identifier);
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, command.IBO_identifier);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, command.IBO_identifier);
|
||||||
|
|
||||||
@ -396,15 +399,18 @@ void Renderer::Render(Scene& scene)
|
|||||||
|
|
||||||
for (const DrawCommand& command : commands)
|
for (const DrawCommand& command : commands)
|
||||||
{
|
{
|
||||||
|
if (command.isDynamic == false)
|
||||||
|
continue;
|
||||||
|
|
||||||
glBindVertexArray(command.VAO_identifier);
|
glBindVertexArray(command.VAO_identifier);
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, command.IBO_identifier);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, command.IBO_identifier);
|
||||||
|
|
||||||
command.shader.Use();
|
forwardShader.Use();
|
||||||
|
|
||||||
command.shader.setUniformVec3("Color", command.color);
|
forwardShader.setUniformVec3("Color", command.color);
|
||||||
command.shader.setUniformMat4("M", command.transform.LocalTransform);
|
forwardShader.setUniformMat4("M", command.transform.LocalTransform);
|
||||||
command.shader.setUniformMat4("V", cam.ViewMatrix);
|
forwardShader.setUniformMat4("V", cam.ViewMatrix);
|
||||||
command.shader.setUniformMat4("P", cam.ProjectionMatrix);
|
forwardShader.setUniformMat4("P", cam.ProjectionMatrix);
|
||||||
|
|
||||||
glDrawElements(GL_TRIANGLES, static_cast<unsigned int>(command.num_elements),
|
glDrawElements(GL_TRIANGLES, static_cast<unsigned int>(command.num_elements),
|
||||||
GL_UNSIGNED_INT, NULL);
|
GL_UNSIGNED_INT, NULL);
|
||||||
|
@ -50,6 +50,8 @@ namespace YoggieEngine {
|
|||||||
unsigned int skyboxVAO = 0;
|
unsigned int skyboxVAO = 0;
|
||||||
CubeMap sky;
|
CubeMap sky;
|
||||||
|
|
||||||
|
Shader forwardShader;
|
||||||
|
|
||||||
// deferred rending parameters
|
// deferred rending parameters
|
||||||
unsigned int gBuffer, gPosition, gNormal, gColorSpec, gDepth;
|
unsigned int gBuffer, gPosition, gNormal, gColorSpec, gDepth;
|
||||||
Shader lightingPassShader;
|
Shader lightingPassShader;
|
||||||
|
@ -48,11 +48,10 @@ namespace YoggieEngine {
|
|||||||
Mesh mesh;
|
Mesh mesh;
|
||||||
// TODO: becomes a material
|
// TODO: becomes a material
|
||||||
glm::vec3 color;
|
glm::vec3 color;
|
||||||
Shader shader;
|
bool isStatic;
|
||||||
|
|
||||||
Render3DComponent()
|
Render3DComponent()
|
||||||
: shader(Shader("build/Debug/Shaders/forward/geometry.vert", "build/Debug/Shaders/forward/geometry.frag")),
|
: color(glm::vec3(1.0f, 0.0f, 0.0f)) , isStatic(true)
|
||||||
color(glm::vec3(1.0f, 0.0f, 0.0f))
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user