Skip to content

Commit

Permalink
midway through adding the polygon and leaf stuff to the forest class,
Browse files Browse the repository at this point in the history
it's not running atm though :/
  • Loading branch information
BenCarey88 authored and Ben Carey committed Aug 10, 2019
1 parent 392999f commit 511b26e
Show file tree
Hide file tree
Showing 15 changed files with 329 additions and 83 deletions.
6 changes: 6 additions & 0 deletions ForestGenerator/include/Instance.h
Expand Up @@ -34,6 +34,12 @@ struct Instance
size_t m_instanceEnd;
//std::vector<GLshort> m_indices;

size_t m_instanceLeafStart;
size_t m_instanceLeafEnd;

size_t m_instancePolygonStart;
size_t m_instancePolygonEnd;

struct ExitPoint
{
ExitPoint(size_t _exitId, size_t _exitAge, ngl::Mat4 _transform);
Expand Down
4 changes: 2 additions & 2 deletions ForestGenerator/include/InstanceCacheMacros.h
Expand Up @@ -19,8 +19,8 @@
/// of variable, I have created the following macros to reduce repetition and improve readability of the code
///
/// (I initially tried to do this with a templated class, but ran into issues when I tried to pass a unique
/// pointer as the template argument, since some of the methods would have required calling the copy constructor
/// of the unique pointer)
/// pointer as the template argument (for the VAOs in the NGLScene class) since some of the methods would have
/// required calling the deleted copy constructor of the unique pointer)
//----------------------------------------------------------------------------------------------------------------------

#define CACHE_STRUCTURE(_class) std::vector<std::vector<std::vector<_class>>>
Expand Down
22 changes: 15 additions & 7 deletions ForestGenerator/include/LSystem.h
Expand Up @@ -159,22 +159,30 @@ class LSystem
std::vector<ngl::Vec3> m_rightVectors;
std::vector<float> m_thicknessValues;

std::vector<ngl::Vec3> m_heroVertices = {};
std::vector<GLshort> m_heroIndices= {};
std::vector<ngl::Vec3> m_heroRightVectors = {};
std::vector<float> m_heroThicknessValues= {};

std::vector<ngl::Vec3> m_leafVertices = {};
std::vector<GLushort> m_leafIndices = {};
std::vector<GLshort> m_leafIndices = {};
std::vector<ngl::Vec3> m_leafDirections = {};
std::vector<ngl::Vec3> m_leafRightVectors = {};

//polygons will be drawn with gl triangles not triangle strips
//to allow for multiple ones in different places
std::vector<ngl::Vec3> m_polygonVertices = {};
std::vector<GLushort> m_polygonIndices = {};
std::vector<GLshort> m_polygonIndices = {};
//std::vector<ngl::Vec3> m_polygonRightVectors = {};

std::vector<ngl::Vec3> m_heroVertices = {};
std::vector<GLshort> m_heroIndices= {};
std::vector<ngl::Vec3> m_heroRightVectors = {};
std::vector<float> m_heroThicknessValues= {};

std::vector<ngl::Vec3> m_heroLeafVertices = {};
std::vector<GLshort> m_heroLeafIndices = {};
std::vector<ngl::Vec3> m_heroLeafDirections = {};
std::vector<ngl::Vec3> m_heroLeafRightVectors = {};

std::vector<ngl::Vec3> m_heroPolygonVertices = {};
std::vector<GLshort> m_heroPolygonIndices = {};

size_t m_maxInstancePerLevel = 10;
bool m_forestMode = false;

Expand Down
12 changes: 10 additions & 2 deletions ForestGenerator/include/NGLScene.h
Expand Up @@ -267,6 +267,8 @@ public slots:
//third layer separates by age
//inner index corresponds to different instances of a given age and id
std::vector<CACHE_STRUCTURE(std::unique_ptr<ngl::AbstractVAO>)> m_forestVAOs;
std::vector<CACHE_STRUCTURE(std::unique_ptr<ngl::AbstractVAO>)> m_forestLeafVAOs;
std::vector<CACHE_STRUCTURE(std::unique_ptr<ngl::AbstractVAO>)> m_forestPolygonVAOs;

//----------------------------------------------------------------------------------------------------------------------
/// @brief bool to tell paintGL whether or not we need to rebuild the current LSystem VAO
Expand Down Expand Up @@ -350,9 +352,12 @@ public slots:
void buildSimpleIndexVAO(std::unique_ptr<ngl::AbstractVAO> &_vao, std::vector<ngl::Vec3> &_vertices,
std::vector<dataType> &_indices, GLenum _mode, GLenum _indexType);

void buildInstanceCacheVAO(std::unique_ptr<ngl::AbstractVAO> &_vao,
/* void buildInstanceCacheVAO(std::unique_ptr<ngl::AbstractVAO> &_vao,
LSystem &_treeType, Instance &_instance,
std::vector<ngl::Mat4> &_transforms);
std::vector<ngl::Mat4> &_transforms);*/
void buildInstanceCacheVAO(std::unique_ptr<ngl::AbstractVAO> &_vao, std::vector<ngl::Vec3> &_vertices,
std::vector<GLshort> &_indices, std::vector<ngl::Mat4> &_transforms,
Instance &_instance, GLenum _mode);

void addBufferToBoundVAO(size_t _bufferSize, const GLvoid * _bufferData);
void buildGridVAO();
Expand All @@ -361,6 +366,9 @@ public slots:
void buildLeafVAO(size_t _treeNum);
void buildPolygonVAO(size_t _treeNum);

void buildForestVAO(size_t _treeNum, size_t _id, size_t _age, size_t _index);
void buildForestLeafVAO(size_t _treeNum, size_t _id, size_t _age, size_t _index);
void buildForestPolygonVAO(size_t _treeNum, size_t _id, size_t _age, size_t _index);
void buildForestVAOs();

void loadTextures(ngl::ShaderLib *_shader, const std::string &_shaderName,
Expand Down
14 changes: 14 additions & 0 deletions ForestGenerator/shaders/ForestLeafFragment.glsl
@@ -0,0 +1,14 @@
#version 330 core

in vec2 UV;

uniform sampler2D textureMap;

/// @brief our output fragment colour
layout (location =0)out vec4 fragColour;

void main ()
{
fragColour = texture(textureMap, UV);
fragColour.a = step(0.0000000000001, fragColour.r+fragColour.g+fragColour.b);
}
32 changes: 32 additions & 0 deletions ForestGenerator/shaders/ForestLeafGeometry.glsl
@@ -0,0 +1,32 @@
#version 330 core

layout (points) in;
layout (triangle_strip, max_vertices=4) out;

in vec4 dir[1];
in vec4 right[1];

uniform mat4 MVP;

out vec2 UV;

void main ()
{
gl_Position = gl_in[0].gl_Position + 0.5*right[0];
UV = vec2(1,0);
EmitVertex();

gl_Position = gl_in[0].gl_Position + 0.5*right[0] + dir[0];
UV = vec2(1,1);
EmitVertex();

gl_Position = gl_in[0].gl_Position - 0.5*right[0];
UV = vec2(0,0);
EmitVertex();

gl_Position = gl_in[0].gl_Position - 0.5*right[0] + dir[0];
UV = vec2(0,1);
EmitVertex();

EndPrimitive();
}
20 changes: 20 additions & 0 deletions ForestGenerator/shaders/ForestLeafVertex.glsl
@@ -0,0 +1,20 @@
#version 330 core

/// @brief the vertex passed in
layout(location =0)in vec3 inVert;
layout(location =1)in mat4 inTransform;
layout(location =5)in vec3 inDir;
layout(location =6)in vec3 inRight;

uniform mat4 MVP;
//out vec3 vertColour;
out vec4 dir;
out vec4 right;

void main()
{
gl_Position = MVP * inTransform * vec4(inVert,1.0);
dir = MVP * inTransform * vec4(inDir,0);
right = MVP * inTransform * vec4(inRight,0);
//vertColour = vec3(1,0,0);
}
11 changes: 11 additions & 0 deletions ForestGenerator/shaders/ForestPolygonFragment.glsl
@@ -0,0 +1,11 @@
#version 330 core

in vec3 vertColour;

/// @brief our output fragment colour
layout (location =0)out vec4 fragColour;

void main ()
{
fragColour = vec4(vertColour,1);
}
14 changes: 14 additions & 0 deletions ForestGenerator/shaders/ForestPolygonVertex.glsl
@@ -0,0 +1,14 @@
#version 330 core

/// @brief the vertex passed in
layout(location =0)in vec3 inVert;
layout(location =1)in mat4 inTransform;

uniform mat4 MVP;
out vec3 vertColour;

void main()
{
gl_Position = MVP * inTransform * vec4(inVert,1.0);
vertColour = vec3(0.3,0.3,0.3);
}
6 changes: 3 additions & 3 deletions ForestGenerator/shaders/ForestVertex.glsl
Expand Up @@ -2,7 +2,7 @@

/// @brief the vertex passed in
layout(location =0)in vec3 inVert;
layout(location =1)in mat4 transform;
layout(location =1)in mat4 inTransform;
layout(location =5)in vec3 inRightVector;
layout(location =6)in float inThicknessValues;

Expand All @@ -17,10 +17,10 @@ void main()
{
//Note that this is identical to the treeVertex shader except that
//we multiply the positions by transform
gl_Position = MVP * transform * vec4(inVert,1.0);
gl_Position = MVP * inTransform * vec4(inVert,1.0);
vertCol = vec3(inVert[0]/10,inVert[1]/10,0);

worldSpacePos = vec3(transform * vec4(inVert,1));
worldSpacePos = vec3(inTransform * vec4(inVert,1));
rightVector = inRightVector;
thickness = inThicknessValues;
}
2 changes: 1 addition & 1 deletion ForestGenerator/shaders/TerrainFragment.glsl
Expand Up @@ -46,7 +46,7 @@ void main ()

// fragColour = vec4(normal,1);
fragColour = lightIntensity * texture(textureMap, UV);
fragColour.a = step(0.0000001, fragColour.r+fragColour.g+fragColour.b);
fragColour.a = 1;// step(0.0000001, fragColour.r+fragColour.g+fragColour.b);

//fragColour = vec4(normal,1);
//fragColour = vec4(vertColour,1);
Expand Down

0 comments on commit 511b26e

Please sign in to comment.