Mc0072 Cg Set 2
-
Upload
naved-azmi -
Category
Documents
-
view
220 -
download
0
Transcript of Mc0072 Cg Set 2
-
8/3/2019 Mc0072 Cg Set 2
1/15
February2011MasterofComputerApplication(MCA)Semester3
MC0072ComputerGraphics4Credits(BookID:B0810)AssignmentSet2
1. Writeashortnoteonthefollowings:A)Videomixing
Ans: Videocontrollerprovidesthe facilityofvideomixing. Inwhich itaccepts informationoftwo imagessimultaneously.Onefromframebufferandotherfromtelevisioncamera,recorderorothersource.
Thisisillustratedinfig2.7.Thevideocontrollermergesthetworeceivedimagestoformacomposite
image.
FrameBuffer VideoController
Monitor
VideoSignalSource
Videomixing
Therearetwotypesofvideomixing.Infirst,agraphicsimageissetintoavideoimage.Heremixingis
accomplishedwith hardware that treats a designated pixel value in the frame buffer as a flag to
indicatethatthevideosignalshouldbeshowninsteadofthesignalfromtheframebuffer,normally
thedesignatedpixelvaluecorrespondstothebackgroundcoloroftheframebufferimage.
Inthesecondtypeofmixing,thevideo image isplacedonthetopoftheframebuffer image.Here,
wheneverbackgroundcolorofvideo imageappears,theframebuffer isshown,otherwisethevideo
imageisshown.
B)FramebufferAns: Aframebufferisavideooutputdevicethatdrivesavideodisplayfromamemorybuffercontaininga
completeframeofdata.
Theinformationinthememorybuffertypicallyconsistsofcolorvaluesforeverypixel(pointthatcan
bedisplayed)on thescreen.Colorvaluesarecommonlystored in1bitbinary (monochrome),4bit
palettized, 8bit palettized, 16bit high color and 24bit true color formats. An additional alpha
channel issometimesusedtoretain informationaboutpixeltransparency.Thetotalamountof the
-
8/3/2019 Mc0072 Cg Set 2
2/15
memoryrequiredtodrivetheframebufferdependsontheresolutionoftheoutputsignal,andonthe
colordepthandpalettesize.
Framebuffersdiffersignificantlyfromthevectordisplaysthatwerecommonpriortotheadventof
the framebuffer.Withavectordisplay,only theverticesof thegraphicsprimitivesarestored.The
electronbeamof theoutputdisplay is thencommanded tomove fromvertex tovertex, tracingan
analog line across the areabetween thesepoints.With a framebuffer, the electronbeam (if the
display technologyusesone) is commanded to tracea lefttoright, toptobottompath across the
entirescreen,thewayatelevisionrendersabroadcastsignal.Atthesametime,thecolorinformation
for each point on the screen is pulled from the frame buffer, creating a set of discrete picture
elements(pixels).
Theterm"framebuffer"hasalsoenteredintocolloquialusagetorefertoabackingstoreofgraphical
information.Thekeyfeaturethatdifferentiatesaframebufferfrommemoryusedtostoregraphics
the
output
device
is
lost
in
this
usage.
DisplaymodesFramebuffersusedinpersonalandhomecomputingoftenhadsetsofdefined"modes"underwhich
the frame buffer could operate. These modes would automatically reconfigure the hardware to
outputdifferentresolutions,colordepths,memorylayoutsandrefreshratetimings.
IntheworldofUnixmachinesandoperatingsystems,suchconvenienceswereusuallyeschewed in
favorofdirectlymanipulatingthehardwaresettings.Thismanipulationwasfarmoreflexible inthat
anyresolution,colordepthandrefreshratewasattainablelimitedonlybythememoryavailableto
theframebuffer.
An unfortunate sideeffect of thismethodwas that thedisplay device couldbe driven beyond its
capabilities. In some cases this resulted inhardwaredamage to thedisplay.[3]More commonly, it
simplyproduced garbled andunusableoutput.ModernCRTmonitors fix thisproblem through the
introductionof"smart"protectioncircuitry.Whenthedisplaymodeischanged,themonitorattempts
toobtainasignallockonthenewrefreshfrequency.Ifthemonitorisunabletoobtainasignallock,or
-
8/3/2019 Mc0072 Cg Set 2
3/15
if the signal isoutside the rangeof itsdesign limitations, themonitorwill ignore the framebuffer
signalandpossiblypresenttheuserwithanerrormessage.
LCDmonitors tend to contain similar protection circuitry,but fordifferent reasons. Since the LCD
mustdigitallysamplethedisplaysignal(therebyemulatinganelectronbeam),anysignalthatisoutof
rangecannotbephysicallydisplayedonthemonitor.
ColorpaletteFramebuffershave traditionally supported awide varietyof colormodes.Due to the expense of
memory,mostearly framebuffersused1bit (2color),2bit (4color),4bit (16color)or8bit (256
color)colordepths.Theproblemwithsuchsmallcolordepthsisthatafullrangeofcolorscannotbe
produced.Thesolutiontothisproblemwastoaddalookuptabletotheframebuffers.Each"color"
stored in frame buffer memory would act as a color index; this scheme was sometimes called
"indexedcolor".
Thelookuptableservedasapalettethatcontaineddatatodefinealimitednumber(suchas256)of
differentcolors.However,eachofthose[256]colors,itself,wasdefinedbymorethan8bits,suchas
24 bits, eight of them for each of the three primary colors. With 24 bits available, colors can be
defined farmore subtlyandexactly,aswellasoffering the full rangegamutwhich thedisplaycan
show.Whilehavingalimitedtotalnumberofcolorsinanimageissomewhatrestrictive,nevertheless
theycanbewellchosen,andthisschemeismarkedlysuperiorto8bitcolor.
Thedata from the framebuffer inthisschemedeterminedwhichof the [256]colors in thepalette
wasforthecurrentpixel,andthedatastoredinthelookuptable(sometimescalledthe"LUT")went
tothreedigitaltoanalogconverterstocreatethevideosignalforthedisplay.
Theframebuffer'soutputdata,insteadofprovidingrelativelycrudeprimarycolordata,servedasan
indexanumbertochooseoneentry in the lookup table. Inotherwords, the indexdetermined
whichcolorandthedatafromthelookuptabledeterminedpreciselywhatcolortouseforthecurrent
pixel.
MemoryaccessWhile frame buffers are commonly accessed via a memory mapping directly to the CPUmemory
space,this
is
not
the
only
method
by
which
they
may
be
accessed.
Frame
buffers
have
varied
widely
inthemethodsusedtoaccessmemory.Someofthemostcommonare:
Mappingtheentireframebuffertoagivenmemoryrange.Portcommandstoseteachpixel,rangeofpixelsorpaletteentry.Mapping a memory range smaller than the frame buffer memory, then bank switching as
necessary.
-
8/3/2019 Mc0072 Cg Set 2
4/15
Theframebufferorganizationmaybechunky(packedpixel)orplanar.
VirtualframebuffersMany systems attempt to emulate the function of a frame buffer device, often for reasons of
compatibility.The
two
most
common
"virtual"
frame
buffers
are
the
Linux
frame
buffer
device
(fbdev)
andtheXVirtualFramebuffer(Xvfb).TheXVirtualFramebufferwasaddedtotheXWindowSystem
distribution toprovideamethod for runningXwithoutagraphical framebuffer.While theoriginal
reasonsforthisare losttohistory, it isoftenusedonmodernsystemstosupportprogramssuchas
the Sun Microsystems JVM that do not allow dynamic graphics to be generated in a headless
environment.
The Linux frame buffer device was developed to abstract the physical method for accessing the
underlying framebuffer into a guaranteedmemorymap that is easy forprograms to access. This
increasesportability,asprogramsarenotrequiredtodealwithsystemsthathavedisjointedmemory
mapsorrequirebankswitching.
PageflippingSinceframebuffersareoftendesignedtohandlemorethanoneresolution,theyoftencontainmore
memory than isnecessary todisplayasingle frameat lower resolutions.Sincethismemorycanbe
considerable insize,atrickwasdeveloped toallow fornew framestobewritten tovideomemory
withoutdisturbingtheframethatiscurrentlybeingdisplayed.Theconceptworksbytellingtheframe
buffertouseaspecificchunkofitsmemorytodisplaythecurrentframe.Whilethatmemoryisbeing
displayed, a completely separatepartofmemory is filledwith data for the next frame.Once the
secondarybufferisfilled(oftenreferredtoasthe"backbuffer"),theframebufferisinstructedtolook
atthesecondarybufferinstead.Theprimarybuffer(oftenreferredtoasthe"frontbuffer")becomes
the secondarybuffer, and the secondary bufferbecomes theprimary. This switch is usually done
during theverticalblanking interval toprevent thescreen from"tearing" (i.e.,half theold frame is
shown,andhalfthenewframeisshown).
Mostmodernframebuffersaremanufacturedwithenoughmemorytoperformthistrickevenathigh
resolutions.Asaresult,ithasbecomeastandardtechniqueusedbyPCgameprogrammers.
GraphicsacceleratorsAsthedemandforbettergraphicsincreased,hardwaremanufacturerscreatedawaytodecreasethe
amountofCPUtimerequiredtofilltheframebuffer.Thisiscommonlycalleda"graphicsaccelerator"
intheUnixworld.
Commongraphicsdrawingcommands(manyofthemgeometric)aresenttothegraphicsaccelerator
in their raw form.Theaccelerator then rasterizes the resultsof thecommand to the framebuffer.
-
8/3/2019 Mc0072 Cg Set 2
5/15
ThismethodcansavefromthousandstomillionsofCPUcyclespercommand,astheCPUisfreedto
dootherwork.
While early accelerators focusedon improving theperformanceof 2DGUI systems,mostmodern
acceleratorsfocusonproducing3D imagery inrealtime.Acommondesign istosendcommandsto
the graphics acceleratorusing a library such asOpenGL. TheOpenGL driver then translates those
commands to instructions for theaccelerator'sgraphicsprocessingunit (GPU).TheGPUuses those
microinstructionstocomputetherasterizedresults.Thoseresultsarebitblittedtotheframebuffer.
Theframebuffer'ssignalisthenproducedincombinationwithbuiltinvideooverlaydevices(usually
usedtoproducethemousecursorwithoutmodifyingtheframebuffer'sdata)andanyanalogspecial
effectsthatareproducedbymodifyingtheoutputsignal.Anexampleofsuchanalogmodificationwas
theantialiasing techniqueusedby the3dfxVoodoocards.Thesecardsadda slightblur tooutput
signalthatmakesaliasingoftherasterizedgraphicsmuchlessobvious.
Popular
manufacturers
of
3D
graphics
accelerators
are
Nvidia
and
ATI
Technologies.
C)ColortableAns: Incolordisplays,24 bitsperpixelare commonlyused,where8bits represent256 levels foreach
color. Here it is necessary to read 24bits for each pixel from frame buffer. This is very time
consuming. To avoid this video controller uses look up table (LUT) to store many entries of pixel
values inRGB format.With this facility,now it isnecessaryonly to read index to the lookup table
fromtheframebufferforeachpixel.Thisindexspecifiestheoneoftheentries inthe lookuptable.
ThespecifiedentryintheloopuptableisthenusedtocontroltheintensityorcoloroftheCRT.
Usually,lookuptablehas256entries.Therefore,theindextothelookuptablehas8bitsandhence
foreachpixel, the framebufferhas to store8bitsperpixel insteadof24bits. Fig.2.6 shows the
organizationofacolor(Video)lookuptable.
Organization of a Video look-up table
Thereareseveraladvantagesinstoringcolorcodesinalookuptable.Useofacolortablecanprovide
a "reasonable" number of simultaneous colors without requiring Iarge frame buffers. For most
applications,256or512differentcolorsaresufficientforasinglepicture.Also,tableentriescanbe
changedatanytime,allowingausertobeabletoexperimenteasilywithdifferentcolorcombinations
inadesign,scene,orgraphwithoutchangingtheattributesettingsforthegraphicsdatastructure.In
-
8/3/2019 Mc0072 Cg Set 2
6/15
visualizationand imageprocessingapplications,color tablesareconvenientmeans forsettingcolor
thresholdssothatallpixelvaluesaboveorbelowaspecifiedthresholdcanbesettothesamecolor.
Forthesereasons,somesystemsprovidebothcapabilitiesforcolorcodestorage,sothatausercan
electeithertousecolortablesortostorecolorcodesdirectlyintheframebuffer.
DisplaytechnologyThe image isshownonascreen (alsocalledamoniteur),which isanoutputperipheraldevice that
allowsavisual representation tobeoffered.This informationcomes from thecomputer,but inan
indirect way. Indeed, the processor does not directly send information to the monitor, but
processestheinformationcomingfromitsRandomaccessmemory(RAM),thensendsittoagraphics
cardthatconvertstheinformationintoelectricalimpulses,whichitthensendstothemonitor.
Computermonitorsareusuallycathodetubes,i.e.atubemadeoutofglassinwhichanelectrongun
emits electrons which are then directed by a magnetic field towards a screen on which small
phosphorescent elements (luminophores) are laid out, constituting points (pixels) that emit light
whentheelectronshitthem.
ThepixelconceptAn image consists of a set of points called pixels (the word pixel is an abbreviation of PICture
ELement)Thepixelisthusthesmallestcomponentofadigitalimage.Theentiresetofthesepixelsis
containedin
atwo
dimensional
table
constituting
the
image:
-
8/3/2019 Mc0072 Cg Set 2
7/15
Thescreensweepingiscarriedoutfromlefttorightandfromtoptobottom,itisusualtoindicatethe
pixellocatedatthetoplefthandcorneroftheimageusingthecoordinates[0,0],thismeansthatthe
directionsoftheimageaxesarethefollowing:
ThedirectionoftheXaxisisfromlefttoright Thedirectionof theYaxis is from top tobottom, contrary to the conventionalnotation in
mathematics,wherethedirectionoftheYaxisisupwards.
DefinitionandresolutionThenumberofpoints(pixels)constitutingtheimage,thatis,itsdimensions(thenumberofcolumns
ofthe imagemultipliedby itsnumberofrows) isknownasthedefinition.An image640pixelswide
and480pixelshighwillhaveadefinitionof640by480pixels,whichiswrittenas640x480.
Ontheotherhand,theresolution,atermoftenconfusedwiththedefinition,isdeterminedbythe
numberof
points
per
unit
of
area,
expressed
in
dots
per
inch
(DPI),
an
inch
being
equivalent
to
2.54
cm.Theresolutionthusmakesitpossibletoestablishtherelationshipbetweenthenumberofpixels
ofan imageand theactualsizeof itsrepresentationonaphysicalsupport.A resolutionof300dpi
thusmeans300columnsand300 linesofpixels inasquare inchwhichthusyields90000pixels ina
square inch.The72dpireferenceresolutiongivesusa1/72(an inchdividedby72)pixel,thatisto
say0.353mm,correspondingtoapica(AngloSaxontypographicalunit).
ColourmodelsAnimageisthusrepresentedbyatwodimensionaltableinwhicheachcellisapixel.Torepresentan
imageby
means
of
computer,
it
is
thus
enough
to
create
apixel
table
in
which
each
cell
contains
a
value.Thevaluestored inacell iscodedonacertainnumberofbitswhichdeterminethecolouror
the intensity of the pixel, This is called the coding depth (or is sometimes also called the colour
depth).Thereareseveralcodingdepthstandards:
Blackandwhitebitmap:bystoringonebitineachcell,itispossibletodefinetwocolours(blackorwhite).
Bitmapwith16
-
8/3/2019 Mc0072 Cg Set 2
8/15
FigureshowsthestarbustpatternsforcharactersAandM.thepatternsforparticularcharactersare
stored in the formof24bit code,eachbit representingone line segment.Thebit is set toone to
highlightthelinesegment;otherwiseitissettozero.Forexample,24bitcodeforCharacterAis0011
00000011110011100001andforcharacterMis000000110000110011110011.
Thismethodofcharactergenerationhassomedisadvantages.Theyare
1.The24bitsarerequiredtorepresentacharacter.Hencemorememoryisrequired2.Requirescodeconversionsoftwaretodisplaycharacterfromits24bitcode3.Characterqualityispoor.Itisworstforcurveshapedcharacters.C)BitmapmethodThethirdmethodforcharactergenerationisthebitmapmethod.Itisalsocalleddotmatrixbecause
inthis
method
characters
are
represented
by
an
array
of
dots
in
the
matrix
form.
It
is
atwo
dimensionalarrayhavingcolumnsandrows.An5x7arrayiscommonlyusedtorepresentcharacters
asshowninthebelowfigure.However7x9and9x13arraysarealsoused.Higherresolutiondevices
suchasinkjetprinterorlaserprintermayusecharacterarraysthatareover100x100.
CharacterAin5x7dotmatrixformatEachdotinthematrixisapixel.Thecharacterisplacedonthescreenbycopyingpixelvaluesfromthe
characterarray into someportionof the screens framebuffer.Thevalueof thepixelcontrols the
intensityofthepixel.
-
8/3/2019 Mc0072 Cg Set 2
9/15
3. Discussthehomogeneouscoordinatesfortranslation,rotationandscalingAns: For translation: The third 2D graphics transformation we consider is that of translating a 2D line
drawingbyanamount alongthe axisand alongthe axis.Thetranslationequationsmaybewrittenas:
(5)Wewish towrite theEquations5 as a singlematrixequation.This requires thatwe finda2by2
matrix,
Such
that
x
+
x
=
+
From this it is clear that a=1 and c=0, but there is no way to obtainthe term required in the first equation of Equations 5. Similarly we must have x + x = +
. Therefore, b=0 and d=1, and there is no way to obtain the term required in the second
equation of Equations 5.
ForRotation: Supposewewish to rotate a figure around theoriginofour 2D coordinate system.Belowfigureshowsthepoint beingrotated degrees(byconvention,counterclockwisedirection
ispositive)abouttheorigin.
RotatingaPointAbouttheOrigin
Theequations
for
changes
in
the
and
coordinates
are:
(1)
Ifweconsiderthecoordinatesofthepoint( )asaonerowtwocolumnmatrix[ ] andthematrix
-
8/3/2019 Mc0072 Cg Set 2
10/15
-
8/3/2019 Mc0072 Cg Set 2
11/15
Then,giventheJdefinitionformatrixproduct,mp=:+/.*,wecanwriteEquations(1)asthematrix
equation
(2)
Wecandefinea Jmonad, rotate,whichproduces the rotationmatrix.Thismonad isapplied toan
angle, expressed in degrees. Positive angles are measured in a counterclockwise direction by
convention.
rotate=:monaddef'22$11_11*2112o.(o.y.)%180'
rotate90
01
_10
rotate360
`1_2.44921e_16
2.44921e_16 1
WecanrotatethesquareofFigure1by:
squaremprotate90
0 0
010
_1010
_10 0
0 0
producingtherectangleshowninbelowfigure.
TheSquare,Rotated90Degrees
-
8/3/2019 Mc0072 Cg Set 2
12/15
ForScaling:Nextweconsider theproblemof scaling (changing the sizeof)a2D linedrawing.Sizechangesarealwaysmadefromtheoriginofthecoordinatesystem.Theequationsforchangesin the
and coordinatesare:
(3)
Asbefore,weconsiderthecoordinatesofthepoint( ) asaonerowtwocolumnmatrix[ ] and
thematrix
then,wecanwriteEquations(3)asthematrixequation
(4)
WenextdefineaJmonad,scale,whichproducesthescalematrix.Thismonad isappliedtoa listof
twoscalefactorsfor and respectively.
scale=:monaddef'22$(0{y.),0,0,(1{y.)'
scale23
20
03
WecannowscalethesquareofFigure1by:
squarempscale23
0 0
20 0
2030
030
0 0
producingthesquareshowninbelowfigure.
-
8/3/2019 Mc0072 Cg Set 2
13/15
ScalingaSquare4. DescribethefollowingwithrespecttoProjection:
A)Parallel
Projection
Ans: Inparallelprojection,zcoordinateisdiscardedandparallel linedfromeachvertexontheobjectare
extendeduntiltheyintersecttheviewplane.Thepointofintersectionistheprojectionofthevertex.
Weconnecttheprojectedverticesbylinesegmentswhichcorrespondtoconnectionsontheoriginal
object.
Parallelprojectionofanobjecttotheviewplane
AsshownintheFigureabove,aparallelprojectionpreservesrelativeproportionsofobjectsbutdoes
notproducetherealisticviews.
B)PerspectiveProjectionAns: Theperspectiveprojection,ontheotherhand,producesrealisticviewsbutdoesnotpreserverelative
proportions. In perspective projection, the lines of projection are not parallel. Instead, they all
coverageata singlepointcalled the centerofprojectionorprojection referencepoint.Theobject
positionsaretransformedtotheviewplanealongtheseconvergedprojectionlinesandtheprojected
viewofanobjectisdeterminesbycalculatingtheintersectionoftheconvergedprojectionlineswith
theviewplane,asshownintheshownfigure
-
8/3/2019 Mc0072 Cg Set 2
14/15
PerspectiveprojectionofanobjecttotheviewplaneC)TypesofParallelProjections
Ans: Parallelprojectionsarebasicallycategorized intotwotypes,dependingontherelationbetweenthedirectionofprojection and thenormal to the viewplane.When thedirectionof theprojection is
normal(perpendicular)
to
the
view
plane,
we
have
an
orthographic
parallel
projection.
Otherwise,
we
haveanobliqueparallelprojection.Figureabove illustratesthetwotypesofparallelprojection.
OrthographicProjectionThe orthographic projection can display more than one face of an object. Such as orthographic
projectioniscalledaxonometricorthographicprojection.Itusesprojectionplanes(viewplanes)that
arenotnormaltoaprincipleaxis.Theyresembletheperspectiveprojectioninthisway,butdifferin
that the foreshortening is uniform rather than being related to the distance from the center of
projection.Parallelismoflinesispreservedbutanglesarenot.Themostcommonlyusedaxonometric
orthographic
projection
is
the
isometric
projection.
The isometric projection can be generated by aligning the view plane so that it intersects each
coordinateaxis inwhichtheobject isdefinedatthesamedistancefromtheorigin.Asshown inthe
shown figure, the isometricprojection isobtainedby aligning theprojection vectorwith the cube
diagonal. Itusesanusefulpropertythatallthreeprincipleaxesareequally foreshortened,allowing
measurementsalongtheaxestobemadetothesamescale(hencethename:isoforequal,metricfor
measure).
-
8/3/2019 Mc0072 Cg Set 2
15/15
Isometricprojectionofanobjectontoaviewingplane
ObliqueProjectionAnobliqueprojectionisobtainedbyprojectingpointsalongparallel linesthatarenotperpendicular
tothe
projection
plane.
Notice
that
the
view
plane
normal
and
the
direction
of
projection
are
not
the
same.Theobliqueprojectionsare furtherclassifiedasthecavalierandcabinetprojections.Forthecavalierprojection,thedirectionofprojectionmakesa450anglewiththeviewplane.Asaresult,the
projectionofalineperpendiculartotheviewplanehasthesamelengthasthelineitself;thatis,there
isnoforeshortening.
CavalierProjectionsoftheunitcubeWhen the direction of projection makes an angle of arctan (2)=63.40 with the view plane, the
resultingviewiscalledacabinetprojection.Forthisangle,linesperpendiculartotheviewingsurfaceare
projected
at
one
half
their
actual
length.
Cabinet
projections
appear
more
realistic
than
cavalier
projections because of this reduction in the length of perpendiculars. Figure below shows the
examplesofcabinetprojectionsforacube.
CabinetprojectionsoftheUnitCube