opengl - 使用 OpenGL 实现更平滑的渐变过渡?
问题描述
我正在使用以下着色器来渲染天穹以模拟夜空。我的问题是颜色之间清晰可见的过渡。
是什么导致了这些苛刻的梯度过渡?
片段着色器:
#version 330
in vec3 worldPosition;
layout(location = 0) out vec4 outputColor;
void main()
{
float height = 0.007*(abs(worldPosition.y)-200);
vec4 apexColor = vec4(0,0,0,1);
vec4 centerColor = vec4(0.159, 0.132, 0.1, 1);
outputColor = mix(centerColor, apexColor, height);
}
Fbo像素格式:
GL.TexImage2D(
TextureTarget.Texture2D,
0,
PixelInternalFormat.Rgb32f,
WindowWidth,
WindowHeight,
0,
PixelFormat.Rgb,
PixelType.Float,
IntPtr.Zero )
解决方案
正如 Ripi2 解释的那样,24 位颜色无法完美地表示渐变,可表示颜色之间的不连续性在单一颜色的渐变中变得刺眼可见。
为了隐藏色带,我实现了一种简单形式的有序抖动,并使用这种拜耳矩阵算法生成了 8x8 纹理。
vec4 dither = vec4(texture2D(MyTexture0, gl_FragCoord.xy / 8.0).r / 32.0 - (1.0 / 128.0));
colourOut += dither;
推荐阅读
- azure - 使用用户分配的托管标识进行 Azure 服务总线身份验证
- javascript - 异步函数存储另一个异步函数的数据
- rest - 使用机器人框架和 REST 上传带有 Post 请求的 zip 文件
- c# - 我应该在哪里过滤微服务架构模式中的 MS 级外部服务响应?
- powershell - 如何使用powershell运行cmd命令
- javascript - 使用节点中嵌套对象的字符串文字进行 JSON 解析
- javascript - 如何确定使用 JavaScript 进行电子邮件混淆是否有效?
- python-3.x - TypeError:“PngImageFile”对象不可迭代
- java - 硒 moveToElement() 到硒
- django - 如何在我的序列化程序中创建一个字段以避免“TypeError:无法解压缩不可迭代的地址对象”错误?