本文介绍了为什么此GLSL着色器在GeForce上可以正常工作,但是在Intel HD 4000上却忽然闪烁?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用OpenGL 3.3核心配置文件,我通过 gl.DrawArrays(gl.TRIANGLES,0,3)使用以下内容渲染全屏四边形"(作为单个超大三角形)着色器.

Using OpenGL 3.3 core profile, I'm rendering a full-screen "quad" (as a single oversized triangle) via gl.DrawArrays(gl.TRIANGLES, 0, 3) with the following shaders.

顶点着色器:

#version 330 core
#line 1

vec4 vx_Quad_gl_Position () {
    const float extent = 3;
    const vec2 pos[3] = vec2[](vec2(-1, -1), vec2(extent, -1), vec2(-1, extent));
    return vec4(pos[gl_VertexID], 0, 1);
}

void main () {
    gl_Position = vx_Quad_gl_Position();
}

片段着色器:

#version 330 core
#line 1
out vec3 out_Color;

vec3 fx_RedTest (const in vec3 vCol) {
    return vec3(0.9, 0.1, 0.1);
}

vec3 fx_Grayscale (const in vec3 vCol) {
    return vec3((vCol.r * 0.3) + (vCol.g * 0.59) + (vCol.b * 0.11));

}

void main () {
    out_Color = fx_RedTest(out_Color);
    out_Color = fx_Grayscale(out_Color);
}

现在,代码可能看起来有些奇怪,目前的目的似乎没用,但这不应该对GL驱动程序进行定级.

Now, the code may look a bit odd and the present purpose of this may seem useless, but that shouldn't phase the GL driver.

在GeForce上,获得预期的灰屏.也就是说,灰度效果"应用于硬编码的颜色红色"(0.9、0.1、0.1).

On a GeForce, a get a gray screen as expected. That is, the "grayscale effect" applied to the hard-coded color "red" (0.9, 0.1, 0.1).

但是,Intel HD 4000 [驱动程序9.17.10.2932(12-12-2012)版本-至今是最新的]始终重复显示以下不断闪烁的噪声模式:

However, Intel HD 4000 [driver 9.17.10.2932 (12-12-2012) version -- the newest as of today] always, repeatedly shows nothing but the following constantly-flickering noise pattern:

现在,为了进行一些实验,我稍微修改了fx_Grayscale()函数-实际上,它应该产生相同的视觉结果,只是编码略有不同:

Now, just to experiment a little, I changed the fx_Grayscale() function around a little bit -- effectively it should be yielding the same visual result, just with slightly different coding:

vec3 fx_Grayscale (const in vec3 vCol) {

    vec3 col = vec3(0.9, 0.1, 0.1);
    col = vCol;
    float x = (col.r * 0.3) + (col.g * 0.59) + (col.b * 0.11);
    return vec3(x, x, x);
}

再次,Nvidia会做正确的事,而Intel HD现在总是会反复产生一种非常不同但仍在不断闪烁的噪声模式:

Again, Nvidia does the correct thing whereas Intel HD now always, repeatedly produces a rather different, but still constantly-flickering noise pattern:

我必须怀疑(还有另一个)Intel GL驱动程序错误,或者您是否看到我的GLSL代码有任何问题-不是从漂亮的角度来看(这是着色器代码生成实验项目的一部分) ),但仅从规范正确性的角度来看?

Must I suspect (yet another) Intel GL driver bug, or do you see any issues with my GLSL code -- not from a prettiness perspective (it's part of a shader code-gen experimental project) but from a mere spec-correctness point of view?

推荐答案

我认为将输出"颜色作为参数发送给另一个函数看起来很奇怪.我会这样重写它:

I think it looks strange to send in a "out" color as parameter to another function. I would rewrite it something like this:

void main () {
    vec3 col = vec3(0f,0f,0f);
    col = fx_RedTest(col);
    col = fx_Grayscale(col);
    out_Color = col;
}

有什么区别吗?

这篇关于为什么此GLSL着色器在GeForce上可以正常工作,但是在Intel HD 4000上却忽然闪烁?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 06:37