Graphics Reference
In-Depth Information
This code configures the fixed-function pipeline to perform a modulate
( A × B ) between the primary color (the vertex color) and the texture color.
If this code doesn't make sense to you, don't worry, as none of it exists
in OpenGL ES 3.0. Rather, we are simply trying to show how this would
map to a fragment shader. In a fragment shader, this same modulate
computation could be accomplished as follows:
#version 300 es
precision mediump float;
uniform sampler2D s_tex0;
in vec2 v_texCoord;
in vec4 v_primaryColor;
layout(location = 0) out vec4 outColor;
void main()
{
outColor = texture(s_tex0, v_texCoord) * v_primaryColor;
}
The fragment shader performs the exact same operations that would be
performed by the fixed-function setup. The texture value is fetched from
a sampler (that is bound to texture unit 0) and a 2D texture coordinate
is used to look up that value. Then, the result of that texture fetch is
multiplied by v_primaryColor , an input value that is passed in from the
vertex shader. In this case, the vertex shader would have passed the color
to the fragment shader.
It is possible to write a fragment shader that would perform the equivalent
computation as any possible fixed-function texture combine setup. It is
also possible, of course, to write shaders with much more complex and
varied computations than just fixed functions would allow. However, the
point of this section was just to drive home how we have transitioned
from fixed-function to programmable shaders. Now, we begin to look at
some specifics of fragment shaders.
Fragment Shader Overview
The fragment shader provides a general-purpose programmable method
for operating on fragments. The inputs to the fragment shader consist of
the following:
• Inputs (or varyings)—Interpolated data produced by the vertex shader.
The outputs of the vertex shader are interpolated across the primitive
and passed to the fragment shader as inputs.
• Uniforms—State used by the fragment shader. These are constant
values that do not vary per fragment.
 
 
Search WWH ::




Custom Search