平滑从顶点到片段着色器的 64 位输入 - "error C7570: 64 bit input should be flat"

smooth 64bit input from vertex to frag shader - "error C7570: 64 bit input should be flat"

我在 OpenGL 中编写了一个小程序来绘制 Mandelbrot set,但是我在片段着色器中使用 64 位值时遇到了一些问题。当我像这样在我的着色器中使用 vec2 类型并在 C++ 中为我的顶点数组使用双精度数组时,一切都按预期工作:

#shader vertex
#version 410 core

layout(location = 0) in vec4 a_position;
layout(location = 1) in vec3 a_colour;
layout(location = 2) in vec2 mandelbrot;
smooth out vec3 frag_colour;
smooth out vec2 frag_mandelbrot;
uniform float view_zoom;
uniform vec2 view_translate;
void main()
{
    gl_Position = a_position;
    frag_colour = a_colour;
    frag_mandelbrot = (mandelbrot / view_zoom) + view_translate;
};


#shader fragment
#version 410 core

layout(location = 0) out vec3 colour;
in vec3 frag_colour;
in vec2 frag_mandelbrot;

void main()
{
    double x = 0;
    double y = 0;
    vec3 start = vec3(0.0f, 0.0f, 0.0f);
    vec3 end = vec3(1.0f, 1.0f, 1.0f);
    int iteration = 0;
    int max_iteration = 250;
    while (x*x + y * y <= 2 * 2 && iteration < max_iteration) {
        double xtemp = x * x - y * y + frag_mandelbrot[0];
        y = 2 * x*y + frag_mandelbrot[1];
        x = xtemp;
        iteration++;
    }
    float t = float(iteration) / float(max_iteration);
    colour = mix(start,end,t);
};

然而,当我尝试像这样使用 dvec2 类型时:

#shader vertex
#version 410 core

layout(location = 0) in vec4 a_position;
layout(location = 1) in vec3 a_colour;
layout(location = 2) in dvec2 mandelbrot;
smooth out vec3 frag_colour;
smooth out dvec2 frag_mandelbrot;
uniform double view_zoom;
uniform dvec2 view_translate;
void main()
{
    gl_Position = a_position;
    frag_colour = a_colour;
    frag_mandelbrot = (mandelbrot / view_zoom) + view_translate;
};


#shader fragment
#version 410 core

layout(location = 0) out vec3 colour;
in vec3 frag_colour;
in dvec2 frag_mandelbrot;

void main()
{
    double x = 0;
    double y = 0;
    vec3 start = vec3(0.0f, 0.0f, 0.0f);
    vec3 end = vec3(1.0f, 1.0f, 1.0f);
    int iteration = 0;
    int max_iteration = 250;
    while (x*x + y * y <= 2 * 2 && iteration < max_iteration) {
        double xtemp = x * x - y * y + frag_mandelbrot[0];
        y = 2 * x*y + frag_mandelbrot[1];
        x = xtemp;
        iteration++;
    }
    float t = float(iteration) / float(max_iteration);
    colour = mix(start,end,t);
};

我的片段着色器出现以下编译错误:

0(5) : error C7570: 64 bit input 'frag_mandelbrot' should be flat

我的问题是,为什么它应该是平的? GLSL 文档说明如下:

"Note: Precision qualifiers in GLSL are supported for compatibility with OpenGL ES. They use the same syntax as ES's qualifiers, but they have no functional effects. Do not use them unless you want your shaders to be ES compatible."

所以我认为这些(highp、mediump 等)不适用于普通桌面 opengl。片段着色器不可能将从顶点属性插值的 64 位值作为输入吗?还是我只是在某个地方犯了一些愚蠢的错误?

片段着色器输入的类型

in dvec2 frag_mandelbrot;

是 double-precision floating-point 类型。

查看最新的 GLSL 规范,OpenGL Shading Language 4.60 Specification (HTML) - 4.3.3. Constant Expressions

[...]
Fragment shader inputs that are, or contain, integral or double-precision floating-point types must be qualified with the interpolation qualifier flat.
[...]