Moving vegetation test to the renderer
This commit is contained in:
parent
0f9be33bd6
commit
d5a6ddb9d5
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include "../../YoggieEngine/src/YoggieEngine.h"
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include "../../YoggieEngine/src/YoggieEngine.h"
|
||||
|
||||
enum class ASSET_TYPE {
|
||||
Unknown = -1,
|
||||
|
@ -14,7 +14,6 @@
|
||||
#include "SceneSerializer.h"
|
||||
#include "AssetManagement/AssetManager.h"
|
||||
#include "UI/MainMenuBar.h"
|
||||
const unsigned int MS_PER_UPDATE = 2;
|
||||
void CreateTestProject(std::unique_ptr<Project>& project, Scene& scene);
|
||||
|
||||
RendererConfig EditorSceneRendererConfig{
|
||||
@ -25,7 +24,7 @@ RendererConfig EditorSceneRendererConfig{
|
||||
};
|
||||
|
||||
glm::vec3 temp = glm::vec3(0);
|
||||
Camera cam = Camera(glm::vec3(12.0f, 1.0f, 0.0f), glm::vec3(45.0f, 0.0f, 0.0f), 90);
|
||||
Camera cam = Camera(glm::vec3(14.0f, 1.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), 90);
|
||||
class Editor : public Application {
|
||||
public:
|
||||
Editor()
|
||||
@ -120,7 +119,11 @@ public:
|
||||
|
||||
// Create the physics engine demo!
|
||||
Physics Physics;
|
||||
//Physics.Demo();
|
||||
Physics.Demo();
|
||||
/*Physics.EnableDebugVisuals();
|
||||
Physics.Step(0);
|
||||
Physics.SubmitMesh();
|
||||
*/
|
||||
|
||||
double previous = glfwGetTime();
|
||||
double lag = 0.0;
|
||||
@ -134,21 +137,12 @@ public:
|
||||
|
||||
AppWindow.Poll();
|
||||
|
||||
if (SimulatePhysics)
|
||||
{
|
||||
Physics.Step(1.0f / 60.0f);
|
||||
}
|
||||
|
||||
|
||||
while (lag >= MS_PER_UPDATE)
|
||||
{
|
||||
ActiveScene.Update();
|
||||
lag -= MS_PER_UPDATE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Physics.Step(elapsed);
|
||||
ActiveScene.Update();
|
||||
|
||||
RenderScene();
|
||||
/*Physics.DebugRender(*framebuffer);*/
|
||||
|
||||
RenderEditorGUI();
|
||||
|
||||
@ -173,7 +167,7 @@ private:
|
||||
GUIRenderer EditorGUIRenderer;
|
||||
|
||||
// Editor State
|
||||
bool SimulatePhysics = false;
|
||||
bool SimulatePhysics = true;
|
||||
entt::entity Selected;
|
||||
|
||||
std::unique_ptr<Project> CurrentProject;
|
||||
@ -218,10 +212,11 @@ void CreateTestProject(std::unique_ptr<Project>& project, Scene& scene ) {
|
||||
auto cube2 = scene.AddEntity("Cube2");
|
||||
auto& rendercube2 = cube2.AddComponent<Render3DComponent>();
|
||||
rendercube2.mesh = *(model->renderable->mesh);
|
||||
|
||||
auto relationcube = cube.AddComponent<RelationComponent>(cube2);
|
||||
|
||||
|
||||
auto Grass = scene.AddEntity("Grass/Window-Pane");
|
||||
//auto& renderGrass = Grass.AddComponent<Render3DComponent>();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,4 @@
|
||||
#pragma once
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
|
||||
#include "../Graphics/Primitives/Mesh.h"
|
||||
#include <assimp/Importer.hpp>
|
||||
|
@ -9,13 +9,25 @@ namespace YoggieEngine {
|
||||
Camera::Camera(glm::vec3 position, glm::vec3 rotation, float zoom)
|
||||
: Position(position), Rotation( rotation)
|
||||
{
|
||||
|
||||
Front = glm::vec3(-1.0f, 0.0f, 0.0f);
|
||||
Right = glm::vec3(0.0f, 0.0f, 1.0f);
|
||||
glm::vec3 WorldUp = glm::vec3(0.0f, 1.0f, 0.0f);
|
||||
Front = glm::vec3(0.0f, 0.0f, 1.0f);
|
||||
Right = glm::vec3(-1.0f, 0.0f, 0.0f);
|
||||
Up = glm::vec3(0.0f, 1.0f, 0.0f);
|
||||
Zoom = zoom;
|
||||
|
||||
|
||||
glm::vec3(direction);
|
||||
float yaw = 180;
|
||||
float pitch = 0;
|
||||
|
||||
direction.x = cos(glm::radians(yaw)) * cos(glm::radians(pitch));
|
||||
direction.z = sin(glm::radians(yaw));
|
||||
direction.y = sin(glm::radians(pitch)) * cos(glm::radians(pitch));
|
||||
Front = glm::normalize(direction);
|
||||
Right = glm::normalize(glm::cross(Front, WorldUp));
|
||||
Up = glm::normalize(glm::cross(Right, Front));
|
||||
|
||||
|
||||
ViewMatrix = glm::lookAt(
|
||||
Position,
|
||||
Position + Front,
|
||||
|
@ -2,6 +2,7 @@
|
||||
namespace YoggieEngine {
|
||||
class Texture {
|
||||
public:
|
||||
Texture() = default;
|
||||
Texture(const std::string texturePath, bool Transparency = false);
|
||||
|
||||
void Bind();
|
||||
|
@ -6,11 +6,20 @@
|
||||
#include "../Graphics/Memory/VertexArray.h"
|
||||
#include "../Graphics/Primitives/DrawCommand.h"
|
||||
|
||||
|
||||
extern YoggieEngine::Camera cam;
|
||||
namespace YoggieEngine {
|
||||
unsigned int quadVAO = 0;
|
||||
unsigned int quadVBO = 0;
|
||||
// vegetation test
|
||||
std::vector<glm::vec3> vegetation = {
|
||||
glm::vec3(-1.5f, 0.0f, -0.48f),
|
||||
glm::vec3(1.5f, 0.0f, 0.51f),
|
||||
glm::vec3(0.0f, 0.0f, 0.7f),
|
||||
glm::vec3(-0.3f, 0.0f, -2.3f)
|
||||
};
|
||||
|
||||
unsigned int transparentVAO, transparentVBO;
|
||||
Texture grassTexture;
|
||||
|
||||
|
||||
float skyboxVertices[]{
|
||||
@ -62,7 +71,8 @@ Renderer::Renderer(RendererConfig& config)
|
||||
: m_framebuffer(Framebuffer(config.ScreenWidth, config.ScreenHeight)),
|
||||
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"),
|
||||
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")
|
||||
{
|
||||
width = config.ScreenWidth;
|
||||
height = config.ScreenHeight;
|
||||
@ -136,6 +146,12 @@ Renderer::Renderer(RendererConfig& config)
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
|
||||
|
||||
#ifdef WINDOW
|
||||
grassTexture = Texture("build/Debug/Texture/blending_transparent_window.png", true);
|
||||
#else
|
||||
grassTexture = Texture("build/Debug/Texture/grass.png", true);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
@ -147,6 +163,37 @@ Camera& Renderer::getCamera() {
|
||||
return cam;
|
||||
}
|
||||
|
||||
void SubmitVegetationDemo() {
|
||||
|
||||
|
||||
if (transparentVAO == 0) {
|
||||
float transparentVertices[] = {
|
||||
// positions // texture Coords (swapped y coordinates because texture is flipped upside down)
|
||||
0.0f, 0.5f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, -0.5f, 0.0f, 0.0f, 1.0f,
|
||||
1.0f, -0.5f, 0.0f, 1.0f, 1.0f,
|
||||
|
||||
0.0f, 0.5f, 0.0f, 0.0f, 0.0f,
|
||||
1.0f, -0.5f, 0.0f, 1.0f, 1.0f,
|
||||
1.0f, 0.5f, 0.0f, 1.0f, 0.0f
|
||||
};
|
||||
|
||||
glGenVertexArrays(1, &transparentVAO);
|
||||
glGenBuffers(1, &transparentVBO);
|
||||
glBindVertexArray(transparentVAO);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, transparentVBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(transparentVertices), transparentVertices, GL_STATIC_DRAW);
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0);
|
||||
glEnableVertexAttribArray(1);
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3 * sizeof(float)));
|
||||
glBindVertexArray(0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Renderer::Submit( Render3DComponent& renderComponent, TransformComponent& transform) {
|
||||
if (renderComponent.VAO == 0 || renderComponent.IBO == 0)
|
||||
{
|
||||
@ -189,7 +236,6 @@ void Renderer::Submit( Render3DComponent& renderComponent, TransformComponent& t
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Renderer::GeometryPass() {
|
||||
// 1.0 Geometry pass
|
||||
gBufferShader.Use();
|
||||
@ -213,7 +259,6 @@ void Renderer::GeometryPass() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Renderer::SkyboxPass() {
|
||||
// Render skybox
|
||||
glDepthMask(GL_FALSE);
|
||||
@ -295,9 +340,42 @@ void Renderer::lightingPass(Scene& scene){
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
||||
void Renderer::BlendingPass() {
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
// Vegetation / blending test;
|
||||
BlendingShader.Use();
|
||||
glBindVertexArray(transparentVAO);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, grassTexture.GetID());
|
||||
|
||||
BlendingShader.setUniformMat4("V", cam.ViewMatrix);
|
||||
BlendingShader.setUniformMat4("P", cam.ProjectionMatrix);
|
||||
|
||||
|
||||
for (unsigned int i = 0; i < vegetation.size(); i++) {
|
||||
auto rotation = glm::rotate(glm::mat4(1.0f), 45.0f, glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
auto translation = glm::translate(glm::mat4(1.0f), vegetation[i]);
|
||||
auto transform = translation * rotation;
|
||||
BlendingShader.setUniformMat4("M", transform);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
|
||||
}
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Renderer::Render(Scene& scene)
|
||||
{
|
||||
|
||||
SubmitVegetationDemo();
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, gBuffer);
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
@ -334,6 +412,7 @@ void Renderer::Render(Scene& scene)
|
||||
glBindVertexArray(0);
|
||||
|
||||
}
|
||||
BlendingPass();
|
||||
|
||||
|
||||
|
||||
|
@ -35,6 +35,8 @@ namespace YoggieEngine {
|
||||
void GeometryPass();
|
||||
void SkyboxPass();
|
||||
void lightingPass(Scene& scene);
|
||||
void BlendingPass();
|
||||
|
||||
|
||||
|
||||
private:
|
||||
@ -54,5 +56,7 @@ namespace YoggieEngine {
|
||||
Shader gBufferShader;
|
||||
Shader SkyboxShader;
|
||||
|
||||
// blending
|
||||
Shader BlendingShader;
|
||||
};
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include <YoggieEngine.h>
|
||||
#include <glm/gtc/type_precision.hpp>
|
||||
#include "Physics.h"
|
||||
|
||||
namespace YoggieEngine {
|
||||
@ -58,21 +59,75 @@ namespace YoggieEngine {
|
||||
|
||||
void Physics::Step(float dt)
|
||||
{
|
||||
mScene->simulate(dt);
|
||||
mScene->simulate(1.0f/60.0f);
|
||||
mScene->fetchResults(true);
|
||||
}
|
||||
|
||||
void Physics::Demo()
|
||||
{
|
||||
createScene();
|
||||
|
||||
SetupPvdDebug();
|
||||
|
||||
createGroundPlane();
|
||||
|
||||
createStack(PxTransform(PxVec3(0, 0, stackZ -= 10.0f)), 10, 2.0f);
|
||||
}
|
||||
|
||||
void Physics::EnableDebugVisuals() {
|
||||
mScene->setVisualizationParameter(PxVisualizationParameter::eSCALE, 1.0f);
|
||||
mScene->setVisualizationParameter(PxVisualizationParameter::eACTOR_AXES, 2.0f);
|
||||
|
||||
}
|
||||
|
||||
|
||||
static unsigned int VisualizationVAO, VBO;
|
||||
static unsigned int numLines;
|
||||
void Physics::SubmitMesh() {
|
||||
const PxRenderBuffer& rb = mScene->getRenderBuffer();
|
||||
|
||||
|
||||
std::vector<PxVec3> lines= std::vector<PxVec3>();
|
||||
|
||||
numLines = rb.getNbLines();
|
||||
|
||||
for (unsigned int i = 0; i < numLines; i++) {
|
||||
auto line = rb.getLines()[i];
|
||||
lines.push_back(line.pos0);
|
||||
lines.push_back(line.pos1);
|
||||
|
||||
}
|
||||
|
||||
glGenVertexArrays(1, &VisualizationVAO);
|
||||
glGenBuffers(1, &VBO);
|
||||
|
||||
glBindVertexArray(VisualizationVAO);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, lines.size() * sizeof(PxVec3), &lines, GL_STATIC_DRAW);
|
||||
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
|
||||
|
||||
glBindVertexArray(0);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Physics::DebugRender(Framebuffer& framebuffer) {
|
||||
glDepthMask(GL_FALSE);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.GetId());
|
||||
|
||||
debugDraw.Use();
|
||||
glBindVertexArray(VisualizationVAO);
|
||||
glDrawArrays(GL_LINES, 0, numLines );
|
||||
glBindVertexArray(0);
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
glDepthMask(GL_TRUE);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
PxRigidDynamic* Physics::createDynamic(const PxTransform& t, const PxGeometry& geometry, const PxVec3& velocity = PxVec3(0)) {
|
||||
PxRigidDynamic* dynamic = PxCreateDynamic(*mPhysics, t, geometry, *gMaterial, 10.0f);
|
||||
dynamic->setAngularDamping(0.5f);
|
||||
|
@ -26,8 +26,14 @@ namespace YoggieEngine {
|
||||
|
||||
void Demo();
|
||||
|
||||
void EnableDebugVisuals();
|
||||
void SubmitMesh();
|
||||
|
||||
void DebugRender(Framebuffer& framebuffer);
|
||||
|
||||
|
||||
private:
|
||||
Shader debugDraw = Shader("build/Debug/Shaders/forward/debug.vert", "build/Debug/Shaders/forward/debug.frag");
|
||||
|
||||
PxRigidDynamic* createDynamic(const PxTransform& t, const PxGeometry& geometry, const PxVec3& velocity);
|
||||
void createStack(const PxTransform& t, PxU32 size, PxReal halfextent);
|
||||
@ -36,6 +42,7 @@ namespace YoggieEngine {
|
||||
|
||||
void SetupPvdDebug();
|
||||
|
||||
|
||||
|
||||
// Memory Management
|
||||
bool recordMemoryAllocations = true;
|
||||
|
Loading…
Reference in New Issue
Block a user