Jump to content

  • Log In with Google      Sign In   
  • Create Account

Getov

Member Since 01 Sep 2012
Offline Last Active Dec 11 2014 03:38 AM

Topics I've Started

Flickering when using Occlusion culling

04 December 2014 - 07:50 AM

Hello everyone!

I have implemented occlusion culling in my app and I think why the problem is happening but I am not sure how to solve it.

My scene is divided in different chunks (voxels) and I am rendering each voxel in a separate draw call.

In the 1st pass I render only the bounding box of the voxel and I start queries to check if the voxel is visible:

glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);

glDepthMask(GL_FALSE);
for (int i=0; i<numberOfVoxels; ++i) 
{
    glBeginQuery(GL_ANY_SAMPLES_PASSED, queryHandle[i]);
    renderBoundingBox(i);
    glEndQuery(GL_ANY_SAMPLES_PASSED);
}
glDepthMask(GL_TRUE);

In the 2nd pass I get the result from the query and if the voxel is visible I render it, otherwise - no :

for (int i=0; i<numberOfVoxels; ++i)
{
    glGetQueryObjectiv(queryHandle[i], GL_QUERY_RESULT , &voxel[i].isVisible);
    if (!voxel[i].isVisible) continue;

    glBindVertexArray(vao[i]);
    glDrawArrays(GL_TRIANGLES, 0, voxel[i].dataSize);
}

The problem appears when the bounding box is much bigger than the geometry in it, and there is huge empty gap in the box. When checking for depth test, this big box is hiding the smaller voxels behind it and this results in flickering.

One potential fix I came across is to divide such almost empty bboxes into smaller ones, as described in GPU Gems. But this is not that easy to do in my app and the performance may become even worse.

Do you have any other possible ideas and techniques I can use to solve that problem ?


How to shade hair (line segments) in OpenGL

03 July 2014 - 12:43 AM

Hi everyone, I hope you could give me any suggestions for my problem!

I render my hair geometry in line segments. The problem I have is with the correct shading of the hair.

From what I've read I understood that I need the direction of the line segment and the direction to the light source. Then the dot product of these direction vectors defines how the current vertex is shaded.

My vertex data is in one array buffer and I've decided to pass to GLSL 2 pointers - one for the current vertex and one for the next vertex, so I can calculate the direction of the line segment.

glEnableVertexAttribArray(gpuProgram->attrib("vert"));
glVertexAttribPointer(gpuProgram->attrib("vert"), 3, GL_FLOAT, GL_FALSE, 0, NULL);
glEnableVertexAttribArray(gpuProgram->attrib("vertNext"));
glVertexAttribPointer(gpuProgram->attrib("vertNext"), 3, GL_FLOAT, GL_FALSE, 0, (void*)sizeof(Vertex));

Where Vertex is a struct with 3 floats.

 

My vertex shader:

#version 150

uniform mat4 projection;
uniform mat4 view;
uniform mat4 model;
in vec3 vert;
in vec3 vertNext;
in vec3 color;
out vec3 fragVert;
out vec3 fragColor;
out vec3 fragVertNext;

void main(void)
{
    fragColor = color;
    fragVert = vert;
    fragVertNext = vertNext;
    gl_Position = projection * view * model * vec4(vert, 1);
}

My fragment shader:

#version 150

uniform mat4 model;
uniform vec3 lightPosition;
uniform vec4 surfaceColor;
in vec3 fragVertNext;
in vec3 fragVert;
in vec3 fragColor;
out vec4 finalColor;

void main(void)
{
    vec3 lightColor = vec3(1.0, 1.0, 1.0);

    vec3 vertPos1 = vec3(model * vec4(fragVert, 1));
    vec3 vertPos2 = vec3(model * vec4(fragVertNext, 1));

    vec3 segmentDir = normalize(vertPos1-vertPos2);
    vec3 dirToLight = normalize(lightPosition-vertPos1);

    float diffCoef = 1.0 - dot(segmentDir, dirToLight);

    vec3 diffuse = ambient + lightColor * diffCoef * fragColor;

    vec3 result = min(diffuse, vec3(1.0));
    finalColor = vec4(result, 1);
}

This is just the diffuse shading without specular reflection. And the result is wrong. I have to mention that 1 hair strand is composed of a couple line segments, and also there seems to be bug in the shading of the very last line segment - it appears black.


Mathematics for 3D programming - Exercises

22 January 2014 - 04:03 AM

Hello,

 

I am looking for book or other kind of source, that has exercises related to 3D programming math - linear algebra, transformations, rotations, vector operations, coordinate systems, distance between planes, projections ... etc.

 

I just want to sharpen my skills and find out where my weak points are, because reading only theory without practicing it is not really useful.


Configuring OpenGL problem

