GLSL: smooth double in

Viewed 231

I'd like to do this:

layout(location = 0) in dvec2 c;

But apparently I can't:

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

However, I require this input be interpolated, not flat. Is there a way to do this?

2 Answers

Nope:

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

So you're going to have to make them floats.

While Nicol's answer appears to be technically correct, there is a work-around. A float value has more than enough precision to target a pixel on a screen; it just may not have enough to target a position within the "world" (in this case, a fractal).

The solution then is to use a uniform buffer to pass world coordinates for some fixed point relative to the screen (in this case, the centre), then compute pixel coordinates from that:

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

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