3

I'm using OpenTK for C#. I'm kinda new to graphics programming.

Is there a way to pass an attribute directly to the fragment shader and skip the vertex shader?

It'd be useful when working with uvs. I want to pass the uv to the fragment shader because I change nothing in the vertex shader.

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
gutyina70
  • 33
  • 4

1 Answers1

4

You can't. The vertex shader is executed once per vertex coordinate, the fragment shader is executed per fragment (even more for multisampling). The outputs of the vertex shader are interpolated for the fragments which are covered by a primitive. The interpolated values (coordinates) are the inputs to the fragment shader (if the fragment shader stage directly follows the vertex shader).
You need to specify which attribute is an output from the vertex shader and ultimately an input to the fragment shader. This is done by an assignment in the vertex shader.

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
  • Thanks, I want to know one more thing: I have this code int the vertex shader: ```in inUV; out outUV; void main() { outUV = inUV }``` can I somehow skip having an in and out variable just to pass the data? – gutyina70 Sep 19 '19 at 10:33
  • @gutyina70 No, you've to "tell", that `inUV` has to be assigned to `outUV`. – Rabbid76 Sep 19 '19 at 10:36
  • As @Rabbid76 said, you can't, but a uniform can be a good option for those cases in which you don't need the interpolation – Sebastian Oscar Lopez Jan 02 '22 at 03:06