From-ShaderX-2-–-Shader-Programming-Tips-and-Trick.docx

上传人:王** 文档编号:1070085 上传时间:2024-03-24 格式:DOCX 页数:29 大小:470.73KB
下载 相关 举报
From-ShaderX-2-–-Shader-Programming-Tips-and-Trick.docx_第1页
第1页 / 共29页
From-ShaderX-2-–-Shader-Programming-Tips-and-Trick.docx_第2页
第2页 / 共29页
From-ShaderX-2-–-Shader-Programming-Tips-and-Trick.docx_第3页
第3页 / 共29页
From-ShaderX-2-–-Shader-Programming-Tips-and-Trick.docx_第4页
第4页 / 共29页
From-ShaderX-2-–-Shader-Programming-Tips-and-Trick.docx_第5页
第5页 / 共29页
From-ShaderX-2-–-Shader-Programming-Tips-and-Trick.docx_第6页
第6页 / 共29页
From-ShaderX-2-–-Shader-Programming-Tips-and-Trick.docx_第7页
第7页 / 共29页
From-ShaderX-2-–-Shader-Programming-Tips-and-Trick.docx_第8页
第8页 / 共29页
From-ShaderX-2-–-Shader-Programming-Tips-and-Trick.docx_第9页
第9页 / 共29页
From-ShaderX-2-–-Shader-Programming-Tips-and-Trick.docx_第10页
第10页 / 共29页
亲,该文档总共29页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《From-ShaderX-2-–-Shader-Programming-Tips-and-Trick.docx》由会员分享,可在线阅读,更多相关《From-ShaderX-2-–-Shader-Programming-Tips-and-Trick.docx(29页珍藏版)》请在优知文库上搜索。

1、AdvancedImageProcessingwithDirectX9PixelShadersJasonL.Mitchell,MarwanY.AnsariandEvanHart3DApplicationResearchGroupATIResearchIntroductionWiththeintroductionoftheps_2_0pixelshadermodelinDirectX9.0,weareabletosignificantlyexpandourabilitytouseconsumergraphicshardwaretoperformimageprocessingoperations.

2、Thisisduetothelongerprogramlength,theabilitytosamplemoretimesfromtheinputimage(s)andtheadditionoffloatingpointinternaldatarepresentation.InthefirstShaderXbook,weusedtheps_l_4pixelshadermodelinDirectX8.1toperformbasicimageprocessingtechniquessuchassimpleblurs,edgedetection,transferfunctionsandmorphol

3、ogicaloperatorsMitchell02.Inthischapter,wewillextendourimageprocessingtoolboxtoincludecolorspaceconversion,abetteredgedetectionfiltercalledtheCannyfilter,separableGaussianandmedianfilters,andareal-timeimplementationoftheFastFourierTransform.ReviewAsshowninouroriginalimageprocessingchapterinthefirstS

4、haderXbook,post-processingof3Dframesisfundamentaltoproducingavarietyofinterestingeffectsingamescenes.ImageprocessingisperformedonaGPUbyusingthesourceimageasatextureanddrawingascreen-alignedquadrilateralintothebackbufferoranothertexture.Apixelshaderisusedtoprocesstheinputimagetoproducethedesiredresul

5、tintherendertarget.Figure 1 - Using a pixel shader for image processing by rendering from one image to anotherOutputImageImageprocessingisespeciallypowerfulwhenthecolorofthedestinationpixelistheresultofcomputationsdoneonmultiplepixelsfromthesourceimage.Inthiscase,wesamplethesourceimagemultipletimesa

6、ndusethepixelshadertocombinethedatafromthemultiplesamples(ortaps)toproduceasingleoutput.ColorSpaceConversionBeforewegetintointerestingmulti-tapfilters,we,llpresentapairofshaderswhichcanbeusedtoconvertbetweenHSVandRGBcolorspaces.Theseshadersperformsomerelativelycomplexoperationstoconvertbetweencolors

