1mjb – January 29, 2008Oregon State UniversityComputer GraphicsUsing Fragment Shaders to Manipulate ImageryMike BaileyOregon State Universitymjb – January 29, 2008Oregon State UniversityComputer GraphicsImage BasicsResSResTTreat the image as a textureTo get from the current texel to a neighboring texel, add ± (1./ResS , 1./ResT) to the current (S,T)2mjb – January 29, 2008Oregon State UniversityComputer GraphicsImage Negative( R, G, B ) ( 1.-R, 1.-G, 1.-B )mjb – January 29, 2008Oregon State UniversityComputer GraphicsImage Distortionuniform float S, T;uniform float Power;uniform sampler2D TexUnit;voidmain( ){vec2 st = gl_TexCoord[0].st;vec2 delta = st - vec2(S,T);st = vec2(S,T) + sign(delta) * pow( abs(delta), Power );vec3 rgb = texture2D( TexUnit, st ).rgb;gl_FragColor = vec4( rgb, 1. );}3mjb – January 29, 2008Oregon State UniversityComputer GraphicsImage Un-MaskingtWhat Idon’t wantMore of what Ido wantWhat I started with0.0 1.0 2.0Iout= (1.-t)*Idontwant+ t*Iin}}Blend of what don’t want and what haveBlend of what have and what want more ofmjb – January 29, 2008Oregon State UniversityComputer GraphicsBrightnessIdontwant= vec3( 0., 0., 0. );T = 0. T = 1. T = 2.4mjb – January 29, 2008Oregon State UniversityComputer GraphicsContrastIdontwant= vec3( 0.5, 0.5, 0.5 );T = 0. T = 1. T = 2.mjb – January 29, 2008Oregon State UniversityComputer GraphicsHDTV Luminance StandardLuminance = 0.2125*Red + 0.7154*Green + 0.0721*Blue5mjb – January 29, 2008Oregon State UniversityComputer GraphicsIdontwant= vec3( luminance, luminance, luminance );SaturationT = 0. T = 1. T = 3.mjb – January 29, 2008Oregon State UniversityComputer GraphicsDifferenceIdontwant= IbeforeIin= IafterT = 0. T = 2.T = 1.6mjb – January 29, 2008Oregon State UniversityComputer GraphicsChromaKeyReplace fragment if:R < TG < TB > 1.-TT = 0. T = 0.5 T = 1.mjb – January 29, 2008Oregon State UniversityComputer GraphicsBlur Convolution:Blur⎥⎥⎥⎦⎤⎢⎢⎢⎣⎡=121242121.16.1B7mjb – January 29, 2008Oregon State UniversityComputer GraphicsBlur Convolution:Sharpening⎥⎥⎥⎦⎤⎢⎢⎢⎣⎡=121242121.16.1BIdontwant= Iblurmjb – January 29, 2008Oregon State UniversityComputer GraphicsSharpeningT = 0.T = 1.T = 2.8mjb – January 29, 2008Oregon State UniversityComputer GraphicsEmbossingvec2 stp0 = vec2( 1./ResS, 0. );vec2 stpp = vec2( 1./ResS, 1./ResT);vec3 c00 = texture2D( ImageUnit, st ).rgb;vec3 cp1p1 = texture2D( ImageUnit, st + stpp ).rgb;vec3 diffs = c00 - cp1p1;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. );vec4 grayVersion = vec4( gray, gray, gray, 1. );vec4 colorVersion = vec4( gray*c00, 1. );color = mix( grayVersion, colorVersion, T );mjb – January 29, 2008Oregon State UniversityComputer GraphicsHorizontal and Vertical Sobel Convolutions:Edge Detection⎥⎥⎥⎦⎤⎢⎢⎢⎣⎡−−−=121000121H⎥⎥⎥⎦⎤⎢⎢⎢⎣⎡−−−=101202101VVHS22+=Θ = atan2( V, H )9mjb – January 29, 2008Oregon State UniversityComputer GraphicsEdge Detectionvec2 stp0 = vec2(1./ResS, 0. );vec2 st0p = vec2(0. , 1./ResT);vec2 stpp = vec2(1./ResS, 1./ResT);vec2 stpm = vec2(1./ResS, -1./ResT);float i00 = dot( texture2D( ImageUnit, st ).rgb, vec3(0.2125,0.7154,0.0721) );float im1m1 = dot( texture2D( ImageUnit, st-stpp ).rgb, vec3(0.2125,0.7154,0.0721) );float ip1p1 = dot( texture2D( ImageUnit, st+stpp ).rgb, vec3(0.2125,0.7154,0.0721) );float im1p1 = dot( texture2D( ImageUnit, st-stpm ).rgb, vec3(0.2125,0.7154,0.0721) );float ip1m1 = dot( texture2D( ImageUnit, st+stpm ).rgb, vec3(0.2125,0.7154,0.0721) );float im10 = dot( texture2D( ImageUnit, st-stp0 ).rgb, vec3(0.2125,0.7154,0.0721) );float ip10 = dot( texture2D( ImageUnit, st+stp0 ).rgb, vec3(0.2125,0.7154,0.0721) );float i0m1 = dot( texture2D( ImageUnit, st-st0p ).rgb, vec3(0.2125,0.7154,0.0721) );float i0p1 = dot( texture2D( ImageUnit, st+st0p ).rgb, vec3(0.2125,0.7154,0.0721) );float h = -1.*im1p1 - 2.*i0p1 - 1.*ip1p1 + 1.*im1m1 + 2.*i0m1 + 1.*ip1m1;float v = -1.*im1m1 - 2.*im10 - 1.*im1p1 + 1.*ip1m1 + 2.*ip10 + 1.*ip1p1;float mag = sqrt( h*h + v*v );vec3 target = vec3( mag,mag,mag );color = vec4( mix( irgb, target, T ), 1. );mjb – January 29, 2008Oregon State UniversityComputer GraphicsEdge DetectionT = 0. T = 0.5 T = 1.10mjb – January 29, 2008Oregon State UniversityComputer Graphicsfloat mag = sqrt( h*h + v*v );if( mag > MagTol ){color = vec4( 0., 0., 0., 1. );}else{rgb.rgb *= Quantize;rgb.rgb += vec3( .5, .5, .5 );ivec3 irgb = ivec3( rgb.rgb );rgb.rgb = vec3( irgb ) / Quantize;color = vec4( rgb, 1. );}Toon Renderingmjb – January 29, 2008Oregon State UniversityComputer GraphicsToon RenderingOriginal ImageColors QuantizedOutlines Added11mjb – January 29, 2008Oregon State UniversityComputer Graphicsmjb – January 29, 2008Oregon State UniversityComputer GraphicsUse the GPU to enhance scientific, engineering, and architectural illustrationToon Rendering for Non-Photorealistic Effects12mjb – January 29, 2008Oregon State UniversityComputer GraphicsToon Rendering for Non-Photorealistic EffectsUse the GPU to enhance scientific, engineering, and architectural illustrationmjb – January 29, 2008Oregon State UniversityComputer GraphicsMandelbrot Setzzzii 021+=+How fast does itconverge, if ever?13mjb – January 29, 2008Oregon State UniversityComputer GraphicsJulia Setczzii+=+21How fast does itconverge, if
View Full Document