0

I've been reading up on a vulkan tutorial online, here: https://vulkan-tutorial.com. This question should apply to any 3D rendering API however.

In this lesson https://vulkan-tutorial.com/Vertex_buffers/Index_buffer, the tutorial had just covered using indexed rendering in order to reuse vertices when drawing the following simple two-triangle quad:

Text

The four vertices were assigned red, green, blue and white colours as vertex attributes and the fragment shader had those colours interpolated across the triangles as expected. This leads to the ugly visual artefact on the diagonal where the two triangles meet. As I understand it, the interpolation will only be happening across each triangle, and so where the two triangles meet the interpolation doesn't cross the boundary.

How could you, generally in any rendering api, have the colours smoothly interpolated over all four corners for a nice colour wheel affect without having this hard line?

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
FShrike
  • 323
  • 1
  • 10
  • where is the code? Do you have Perspective view? If yes are you using Perspective correct interpolation? – Spektre Jul 31 '20 at 15:48
  • @Spektre The code is on the website but is extremely trivial... my question is a general theory question - I’m not asking for a code fix, this isn’t even my own code it’s just something I saw on a website and couldn’t find an answer to online. – FShrike Jul 31 '20 at 21:42

1 Answers1

1

This is a correct output from a graphics api point of view. You can achieve your own desired output (a color gradient) within the shader code. You basically need to interpolate the colors yourself. To get an idea on how to do this, here is a glsl piece of code from this answer:

uniform vec2 resolution;

void main(void)
{
    vec2 p = gl_FragCoord.xy / resolution.xy;
    float gray = 1.0 - p.x;
    float red = p.y;
    gl_FragColor = vec4(red, gray*red, gray*red, 1.0);
}
Amin
  • 543
  • 7
  • 12
  • Thank you! I had the colour wheel / gradient image in my mind and that is a much simpler answer than I was expecting – FShrike Aug 10 '20 at 19:48