Added icosphere primitive

simple_math_single_header
Martin Felis 2018-09-14 15:00:37 +02:00
parent 03a3b856d7
commit 48a4725b51
1 changed files with 86 additions and 11 deletions

View File

@ -60,14 +60,30 @@ static const GLfloat g_textured_quad_vertex_buffer_data[] = {
1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f,
}; };
static const GLfloat g_coordinate_system_vertex_buffer_data[] = { static void set_icosphere_point(
0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, VertexArray::VertexData* data,
1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, unsigned int index,
0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, const Vector3f &v) {
0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, assert (index >= 0 && index < 12);
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f,
0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f data[index].x = v[0];
}; data[index].y = v[1];
data[index].z = v[2];
data[index].w = 1.0f;
Vector3f vn = v.normalized();
data[index].nx = vn[0];
data[index].ny = vn[1];
data[index].nz = vn[2];
data[index].s = 0.0f;
data[index].t = 0.0f;
data[index].r = 255.0f;
data[index].g = 255.0f;
data[index].b = 255.0f;
data[index].a = 255.0f;
}
VertexArray gVertexArray; VertexArray gVertexArray;
VertexArrayMesh gCoordinateFrameMesh; VertexArrayMesh gCoordinateFrameMesh;
@ -76,6 +92,7 @@ VertexArrayMesh gXZPlaneMesh;
VertexArrayMesh gUnitCubeMesh; VertexArrayMesh gUnitCubeMesh;
VertexArrayMesh gUnitCubeLines; VertexArrayMesh gUnitCubeLines;
VertexArrayMesh gScreenQuad; VertexArrayMesh gScreenQuad;
VertexArrayMesh gIcoSphere;
AssetFile gAssetFile; AssetFile gAssetFile;
@ -566,6 +583,61 @@ void Renderer::Initialize(int width, int height) {
}; };
gScreenQuad.SetIndexData(screen_quad_indices, 6); gScreenQuad.SetIndexData(screen_quad_indices, 6);
// Icosphere
//
//
// Icosphere
VertexArray::VertexData icosphere_data[12];
float t_icosphere = (1.0f + sqrt(5.0f)) * 0.5f;
set_icosphere_point(icosphere_data, 0, Vector3f (-1.0f, t_icosphere, 0.0f));
set_icosphere_point(icosphere_data, 1, Vector3f ( 1.0f, t_icosphere, 0.0f));
set_icosphere_point(icosphere_data, 2, Vector3f (-1.0f, -t_icosphere, 0.0f));
set_icosphere_point(icosphere_data, 3, Vector3f ( 1.0f, -t_icosphere, 0.0f));
set_icosphere_point(icosphere_data, 4, Vector3f (0.0f, -1.0f, t_icosphere));
set_icosphere_point(icosphere_data, 5, Vector3f (0.0f, 1.0f, t_icosphere));
set_icosphere_point(icosphere_data, 6, Vector3f (0.0f, -1.0f, -t_icosphere));
set_icosphere_point(icosphere_data, 7, Vector3f (0.0f, 1.0f, -t_icosphere));
set_icosphere_point(icosphere_data, 8, Vector3f ( t_icosphere, 0.0f, -1.0f));
set_icosphere_point(icosphere_data, 9, Vector3f ( t_icosphere, 0.0f, 1.0f));
set_icosphere_point(icosphere_data, 10, Vector3f (-t_icosphere, 0.0f, -1.0f));
set_icosphere_point(icosphere_data, 11, Vector3f (-t_icosphere, 0.0f, 1.0f));
gIcoSphere.Initialize(gVertexArray, 12);
gIcoSphere.SetData(icosphere_data, 12);
GLuint icosphere_index_data[] = {
0, 11, 5,
0, 5, 1,
0, 1, 7,
0, 7, 10,
0, 10, 11,
1, 5, 9,
5, 11, 4,
11, 10, 2,
10, 7, 6,
7, 1, 8,
3, 9, 4,
3, 4, 2,
3, 2, 6,
3, 6, 8,
3, 8, 9,
4, 9, 5,
2, 4, 11,
6, 2, 10,
8, 6, 7,
9, 8, 1
};
gIcoSphere.SetIndexData(icosphere_index_data, 20 * 3);
// Simple Shader // Simple Shader
mSimpleProgram = RenderProgram("data/shaders/vs_simple.glsl", "data/shaders/fs_simple.glsl"); mSimpleProgram = RenderProgram("data/shaders/vs_simple.glsl", "data/shaders/fs_simple.glsl");
bool load_result = mSimpleProgram.Load(); bool load_result = mSimpleProgram.Load();
@ -1027,7 +1099,6 @@ void Renderer::DebugDrawShadowCascades() {
gUnitCubeLines.Draw(GL_LINES); gUnitCubeLines.Draw(GL_LINES);
} }
// Draw bounding boxes in world space // Draw bounding boxes in world space
if (mLight.mDebugDrawSplitWorldBounds) { if (mLight.mDebugDrawSplitWorldBounds) {
Vector3f dimensions = (bbox_world.mMax - bbox_world.mMin) * 0.5f; Vector3f dimensions = (bbox_world.mMax - bbox_world.mMin) * 0.5f;
@ -1126,6 +1197,12 @@ void Renderer::RenderScene(RenderProgram &program, const Camera& camera) {
program.SetVec4("uColor", Vector4f (1.0f, 1.0f, 1.0f, 1.0f)); program.SetVec4("uColor", Vector4f (1.0f, 1.0f, 1.0f, 1.0f));
gXZPlaneMesh.Draw(GL_TRIANGLES); gXZPlaneMesh.Draw(GL_TRIANGLES);
program.SetMat44("uModelMatrix",
TranslateMat44(0.0f, 2.0f, 0.0f)
);
program.SetVec4("uColor", Vector4f (1.0f, 0.2f, 0.4f, 1.0f));
gIcoSphere.Draw(GL_TRIANGLES);
gAssetFile.DrawModel(program); gAssetFile.DrawModel(program);
} }
@ -1141,8 +1218,6 @@ void Renderer::DrawGui() {
switch (sRendererSettings.RenderMode) { switch (sRendererSettings.RenderMode) {
case SceneRenderModeDefault: case SceneRenderModeDefault:
mRenderTextureRef.mTextureIdPtr = mRenderTextureRef.mTextureIdPtr =
// &mRenderTarget.mColorTexture;
// &mDeferredLightingTarget.mColorTexture;
mUseDeferred ? &mDeferredLightingTarget.mColorTexture : &mRenderTarget.mColorTexture; mUseDeferred ? &mDeferredLightingTarget.mColorTexture : &mRenderTarget.mColorTexture;
break; break;
case SceneRenderModeColor: case SceneRenderModeColor: