GLSL:平滑双入

GLSL: smooth double in

我想这样做:

layout(location = 0) in dvec2 c;

但显然我不能:

$ glslc mandlebrot.frag
mandlebrot.frag:7: error: 'double' : must be qualified as flat in

但是,我要求对这个输入进行插值,而不是 flat。有办法吗?

Nope:

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

所以你将不得不制作它们 floats。

虽然 Nicol 的回答在技术上看起来是正确的,但有一个解决方法。 float 值的精度足以定位屏幕上的像素;它可能不足以定位 "world"(在本例中为分形)内的位置。

然后解决方案是使用统一缓冲区传递相对于屏幕(在本例中为中心)的某个固定点的世界坐标,然后从中计算像素坐标:

layout(set = 0, binding = 1) uniform Locals {
    dvec2 centre;
    dvec2 scale;
};

void main() {
    dvec2 c = centre + dvec2(cf) * scale;
    ...
}