4

Lately, while getting used to C++ (already knowing OpenGL * fairly * well), I've gotten tired of the visual artifacts I see with textures at a distance, especially with large flat surfaces such as terrain. When coding in Java and OpenGL, I saw the same issues as well. Here's what I'm talking about:

image showing aliasing

I load my textures using the GL_COMPRESSED_RGBA_S3TC_DXT1_EXT (with DXT3 and DXT5 as well) extensions in OpenGL loading, obviously, .DDS images. Each image has 11 mipmaps (1 full-res texture and 11 lower-res textures), each of which are generated with bilinear in Paint.NET. The grass texture in this (where you see most of the artifacts) is 2048x2048. I AM using OpenGL 3.3, with shaders powering almost everything, so I can edit stuff in GLSL. Image Parameters are as follows

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 11);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 16);

In the GLSL Shader, I call texture2D(grassTexture, terrainTexcoord * 512.0f); The '* 512.0f' is so that the grass isn't stretched all over the entire chunk (I'm using chunks w/ heightmap). The sampler is just a generic sampler2D.

And if anyone's wondering, I got the code for the DDS loader from http://www.opengl-tutorial.org/ (best site ever for OpenGL 3.3+ BTW)

I've probably given more can than what's needed but I hate hearing the "Can I see some more code?" Here's what I'd like to know, what is this effect called? What is a good way to fix it? Is there an post processing effect that takes care of this? Am I doing something wrong? (probably the latter, but oh well xD) Thanks!

Tommy
  • 99,986
  • 12
  • 185
  • 204
David
  • 41
  • 6
  • That's a moiré pattern, caused by inaccurate sampling. But you're right that mip mapping should overwhelmingly eliminate it. So this comment isn't an answer. – Tommy Mar 11 '15 at 03:24
  • Anisotropy is a floating-point value (_weird, I know_), you should be setting it with `glTexParameterf (...)`. – Andon M. Coleman Mar 11 '15 at 11:01
  • + Oh yeah it is, it strangely doesn't affect anything though. I don't think OpenGL is toooo picky about that, but who knows, it's an older API. – David Mar 11 '15 at 21:24
  • @David: Have you verified that these texture parameters are even applied? – derhass Mar 12 '15 at 19:22
  • @derhass: They are, textures repeat fine and changing the LINEAR parameters to NEAREST makes the pixelated nightmare that is non-linear filtering. Are there any other parameters that could be applied that might help this, though? – David Mar 13 '15 at 01:58

0 Answers0