Hello Guest

Recent Posts

Pages: 1 2 [3] 4 5 ... 10
21
OpenGL / Re: Improving Performance of Rendering 2D Tiled Terrain
« Last post by Cornix on November 04, 2018, 17:10:51 »
What have you measured? What is your bottleneck?

If you want to "optimize" something you better know how good it is right now and how good it needs to be.
22
OpenGL / Improving Performance of Rendering 2D Tiled Terrain
« Last post by Setlock on November 04, 2018, 16:48:19 »
Hello everyone Ive been working on optimizing my rendering technique for my 2D game. Right now I render quads in the most modern way I can find using VAO for vertices, indices etc. my rendering looks like this:
Code: [Select]
public void render(Map<TexturedModel,List<Entity>> entities)
{
    for(TexturedModel model : entities.keySet())
    {
        if(model!= null)
        {
            prepareTexturedModel(model);
            List<Entity> batch = entities.get(model);
            for(Entity entity : batch)
            {
                prepareInstance(entity);
                GL11.glDrawElements(GL11.GL_TRIANGLES,model.getRawModel().getVertexCount(), GL11.GL_UNSIGNED_INT,0);
            }
            unbindTexturedModel();
        }
    }
}

PrepareTexturedModel(model) simply binds a texture to the quad, prepareInstance(entity) simply sets transformation matrix and other attributes of the entity to be drawn. Currently the game Im making creates 2D terrain using Simplex Noise and creates a new Quad of width 16 and height 16 and ONLY the quads on screen are rendered so depending on the size of the screen more or less quads will be rendered, which increases or decreases performance respectively.


The image above should show how tiles are separated, the water doesnt show a border because its a collection of 32x32 quads instead of 16x16, just to make the texture look bigger.

My main question is how could I go about optimizing the rendering of those tiles, also just a side not they dont have to be individually editable, one idea I was thinking about was grouping similar tiles together and just making one larger tile and then texturing that, which would decrease the number of vertices but I im stumped on how I could go about doing that as well.

