SlideShare a Scribd company logo
Middle East Technical University                   Department of Computer Engineering



                                    CENG 477
                     Introduction to Computer Graphics
                                        Fall ’2011-2012
                            Assignment 1 - Ray Tracer

                          Due date: 13 November 2011, Friday, 23:55


1     Objective
You will implement a ray tracer. In this homework, you will dig into the details of ray tracing.
When you see the light at the end of the tunnel, we promise you’ll be very satisfied with the
result!


2     Specifications
    • You will read a scene file, for example ”scene.txt”. This file includes all the basic
      information you need when rendering a scene. Details of this file is included in the next
      chapter. The scene file will have the extension ”.txt”.

    • The scene file will exist in the workspace, and we will provide its name as the only
      command line argument to your program.

    • You will render the given scene using perspective projection.

    • The time limit is 15 minutes on ineks. If you exceed this time, your program will be
      terminated.

    • All coordinates provided in the scene file are world coordinates. Which means, they are
      only relative to the origin, not to each other.

    • All of the lights provided in the scene file are point light sources, equally shining in all
      directions.
      NOTE: Intensity values of the light need not be between 0-255. They simply define a
      light source’s power, or the amount of light it delivers. When calculating the final color
      of a pixel, you need to map values higher than 255 to maximum pixel intensity 255, for
      each band.

    • Your ray tracing algorithm will implement ambient shading, diffuse shading, specular
      shading, shadows and object reflectance properties.

    • You will save the rendered image to ”$SCENE FILE NAME$.ppm” in the workspace.
      For example, if you are asked to render ”scene.txt”, the output image should be ”scene.ppm”.
      ”.ppm” file format is very easy to write. You may use the sample code we provide for
      writing to a ”.ppm” file. You may find detailed information about the format here.
3     Scene File
The scene file includes every detail you will use when drawing a scene. The scene file format
is given as follows:

    ImageWidth ImageHeight

    Tmin

    Ray Reflect Count

    #Camera
    posx posy posz gazex gazey gazez uprx upy upz left right bottom top distance

    #Material MaterialIndex
    ambr ambg ambb difr difg difb sper speg speb specExpP refr refg refb

    #Triangle
    pos1x pos1y pos1z pos2x pos2y pos2z pos3x pos3y pos3z MaterialIndex

    #Sphere
    posx posy posz Radius MaterialIndex

    #Light
    posx posy posz Ir Ig Ib

    #Ambient
    Ir Ig Ib

    #Background
    Ir Ig Ib



3.1    Explanation of Scene File
The first three lines of a scene file are fixed. The rest may be of any order. There will be only
one camera entry and one ambient entry in the file.

    • ImageWidth ImageHeight

      // The width and height of the image to be rendered. Both Integer.


    • Tmin

      //   When sending a reflecting ray from an object, you should first normalize the ray.
      //   When checking for an intersection with other objects, you should take Tmin
      //   as minimum t parameter for the ray. Intersections with smaller t (such as the
      //   object itself) should not be taken into account.
      //   IMPORTANT: The frustum’s far edge is not defined. There is no limit on the
      //   maximum distance of intersection. You should check ray-object intersection with
      //   each object. If the ray does not intersect with any object in the frustum, then
      //   you assign the pixel background color.
• Ray Reflect Count

  // A ray can bounce off this many times. Integer.


• #Camera
  posx posy posz gazex gazey gazez uprx upy upz left right bottom top distance

  // You will send rays from the camera that is put into scene with the given parameters.
  // position parameters define the position of the camera. All Float.
  // gaze parameters define your viewing direction as a vector. All Float.
  // up parameters define the up vector. All Float.
  // left, right, bottom, up parameters together define the size of viewport. All Float.
  // distance is the distance of viewport from the camera. When sending the ray for
  // the first time, you should check if an intersecting object is on the other side of the
  // viewport, meaning that it is in the frustum. There are two ways for doing this. When
  // calculating the ray’s intersecting pixel’s position on the viewport, you create the ray’s
  // direction vector. If you don’t normalize this direction vector, pixel’s t parameter is
  // equal to 1. Therefore, an intersecting object’s t parameter should be larger than 1.
  // If you normalize the direction vector, then you should calculate t by taking magnitude
  // of it before normalization. Then, intersecting object’s t parameter should be larger
  // than that value. Float.


• #Material MaterialIndex
  ambr ambg ambb difr difg difb sper speg speb specExpP refr refg refb

  //   Objects in your scene will be defined with their material indexes. Materials define
  //   the physical properties of objects. As an example, the material of a table object
  //   can either be wood, or metal. However, we will only define materials with integer
  //   indices, therefore you can think of them as substance 1 and substance 2.
  //   ambient parameters define the percentage the object reflects each band of ambient
  //   light that is cast onto it. For example, if the ambient red property of a material is
  //   0.5, it will absorbe half of the red light it receives, and reflect the other half. Apply
  //   to three bands.
  //   diffuse parameters define the diffusal properties of the material.
  //   specular parameters define the specular properties of the material. Specular
  //   exponent specExpP should also be taken into account, when calculating an the
  //   amount of specular light an object reflects.
  //   reflective parameters are provided to be used with bouncing rays. The bouncing
  //   off ray will contribute to the color of the point it hits first. The reflective parameters
  //   are provided to calculate the amount of of added light (in terms of all three bands)
  //   to the point. If all reflective parameters are close to 1, this is a mirror-like material.
  //   All parameters except specExpP are Floats. specExpP is Integer.


• #Triangle
  pos1x pos1y pos1z pos2x pos2y pos2z pos3x pos3y pos3z MaterialIndex

  // A triangle is defined as three points in world coordinates. positions of three points
  //are given in an ordered manner. Normals should be calculated within this order.
  // MaterialIndex defines the material of the triangle. Use the indexed material for color
  // calculations. All parameters except MaterialIndex are floats. MaterialIndex is
// Integer.


    • #Sphere
      posx posy posz Radius MaterialIndex

      //   Position parameters of a sphere define its center’s position in world coordinates.
      //   Radius is the radius of the sphere.
      //   MaterialIndex defines the material of the sphere. Use the indexed material.
      //   All parameters except MaterialIndex are Floats. MaterialIndex is Integer.


    • #Light
      posx posy posz Ir Ig Ib

      // Position parameters of the light define the light’s position in world coordinates. All
      // Floats. Intensity parameters of the light define the light’s intensity values it delivers
      // in all directions. Intensity values could be higher than 255. Integers.


    • #Ambient
      Ir Ig Ib

      // Intensity parameters of the light define the ambient light’s intensity values in all three
      // bands. This is the amount of light each object’s each point receives even if it is under
      // shadow. Intensity values could be higher than 255. Integers.


    • #Background
      Ir Ig Ib

      // If a ray does not hit anything, the corresponding pixel will take this value. Just as
      // simple as that.


4     Hints & Tips
    • You will implement the ray tracer in C++.

    • You are highly advised to follow a object-oriented approach. The basic classes you may
      need to create are Vector3, Camera, Ray, Shape, Triangle, Sphere, Scene classes. Writing
      a ray tracer is a tedious work, and writing a code neatly by using classes properly will
      save you a huge amount of time, especially when debugging.

    • You are encouraged to use the Vector3 class you implemented in the warm-up.

    • We will test your codes on departmental machines using “g++”. Please make sure to
      run tests on ineks.

    • You may compile your code with -O2 for optimization.

    • In triangle calculations, if the values of beta, gamma and t are not in the expected
      interval, you may choose not to calculate the others. This will provide a certain speed-
      up.
• Normal vectors of triangles are needed for each ray. Pre-computation of normal vectors
      before casting rays will greatly speed-up the process.

    • For a triangle<a,b,c>, you may pre-compute the b-a and c-a vectors and access them
      when casting rays.


5     Submission
Submission will be done via COW. You should upload a single zipped file called “hw1.zip”. In
addition to your code, provide a makefile. Your executable should have the name ”raytracer”.
We will test your code as:

$./raytracer "$SCENE FILE NAME$.txt"

Follow the newsgroup for details.

Late submissions are allowed for this homework, regarding to the policy on the
course’s web site.


6     Grading
Grading will be made using the scala on the course’s website.


7     Cheating Policy
We have zero tolerance policy for cheating. People involved in cheating will be punished
according to the university regulations. See the course website for more information.

More Related Content

PDF
Department of Avionics Engineering The Superior University, Lahore Lab Manual...
PPT
Single Electron Spin Detection Slides For Uno Interview
PDF
Masters' Thesis Defense Slides
PPTX
FME Store
PPTX
Quick Look At Clustering
PPTX
GPU-based Accelerated Spectral Caustic Rendering of Homogeneous Caustic Objects
PPT
Kampanje på Facebook
PPTX
Empathy map hmwk
Department of Avionics Engineering The Superior University, Lahore Lab Manual...
Single Electron Spin Detection Slides For Uno Interview
Masters' Thesis Defense Slides
FME Store
Quick Look At Clustering
GPU-based Accelerated Spectral Caustic Rendering of Homogeneous Caustic Objects
Kampanje på Facebook
Empathy map hmwk

Viewers also liked (13)

PDF
Nal
PDF
PPT
Kampanje
PDF
CV-Farhan Mushtaq
PPT
Sante barley
PPTX
Spreekbeurt St. Dierenlot oktober 2012
PPTX
Spreekbeurt grasparkieten
PPTX
Model-Based Testing: Theory and Practice. Keynote @ MoTiP (ISSRE) 2012.
DOCX
ELABORACION DE NECTAR
DOCX
Case study on testing
PPTX
Boekbespreking inge
PDF
20372748 case-study-on-computer-networking-kotak-mahindra-bank
Nal
Kampanje
CV-Farhan Mushtaq
Sante barley
Spreekbeurt St. Dierenlot oktober 2012
Spreekbeurt grasparkieten
Model-Based Testing: Theory and Practice. Keynote @ MoTiP (ISSRE) 2012.
ELABORACION DE NECTAR
Case study on testing
Boekbespreking inge
20372748 case-study-on-computer-networking-kotak-mahindra-bank
Ad

Similar to Hw1 updated (20)

PDF
Volumetric Lighting for Many Lights in Lords of the Fallen
PPTX
Defect detection in circlips using image processing in ni lab view
PDF
PapersWeLove - Rendering Synthetic Objects Into Real Scenes - Paul Debevec.pdf
PPT
november6.ppt
PPTX
Compressed Sensing - Achuta Kadambi
PDF
Poster cs543
PPTX
Object detection at night
PDF
"Image Sensors for Vision: Foundations and Trends," a Presentation from ON Se...
PPTX
06 image features
PDF
5 ray casting computer graphics
PDF
PR-284: End-to-End Object Detection with Transformers(DETR)
PDF
Simulating X-ray Observations with yt
PPTX
data structures using C 2 sem BCA univeristy of mysore
PDF
Deferred shading
PDF
Lecture1
PDF
super-cheatsheet-deep-learning.pdf
PDF
_AI_Stanford_Super_#DeepLearning_Cheat_Sheet!_😊🙃😀🙃😊.pdf
PPTX
UNIT-4.pptx
PDF
A computer vision approach to speech enhancement
PPTX
Wits presentation 6_28072015
Volumetric Lighting for Many Lights in Lords of the Fallen
Defect detection in circlips using image processing in ni lab view
PapersWeLove - Rendering Synthetic Objects Into Real Scenes - Paul Debevec.pdf
november6.ppt
Compressed Sensing - Achuta Kadambi
Poster cs543
Object detection at night
"Image Sensors for Vision: Foundations and Trends," a Presentation from ON Se...
06 image features
5 ray casting computer graphics
PR-284: End-to-End Object Detection with Transformers(DETR)
Simulating X-ray Observations with yt
data structures using C 2 sem BCA univeristy of mysore
Deferred shading
Lecture1
super-cheatsheet-deep-learning.pdf
_AI_Stanford_Super_#DeepLearning_Cheat_Sheet!_😊🙃😀🙃😊.pdf
UNIT-4.pptx
A computer vision approach to speech enhancement
Wits presentation 6_28072015
Ad

Recently uploaded (20)

PPTX
History, Philosophy and sociology of education (1).pptx
PDF
Yogi Goddess Pres Conference Studio Updates
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
LDMMIA Reiki Yoga Finals Review Spring Summer
PDF
Weekly quiz Compilation Jan -July 25.pdf
PDF
Computing-Curriculum for Schools in Ghana
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PPTX
UV-Visible spectroscopy..pptx UV-Visible Spectroscopy – Electronic Transition...
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
Lesson notes of climatology university.
PPTX
Cell Types and Its function , kingdom of life
PPTX
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Complications of Minimal Access Surgery at WLH
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PPTX
Cell Structure & Organelles in detailed.
PDF
Anesthesia in Laparoscopic Surgery in India
History, Philosophy and sociology of education (1).pptx
Yogi Goddess Pres Conference Studio Updates
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
2.FourierTransform-ShortQuestionswithAnswers.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
LDMMIA Reiki Yoga Finals Review Spring Summer
Weekly quiz Compilation Jan -July 25.pdf
Computing-Curriculum for Schools in Ghana
Paper A Mock Exam 9_ Attempt review.pdf.
UV-Visible spectroscopy..pptx UV-Visible Spectroscopy – Electronic Transition...
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Lesson notes of climatology university.
Cell Types and Its function , kingdom of life
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
Final Presentation General Medicine 03-08-2024.pptx
Complications of Minimal Access Surgery at WLH
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
Cell Structure & Organelles in detailed.
Anesthesia in Laparoscopic Surgery in India

