Flipping the viewport

I’m following Ray Tracing In a Weekend, and would like to implement this in Vulkan. In Chapter one, we iterate through all the fragments and color them. Here is the resulting image from vulkan, versus one made in ShaderToy. Both same fragment shader

And from ShaderToy

As you can see, the image seems to be flipped.

Things that I have tried.
Invert gl_Position.y in fragment shader. No change to output.
Invert viewport.y and submitting vkCmdSetViewport(), no change to output.

What must I be doing wrong? Or is the underlying problem something else? Any input would be appreciated, thank you.

EDIT: The correct output should be the one from ShaderToy.

The straightforward solution would be to simply flip the y-component of your rg-vector.

The more correct way would be flipping the viewport itself by using a negative viewport height. This requires VK_KHR_Maintenance1 (or Vulkan 1.1 upwards). I wrote a bit about using this here.

@Sascha_Willems Thank you for your reply. I have visited your website and attempted that solution. However, the result was the same regardless of those two options that are mentioned there.
This however, fixed the problem, as you’ve recommended.

I’m very new to this, any ideas as to why this method works and the other ( flipping the viewport ) doesn’t? My only guess, which could be completely wrong, is that even after flipping the viewport, the fragment shader still starts at lower left corner as opposed to upper left? Hence after the viewport flip, the result is the same. Any ideas as to why? I’d love to know the reason. Thank you for your help.

Vulkan semantics GLSL has origin at upper left.

I think the problem is you are using gl_FragCoord, which is the value after the viewport transform.