3D Render
-
I am trying to solve the below. I am newbie to game programming. Any pointers would be helpful here.
Consider the following 3D scene representing an old town's main square:
• A single statue
static geometry, high polygon count
low complexity fragment shader
• A particle system simulating smoke
animated, rendered as a large set of points
• A small set of characters
animated geometry, medium polygon count
medium complexity fragment shader
• A large set of buildings
static geometry, low polygon count
low complexity fragment shader
• A background image/skybox
• The camera/viewpoint is continuously moving within the scene.How would you render the statue - by itself – using OpenGL to achieve maximum vertex performance (vertices/second)?
How would you render the particle system - by itself - using OpenGL to achieve maximum vertex performance (vertices/second)?
How would you render the scene - as a whole - most efficiently on a GPU using OpenGL?
Given that the 3D scene was being rendered correctly but that you wanted to improve the performance further, how would you determine if the main performance limitation/bottleneck was located in the application, in the vertex processing stage, or in the fragment processing stage?
-
Anyone has any suggestions here? I am new to OpenGL programming.
To render particles, I can use shaders.Code is as below. Any comments?
``
#version 330 core
layout (location = 0) in vec4 vertex; // <vec2 position, vec2 texCoords>out vec2 TexCoords;
out vec4 ParticleColor;uniform mat4 projection;
uniform vec2 offset;
uniform vec4 color;void main()
{
float scale = 10.0f;
TexCoords = vertex.zw;
ParticleColor = color;
gl_Position = projection * vec4((vertex.xy * scale) + offset, 0.0, 1.0);
}//Below code to render particles
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
particleShader.Use();
for (Particle particle : particles)
{
if (particle.Life > 0.0f)
{
particleShader.SetVector2f("offset", particle.Position);
particleShader.SetVector4f("color", particle.Color);
particleTexture.Bind();
glBindVertexArray(particleVAO);
glDrawArrays(GL_TRIANGLES, 0, 6);
glBindVertexArray(0);
}
}
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
``