3Dickulus / FragM

Derived from https://github.com/Syntopia/Fragmentarium/
GNU General Public License v3.0
349 stars 30 forks source link

mipmaps broken #120

Closed claudeha closed 4 years ago

claudeha commented 4 years ago

Describe the bug Trying to enable mipmaps (for anti-aliasing) leads to blank black image.

To Reproduce Steps to reproduce the behavior:

  1. Frag:
    #version 130
    #include "2D.frag"
    uniform sampler2D Texture; file[image.png]
    #TexParameter Texture GL_TEXTURE_MIN_FILTER GL_LINEAR_MIPMAP_LINEAR
    vec3 color(vec2 p) { return texture(Texture, p).rgb; }
  2. Load an image file (that isn't blank black).
  3. Rebuild the frag.
  4. See error: blank black screen
  5. Delete the TexParameter line
  6. Clear texture cache
  7. Rebuild the frag
  8. Texture is displayed, but without mipmapping. Zoom out to see the aliasing.

Expected behavior Mipmapping to work.

Desktop (please complete the following information):

Additional context Very partial workround for less ugly images: use GL_NEAREST and bump up the subframe count.

claudeha commented 4 years ago

I looked at the source code to see if I need to fix it, and found a workaround/solution: specify

#TexParameter Texture GL_TEXTURE_MAX_LEVEL 1000

in addition to requesting mipmaps, otherwise you get a blank black image.

3Dickulus commented 4 years ago

yes, you need to specify all of the texture parameters after the sampler decl as in...

uniform sampler2D myTexture; file[test.png]
#TexParameter myTexture GL_TEXTURE_MAX_LEVEL 1000
#TexParameter myTexture GL_TEXTURE_WRAP_S GL_REPEAT
#TexParameter myTexture GL_TEXTURE_WRAP_T GL_REPEAT
#TexParameter myTexture GL_TEXTURE_MAG_FILTER GL_LINEAR
#TexParameter myTexture GL_TEXTURE_MIN_FILTER GL_LINEAR_MIPMAP_LINEAR

if any are missing you may have undefined result

keys...

GL_TEXTURE_WRAP_T
GL_TEXTURE_WRAP_S
GL_TEXTURE_MIN_FILTER
GL_TEXTURE_MAG_FILTER
GL_TEXTURE_MAX_LEVEL
GL_TEXTURE_MAX_ANISOTROPY

values...

GL_CLAMP
GL_REPEAT
GL_NEAREST
GL_LINEAR
GL_LINEAR_MIPMAP_LINEAR
GL_LINEAR_MIPMAP_NEAREST
GL_NEAREST_MIPMAP_LINEAR
GL_NEAREST_MIPMAP_NEAREST

when no texture parameters are defined by user mipmap is disabled.

3Dickulus commented 4 years ago

yes, you need to specify all of the texture parameters after the sampler decl as in...

uniform sampler2D myTexture; file[test.png]
#TexParameter myTexture GL_TEXTURE_MAX_LEVEL 1000
#TexParameter myTexture GL_TEXTURE_WRAP_S GL_REPEAT
#TexParameter myTexture GL_TEXTURE_WRAP_T GL_REPEAT
#TexParameter myTexture GL_TEXTURE_MAG_FILTER GL_LINEAR
#TexParameter myTexture GL_TEXTURE_MIN_FILTER GL_LINEAR_MIPMAP_LINEAR

if any are missing you may have undefined result

keys...

GL_TEXTURE_WRAP_T
GL_TEXTURE_WRAP_S
GL_TEXTURE_MIN_FILTER
GL_TEXTURE_MAG_FILTER
GL_TEXTURE_MAX_LEVEL
GL_TEXTURE_MAX_ANISOTROPY

values...

GL_CLAMP
GL_REPEAT
GL_NEAREST
GL_LINEAR
GL_LINEAR_MIPMAP_LINEAR
GL_LINEAR_MIPMAP_NEAREST
GL_NEAREST_MIPMAP_LINEAR
GL_NEAREST_MIPMAP_NEAREST

when no texture parameters are defined by user mipmap is disabled.