Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

opengl

opentk

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.

like image 523
gutyina70 Avatar asked Oct 25 '25 12:10

gutyina70


1 Answers

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.

like image 56
Rabbid76 Avatar answered Oct 27 '25 02:10

Rabbid76