7、paceseventhoughtheyareonlysingle-tapfilters.ForthosewhomaynotbefamiliarwithHSVspace,itisacolorspacewhichisdesignedtobeintuitivetoartistswhothinkofacolorstint,shadeandtoneSmith78.InterpolationinthiscolorspacecanbemoreaestheticallypleasingthaninterpolationinRGBspace.Additionally,whencomparingcolors,it

8、maybedesirabletodosoinHSVspace.Forexample,inRGBspace,thecolor100,0,0)isverydifferentfromthecolor0,0,100.However,theirVcomponentsinHSVspaceareequal.Colors,representedbyhue,saturation,valuetriplesaredefinedtoliewithinahexagonalpyramidasshowninFigure2below.Thehueofacolorisrepresentedbyananglebetween0an

9、d360oaroundthecentralaxisofthehexagonalcone.Acolor,ssaturationisthedistancefromthecentral(achromatic)axisanditsvalueisthedistancealongtheaxis.Bothsaturationandvaluearedefinedtobebetween0and1.WehavetranslatedthepseudocodeRGB-to-HSVtransformationfromFoley90totheDirectX9HighLevelShadingLanguage(HLSL)an

10、dcompileditfortheps_2_0target.IfyouareunfamiliarwithHLSL,youcanreferbacktotheintroductorychapterIntroductiontotheDirectX9HighLevelShadingLanguage.AsdescribedinSmith79,youcanseethattheRGB_to_HSV()functioninthisshaderfirstdeterminestheminimumandmaximumchannelsoftheinputRGBcolor.Themaxchanneldetermines

11、thevalueoftheHSVcolor,orhowfaralongtheachromaticcentralaxisofthehexagonalconetheHSVcolorwillbe.ThesaturationisthencomputedasthedifferencebetweenthemaxandminRGBchannelsdividedbythemax.Hue(theanglearoundthecentralachromaticaxis)isthenafunctionofwhichchannelhadthemaxmagnitudeandthusdeterminedthevalue.f

12、loat4RGB_to_HSV(float4color)(floatrzg,b,delta;floatColorMaxzcolorMin;floath=0,s=0,v=0;float4hsv=0;r=color0;g=color1;b=color2;ColorMax=max(rzg);ColorMax=max(colorMax,b);colorMin=min(rzg);colorMin=min(colorMin,b);v=colorMax;/thisisvalueif(colorMax!=O)(s=(colorMax-colorMin)/colorMax;if(s!=O)/ifnotachro

13、matic(delta=colorMax-colorMin;if(r=colorMax)h=(g-b)/delta;elseif(g=colorMax)Ih=2.0+(b-r)/delta;else/bismaxIh=4.0+(r-g)/delta;h*=60;if(h0)(h+=360;hsv0=h/360.0;/movinghtobebetween0and1.hsv1=s;hsv2=v;returnhsv;TheHSV-to-RGBtransformation,alsotranslatedfromFoley901,isshownbelowinHLSL.float4HSV_to_RGB(fl

14、oat4hsv)(float4color=0;floatfzpzq,t;floath,s,v;floatr=0,g=0,b=0;floati;if(hsvl=0)(if(hsv2!=0)(color=hsv2;else(h=hsv.x*360.0;s=hsv.y;v=hsv.z;if(h=360.0)(h=0;)h/=60;i=floor(h);f=h-i;p=v*(1.0-s);q=V*t=V*(1.0-(s(1.0-(s*f);*(1.0-f);if(i=0)(r=v;g=t;b=)P;elseif(i=1)r=q;g=v;b=)P;elseif(i=2)r=P;g=v;b=)t;elseif(i=3)r=P;g=q;b=V;elseifI(i=4)r=t;g=P;b=V;elseif(i=5)r=v;g=P;b=)q;color.r=r;color.g=g;color.b)=b;returncoloOtherColorSpacesItisworthnotingthatRGBandHSVarenottheonlycolorspacesofinterestincomputergraphics.Forexample,theoriginalpaperSmith78whichintroducedHSValsointroducedacolorspac

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 医学/心理学 > 眼科学

copyright@ 2008-2023 yzwku网站版权所有

经营许可证编号:宁ICP备2022001189号-2

本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!