Fragment Shader Challenge

With our varying imported into fragment.glsl, we can now use it to determine what color our pixel should be relative to our imported uniform sampler2D texture.

Recall, texture2D takes two arguments: a sampler2D texture and a UV coordinate:

texture2D(sampler2D, UVCoordinate);

To obtain RGB values returned from texture2D, we can chain on .xyz to the end of the function, then add it directly into our vec4 to take up the first three values that determine our pixel color:

void main() {
  gl_FragColor = vec4(texture2D(sampler2D, UVCoordinate).xyz, 1.0);
}

Using our imported uniform and varying, insert the two into vec4 using a texture2D function, making sure that you're only referencing the first three values that texture2D returns.

This will finish the texture and you should see it overlaid on top of your geometry.

fragment.glsl

Providing the lift to launch your development career

© 2024 Chris Courses. All rights reserved.