Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 3 123 LastLast
Results 1 to 10 of 21

Thread: Problem with 'edge' of hill and fog

  1. #1
    Intern Newbie
    Join Date
    Jan 2013
    Posts
    42

    Problem with 'edge' of hill and fog

    Hi I have a visual artefact in my scene that I don't quite understand. Some background information:

    In the pre-render I write to 3 buffers:
    -color
    -normal
    -position

    then in the render I render a quad and read the those values and calculate lighting and fog (based on distance from camera to fragment).

    also to detect the 'sky' I now check for zero-length normals. Further, I made the fog color the same as the sky color.

    Now the following artefact shows on the edges of the hills of my terrain:


    Click image for larger version. 

Name:	hillproblem.png 
Views:	176 
Size:	7.5 KB 
ID:	1045

    (click on the image to see the larger version. You can see in the middle that there is a hard line where the edge of the hill ends and the sky begins. In the 'non-deffered' rendering method I did not see this artefact.)

    It kinda seems like on the edge you see no fog, or it is fog combined with a black color... in other words: I'm not sure what is happening there, so I also don't know how to fix it.

    Anyone has an idea what it could be? Or maybe even know a way to fix it?

    Thanks!

  2. #2
    Intern Newbie
    Join Date
    May 2010
    Posts
    38
    Are you using nearest/point sampling when reading from those textures?

  3. #3
    Intern Newbie
    Join Date
    Jan 2013
    Posts
    42
    Yes I am, is that good or bad?

  4. #4
    Intern Newbie
    Join Date
    May 2010
    Posts
    38
    Quote Originally Posted by STTrife View Post
    Yes I am, is that good or bad?
    Yes its good.
    Because when sampling on the edge of the mountain its important to not read the pixels that belonging to the sky, and with linear sampling you do just that.

  5. #5
    Intern Newbie
    Join Date
    Jan 2013
    Posts
    42
    Thanks for the info. I did make sure the textures have the same size as the viewport/window so it should be a one on one pixel readout. But as the filtering of the buffers as textures for the quad is not the problem, I'm not sure how to continue investigating it.
    Any idea what else could be the cause of this or how I could find out what goes wrong?

    Thanks!

  6. #6
    Intern Newbie
    Join Date
    May 2010
    Posts
    38
    Well it could be anything but when I have similar problems I usually render the values from those buffers to get a visual view of the content.
    result = max( vec3( 0.0 ), normal.xyz );
    ...and so on.
    But you probably already do that.

  7. #7
    Intern Newbie
    Join Date
    Jan 2013
    Posts
    42
    Yeah I'm doing that, but it's really puzzeling. I tried finding the edge problem in one of the source buffers, but if I render those buffers as color values (making sure they are in range) then the hills are ok, there are no weird anomalies around the hill edges.
    Also I thought they might be misaligned, but even if I combine different values from buffers (like a normal and a position) there are still no anomalies around the hill edges.

    What I found is that the weird thing is only visible in the 'volume fog' that I made. It samples from a 3d texture like 25 times to simulate moving fog.

    But this value is only based on the camera position (a uniform) and the position of the fragment.
    I also use a variable distance, which is

    Code :
    float dist = distance(camPos,position);

    Now the weird thing is: the dist variable doesn't show any weird thing around the hill edges, the position variables itself are fine too, but the totalFog variable is doing the weird thing. But the fog variable IS based on the position of the camera and the position of the fragment. I really don't understand how that is possible.

    In the follow pic you can see the 'totalfog' coded in the red channel, and the 'dist' in the green channel. Both based on camPos and Position, but the dist is fine, and the total fog isn't.

    Click image for larger version. 

Name:	hilledge.png 
Views:	51 
Size:	1.6 KB 
ID:	1047

    ANY idea what could cause this? Or any idea how I could further investigate? Really stuck here...

    thanks!

  8. #8
    Intern Newbie
    Join Date
    May 2010
    Posts
    38
    What texture format do you have for your position-buffer?

  9. #9
    Intern Newbie
    Join Date
    Jan 2013
    Posts
    42
    The format I use is GL_RGB32F_ARB. I use OSG, so this is what I use:

    Code :
    osg::TextureRectangle* positionsRect;
    positionsRect = new osg::TextureRectangle;
    positionsRect->setTextureSize(screenWidth, screenHeight);
    positionsRect->setInternalFormat(GL_RGB32F_ARB);
    positionsRect->setSourceFormat(GL_RGB);
    positionsRect->setSourceType(GL_FLOAT);
    positionsRect->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::NEAREST);
    positionsRect->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::NEAREST);

  10. #10
    Intern Newbie
    Join Date
    May 2010
    Posts
    38
    Well it seems that you know what your're talking about.
    Just one question... how do you test that normal is zero?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •