| ECE291 | Computer Engineering II | Lockwood, Spring 1999 |

Team Members: |
Nikhil Tilwalli - physical conceptualization and subsequent algorithm development (including use of FPU), file output Shelly Henry - physical conceptualization and subsequent algorithm development (including use of FPU), file output Shyam Kurup - input, VESA graphics, protected mode implementation (and NASM syntax conversion) Peter J. Arialis - input, VESA graphics, protected mode implementation (and NASM syntax conversion) |
Introduction: |
Our goal is to implement a raytracer, in 32-bit protected mode, at a resolution of 1024x768 with 24-bit (true) color. A raytracer traces individual rays of light from a light source to objects, and the objects are shaded according to the perspective of the viewer. The objects (primitives) will be spheres, cylinders, and planes. The user will be able to specify up to five of each of these (15 total primitives) and their properties. |
Problem
|
There are many aspects that make this project challenging. The algorithms for raytracing are complex and must use the FPU. We have to familiarize ourselves with 32-bit protected mode programming (as opposed to real mode programming, which we have used in all of our MP's). For graphics, we are using 1024x768 pixels, with 24-bit (true) color. This is a VESA mode, which also was not touched upon, in any of our MP's. |
Proposed
|
Input (for type, number, location, etc. of primitives and the light source) is obtained from user, via keyboard, and stored in light source, sphere, cylinder, and plane structures. A buffer is allocated in memory, which will store the raytraced image. The video mode is set to 1024x768x24bpp (VESA). Raytracing algoritms are called to read input, and perform calculations by calling appropiate procedures, based on primitve attributes. After calculations are completed and ImageBuffer is filled, DrawScreen is called to transfer the image to video memory (display on screen), using bank-switching procedures. The image remains on the screen until the user presses a key. |
Actual
|
The algorithms were written in real mode, and upon conversion to 32-bit protected mode (and NASM syntax) functioned somewhat erratically. That is, whenever the primitives were displaced in the x-direction (the y-direction and z-direction worked properly), screen anomalies were noted. After _much_ scrutiny, we were unable to determine the source of these problems. Therefore, our final program runs in real mode and outputs to a BMP file (we decided to move to 640x480x24bpp BMP, to make smaller AVI demos). Input is still obtained from the user via keyboard. AVI's were made from individual BMP files generated from the program and are included with the program. We also include "pmode.exe" in the program directory to demonstrate proper 32-bit protected mode and 1024x768x24bpp VESA execution, with a shaded sphere in the center of the screen (where the anomalies are not noted). The user can input a light source location (x=0.00, y=0.00, z=-10.00 is recommended). |
Screen Shots: |
|
|
|
|
|
Procedures: |
ShortestIntersect
CalcWritePixel
ReadWriteHeader
WriteArray
InitializeVars
SphereCalcIntensity
CylinderCalcIntensity
PlaneCalcIntensity
ChangeControl
RestoreControl
FloatPower
SphereReflectRayCalc
CylReflectRayCalc
PlaneReflectRayCalc
SphereSpecIntensity
CylinderSpecIntensity
PlaneSpecIntensity
CalcIntersectSphere
CalcIntersectCylinder
CalcIntersectPlane
CalcDir
Shadow
Load procedures (a collection of 15 procedures)
GetInput
OneSphereInput
OneCylinderInput
OnePlaneInput
ConvertFloatInput
ConvertIntegerInput
ReadOneLineInput
WaitForEscapeKey
DOSXIT and DSPMSG were used from LIB291 Some Additional Procedures Used In "pmode.exe"Main
SetVideoMode
SetVideoBank
AllocateImageBuffer
FillBuffer
DrawScreen
|
Data Structures: |
Sphere STRUC
Xc Real4 -4.69926
Yc Real4 3.52445
Zc Real4 -7.3426
Rad Real4 3.0
Alp Real4 40.0
Dk Real4 1.0
Lk Real4 1.0
Sk Real4 0.0
RColor dw 0
GColor dw 255
BColor dw 255
Active dw 0
Index dw ?
Cylinder STRUC
Xc Real4 0.0
Yc Real4 0.0
Zc Real4 -8.2
Radius Real4 1.2
Height Real4 1.5
Dk Real4 1.0
Lk Real4 1.0
Sk Real4 0.0
Alp Real4 20.0
RColor dw 255
GColor dw 0
BColor dw 255
Active dw 0
Index dw ?
Plane STRUC
Xcoef Real4 1.0
Ycoef Real4 0.0
Zcoef Real4 1.0
Const Real4 -20.0
NormMag Real4 ?
Xunit Real4 ?
Yunit Real4 ?
Zunit Real4 ?
Dk Real4 1.0
Lk Real4 1.0
Sk Real4 0.0
Alp Real4 20.0
RColor dw 255
GColor dw 255
BColor dw 0
Active dw 0
Index dw ?
Origin STRUC
xOrig Real4 0.0
yOrig Real4 0.0
zOrig Real4 0.0
PixelRay STRUC
x Real4 0.0
y Real4 0.0
z Real4 -5.0
Xdir Real4 ?
Ydir Real4 ?
Zdir Real4 ?
dist Real4 ?
LSource STRUC
Xl Real4 0.0
Yl Real4 2.0
Zl Real4 0.0
Vector STRUC
Xcomp Real4 0.0
Ycomp Real4 0.0
Zcomp Real4 0.0
NormMag Real4 0.0
Xunit Real4 0.0
Yunit Real4 0.0
Zunit Real4 0.0
SNormV STRUC
Xcomp Real4 0.0
Ycomp Real4 0.0
Zcomp Real4 0.0
NormMag Real4 0.0
Xunit Real4 0.0
Yunit Real4 0.0
Zunit Real4 0.0
OLSourceV STRUC
Xcomp Real4 0.0
Ycomp Real4 0.0
Zcomp Real4 0.0
NormMag Real4 0.0
Xunit Real4 0.0
Yunit Real4 0.0
Zunit Real4 0.0
CurrentBank dw 0
TempInput dw 0
FloatInput Real4 0.0
IntegerInput dw 0
BallPointer dw 0
RodPointer dw 0
FlatsPointer dw 0
NumCharacters db 0
InputString db 25 dup('0')
TwoLines db 0Ah,0Dh,0Ah,0Dh,'$'
NumSpheresMsg db 0Dh,0Ah
db 'How Many Spheres Would You Like?'
db ' (0-5)', 0Dh,0Ah,'$'
NumCylindersMsg db 0Dh,0Ah
db 'How Many Cylinders Would You Like?'
db ' (0-5)', 0Dh,0Ah,'$'
NumPlanesMsg db 0Dh,0Ah
db 'How Many Planes Would You Like?'
db ' (0-5)', 0Dh,0Ah,'$'
InputErrorMsg db 0Dh,0Ah
db 'Input Is Invalid - Program Terminating'
db 0Dh,0Ah,'$'
XcMsg db 0Dh,0Ah
db 'Enter the x-coordinate of the center'
db ' (-10.00 to 10.00)'
db 0Dh,0Ah,'$'
YcMsg db 0Dh,0Ah
db 'Enter the y-coordinate of the center'
db ' (-10.00 to 10.00)'
db 0Dh,0Ah,'$'
ZcMsg db 0Dh,0Ah
db 'Enter the z-coordinate of the center'
db ' (-10.00 to 10.00)'
db 0Dh,0Ah,'$'
RadiusMsg db 0Dh,0Ah
db 'Enter the radius'
db ' (0.00 to 20.00)'
db 0Dh,0Ah,'$'
XcoefMsg db 0Dh,0Ah
db 'Enter the x-coefficient of the plane equation'
db ' (1.00 to 20.00)'
db 0Dh,0Ah,'$'
YcoefMsg db 0Dh,0Ah
db 'Enter the y-coefficient of the plane equation'
db ' (1.00 to 20.00)'
db 0Dh,0Ah,'$'
ZcoefMsg db 0Dh,0Ah
db 'Enter the z-coefficient of the plane equation'
db ' (1.00 to 20.00)'
db 0Dh,0Ah,'$'
ConstMsg db 0Dh,0Ah
db 'Enter the constant of the plane equation'
db ' (-20.00 to -5.01)'
db 0Dh,0Ah,'$'
RedMsg db 0Dh,0Ah
db 'Enter the amount of red'
db ' (0 to 255)'
db 0Dh,0Ah,'$'
BlueMsg db 0Dh,0Ah
db 'Enter the amount of blue'
db ' (0 to 255)'
db 0Dh,0Ah,'$'
GreenMsg db 0Dh,0Ah
db 'Enter the amount of green'
db ' (0 to 255)'
db 0Dh,0Ah,'$'
KdMsg db 0Dh,0Ah
db 'Enter the coefficient of diffusivity'
db ' (0.00 to 1.00)'
db 0Dh,0Ah,'$'
KsMsg db 0Dh,0Ah
db 'Enter the coefficient of specularity'
db ' (0.00 to 1.00)'
db 0Dh,0Ah,'$'
AlphaMsg db 0Dh,0Ah
db 'Enter the alpha value'
db ' (0.00 to 99.99)'
db 0Dh,0Ah,'$'
CylHeightMsg db 0Dh,0Ah
db 'Enter the height of the cylinder'
db ' (0.00 to 10.00)'
db 0Dh,0Ah,'$'
XlMsg db 0Dh,0Ah
db 'Enter the x-coordinate of the light source'
db ' (-99.99 to 99.99)'
db 0Dh,0Ah,'$'
YlMsg db 0Dh,0Ah
db 'Enter the y-coordinate of the light source'
db ' (-99.99 to 99.99)'
db 0Dh,0Ah,'$'
ZlMsg db 0Dh,0Ah
db 'Enter the z-coordinate of the light source'
db ' (-99.99 to 99.99)'
db 0Dh,0Ah,'$'
CreditsMsg db 0Dh, 0Ah
db 'RAYTRACER'
db 0Dh, 0Ah
db 'Nikhil Tilwalli - Raytracing algorithms, Primitive Sorting, BMP files'
db 0Dh, 0Ah
db 'Shelly Henry - Raytracing algorithms, Primitive Sorting, BMP files'
db 0Dh, 0Ah
db 'Peter Arialis - Protected Mode, Graphics, Input'
db 0Dh, 0Ah
db 'Shyam Kurup - Protected Mode, Graphics, Input'
db 0Dh, 0Ah, '$'
FileNameMsg db 0Dh, 0Ah
db 'Please Enter Pathname of .bmp file to use'
db 0Dh, 0Ah, '(Must be already created file)'
db 0Dh, 0Ah, '$'
NumOfSpheres db 0
NumOfCylinders db 0
NumOfPlanes db 0
HeaderArray db 60 dup (0)
errormsg db 'Error: file not opened'
db 0Dh,0Ah,'$'
goodmsg db 'File was opened successfully'
db 0Dh,0Ah,'$'
goodclose db 'File closed'
db 0Dh,0Ah,'$'
filenotclosed db 'No file close'
db 0Dh,0Ah,'$'
didnotread db 'No read'
db 0Dh,0Ah,'$'
didnotwrite db 'No write'
db 0Dh,0Ah,'$'
didread db 'Read done'
db 0Dh,0Ah,'$'
didwrite db 'Write done'
db 0Dh,0Ah,'$'
message db 'a'
db 0Dh,0Ah,'$'
writetest db 30 dup (0)
HANDLE dw 0
FileOpenVar db 0
ReadErr db 0
WriteErr db 0
MaxFileSize dd 921600
MaxBufferSize dw 49152
FileByteCtr dd 0
RedColor dw 150
GreenColor dw 150
BlueColor dw 150
BufferByteCtr dw 49152
A Real4 1.0
B Real4 ?
Cr Real4 ?
Discr Real4 ?
Comp dw ?
ScDist Real4 ?
BallshiftXc Real4 ?
BallshiftYc Real4 ?
BallshiftZc Real4 ?
Ymin dw ?
Ymax dw ?
Ycheck dw ?
RodshiftXc Real4 ?
RodshiftYc Real4 ?
RodshiftZc Real4 ?
Numerator Real4 ?
Denominator Real4 ?
RaysaveXc Real4 ?
RaysaveYc Real4 ?
RaysaveZc Real4 ?
shadowfl db 0
RayshiftX Real4 ?
RayshiftY Real4 ?
RayshiftZ Real4 ?
Ltux Real4 0.0
Ltuy Real4 0.0
Ltuz Real4 0.0
Opux Real4 0.0
Opuy Real4 0.0
Opuz Real4 0.0
Snux Real4 0.0
Snuy Real4 0.0
Snuz Real4 0.0
Rux Real4 0.0
Ruy Real4 0.0
Ruz Real4 0.0
bxc Real4 0.0
byc Real4 0.0
bz Real4 0.0
bn Real4 0.0
bxu Real4 0.0
byu Real4 0.0
bzu Real4 0.0
lx Real4 0.0
ly Real4 0.0
lz Real4 0.0
ln Real4 0.0
lxu Real4 0.0
lyu Real4 0.0
lzu Real4 0.0
IntensityInt dw 0
Xcoord Real4 -3.21
Ycoord Real4 2.41
checkw Real4 0.0
Hundredth Real4 0.01
ThreePt2 Real4 3.20
NegTwoPt4 Real4 -2.40
NegThreePt21 Real4 -3.21 ; ystart coord
TwoPt41 Real4 2.41 ;xstart coord
two Real4 2.0
four Real4 4.0
hundred Real4 100.0
Thousand Real4 1000.0
TenThousand Real4 10000.0
point5 Real4 0.75
TwoFiftyFive Real4 255.0
Zero Real4 0.0
Three Real4 3.0
Twenty Real4 20.0
HundredThousand Real4 100000.0
IntFlag db 0
T Real4 ?
PixelIntensity Real4 0.0
check dw ?
check2 Real4 ?
flag db 'Intensity starts after here'
ShadowFlag db 1
SourceX Real4 0.0
SourceY Real4 0.0
SourceZ Real4 0.0
SphereActive0 dw 0
SphereXc0 Real4 -2.1
SphereYc0 Real4 1.0
SphereZc0 Real4 -5.5
SphereRad0 Real4 0.5
SphereDk0 Real4 1.0
SphereSk0 Real4 0.5
SphereAlp0 Real4 10.0
SphereRColor0 dw 255
SphereGColor0 dw 255
SphereBColor0 dw 0
SphereActive1 dw 0
SphereXc1 Real4 -1.7
SphereYc1 Real4 1.0
SphereZc1 Real4 -9.0
SphereRad1 Real4 0.5
SphereDk1 Real4 1.0
SphereSk1 Real4 0.5
SphereAlp1 Real4 10.0
SphereRColor1 dw 0
SphereGColor1 dw 0
SphereBColor1 dw 255
SphereActive2 dw 0
SphereXc2 Real4 -1.3
SphereYc2 Real4 1.0
SphereZc2 Real4 -12.5
SphereRad2 Real4 0.5
SphereDk2 Real4 1.0
SphereSk2 Real4 0.5
SphereAlp2 Real4 10.0
SphereRColor2 dw 255
SphereGColor2 dw 0
SphereBColor2 dw 255
SphereActive3 dw 0
SphereXc3 Real4 -0.9
SphereYc3 Real4 1.0
SphereZc3 Real4 -16.0
SphereRad3 Real4 0.5
SphereDk3 Real4 1.0
SphereSk3 Real4 0.5
SphereAlp3 Real4 10.0
SphereRColor3 dw 0
SphereGColor3 dw 200
SphereBColor3 dw 50
SphereActive4 dw 0
SphereXc4 Real4 -0.5
SphereYc4 Real4 1.0
SphereZc4 Real4 -19.5
SphereRad4 Real4 0.5
SphereDk4 Real4 1.0
SphereSk4 Real4 0.5
SphereAlp4 Real4 10.0
SphereRColor4 dw 0
SphereGColor4 dw 255
SphereBColor4 dw 255
RodActive0 dw 0
RodXc0 Real4 2.1
RodYc0 Real4 0.0
RodZc0 Real4 -5.5
RodHeight0 Real4 3.5
RodRad0 Real4 0.5
RodDk0 Real4 1.0
RodSk0 Real4 0.6
RodAlp0 Real4 10.0
RodRColor0 dw 255
RodGColor0 dw 0
RodBColor0 dw 255
RodActive1 dw 0
RodXc1 Real4 1.7
RodYc1 Real4 0.0
RodZc1 Real4 -9.0
RodHeight1 Real4 3.0
RodRad1 Real4 0.5
RodDk1 Real4 1.0
RodSk1 Real4 1.0
RodAlp1 Real4 20.0
RodRColor1 dw 0
RodGColor1 dw 200
RodBColor1 dw 0
RodActive2 dw 0
RodXc2 Real4 1.3
RodYc2 Real4 0.0
RodZc2 Real4 -12.5
RodHeight2 Real4 3.0
RodRad2 Real4 0.5
RodDk2 Real4 1.0
RodSk2 Real4 1.0
RodAlp2 Real4 20.0
RodRColor2 dw 255
RodGColor2 dw 30
RodBColor2 dw 255
RodActive3 dw 0
RodXc3 Real4 0.9
RodYc3 Real4 0.0
RodZc3 Real4 -16.0
RodHeight3 Real4 3.0
RodRad3 Real4 0.5
RodDk3 Real4 1.0
RodSk3 Real4 1.0
RodAlp3 Real4 20.0
RodRColor3 dw 30
RodGColor3 dw 255
RodBColor3 dw 180
RodActive4 dw 0
RodXc4 Real4 0.5
RodYc4 Real4 0.0
RodZc4 Real4 -19.5
RodHeight4 Real4 3.0
RodRad4 Real4 0.5
RodDk4 Real4 1.0
RodSk4 Real4 0.3
RodAlp4 Real4 20.0
RodRColor4 dw 124
RodGColor4 dw 233
RodBColor4 dw 189
FlatsActive0 dw 0
Xeff0 Real4 1.0
Yeff0 Real4 0.0
Zeff0 Real4 1.0
FlatsConst0 Real4 -30.0
FlatsDk0 Real4 1.0
FlatsSk0 Real4 0.5
FlatsAlp0 Real4 10.0
FlatsRColor0 dw 0
FlatsGColor0 dw 0
FlatsBColor0 dw 150
FlatsActive1 dw 0
Xeff1 Real4 -1.0
Yeff1 Real4 0.0
Zeff1 Real4 1.0
FlatsConst1 Real4 -30.0
FlatsDk1 Real4 1.0
FlatsSk1 Real4 0.5
FlatsAlp1 Real4 10.0
FlatsRColor1 dw 0
FlatsGColor1 dw 0
FlatsBColor1 dw 150
FlatsActive2 dw 0
Xeff2 Real4 0.0
Yeff2 Real4 -1.0
Zeff2 Real4 1.0
FlatsConst2 Real4 -25.0
FlatsDk2 Real4 1.0
FlatsSk2 Real4 0.5
FlatsAlp2 Real4 10.0
FlatsRColor2 dw 0
FlatsGColor2 dw 0
FlatsBColor2 dw 150
FlatsActive3 dw 0
Xeff3 Real4 0.0
Yeff3 Real4 1.0
Zeff3 Real4 1.0
FlatsConst3 Real4 -25.0
FlatsDk3 Real4 1.0
FlatsSk3 Real4 0.7
FlatsAlp3 Real4 30.0
FlatsRColor3 dw 0
FlatsGColor3 dw 0
FlatsBColor3 dw 150
FlatsActive4 dw 0
Xeff4 Real4 0.0
Yeff4 Real4 0.0
Zeff4 Real4 1.0
FlatsConst4 Real4 -20.0
FlatsDk4 Real4 1.0
FlatsSk4 Real4 0.5
FlatsAlp4 Real4 10.0
FlatsRColor4 dw 0
FlatsGColor4 dw 0
FlatsBColor4 dw 150
Specularity Real4 0.0
OrigCWord dw ?
RoundCWord dw ?
TwoToInt dw 0
IntPart dw ?
Base Real4 0.1
AlphaT Real4 6.2
LogB2X Real4 ?
check4 Real4 ?
One Real4 1.0
ZeroNum Real4 0.0
Tint Real4 ?
TSaveInt Real4 ?
TSave Real4 ?
XSave Real4 ?
YSave Real4 ?
ZSave Real4 ?
SecInt db ?
DotProd Real4 ?
SpecDot Real4 ?
SpecColor Real4 ?
SpecCheck dw ?
ObjRedColor dw ?
ObjGreenColor dw ?
ObjBlueColor dw ?
ObjDk Real4 ?
ObjSk Real4 ?
Ball_0 Sphere < >
BallScrew0 Sphere < >
Ball_1 Sphere < >
BallScrew1 Sphere < >
Ball_2 Sphere < >
BallScrew2 Sphere < >
Ball_3 Sphere < >
BallScrew3 Sphere < >
Ball_4 Sphere < >
BallScrew4 Sphere < >
Rod_0 Cylinder < >
RodScrew0 Cylinder < >
Rod_1 Cylinder < >
RodScrew1 Cylinder < >
Rod_2 Cylinder < >
RodScrew2 Cylinder < >
Rod_3 Cylinder < >
RodScrew3 Cylinder < >
Rod_4 Cylinder < >
RodScrew4 Cylinder < >
IntersectRod Cylinder < >
IntersectFlats Plane < >
IntersectBall Sphere < >
ShortBall Sphere < >
ShortRod Cylinder < >
ShortFlats Plane < >
CurrentIndex dw ?
ShortIndex dw ?
Flats_0 Plane < >
Flats_1 Plane < >
Flats_2 Plane < >
Flats_3 Plane < >
Flats_4 Plane < >
Tshort Real4 9999.9
Tcurrent Real4 ?
XintCurr Real4 ?
YintCurr Real4 ?
ZintCurr Real4 ?
Xint Real4 ?
Yint Real4 ?
Zint Real4 ?
CurrentDistInt dd ?
ShortDistInt dd 9999999
Ray PixelRay < >
;Ball Sphere < >
Rod Cylinder < >
Flats Plane < >
Origin0 Origin < >
Bulb LSource < >
CylNorm Vector < >
SphereNorm Vector < >
LightRay Vector < >
ReflectRay Vector < >
|