仅当在我的Android仿真器上使用硬件加速渲染时,我才似乎对色谱的低端失去了相当大的精度。

使用硬件加速(ANGLE D3D11或Desktop Native OpenGL):
android - 具有硬件加速功能的Android仿真器色带OpenGL ES 3.0-LMLPHP

没有硬件加速(SwiftShader):
android - 具有硬件加速功能的Android仿真器色带OpenGL ES 3.0-LMLPHP

条带显然是非线性的,并且在尝试渲染平滑的光照时变得非常突出。

我已经设置了getWindow().setFormat(PixelFormat.RGBA_8888);,并且在片段着色器中使用了precision highp float;

我们使用Android Studio 3.1.1,Windows 10,OpenGL ES 3.0。

*编辑:这是同时增加亮度和对比度的
android - 具有硬件加速功能的Android仿真器色带OpenGL ES 3.0-LMLPHP

最佳答案

看起来sRGB颜色在某个时候以线性8位格式存储,然后转换回sRGB。这将完全导致您正在观察的那种低亮度不精确度。

调用eglCreateWindowSurface时,请尝试在{EGL_COLORSPACE_KHR, EGL_COLORSPACE_SRGB_KHR, EGL_NONE}参数中传递attrib_list。如果使用的是GLSurfaceView,则需要实现EGLWindowSurfaceFactory并调用setEGLWindowSurfaceFactory。这要求出现EGL_KHR_gl_colorspace扩展名。

public class EGLFactory implements GLSurfaceView.EGLWindowSurfaceFactory {
  private static final int EGL_GL_COLORSPACE_KHR = 0x309D;
  private static final int EGL_GL_COLORSPACE_SRGB_KHR = 0x3089;
  public EGLSurface createWindowSurface(EGL10 egl, EGLDisplay display,
                                        EGLConfig config, Object nativeWindow) {
    final int[] attribList = {
      EGL_GL_COLORSPACE_KHR,
      EGL_GL_COLORSPACE_SRGB_KHR,
      EGL10.EGL_NONE
    };
    return egl.eglCreateWindowSurface(display, config, nativeWindow, attribList);
  }
  public void destroySurface(EGL10 egl, EGLDisplay display, EGLSurface surface) {
    egl.eglDestroySurface(display, surface);
  }
}


如果您想了解有关sRGB的更多信息,这是一篇好文章:http://blog.johnnovak.net/2016/09/21/what-every-coder-should-know-about-gamma/

10-07 19:31
查看更多