gutyina70
gutyina70

Reputation: 43

How to pass attributes directly to the fragment shader in OpenGL?

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.

Upvotes: 4

Views: 2777

Answers (1)

Rabbid76
Rabbid76

Reputation: 210878

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.

Upvotes: 5

Related Questions