0% found this document useful (0 votes)
65 views

Attributes

Computer Graphics

Uploaded by

ssa_joe
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views

Attributes

Computer Graphics

Uploaded by

ssa_joe
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 18

Copyright @ 2002 by Jim X.

Chen:
[email protected]

Pattern filling in scancon!ersion

"ntialiasing

#oublebuffering and animation


.1.
ATTRIBUTES
ATTRIBUTES

Any parameter that affects a primitive


displayed is an attribute parameter.

Polygon Attributes
$
pattern, color, anti-aliasing

Line Attributes
$
type (solid, dashed, dotted), width, cap (butt,
round, suare), !oin (miter, round, etc.),
color, grayscale, anti-aliasing
Copyright @ 2002 by Jim X. Chen:
[email protected]
.".
Copyright @ 2002 by Jim X. Chen:
[email protected]
.#.
PATTERN FILLING (bitmap patterns)
PATTERN FILLING (bitmap patterns)
The 1s & 0s select foreground and background
color, respectively. For transparent mode,
only 1s are written with foreground color.
Anchor the pattern at a verte of a primitive! this choice
allows the pattern to move with the primitive
"enerating patterns while scan#converting, or scan
converting a primitive first into a rectangular work
area, and then copy piels from the rectangular
bitmap to the appropriate space in the background.
Anchor the pattern at the corner of the drawing area!
the pattern does not move with the primitive
Triangle Pattern
Triangle Pattern

%enerating color patterns on a span


