本文介绍了具有硬件加速 OpenGL ES 3.0 的 Android 模拟器色带的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只有在我的 Android 模拟器上使用硬件加速渲染时,我似乎才会在色谱的低端失去相当多的精度.

I seem to be loosing considerable precision toward the lower end of the color spectrum only when using hardware accelerated rendering on my Android emulator.

使用硬件加速(ANGLE D3D11 或桌面原生 OpenGL):

With hardware acceleration (ANGLE D3D11 or Desktop Native OpenGL):

没有硬件加速(SwiftShader):

Without hardware acceleration (SwiftShader):

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

The banding is clearly non linear and becomes quite obtrusive when trying to render smooth lighting.

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

I've set getWindow().setFormat(PixelFormat.RGBA_8888); and am using precision highp float; in my fragment shader.

我们使用的是 Android Studio 3.1.1、Windows 10、OpenGL ES 3.0.

This us using Android Studio 3.1.1, Windows 10, OpenGL ES 3.0.

*这是一个增加亮度和对比度的并排图片

* Here's a side by side with increased brightness and contrast

推荐答案

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

This looks like sRGB colors are being stored in a linear 8-bit format at some point, then are converted back to sRGB. It would lead to exactly the kind of low-brightness imprecision you are observing.

调用 eglCreateWindowSurface 时,请尝试在 attrib_list 参数中传递 {EGL_COLORSPACE_KHR, EGL_COLORSPACE_SRGB_KHR, EGL_NONE}.如果您使用 GLSurfaceView,这将需要实现 EGLWindowSurfaceFactory 并调用 setEGLWindowSurfaceFactory.这需要存在 EGL_KHR_gl_colorspace 扩展.

When calling eglCreateWindowSurface, try passing {EGL_COLORSPACE_KHR, EGL_COLORSPACE_SRGB_KHR, EGL_NONE} in the attrib_list parameter. If you are using GLSurfaceView, this will require implementing EGLWindowSurfaceFactory and calling setEGLWindowSurfaceFactory. This requires the EGL_KHR_gl_colorspace extension to be present.

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/

Here is a good post if you want to learn more about sRGB: http://blog.johnnovak.net/2016/09/21/what-every-coder-should-know-about-gamma/

这篇关于具有硬件加速 OpenGL ES 3.0 的 Android 模拟器色带的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-02 21:11