Graphics Reference
In-Depth Information
Figure 11.12. An original photo (left) along with the emboss operation results (right).
code includes #define statements to create grayscale or color embossing; both
are shown in the figure.
#define GRAY
uniform sampler2D uImageUnit;
in vec2 vST;
out vec4 fFragColor;
void main( )
{
ivec2 ires = textureSize( uImageUnit, 0 );
float ResS = float( ires.s );
float ResT = float( ires.t );
vec3 irgb = texture( uImageUnit, vST ).rgb;
vec2 stp0 = vec2(1./ResS, 0. );
vec2 stpp = vec2(1./ResS, 1./ResT);
vec3 c00 = texture( uImageUnit, vST ).rgb;
vec3 cp1p1 = texture( uImageUnit, vST + stpp ).rgb;
vec3 diffs = c00 - cp1p1; // vector difference
float max = diffs.r;
if ( abs(diffs.g)) > abs(max) ) max = diffs.g;
if ( abs(diffs.b)) > abs(max) ) max = diffs.b;
float gray = clamp( max + .5, 0., 1. );
vec3 color = vec3( gray, gray, gray );
fFragColor = vec4( color, 1. );
}
Search WWH ::




Custom Search