OSU CS 519 - Using Fragment Shaders to Manipulate Imagery

Unformatted text preview:

1mjb – January 29, 2013Oregon State UniversityComputer GraphicsUsing Fragment Shaders to Manipulate ImageryMike [email protected] State Universitymjb – January 29, 2013Oregon State UniversityComputer GraphicsImage BasicsResSResTTreat the image as a texture. If you need it, the resolution of this texture can be found by saying:To get from the current texel to a neighboring texel, add±(1./ResS , 1./ResT)to the current (S,T) ivec2 ires = textureSize( ImageUnit, 0 );float ResS = float( ires.s );float ResT = float( ires.t );2mjb – January 29, 2013Oregon State UniversityComputer GraphicsImage Negative( R, G, B ) ( 1.-R, 1.-G, 1.-B )mjb – January 29, 2013Oregon State UniversityComputer GraphicsImage Distortionuniform float uS0, uT0;uniform float uPower;uniform sampler2D uTexUnit;in vec2 vST;out vec4 fFragColor;voidmain( ){vec2 delta = vST - vec2(uS0,uT0);st = vec2(uS0,uT0) + sign(delta) * pow( abs(delta), uPower );vec3 rgb = texture2D( uTexUnit, vST ).rgb;fFragColor = vec4( rgb, 1. );}3mjb – January 29, 2013Oregon State UniversityComputer Graphics0 1(1 )Q t Q tQ= − +Image Un-masking:Interpolation can still happen when t < 0. or t > 1.t = -1.t = 0.t = 2.t = 1.mjb – January 29, 2013Oregon State UniversityComputer GraphicsImage Un-Masking:Abusing the Linear Blending Equation for a Good PurposetWhat Idon’t wantMore of what Ido wantWhat I have to start with0.0 1.0 2.0Iout= (1 - t)*Idontwant+ t*Iin}}Blend of what I have and what I don’t wantBlend of what I have and less of what I don’t want0 1(1 )Q t Q tQ= − +4mjb – January 29, 2013Oregon State UniversityComputer GraphicsBrightnessIdontwant= vec3( 0., 0., 0. );T = 0. T = 1. T = 2.mjb – January 29, 2013Oregon State UniversityComputer GraphicsContrastIdontwant= vec3( 0.5, 0.5, 0.5 );T = 0. T = 1. T = 2.5mjb – January 29, 2013Oregon State UniversityComputer GraphicsHDTV Luminance StandardLuminance = 0.2125*Red + 0.7154*Green + 0.0721*Bluemjb – January 29, 2013Oregon State UniversityComputer GraphicsIdontwant= vec3( luminance, luminance, luminance );SaturationT = 0. T = 1. T = 3.6mjb – January 29, 2013Oregon State UniversityComputer GraphicsDifferenceIdontwant= IbeforeIin= IafterT = 0. T = 2.T = 1.mjb – January 29, 2013Oregon State UniversityComputer GraphicsChromaKeyReplace fragment if:R < TG < TB > 1.-TT = 0. T = 0.5 T = 1.7mjb – January 29, 2013Oregon State UniversityComputer GraphicsBlur Convolution:Blur=121242121.16.1Bmjb – January 29, 2013Oregon State UniversityComputer GraphicsBlur Convolution:Sharpening=121242121.16.1BIdontwant= Iblur8mjb – January 29, 2013Oregon State UniversityComputer GraphicsSharpeningvec2 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);vec3 i00 = texture2D( uImageUnit, vST ).rgb;vec3 im1m1 = texture2D( uImageUnit, vST-stpp ).rgb;vec3 ip1p1 = texture2D( uImageUnit, vST+stpp ).rgb;vec3 im1p1 = texture2D( uImageUnit, vST-stpm ).rgb;vec3 ip1m1 = texture2D( uImageUnit, vST+stpm ).rgb;vec3 im10 = texture2D( uImageUnit, vST-stp0 ).rgb;vec3 ip10 = texture2D( uImageUnit, vST+stp0 ).rgb;vec3 i0m1 = texture2D( uImageUnit, vST-st0p ).rgb;vec3 i0p1 = texture2D( uImageUnit, vST+st0p ).rgb;vec3 target = vec3(0.,0.,0.);target += 1.*(im1m1+ip1m1+ip1p1+im1p1);target += 2.*(im10+ip10+i0m1+i0p1);target += 4.*(i00);target /= 16.;fFragColor = vec4( mix( target, irgb, T ), 1. );mjb – January 29, 2013Oregon State UniversityComputer GraphicsSharpeningT = 0.T = 1.T = 2.9mjb – January 29, 2013Oregon State UniversityComputer GraphicsEmbossingvec2 stp0 = vec2( 1./ResS, 0. );vec2 stpp = vec2( 1./ResS, 1./ResT);vec3 c00 = texture2D( uImageUnit, vST ).rgb;vec3 cp1p1 = texture2D( uImageUnit, vST + 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. );fFragColor = mix( grayVersion, colorVersion, T );mjb – January 29, 2013Oregon State UniversityComputer GraphicsHorizontal and Vertical Sobel Convolutions:Edge Detection−−−=121000121H−−−=101202101VVHS22+=Θ = atan2( V, H )10mjb – January 29, 2013Oregon State UniversityComputer GraphicsEdge Detectionconst vec3 LUMCOEFFS = vec3( 0.2125,0.7154,0.0721 );. . .vec2 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( uImageUnit, vST ).rgb , LUMCOEFFS );float im1m1 = dot( texture2D( uImageUnit, vST-stpp ).rgb, LUMCOEFFS );float ip1p1 = dot( texture2D( uImageUnit, vST+stpp ).rgb, LUMCOEFFS );float im1p1 = dot( texture2D( uImageUnit, vST-stpm ).rgb, LUMCOEFFS );float ip1m1 = dot( texture2D( uImageUnit, vST+stpm ).rgb, LUMCOEFFS );float im10 = dot( texture2D( uImageUnit, vST-stp0 ).rgb, LUMCOEFFS );float ip10 = dot( texture2D( uImageUnit, vST+stp0 ).rgb, LUMCOEFFS );float i0m1 = dot( texture2D( uImageUnit, vST-st0p ).rgb, LUMCOEFFS );float i0p1 = dot( texture2D( uImageUnit, vST+st0p ).rgb, LUMCOEFFS) );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, 2013Oregon State UniversityComputer GraphicsEdge DetectionT = 0. T = 0.5 T = 1.11mjb – January 29, 2013Oregon State UniversityComputer Graphicsfloat mag = sqrt( h*h + v*v );if( mag > uMagTol ){fFragColor= vec4( 0., 0., 0., 1. );}else{rgb.rgb *= uQuantize;rgb.rgb += vec3( .5, .5, .5 );ivec3 irgb = ivec3( rgb.rgb );rgb.rgb = vec3( irgb ) / uQuantize;fFragColor = vec4( rgb, 1. );}Toon Renderingmjb – January 29, 2013Oregon State UniversityComputer GraphicsToon RenderingOriginal ImageColors QuantizedOutlines Added12mjb – January 29, 2013Oregon State UniversityComputer GraphicsUse the GPU to enhance scientific, engineering, and architectural illustrationToon Rendering for Non-Photorealistic Effectsmjb – January 29, 2013Oregon State UniversityComputer GraphicsToon Rendering for Non-Photorealistic EffectsUse the GPU to enhance scientific, engineering, and architectural


View Full Document

OSU CS 519 - Using Fragment Shaders to Manipulate Imagery

Download Using Fragment Shaders to Manipulate Imagery
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Using Fragment Shaders to Manipulate Imagery and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Using Fragment Shaders to Manipulate Imagery 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?