Graphics Reference
In-Depth Information
void main( )
{
vMCposition = aVertex.xyz;
gl_Position = uModelViewProjectionMatrix * aVertex;
}
The fragment shader shown below does all the work. Because the x coor-
dinates go from −1 to 1, and the required s texture coordinates go from 0 to 1,
the linear mapping is
x
+1
2
s
=
.
The same mapping applies to y and z to create the t and p texture coordinates.
Once we have the s - t - p texture coordinates, we can look up the data value at
this location, which is then used to set the color for this fragment.
const float SMIN = 0.;
const float SMAX = 100.;
uniform int uTexUnit;
uniform float uMin, uMax;
in vec3 vMCposition;
out vec4 fFragColor;
void
main( )
{
vec3 stp = ( vMCposition + 1. ) / 2.; // maps [-1.,1.] to
// [0.,1.]
vec4 rgba = texture( uTexUnit, stp );
float scalar = rgba.r;
if( scalar < uMin )
discard;
if( scalar > uMax )
discard;
float t = ( scalar - SMIN ) / ( SMAX - SMIN );
vec3 rgb = Rainbow( t );
fFragColor = vec4( rgb, 1. );
}
Search WWH ::




Custom Search