2

I've seen the shader code using these two. But i don't understand what's difference between them, between texture and fragment.

As i know, fragment is pixels, so what's texture?

Some use these code:

vec2 uv = gl_FragCoord.xy / rectSize.xy;
vec4 bkg_color = texture2D(CC_Texture0, uv);

some use:

vec4 bkg_color = texture2D(CC_Texture0, v_texCoord);

with v_texCoord = a_texCoord; Both works, except the first way displays inverted image.

TomSawyer
  • 3,711
  • 6
  • 44
  • 79

1 Answers1

0

In your second example 'v_texCoord' looks like a pre-calculated texture coordinate that is passed to the Fragment Shader as a Vertex Attribute, versus the 'uv' coordinate calculated within the Fragment Shader of the first example.

You can base texture coordinates off whatever you like - so long as you give the texture2D sampler normalised coordinates - its all about your use case and what you want to display from a texture.

Perhaps there is such a use-case difference here, which is why they give different visual outputs.

For more information about how texture coordinates work I recommend this question's answer: How do opengl texture coordinates work?

Community
  • 1
  • 1
Peter Flower
  • 363
  • 2
  • 20