Is there an easy way to get shadows in OpenGL? - Stack ...

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

3. Not really. · OpenGL does not make shadows, it renders every point as if there is no hinder between the point and lightsource. – Amir Zadeh · 1. 2022DeveloperSurveyisopen!Takesurvey. Home Public Questions Tags Users Companies Collectives ExploreCollectives Teams StackOverflowforTeams –Startcollaboratingandsharingorganizationalknowledge. CreateafreeTeam WhyTeams? Teams CreatefreeTeam Collectives™onStackOverflow Findcentralized,trustedcontentandcollaboratearoundthetechnologiesyouusemost. Learnmore Teams Q&Aforwork Connectandshareknowledgewithinasinglelocationthatisstructuredandeasytosearch. Learnmore IsthereaneasywaytogetshadowsinOpenGL? AskQuestion Asked 11years,7monthsago Modified 7years,3monthsago Viewed 8ktimes 16 6 Irecentlycreatedsomelandscapecodeandaddedsomediffuselightingtothescene,however,tomydisappointment,therearenoshadows.IlookedaroundthewebforhourslookingforwaystogetshadowsinOpenGL,howevertheyallseemedterriblycomplicated;andveryuniquetotheirowndemoprograms. Arethereanysimplewaystomakeshadows? c++openglterrainshadows Share Improvethisquestion Follow editedNov16,2013at13:45 askedOct3,2010at8:07 user354346user354346 3 3 Notreally.Shadowsaren'tbuiltintothepipeline.Youhavetogeneratethemyourself(therearemanywaystodothis,eachwithit'sownprosandcons)andrenderthemyourself. – GManNickG Oct3,2010at8:11 OpenGLdoesnotmakeshadows,itrenderseverypointasifthereisnohinderbetweenthepointandlightsource – AmirZadeh Oct11,2010at15:03 1 Unlessyouwanttolearntheinnardsofgraphicsprogramming,youmightwanttouseagraphicsengine(suchasHorde3D)orgameengine(OgreorIrrlicht)insteadofpureOpenGL.Itwouldsaveyoufromre-inventingthewheel(well,manywheels,probably)andletyoujumpstraightintowhatyouwanttoachieve.OpenGLisalow-levelAPI. – Kos Oct21,2010at10:08 Addacomment  |  2Answers 2 Sortedby: Resettodefault Highestscore(default) Datemodified(newestfirst) Datecreated(oldestfirst) 30 No.Rasterizationisverybadatthis(evenrecentAAAgameshavenoticeableshadowartefacts),buteverybodyliveswithit. Solutionsinclude(approx.fromeasiest/pooresttobest/hardest): Noshadows.Simplyaccountforocclusionwithdarkercolors.xNormal,Blender. Ifyouwantanapproximateshadowforacharacter,asimpleflatpolygononthegroundwithatransparentandblurrytexturewilldo.SeeZeldascreenshots,forinstance.Evensomerecentgamesstillusethis. Lightmaps.Staticgeometryonly,butperfectlighting(precomputed).Reasonnablysimpletoimplement.Lotsoftoolsexist. Shadowvolumes,popularisedbyCarmack.Pixelperfect,reasonnablysimpletoimplement,quiteslow.Goodforafewobjects.Nosoftshadows. Shadowmaps.AlittlehardtoimplementifyounevermadeanyopenGL.Hardtogetright.Pixellatedshadows.Dealswithlotsofpolygons.Doesn'tdealwithbigworlds. MyriadsofShadowmapsvariants.Lotsofresearchtheserecentyears.CurrentbestisCascadedShadowMaps:Difficult,stillhardtomakeitlookgood,butfast,dealswithloadsofpolygonsandhugeworlds. Raytracedshadows:Thismaybethenext-gen.Nobodyreallyusesthatexceptforsomeresearchpapers.Verycomplicated,doesn'tdowellwithdynamicworlds(yet),hugestaticscenesok.Pixelperfectorsoftshadows,dependingonhowmuchspareGPUyouhave.Severalvariants;asof2014thisstilldidn'tmakeinanygameforperformancereasons. Sotheusualtrickistomixbeautiful-but-static-onlyapproacheswithdynamic-but-not-that-goodapproaches.Forinstance,seemytutorialsonlightmappingandshadowmapping. Share Improvethisanswer Follow editedJan29,2015at15:56 answeredOct3,2010at14:48 Calvin1602Calvin1602 9,24722goldbadges4141silverbadges5454bronzebadges 7 Ifyou'retryingtogetshadowsofthemountainswithastaticsun,lightmapsarethewaytogo.Exportyourmapintoany3Dformat,openinBlender,followanytutorial:you'vegotyourlightmap.Mixwiththetexturewithashader(ordirectlyinPhotoshopifyou'relazy),you'redone. – Calvin1602 Oct4,2010at17:53 Sorry,thepedantinmemakesmecomment:shadowvolumeswerefirstproposedin1977byFrankCrow.They'reatechnique,likeBSPtreesorthatfastsquarerootthatyouseearound,thatCarmackhaspopularisedforgamesbutdefinitelydidn'tinvent. – Tommy Oct18,2010at0:10 Thanksforthecomment,Ididn'tknow.Messageupdatedaccordingly. – Calvin1602 Oct18,2010at11:17 I'djustliketopointoutthatinUnrealEngine4realtimeshadowsaren'treally"research".Decideifit'snext-genornotforyou. – BartekBanachewicz Jan3,2013at13:44 Ifyou'rereferringtoCrassin'spaperasusedbyUE4,voxelsareonlyusedforsecondary"rays".Thereisstillashadowmap. – Calvin1602 Jan4,2013at12:06  |  Show2morecomments 6 No. TheeasiestwayIknowofinvolvesusingapregeneratedshadowtexturethatisoverlaidontotheterrainusingmultitexturing.Thecomplicatedpartisgeneratingthistexture,butifyoudon'tusedirectionallighting,asimple"bigblurrydot"isusuallybetterthannothing. Share Improvethisanswer Follow answeredOct3,2010at8:12 ZoobaZooba 10.9k33goldbadges3434silverbadges4040bronzebadges 4 Oh,theeveneasierwayistouseanenginewithitalreadybuiltin,butIassumethatyou'renotinterestedinjustbuildingmodelsforsomeoneelse'sengine(fairenough,neitheramI). – Zooba Oct3,2010at8:13 No,Idon'twanttobuildmodelsforsomeoneelsesengine.Asfortheanswerabove,wherecouldIfindouthowtodothis? – user354346 Oct3,2010at9:12 Anybasicintroductiontomultitexturingwillcoverit.Thetrickistosetthetexturetowrap(withtransparentedges)andpositionitusingtheUVparametersontheterrain.Alternativelyyoucanmakeanextrasurfacefortheshadow,whichiseasyonaflatsurface,butabitmoreinvolvedonaterrain... – Zooba Oct4,2010at3:37 Alternatively,ifyouwantterrainshadows,theeasiestwayistoturnyourheightmap(assumingblackislowest)intoatextureandapplyitoverthewholeterrain.Iwascomingattheanswerfroma"providingashadowforacharacter"POV,ratherthanaddingterrainshadows. – Zooba Oct4,2010at3:38 Addacomment  |  YourAnswer ThanksforcontributingananswertoStackOverflow!Pleasebesuretoanswerthequestion.Providedetailsandshareyourresearch!Butavoid…Askingforhelp,clarification,orrespondingtootheranswers.Makingstatementsbasedonopinion;backthemupwithreferencesorpersonalexperience.Tolearnmore,seeourtipsonwritinggreatanswers. Draftsaved Draftdiscarded Signuporlogin SignupusingGoogle SignupusingFacebook SignupusingEmailandPassword Submit Postasaguest Name Email Required,butnevershown PostYourAnswer Discard Byclicking“PostYourAnswer”,youagreetoourtermsofservice,privacypolicyandcookiepolicy TheOverflowBlog Makeyouropen-sourceprojectpublicbeforeyou’reready(Ep.444) Thescienceofinterviewingdevelopers FeaturedonMeta AnnouncingthearrivalofValuedAssociate#1214:Dalmarus Improvementstositestatusandincidentcommunication RetiringOurCommunity-SpecificClosureReasonsforServerFaultandSuperUser Temporarilypausingthesitesatisfactionsurvey StagingGround:ReviewerMotivation,Scaling,andOpenQuestions Linked 11 3DShadowimplementationidea Related 1 LightingissueinOpenGL 6 OpenGLrendervs.ownPhongIlluminationImplementation 1945 EasiestwaytoconvertinttostringinC++ 0 WhatisthesimplestmethodforrenderingshadowsonasceneinOpenGL? 0 Away3D-shadowscastbyDirectionalLightareoff 0 OpenGLfragmentshadernotlightingthescene 1 OpenGLLightingwithDisplayLists 0 OpenglLightingArtifact(calculatinglightbeforetranslation) HotNetworkQuestions WhatpreventsmefrommakingonebigestimatedFederaltaxpaymentonJan15? WhatisRNAVtransitionandwhatisthedifferencebetweenRNAVtransitionandRNAVSTAR WhydoesmyMOSFETalwaysburn? QGISreadsblankcellsas"nan"insteadof"NULL" Howtodetectchains(sequenceofdegree2vertices)inagraph? StarWars:R2D2connectedtomainframe Longestgeometricprogressionofprimes Tryingtouseacaralternatorforapowersource(notforcar) Audiosplitterwithoutbufferpossible? Whyweremarijuanarestrictionsimplementedinthe1970smoresuccessfulinSouthKoreathanintheUnitedStates? GN:Howtopassaninstancer'slocalizedtexturecolortoitsinstances? Pleasehelpmeclarifythissentenceabout'microtones'onGroveMusic Myboss:"Ifeeljealous" Movingplayerinsideofmovingspaceship? Using\textsc{}manuallyinsection UnabletomountaLinuxRAIDarray Can'tmultiplywidthin\newcommandforincludegraphics sObjecttypesfromstring HowcanItellwhich3rdpartyflashesarecompatiblewithCanon'sSL3missingpinhotshoemount? WhattapeformatdidtheNintendoFamicomDataRecorderuse? Whydoesthex86nothaveaninstructiontoobtainitsinstructionpointer? Isitdangeroustoconsume30mgofZinc(asZincPicolinate)perday? Isitaredflagforacompanytohave"unlimitedpaidtimeoff"? Howdoyouemptyanonlinevirtualdebitcard? morehotquestions Questionfeed SubscribetoRSS Questionfeed TosubscribetothisRSSfeed,copyandpastethisURLintoyourRSSreader. lang-cpp Yourprivacy Byclicking“Acceptallcookies”,youagreeStackExchangecanstorecookiesonyourdeviceanddiscloseinformationinaccordancewithourCookiePolicy. Acceptallcookies Customizesettings  



請為這篇文章評分?