&hori'ontal line(
void span(int $", int $1, int y) %
double num & cnt'

for (int $ & $"' $($1' $))) %
gl.glColor3d(Math.sin(num*Math.PI/200), Math.cos(num*Math.PI/110),
)ath.sin(num*Math.PI/350));
gl.glPointi!"(1);
dra*Point&+, y(-
num..-
/
/
Copyright @ 2002 by Jim X. Chen:
[email protected]
.*.
Copyright @ 2002 by Jim X. Chen:
[email protected]
+ +

,rawing -eometric .odels ,rawing -eometric .odels
./.
Point and Line Attributes
Point and Line Attributes

void glPoint0i1e(-Lfloat si1e)'

void glLine2idth(-Lfloat width)'

glLine0tipple(1, 3$#435)'
gl6nable(-L7L89670:8PPL6)'

void glLine0tipple(-Lint factor, -lushort pattern)'


0tippled Lines 0tippled Lines
Copyright @ 2002 by Jim X. Chen:
[email protected]
,rawing -eometric .odels ,rawing -eometric .odels
.;.
SPEIF!ING A "L"R
SPEIF!ING A "L"R
gl$olor%f&0.0, 0.0, 0.0'!
draw(ob)ect&A'!
draw(ob)ect&*'!
gl$olor%f&1.0, 0.0, 0.0'!
draw(ob)ect&$'!
gl$olor%f&0.0, 0.0, 0.0'! black
gl$olor%f&1.0, 0.0, 0.0'! red
gl$olor%f&0.0, 1.0, 0.0'! green
gl$olor%f&1.0, 1.0, 0.0'! yellow
gl$olor%f&0.0, 0.0, 1.0'! blue
gl$olor%f&1.0, 0.0, 1.0'! magenta
gl$olor%f&0.0, 1.0, 1.0'! cyan
gl$olor%f&1.0, 1.0, 1.0'! white
Copyright @ 2002 by Jim X. Chen:
[email protected]
.5.
Line Anti#aliasing
Line Anti#aliasing
Antialiasing Antialiasing
Demo Demo
Copyright @ 2002 by Jim X. Chen:
[email protected]
.<.
0upersampling (postfiltering) 0upersampling (postfiltering)

8ncrease sampling rate, each pi$el area is


covered by a finer grid
2e can then use multiple sample points in a pi$el
that is within a line to determine an appropriate
intensity level for the pi$el.
0upersampling algorithms often choose more weight to
subpi$els near the center of a pi$el area+ pi$el-
wighting mas=s

0 2 0
2 1 2
0 2 0
Copyright @ 2002 by Jim X. Chen:
[email protected]
.>.
Area sampling (prefiltering)
Area sampling (prefiltering)
,etermine pi$el intensity by calculating the areas of
overlap of each pi$el with the ob!ects to be displayed

?nweighted Area 0ampling


determines the pi+el intensity by the o!erlap area only

2eighted Area 0ampling


an area closer to the pi+el2s center has greater influence on
the pi+el2s intensity than an e3ual area further a*ay from
the pi+el2s center.
Copyright @ 2002 by Jim X. Chen:
[email protected]
.13.

@one filter , -aussian filter, 8ntensity table, etc.

" simple e3uation for 4pi+el *ide line


Given the current pixels color (r, g, b), we can modify the
intensity by: (r, g, b)*(1-D/1.5). When a pixel is exactly on the
line (D=0), the pixels intensity is not changed. When a pixel is
far away from the center of the line (D=1.5), the pixels
intensity is modified to (0, 0, 0). Therefore, the pixels have
different intensity levels depending on their distances from the
center of the line. For a foreground color F and , we can
use: F*(1-D/1.5) + B*D/1.5. We can read the current pixe
c!!r "r!# the "ra#ebu""er.
!oid gl-et,oublev&-L7@?AA69:7AA0:6A7@BLBA, %5double
6#arams (-
!ow to calculate D"
48L:6A 4?9@:8B90
48L:6A 4?9@:8B90
Copyright @ 2002 by Jim X. Chen:
[email protected]
.11.
Antialiasing a straig$t line
Antialiasing a straig$t line
$
%&
' $
&
( cos
' $ ) sin ( cos
Copyright @ 2002 by Jim X. Chen:
[email protected]
.1".
void IntensifyPixel(int x,int y, double D)
{
float d, r1, g1, b1;
if (D<0) d = -D;
else d = D;
r1=r(1-d!1"#); g1=g(1-d!1"#); b1=b(1-d!1"#);
gl$olor%f(r1, g1, b1);
&rite'ixel(x,y);
(
Antialiasing Antialiasing
E%ample& '()*)Line
Copyright @ 2002 by Jim X. Chen:
[email protected]
.1#.
void antialiased)ine(int x0,int y0,int xn,int yn)
{
int dx, dy, in*r+, in*r,+, d, x, y;
float D=0, sin-a, *os-a, s.*-a, Deno.;
dy=yn-y0; dx=xn-x0; x=x0; y=y0; d=/dy-dx;
in*r+=/dy; in*r,+=/(dy-dx);
Deno. = s0rt(dxdx 1 dydy);
sin-a = dy ! Deno.; *os-a = dx ! Deno.;
s.*-a = sin-a - *os-a;
&2ile (x<xn11) {
IntensifyPixel(x,y,D); !! *urrent 'ixel
IntensifyPixel(x,y11,D-*os-a); !! ,ort2
IntensifyPixel(x,y-1,D1*os-a); !! 3out2
x11;
if (d<=0) { D1=sin-a; d1=in*r+; (
else { D1=s.*-a; y11; d1=in*r,+; (;
(
( ! 4nti4liased 5id'oint 4lgorit2. !
Antialiasing Antialiasing
4rame Aate and Aefresh Aate
4rame Aate and Aefresh Aate

8f the display refreshes at ;3 times per second


(fCs), this means that the fastest image frame
rate you can achieve is ;3 fCs

2hat often happens is that the frame is too


complicated to draw in 1C;3 second, so each
frame is displayed more than once

9otice the difference between the image frame


rate and display refresh rate.
Copyright @ 2002 by Jim X. Chen:
[email protected]
Copyright @ 2002 by Jim X. Chen:
[email protected]
+ +

,rawing -eometric .odels ,rawing -eometric .odels
.1/.
@ircle
*
+
*
+
,1
,2
,3
,-
,1
,2
,12
a) dept$+,
b) dept$+(
,rawing a circle by subdivision

d"#th'0, dra* 1 triangles. d"#th'1, each triangle is subdi!ided


into t*o and *e dra* 7 triangles.

consider ,1, ,2, and ,12 as !ectors. 8hen, ,12 is in the direction
of &,1 ) ,2)'(,1
*
.!2
+
, !0
y
.!2
y
, !0
'
.!2
'
( and 9,19 : 9,29 : 9,129.

,12 : normali!"(,1 ) ,2). ;ormali'ing a !ector is e3ui!alent to


scaling the !ector to a unit !ector.

recursi!ely subdi!ides d"#th times and dra*s 2


d"#th
triangles.
subdivideCircle(int radius, float[] v1, float[] v2, int depth) {
float v11[] = new float[3]; float v22[] = new float[3];
float v00[] = { 0, 0, 0 }; float v12[] = new float[3];
if (depth == 0) {
for (int i = 0; i < 3; i++) {
v11[i] = v1[i] * radius; v22[i] = v2[i] * radius;
}
drawtriangle(v11, v22, v00);
return;
}
v12[0] = v1[0]+v2[0]; v12[1] = v1[1]+v2[1]; v12[2] =
v1[2]+v2[2];
normalize(v12);

CC subdivide a triangle recursively, and draw them
subdivideCircle(radius, v1, v12, depth - 1);
subdivideCircle(radius, v12, v2, depth - 1);
}
Copyright @ 2002 by Jim X. Chen:
[email protected]
E%ample& '()-)ir.le
Copyright @ 2002 by Jim X. Chen:
[email protected]
Clipping- Jim Chen
<=0>7>Circle

#ra* a pentagon *ith antialiasing that rotates in a circle.


=ithin the star there is a filled circle. 8he filled circle
should be filled through subdi!ision *ith your o*n
triangle function.

8he triangle should ha!e a pattern of your choice. ?or


e+ample, random generated color. Clipping should be still
in force.
Copyright @ 200@ by Jim X. Chen:
[email protected]
07
<=4: 2002 ?all Class
<=4: 2002 ?all Class
0. )odify from pre!ious home*orA, so that the points
become small circles that bounces- &10B(
2. 8he small circles bounce *ith one another as *ell-
&10B(
4. Come circles are filled circles, some are not- &20B(

You might also like