final data push

This commit is contained in:
Evert Prants 2020-04-05 17:48:49 +03:00
parent 1e7e81764d
commit 674887d5ce
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
4 changed files with 175 additions and 10 deletions

17
src/Environment.cpp Normal file
View File

@ -0,0 +1,17 @@
#include "Environment.h"
void Environment::draw (Shader* shader)
{
for (int i = 0; i < MAX_LIGHTS; i++) {
/*std::string indx = std::to_string(i);
if (m_lights[i]) {
shader->setUniform("lightColor[" + indx + "]", m_lights[i].color);
shader->setUniform("lightPosition[" + indx + "]", m_lights[i].position);
shader->setUniform("attenuation[" + indx + "]", m_lights[i].attenuation);
} else {
shader->setUniform("lightColor[" + indx + "]", glm::vec3(0.0, 0.0, 0.0));
shader->setUniform("lightPosition[" + indx + "]", glm::vec3(0.0, 0.0, 0.0));
shader->setUniform("attenuation[" + indx + "]", glm::vec3(1.0, 0.0, 0.0));
}*/
}
}

53
src/Environment.h Normal file
View File

@ -0,0 +1,53 @@
#ifndef __ENVIRONMENT_H__
#define __ENVIRONMENT_H__
#include "util/Common.h"
#include "util/Singleton.h"
#include "Shader.h"
#define MAX_LIGHTS 4
struct Light {
Light (glm::vec3 position, glm::vec3 color, glm::vec3 attenuation = glm::vec3(1.0, 0.0, 0.0)) :
position(position), color(color), attenuation(attenuation) {}
glm::vec3 position;
glm::vec3 color;
glm::vec3 attenuation;
};
struct SpotLight : public Light {
SpotLight (glm::vec3 position, glm::vec3 dir, glm::vec3 color, glm::vec3 attenuation) :
Light(position, color, attenuation), direction(dir) {}
glm::vec3 direction;
};
struct DirectionalLight : public SpotLight {
DirectionalLight (glm::vec3 position, glm::vec3 dir, glm::vec3 color) :
SpotLight(position, dir, color, glm::vec3(1.0, 0.0, 0.0)) {}
};
class Environment : public Singleton<Environment>
{
public:
void draw (Shader* shader);
inline void setAmbientColor (glm::vec3 color) { m_ambient = color; }
inline void setSun (Light light) { m_sun = light; }
friend class Singleton<Environment>;
private:
Light m_sun;
// Ambient color
glm::vec3 m_ambient;
// Fog
glm::vec3 m_fogColor;
float m_fogStart;
float m_fogEnd;
// All lights
std::vector<Light> m_lights;
};
#endif // __ENVIRONMENT_H__

View File

@ -56,11 +56,11 @@ void PlanetFaceNode::tick(Camera* camera, GLfloat dtime, bool& tickUpdatedLOD, b
else if (camToOrigin > splitDistance * 2 && !m_leaf)
tickUpdatedLOD = this->merge();
// TODO: fix weird vanishing meshes
if (tickUpdatedLOD)
return;
// TODO: fix weird vanishing meshes
if (m_leaf && m_generated == false)
{
tickGeneratedFace = true;
@ -135,14 +135,20 @@ void PlanetFaceNode::generate()
vertices.push_back({ pos, vertNormal, glm::vec2(j * (1.0 / RESOLUTION), i * (1.0 / RESOLUTION)) });
// Set center
if ((i == RESOLUTION / 2 and j == RESOLUTION / 2))
if ((i == RESOLUTION / 2 && j == RESOLUTION / 2))
m_center = pos;
}
}
bool fanTop = true;
bool fanLeft = true;
bool fanRight = true;
bool fanBottom = true;
// Create indices for mesh
for (int gz = 0; gz < RESOLUTION - 1; gz++)
{
bool slantLeft = gz % 2 == 0;
for (int gx = 0; gx < RESOLUTION - 1; gx++)
{
int topLeft = (gz * RESOLUTION) + gx;
@ -150,12 +156,101 @@ void PlanetFaceNode::generate()
int bottomLeft = ((gz + 1) * RESOLUTION) + gx;
int bottomRight = bottomLeft + 1;
indices.push_back(bottomLeft);
indices.push_back(bottomRight);
indices.push_back(topRight);
indices.push_back(topRight);
indices.push_back(topLeft);
indices.push_back(bottomLeft);
bool uTri1 = true;
bool uTri2 = true;
int tri1[3];
int tri2[3];
if (slantLeft)
{
tri1[0] = topLeft;
tri1[1] = bottomLeft;
tri1[2] = bottomRight;
tri2[0] = topLeft;
tri2[1] = bottomRight;
tri2[2] = topRight;
}
else
{
tri1[0] = topLeft;
tri1[1] = bottomLeft;
tri1[2] = topRight;
tri2[0] = bottomLeft;
tri2[1] = bottomRight;
tri2[2] = topRight;
}
if (fanTop && gz == 0)
{
if (gx % 2 == 0)
{
tri2[0] = topLeft;
tri2[1] = bottomRight;
tri2[2] = topRight + 1;
}
else
{
uTri1 = false;
}
}
if (fanRight && gx == RESOLUTION - 2)
{
if (gz % 2 == 0)
{
tri2[0] = topRight;
tri2[1] = bottomLeft;
tri2[2] = bottomRight + RESOLUTION;
}
else
{
uTri2 = false;
}
}
if (fanBottom && gz == RESOLUTION - 2)
{
if (gx % 2 == 0)
{
tri2[0] = bottomLeft;
tri2[1] = bottomRight + 1;
tri2[2] = topRight;
}
else
{
uTri1 = false;
}
}
if (fanLeft && gx == 0)
{
if (gz % 2 == 0)
{
tri1[0] = topLeft;
tri1[1] = bottomLeft + RESOLUTION;
tri1[2] = bottomRight;
}
else
{
uTri1 = false;
}
}
if (uTri1)
{
indices.push_back(tri1[0]);
indices.push_back(tri1[1]);
indices.push_back(tri1[2]);
}
if (uTri2)
{
indices.push_back(tri2[0]);
indices.push_back(tri2[1]);
indices.push_back(tri2[2]);
}
slantLeft = !slantLeft;
}
}

View File

@ -6,7 +6,7 @@
#include "Shader.h"
#include "Camera.h"
#define RESOLUTION 64
#define RESOLUTION 61
enum Face
{