Hw1 updated

  • 1. Middle East Technical University Department of Computer Engineering CENG 477 Introduction to Computer Graphics Fall ’2011-2012 Assignment 1 - Ray Tracer Due date: 13 November 2011, Friday, 23:55 1 Objective You will implement a ray tracer. In this homework, you will dig into the details of ray tracing. When you see the light at the end of the tunnel, we promise you’ll be very satisfied with the result! 2 Specifications • You will read a scene file, for example ”scene.txt”. This file includes all the basic information you need when rendering a scene. Details of this file is included in the next chapter. The scene file will have the extension ”.txt”. • The scene file will exist in the workspace, and we will provide its name as the only command line argument to your program. • You will render the given scene using perspective projection. • The time limit is 15 minutes on ineks. If you exceed this time, your program will be terminated. • All coordinates provided in the scene file are world coordinates. Which means, they are only relative to the origin, not to each other. • All of the lights provided in the scene file are point light sources, equally shining in all directions. NOTE: Intensity values of the light need not be between 0-255. They simply define a light source’s power, or the amount of light it delivers. When calculating the final color of a pixel, you need to map values higher than 255 to maximum pixel intensity 255, for each band. • Your ray tracing algorithm will implement ambient shading, diffuse shading, specular shading, shadows and object reflectance properties. • You will save the rendered image to ”$SCENE FILE NAME$.ppm” in the workspace. For example, if you are asked to render ”scene.txt”, the output image should be ”scene.ppm”. ”.ppm” file format is very easy to write. You may use the sample code we provide for writing to a ”.ppm” file. You may find detailed information about the format here.
  • 2. 3 Scene File The scene file includes every detail you will use when drawing a scene. The scene file format is given as follows: ImageWidth ImageHeight Tmin Ray Reflect Count #Camera posx posy posz gazex gazey gazez uprx upy upz left right bottom top distance #Material MaterialIndex ambr ambg ambb difr difg difb sper speg speb specExpP refr refg refb #Triangle pos1x pos1y pos1z pos2x pos2y pos2z pos3x pos3y pos3z MaterialIndex #Sphere posx posy posz Radius MaterialIndex #Light posx posy posz Ir Ig Ib #Ambient Ir Ig Ib #Background Ir Ig Ib 3.1 Explanation of Scene File The first three lines of a scene file are fixed. The rest may be of any order. There will be only one camera entry and one ambient entry in the file. • ImageWidth ImageHeight // The width and height of the image to be rendered. Both Integer. • Tmin // When sending a reflecting ray from an object, you should first normalize the ray. // When checking for an intersection with other objects, you should take Tmin // as minimum t parameter for the ray. Intersections with smaller t (such as the // object itself) should not be taken into account. // IMPORTANT: The frustum’s far edge is not defined. There is no limit on the // maximum distance of intersection. You should check ray-object intersection with // each object. If the ray does not intersect with any object in the frustum, then // you assign the pixel background color.
  • 3. • Ray Reflect Count // A ray can bounce off this many times. Integer. • #Camera posx posy posz gazex gazey gazez uprx upy upz left right bottom top distance // You will send rays from the camera that is put into scene with the given parameters. // position parameters define the position of the camera. All Float. // gaze parameters define your viewing direction as a vector. All Float. // up parameters define the up vector. All Float. // left, right, bottom, up parameters together define the size of viewport. All Float. // distance is the distance of viewport from the camera. When sending the ray for // the first time, you should check if an intersecting object is on the other side of the // viewport, meaning that it is in the frustum. There are two ways for doing this. When // calculating the ray’s intersecting pixel’s position on the viewport, you create the ray’s // direction vector. If you don’t normalize this direction vector, pixel’s t parameter is // equal to 1. Therefore, an intersecting object’s t parameter should be larger than 1. // If you normalize the direction vector, then you should calculate t by taking magnitude // of it before normalization. Then, intersecting object’s t parameter should be larger // than that value. Float. • #Material MaterialIndex ambr ambg ambb difr difg difb sper speg speb specExpP refr refg refb // Objects in your scene will be defined with their material indexes. Materials define // the physical properties of objects. As an example, the material of a table object // can either be wood, or metal. However, we will only define materials with integer // indices, therefore you can think of them as substance 1 and substance 2. // ambient parameters define the percentage the object reflects each band of ambient // light that is cast onto it. For example, if the ambient red property of a material is // 0.5, it will absorbe half of the red light it receives, and reflect the other half. Apply // to three bands. // diffuse parameters define the diffusal properties of the material. // specular parameters define the specular properties of the material. Specular // exponent specExpP should also be taken into account, when calculating an the // amount of specular light an object reflects. // reflective parameters are provided to be used with bouncing rays. The bouncing // off ray will contribute to the color of the point it hits first. The reflective parameters // are provided to calculate the amount of of added light (in terms of all three bands) // to the point. If all reflective parameters are close to 1, this is a mirror-like material. // All parameters except specExpP are Floats. specExpP is Integer. • #Triangle pos1x pos1y pos1z pos2x pos2y pos2z pos3x pos3y pos3z MaterialIndex // A triangle is defined as three points in world coordinates. positions of three points //are given in an ordered manner. Normals should be calculated within this order. // MaterialIndex defines the material of the triangle. Use the indexed material for color // calculations. All parameters except MaterialIndex are floats. MaterialIndex is
  • 4. // Integer. • #Sphere posx posy posz Radius MaterialIndex // Position parameters of a sphere define its center’s position in world coordinates. // Radius is the radius of the sphere. // MaterialIndex defines the material of the sphere. Use the indexed material. // All parameters except MaterialIndex are Floats. MaterialIndex is Integer. • #Light posx posy posz Ir Ig Ib // Position parameters of the light define the light’s position in world coordinates. All // Floats. Intensity parameters of the light define the light’s intensity values it delivers // in all directions. Intensity values could be higher than 255. Integers. • #Ambient Ir Ig Ib // Intensity parameters of the light define the ambient light’s intensity values in all three // bands. This is the amount of light each object’s each point receives even if it is under // shadow. Intensity values could be higher than 255. Integers. • #Background Ir Ig Ib // If a ray does not hit anything, the corresponding pixel will take this value. Just as // simple as that. 4 Hints & Tips • You will implement the ray tracer in C++. • You are highly advised to follow a object-oriented approach. The basic classes you may need to create are Vector3, Camera, Ray, Shape, Triangle, Sphere, Scene classes. Writing a ray tracer is a tedious work, and writing a code neatly by using classes properly will save you a huge amount of time, especially when debugging. • You are encouraged to use the Vector3 class you implemented in the warm-up. • We will test your codes on departmental machines using “g++”. Please make sure to run tests on ineks. • You may compile your code with -O2 for optimization. • In triangle calculations, if the values of beta, gamma and t are not in the expected interval, you may choose not to calculate the others. This will provide a certain speed- up.
  • 5. • Normal vectors of triangles are needed for each ray. Pre-computation of normal vectors before casting rays will greatly speed-up the process. • For a triangle<a,b,c>, you may pre-compute the b-a and c-a vectors and access them when casting rays. 5 Submission Submission will be done via COW. You should upload a single zipped file called “hw1.zip”. In addition to your code, provide a makefile. Your executable should have the name ”raytracer”. We will test your code as: $./raytracer "$SCENE FILE NAME$.txt" Follow the newsgroup for details. Late submissions are allowed for this homework, regarding to the policy on the course’s web site. 6 Grading Grading will be made using the scala on the course’s website. 7 Cheating Policy We have zero tolerance policy for cheating. People involved in cheating will be punished according to the university regulations. See the course website for more information.