06 June 2013 - 05:54 AM

Hello,

 

That's the first time I have difficulties with setting up OpenGL. 

I just bought a new laptop with windows 8 64bit and I am using Visual Studio 2012.

I did the usual procedure with installing a 3d party lib just as I installed them on my previous PCs:

1. Download freeglut, glew, glfw, glut, sdl

2. Copy headers into "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include"

3. Copy libs into "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib"

4. Copy dll's into "C:\Windows\SysWOW64"

 

Then I downloaded the project I was developing on my other PC (was developed under windows 8 32bit if that's of any importance) and it would'n compile. The compiler threw me the following linking error:

 

Error 1 error LNK2001: unresolved external symbol __imp__glDrawArrays@12  - about 50 of these 
Error 63 error LNK2019: unresolved external symbol __imp__glClear@4 - again about 50 of these
 
The project is working perfectly on my old PC.
 
I did try to make a simple new project: click
Linked the following libraries (Properties->Linker->Input->Additional Dependencies)
opengl32.lib
glut32.lib
glu32.lib
And again it wouldn't compile, again the same linking errors:
Error 1 error LNK2019: unresolved external symbol __imp__glBegin@4 referenced in function "void __cdecl drawcube(void)" (?drawcube@@YAXXZ) P:\OpenGL_Setup\OpenGL_Setup\opengl_setup.obj
Error 2 error LNK2019: unresolved external symbol __imp__glClear@4 referenced in function "void __cdecl drawcube(void)" (?drawcube@@YAXXZ) P:\OpenGL_Setup\OpenGL_Setup\opengl_setup.obj
Error 3 error LNK2019: unresolved external symbol __imp__glClearColor@16 referenced in function _main P:\OpenGL_Setup\OpenGL_Setup\opengl_setup.obj
Error 4 error LNK2019: unresolved external symbol __imp__glColor3f@12 referenced in function "void __cdecl drawcube(void)" (?drawcube@@YAXXZ) P:\OpenGL_Setup\OpenGL_Setup\opengl_setup.obj
Error 5 error LNK2019: unresolved external symbol __imp__glEnd@0 referenced in function "void __cdecl drawcube(void)" (?drawcube@@YAXXZ) P:\OpenGL_Setup\OpenGL_Setup\opengl_setup.obj
Error 6 error LNK2019: unresolved external symbol __imp__glFlush@0 referenced in function "void __cdecl drawcube(void)" (?drawcube@@YAXXZ) P:\OpenGL_Setup\OpenGL_Setup\opengl_setup.obj
Error 7 error LNK2019: unresolved external symbol __imp__glLoadIdentity@0 referenced in function _main P:\OpenGL_Setup\OpenGL_Setup\opengl_setup.obj
Error 8 error LNK2019: unresolved external symbol __imp__glMatrixMode@4 referenced in function "void __cdecl drawcube(void)" (?drawcube@@YAXXZ) P:\OpenGL_Setup\OpenGL_Setup\opengl_setup.obj
Error 9 error LNK2019: unresolved external symbol __imp__glOrtho@48 referenced in function _main P:\OpenGL_Setup\OpenGL_Setup\opengl_setup.obj
Error 10 error LNK2019: unresolved external symbol __imp__glRotatef@16 referenced in function "void __cdecl drawcube(void)" (?drawcube@@YAXXZ) P:\OpenGL_Setup\OpenGL_Setup\opengl_setup.obj
Error 11 error LNK2019: unresolved external symbol __imp__glVertex3iv@4 referenced in function "void __cdecl drawcube(void)" (?drawcube@@YAXXZ) P:\OpenGL_Setup\OpenGL_Setup\opengl_setup.obj
 
 
I don't know if I am missing something, can you give me some ideas ?
 

Tower Defense Game 3D

05 March 2013 - 08:00 AM

Hello everyone ! 

 

This is my very first 3D project and I have just started it. Also this is the first time I use "modern OpenGL" and shaders. In my project I use some help classes and concepts from http://tomdalling.com/blog/category/modern-opengl/

 

At the moment I am trying to set up the scene so there is nothing related to game mechanics yet. My intention is to keep it simple, not going to load models, just geometric shapes (and maybe textures).

 

Unfortunately I am stuck . Maybe the most annoying thing that could happen - everything seems to work just fine, but the object won't draw on the screen sad.png .

 

I am using Visual Studio 2012 on Windows 8 32bit.

 

Because the source files are many, I will give link to my github repo : https://github.com/getov/tower-defense-3d

GPUProgram class handles shader operations. Util is namespace that has different utilities, at the moment only function for loading  files. The other classes should be clear. Ask me if you don't understand anything.

 

I hope you can help me with that. Also I will be happy if you can give me any ideas or suggestions about how to continue the game.


PARTNERS