Thanks in advance for you help!
23
OpenGL / Re: MSAA Texturing Artifacts
« Last post by Screendead on November 03, 2018, 15:33:57 »
That's delightfully obscure and even more delightfully quick. Instant fix. Thanks!
Github repo here in case you were interested.
24
OpenGL / Re: MSAA Texturing Artifacts
« Last post by KaiHH on November 03, 2018, 15:25:32 »
If this happens only with multisampled rendering, then the issue is very likely that texture coordinates for pixel centered sample locations are sometimes extrapolated when they do not lie inside the rasterized primitive.
Read this for an explanation: https://docs.microsoft.com/en-us/windows/desktop/direct3d11/d3d10-graphics-programming-guide-rasterizer-stage-rules#multisample-anti-aliasing-rasterization-rules
(it's for Direct3D, but the same applies for OpenGL).
To combat this, you can enable "centroid" vertex attribute interpolation for your texture coordinates.
See "centroid" in: https://www.khronos.org/opengl/wiki/Type_Qualifier_(GLSL)#Interpolation_qualifiers
25
OpenGL / MSAA Texturing Artifacts
« Last post by Screendead on November 03, 2018, 15:08:17 »
This occurs in a basic 3D voxel game I've been working on, if I enable MSAA in GLFW window hints.
I use a texture atlas, and each block face is made of two textured triangles, rather than fewer, more optimised, larger triangles.
I'm looking to be pointed in the right direction to solving this problem, and I'll provide any necessary information to get there. Thanks :D
26
Lightweight Java Gaming Library / Re: glEnableVertexAttribArray black background
« Last post by KaiHH on November 03, 2018, 13:30:38 »
In order for your code to work, you would need to make the following changes (unified diff format):
Code: [Select]
@@ -30,6 +30,7 @@ import static org.lwjgl.opengl.ARBShaderObjects.*;
 import static org.lwjgl.opengl.ARBVertexBufferObject.*;
 import static org.lwjgl.opengl.ARBVertexShader.GL_VERTEX_SHADER_ARB;
 import static org.lwjgl.opengl.ARBVertexShader.glEnableVertexAttribArrayARB;
+import static org.lwjgl.opengl.ARBVertexShader.glDisableVertexAttribArrayARB;
 import static org.lwjgl.opengl.ARBVertexShader.glGetAttribLocationARB;
 import static org.lwjgl.opengl.GL11.GL_LINEAR;
 import static org.lwjgl.opengl.GL11.GL_LINEAR_MIPMAP_LINEAR;
@@ -298,9 +299,7 @@ public class WavefrontObjDemo {
         glUseProgramObjectARB(cubemapProgram);
 
         vertexAttribute = glGetAttribLocationARB(program, "aVertex");
-        glEnableVertexAttribArrayARB(vertexAttribute);
         normalAttribute = glGetAttribLocationARB(program, "aNormal");
-        glEnableVertexAttribArrayARB(normalAttribute);
 
         modelMatrixUniform = glGetUniformLocationARB(program, "uModelMatrix");
         viewProjectionMatrixUniform = glGetUniformLocationARB(program, "uViewProjectionMatrix");
@@ -337,6 +336,7 @@ public class WavefrontObjDemo {
         viewMatrix.setLookAt(viewPosition.x, viewPosition.y, viewPosition.z, 0f, 0f, 0f, 0f, 1f,
                 0f);
         projectionMatrix.mul(viewMatrix, viewProjectionMatrix);
+        invViewProjMatrix.set(viewMatrix).setTranslation(0, 0, 0).mulLocal(projectionMatrix).invert(invViewProjMatrix);
 
         glUseProgramObjectARB(cubemapProgram);
         glUniformMatrix4fv(cubemap_invViewProjUniform, false, invViewProjMatrix.get(matrixBuffer));
@@ -354,7 +354,8 @@ public class WavefrontObjDemo {
         drawCubemap();
 
         glUseProgram(program);
-
+        glEnableVertexAttribArrayARB(vertexAttribute);
+        glEnableVertexAttribArrayARB(normalAttribute);
         for (Model.Mesh mesh : model.meshes) {
 
             glBindBuffer(GL_ARRAY_BUFFER, mesh.vertexArrayBuffer);
@@ -381,6 +382,8 @@ public class WavefrontObjDemo {
             glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mesh.elementArrayBuffer);
             glDrawElements(GL_TRIANGLES, mesh.elementCount, GL_UNSIGNED_INT, 0);
         }
+        glDisableVertexAttribArrayARB(vertexAttribute);
+        glDisableVertexAttribArrayARB(normalAttribute);
     }

But I also share the point of mudlee. You seem to be taking on a task which is way over your head and you must spend some more time learning OpenGL.
What you are currently doing is just stitching some snippets from lwjgl3-demos programs together and expecting that to work.
27
Lightweight Java Gaming Library / Re: glEnableVertexAttribArray black background
« Last post by mudlee on November 03, 2018, 07:49:25 »
I pass this to someone, who has more than half an hour to investigate this. You wrote you have 6 month, I would spend the first month at least to go through on this tutorial: https://ahbejarano.gitbook.io/lwjglgamedev/

If you don't do this, you will hit walls every day.
28
Lightweight Java Gaming Library / Re: glEnableVertexAttribArray black background
« Last post by begin on November 02, 2018, 20:40:25 »
29
Lightweight Java Gaming Library / Re: glEnableVertexAttribArray black background
« Last post by mudlee on November 02, 2018, 18:54:50 »
Can you share your full code somewhere? I see minor stuff in the attached code snippets, but to be exact I need to see the whole stuff.
30
Lightweight Java Gaming Library / Re: glEnableVertexAttribArray black background
« Last post by begin on November 02, 2018, 10:44:53 »
The term is. Less than 6 months. I do not think that I will learn at least half of the library in such a period of time, I just have a task in hand, which I need create.
Do not think that as soon as I haved a problem, I immediately go here. In fact, I can spend all my free time on this, but without finding a solution. But it is temporary, at the beginning of the study is always difficult.

So what about my mistake in this thread, can you help me? (Sorry for my bad language)
Pages: 1 2 [3] 4 5 ... 10