What rendering techniques would I use to draw a drop ...

文章推薦指數: 80 %
投票人數:10人

For further trickery, you can alternate between shadow and card render to get effect like (d), or first draw all shadows and then the cards, ... 2022DeveloperSurveyisopen!Takesurvey. GameDevelopmentStackExchangeisaquestionandanswersiteforprofessionalandindependentgamedevelopers.Itonlytakesaminutetosignup. Signuptojointhiscommunity Anybodycanaskaquestion Anybodycananswer Thebestanswersarevotedupandrisetothetop Home Public Questions Tags Users Companies Unanswered Teams StackOverflowforTeams –Startcollaboratingandsharingorganizationalknowledge. CreateafreeTeam WhyTeams? Teams CreatefreeTeam Teams Q&Aforwork Connectandshareknowledgewithinasinglelocationthatisstructuredandeasytosearch. Learnmore WhatrenderingtechniqueswouldIusetodrawadropshadoweffectforcardsinacardgame? AskQuestion Asked 10years,5monthsago Modified 10years,5monthsago Viewed 9ktimes 14 8 \$\begingroup\$ Whattypeofshadingalgorithmmightbeusedtocreateshadowslikethese? theoneI'mmakingissimilarbutitisalldonewitha2DdrawingAPIpoweredbyOpenGLsothereisnoZcoordinate. Inaddition,forthehanditself,I'dreallyliketogetashadedfeellikeseenhere: I'mjustnotsurehowtoachieveashadedlookclosetothat. ThenumberofcardsisboundtochangeandthecardsgetthrownontothetablesoIcan'tuseanytypeoflightmapofsorts. WhatsortsofalgorithmsshouldIlookinto(asidefromblurwhichIknow'llneedtodo?) Thanks Update I'mmakinga2Dcardgame.Iwanttoadddropshadowsoffsetfromthecards,abitlike: ThewayI'mthinkingofdoingitis: Keepatexturethatisthesamesizeasthebackbuffer. Drawdarkrectanglesasmakeshiftcardstothattexture. Blurthattexture. Drawmycardstothattexture. Doadditionallightingonthecards. Drawthistexturetothebackbuffer. Myquestionsare: Isthistherightwaytodothis? Isthereawaytodoitwithoutrendertotexture(keepingabitmap asbigasthebackbuffer)? Isitsafetoassumethatthemaximumtexturesizewillnotbe exceededbythebackbuffersize?(WhatImeanis,ifthebackbuffer is2000x3000,thenisitsafetosaythatIcancreateatexturein videomemoryofthatsize? Thanks algorithmshadersshadowsfragment-shader Share Improvethisquestion Follow editedDec8,2011at22:20 Tetrad 30k1212goldbadges9292silverbadges142142bronzebadges askedDec2,2011at0:44 jmasterxjmasterx 2,04922goldbadges2525silverbadges3737bronzebadges \$\endgroup\$ 1 1 \$\begingroup\$ Anaestheticpointonyoursecondissue:thatisn'treallypossibleifyou'reactuallyholdingthosecardsinyourhand.Cardspressednexttoeachotherdon'tappreciablyshadowoneanother.Notunlessyou'reholdingalotofthem.Youcannotreallyholdcardsthewaythey'redepictedinthatimage;thosecardslooklikethey'reseparatedbyseveralmillimeters;they'renotflatagainstoneanother.Ijustwouldn'tworryaboutit. \$\endgroup\$ – NicolBolas Dec2,2011at7:33 Addacomment  |  5Answers 5 Sortedby: Resettodefault Highestscore(default) Datemodified(newestfirst) Datecreated(oldestfirst) 18 +250 \$\begingroup\$ Ithinkeverybody'sgivingwaytoocomplicatedsolutionstothisproblem.. Sofirst,wehavethecard(orwhateveryouwanttodraw),depictedhereby(a). Next,wetakeacopyofit,fillitinblackandrunagaussianbluronit(b).Allofthishappensinphotoshoporwhateveryourfavoritearttoolis. Next,in-game,whenwewanttodrawthecard,firstdrawtheblurredblackimagewithmultiplicative(oralpha)blend,offsetinsomedirectionabit,andthendrawthecardontopofthat.Voilá. Forfurthertrickery,youcanalternatebetweenshadowandcardrendertogeteffectlike(d),orfirstdrawallshadowsandthenthecards,likein(e)(Icoloredthecardsinthe(e)casetoshowthatthey'restillseparate=) It'salsobestnottousepureblack(orfullalpha)fortheshadowtocreatemoresubtle,transparentshadows. Share Improvethisanswer Follow editedDec12,2011at10:11 answeredDec12,2011at9:41 JariKomppaJariKomppa 7,77333goldbadges2828silverbadges6161bronzebadges \$\endgroup\$ 2 2 \$\begingroup\$ +1fordoingtheshadowsoutofgame.Youcouldalsotakeitastepfurtherandmodifywheretheshadowisplacedaifthereisalightinthescene. \$\endgroup\$ – FrenchyNZ Dec12,2011at10:21 \$\begingroup\$ +1,niceillustration.Furthermore,incaseEyoucoulduserenderdarkshadowsontotableandsemi-brightoncardswithstencil.Thatwillbemorecomplicated,buttheeffectwillbeevennicer:) \$\endgroup\$ – Kromster Dec12,2011at11:19 Addacomment  |  2 \$\begingroup\$ Thefirstoneisn'ttoohard.Ifyourenderanalphachannelforyourhandofcards(whichcouldbeassimpleasblackforapixelwithacardinit,andwhitefortransparent),youcanperformanykindofbluryouwantonjustthealphachannel,andthenoffsetitandusethattocontrolthelightingofthetable.(Presumably,ifyoudon'thaveaZ-buffer,you'dhavetofirstrenderoutthealphachanneloffscreensomewhere,thendothetablewiththemask,thenrendertheactualcards.) ThesecondonelooksabitlikeSSAO(screen-spaceambientocclusion).ThattechniquerequiresaZcoordinate.However,ifyoudon'thavethevaryinganglesbetweencards(whichiswhatIwouldguessifyouhavenoZ-buffer),youcanprobablydoaprettygoodapproximationbyrenderingadropshadow(likethefirstone)foreachcard.Theperformancecouldbealittletricky,though—everyplanewouldneedablurredalphachannelforalltheplanesaboveit,andifthereareabunchofcardsonthetable,thatcouldbequiteafewrenderingpasses. Share Improvethisanswer Follow answeredDec2,2011at2:16 JohnCalsbeekJohnCalsbeek 4,73211goldbadge2020silverbadges1717bronzebadges \$\endgroup\$ 1 \$\begingroup\$ SSAOisoverkill=)It'sverydifficulttotellwhatshadowingtechniqueisusedwithoutseeingtheexampleanimated.Ifthecardsalwaysfallinthatorderandspacingontopofoneanotheritwouldbeeasiesttosimplypre-rendertheshadowsin,butyou'dneverknoww/outseeingthegameinaction. \$\endgroup\$ – PatrickHughes Dec2,2011at4:04 Addacomment  |  0 \$\begingroup\$ Couldyounotdoashadowmap?Renderthescenetoafbo.Saveonlythedepthvaluesanddothenormaldepthvaluecheckintheshadertoseeifashadowshouldberenderedornot. Share Improvethisanswer Follow answeredDec8,2011at20:45 JoeyGreenJoeyGreen 2,49944goldbadges2525silverbadges4646bronzebadges \$\endgroup\$ 1 \$\begingroup\$ I'mnotusingaZBuffer,thereisno'depth'. \$\endgroup\$ – jmasterx Dec8,2011at20:48 Addacomment  |  0 \$\begingroup\$ Thefollowingprocessdoesn'trequireanoff-screenrendertarget.However,insodoing,itgainstherequirementthatthetablebedrawnfirst.Oratleast,nothingisdrawnonthepixelsthatthetablewillcoverbeforethetableisdrawn.Italsorequiresthatthetableitselfbeone,single,non-overlappingpiece:animage. Also,yourframebufferneedsanalphacomponent. Getagreyscaleimageofacard.Makeitfuzzyaroundtheedges,possiblyexpandingitssize.Thisisyourshadowcardimage.Notethatthisisasingle-channelimage.Whenyouaccessthistextureinyourshader,youshouldmakesurethatyouputthesinglevalueinthealphacomponent.Thiscanbedoneinyourshaderorsomewhereelse. Avalueof0.0intheimagemeansthatthereisnoshadow.Avalueof1.0intheimagemeanstotalshadow.Thatis,completelypitchblack.Youprobablywantavalueof0.5orsoasyourdarkestcolor. Clearthescreensuchthatthealphaissettozero. Beforerenderinganything(oratleastanythingthatwillberendered"under"thetable),foreachcard,renderthefuzzytexture,offsetfromtheactualpositionofthecard(butwiththesameorientation).ThecoloroutputbytheshadershouldbeTheblendconfigurationforthisshouldbe(inOpenGLparlance): glBlendEquation(GL_MAX); Thisblendmodeisusedtokeepoverlappingshadowsfromgrowingeverdarkerorlighter.Itsimplytakesthedarkestvaluewrittentothatpixel.Itshouldlookgoodenough. Youshouldalsousethecolorwritemasktoturnoffcolorwrites. Renderthetable.WhendoingsoTheblendingshouldbesetupasfollows: glBlendEquation(GL_ADD); glBlendFunc(GL_ONE_MINUS_DST_ALPHA,GL_ZERO); Iftherestrictionsaretoorestrictiveforyou,thenyouhavetousearendertarget.Thisisdoneasfollows: Createtheshadowcardimageasbefore. First,rendertheshadows.Bindtheshadowframebuffer(whichonlyneedstobeasingle-channelimage,ifyourhardwarecanrendertooneofthose).Clearitsvaluetozero. Foreachcard,rendertheshadowcardimage,offsetasbefore.Yourshadershouldwritethesamevaluetoallfourcomponentsoftheoutputcolor.TheblendmodeagainshouldbeglBlendEquation(GL_MAX). Switchbacktotheregularframebuffer.Draweverythingyouwanttobeshadowed. Nowdrawafull-screenquadwithshadowimagewerendered.Theshadershouldstorethetexelfetchedfromtheshadowimageinthealphaoftheoutput;theRGBisirrelevant.Theblendmodeshouldbe: glBlendEquation(GL_ADD); glBlendFunc(GL_ZERO,GL_ONE_MINUS_SRC_ALPHA); Share Improvethisanswer Follow answeredDec8,2011at22:07 NicolBolasNicolBolas 25.8k33goldbadges7373silverbadges103103bronzebadges \$\endgroup\$ 3 \$\begingroup\$ Inthefirstmethod,Ithinkyouforgotstep5:disableblendingandrenderthecards.Also,it'sworthnotingthatthefirstmethoddoesn'tallowyoutogetinter-cardshadowsasseenintheOP'ssecondscreenshot. \$\endgroup\$ – NathanReed Dec8,2011at22:16 \$\begingroup\$ @NathanReed:Ifiguredheknewhowtoturnthingsoffhimself.Also,the"inter-cardshadows"doesn'tmakeanysense,asIpointedoutinmycommentunderthequestion. \$\endgroup\$ – NicolBolas Dec8,2011at22:22 1 \$\begingroup\$ Itmaynotrealisticallyrepresenthowyou'dactuallyholdcards,butitlookscool!Itdoesn'treally"makesense"forthecardstofloatabovethetableastheydointhefirstshot,either... \$\endgroup\$ – NathanReed Dec8,2011at23:02 Addacomment  |  0 \$\begingroup\$ I'dusethestencilbuffer.Clearitto1(preferablyatthesametimeasyoucleardepth),drawyourtable.Thenenablestenciltest,drawtheshadowsusingablurryrectangletexture,incrementingifstencilanddepthpass,doingnothingifstencilfail,nothingifdepthfail,andsetyourstencilfunctoGL_EQUAL(ref1,mask0xff),disablestenciltest.(Ihaven'tfullytestedthisbutit'sderivedfromcodethatdoessimilarandshouldworkfine;youmayneedtotweaktheparams).Thendraweverythingelse. Thecallswouldbe: glEnable(GL_STENCIL_TEST); glStencilFunc(GL_EQUAL,1,2); glStencilOp(GL_KEEP,GL_KEEP,GL_INCR); //drawshadowtextures glDisable(GL_STENCIL_TEST); Theonlytimethismaycausetroubleisifyouhavetwoblurrededgesthatoverlapslightly;otherwiseitneedsnothingfancybeyondwhatbasicOpenGL1.1offersandwillworkonallhardware(expectperhapsold3DFXcards,whichIassumeyou'renotreallyworriedaboutsupporting...) Asecondalternative,thatshouldworkverywellinanon-performance-criticalgame,isglCopyTexSubImage2D.Thatwillworkwithatexturesmallerthanthebackbuffertooandisalsosupportedwellonallhardware(it'spartofOpenGL1.1andDoom3usedit,soyoucanexpectsupporttobeverygood). Thebasicsetupwouldgolikethis: Clearcolourtoblack. Disabledepthwriting(althoughthismethoddoesn'tneedadepthbuffer,soyoucanignorethatpartasyou'renotusingone). Setaviewportthesamedimensionsasyourtexture. Drawcardsaswhitefilledgeometry. glCopyTexSubImage2Dtoyourtexture. Switchviewportbacktofullwindowsize. Drawtableasnormal. Drawtextureasafullscreenblendedquad,usingashadertobluritandinvertcolour. Draweverythingelse. Thatshouldalsoworkverywell,it'salittlemoreGPUintensivethanthestencilbuffermethodbuthandlestheoverlappingcasecorrectlyand-likeIsaid-IthinkagamelikeyouronewillhaveGPUpowertoburn,evenonalow-endcard. Share Improvethisanswer Follow answeredDec9,2011at0:58 MaximusMinimusMaximusMinimus 19.4k22goldbadges3535silverbadges6262bronzebadges \$\endgroup\$ Addacomment  |  Youmustlogintoanswerthisquestion. Nottheansweryou'relookingfor?Browseotherquestionstaggedalgorithmshadersshadowsfragment-shader. TheOverflowBlog Makeyouropen-sourceprojectpublicbeforeyou’reready(Ep.444) Thescienceofinterviewingdevelopers FeaturedonMeta AnnouncingthearrivalofValuedAssociate#1214:Dalmarus Improvementstositestatusandincidentcommunication Related 0 Myblurgetsuglywhenradiustoohigh 5 Dealingwithalphafor2Dperpixellighting 1 Howtoshadeatexturetwodifferentcolors? 0 OpenGLRTTFrameBufferquestionandRenderingtotexturewhilesamplingit 4 Shadowartifactscausedbyfiltering 16 Modernshadowrenderingtechniques? 7 WhatShading/Renderingtechniquesarebeingusedinthisimage? 2 MathbehindXNA'sspriteBatch.draw()colorparameter? 1 Softshadowscreategraphicalerrors 2 Openglmutipletextureinashader HotNetworkQuestions GameinJamesBondfilm"FromRussiawithlove" Audiosplitterwithoutbufferpossible? OutputofaHubDynamomeasuredwithanOscilloscope Whatdisadvantagesaretheretoencryptinganentireharddriveorahomedirectory? Iwant8bitsforeverycharacter! Non-committingauthenticatedencryptionschemesvscommittingauthenticatedencryptionschemes GenerateAll8Knight'sMoves ShouldIrevealmyslidesbit-by-bitwhengivingapresentation/lecture? Isthereanargumentagainstusingthe(reviewed)predictionsofamodelasgroundtruthtofurthertrainexactlythismodel? CanImakeGooglePlayshowmeALLreviewsforanapp? Currentlyself-studyingQFTandTheStandardModelbySchwartzandI'mstuckatequation1.5inPart1regardingblack-bodyradiation Pleasehelpmeclarifythissentenceabout'microtones'onGroveMusic WhyisMIDIgainbasedonafactorof40? Isitdangeroustoconsume30mgofZinc(asZincPicolinate)perday? Whatdoestheidiomaticphrase"erronthesideof"mean? CanWgatebewrittenonlyusingH,T? Whatisthemostecologicallysustainablewaytohandleragscoveredinchaingrease? Meaningandoriginoftheword"muist" GapsincardinalitiesofMADfamilies Whyweremarijuanarestrictionsimplementedinthe1970smoresuccessfulinSouthKoreathanintheUnitedStates? Googlespreadsheets UnabletomountaLinuxRAIDarray Softwareforcreatinghand-writtenslidesthatarerevealedgradually Howcanaprivatekeybeimportedtoadescriptorwallet? morehotquestions Questionfeed SubscribetoRSS Questionfeed TosubscribetothisRSSfeed,copyandpastethisURLintoyourRSSreader. default Yourprivacy Byclicking“Acceptallcookies”,youagreeStackExchangecanstorecookiesonyourdeviceanddiscloseinformationinaccordancewithourCookiePolicy. Acceptallcookies Customizesettings  



請為這篇文章評分?