gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 10:27:50 25 4
gpt4 key购买 nike

我已经在OpenGL中制作了一个绘制Mandelbrot set的小程序,但是在片段着色器中使用64位值时遇到了一些麻烦。当我在着色器中使用vec2类型时,一切都按预期工作,而在c++中,我的顶点数组使用 double 数组:

#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 浮点类型。
请参阅最新的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.
[...]

关于c++ - 从顶点到片段着色器的平滑64位输入- “error C7570: 64 bit input should be flat”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63535262/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com