Difference between revisions of "User:Akopytov"

From CDOT Wiki
Jump to: navigation, search
(Lighting Project)
 
(31 intermediate revisions by the same user not shown)
Line 2: Line 2:
 
Name: Andrei Kopytov
 
Name: Andrei Kopytov
  
Seneca e-mail address: [mailto:akopytov@learn.senecac.on.ca akopytov@learn.senecac.on.ca]
+
Seneca e-mail address: [mailto:akopytov@myseneca.ca akopytov@myseneca.ca]
  
/******************************************************************************
+
== Lighting Project==
  ************************ Lighting Documentation v1.00 ************************
+
<h3>NOTE: This project used the Winter 2011 version of the game framework, which has since been extensively modified. The majority of these instructions are outdated and invalid.</h3>
*
+
 
 +
Instructions to incorporate advanced lighting into your game:<br />
 +
 
 +
Download the full working solution here: [http://matrix.senecac.on.ca/~satijas/Lighting_-_Full_Solution.zip Download]<br />
 +
OR<br />
 +
Download just the files that have changes relevant to lighting here: [http://matrix.senecac.on.ca/~satijas/Lighting.zip Download]<br />
 +
 
 +
<h3>WARNING: This Feature has been implemented using solution 28. Modification and additional coding may be required to prior and later solutions.</h3>
 +
Copy from the files or manually code the following:<br />
 +
 
 +
<b>Configuration.h</b>
 +
*Increase the MAX_STR_ARRAYS macro by 1 (Line 46)
 +
*Add two more elements to the Integer enum: GF_NO_ALGS and GF_DF_ALGO (Line 88-89)
 +
*Add an element to the StrArray enum: GF_LITDESC (Line 127)
 +
*Create a macro called LIGHT_DESCRIPTIONS (Line 331)
 +
*Create an enum called LightAlgorithm (Line 389)
 +
 
 +
<b>Context.cpp</b>
 +
*Allocate memory for str array and set it to LIGHT_DESCRIPTIONS (Line 67-69)
 +
*Set the GF_NO_ALGS element to the number of algorithms (Line 70)
 +
 
 +
<b>iUserDialog.h</b>
 +
*Add virtual void populateLightingList(void*) = 0; to the interface (Line 29)
 +
 
 +
<b>UserDialog.h</b>
 +
*Add a wchar_t variable to store the lighting description (Line 34)
 +
*Add void populateLightingList(void*); to the header file (Line 54)
 +
 
 +
<b>UserDialog.cpp</b>
 +
*Set the previously created wchar_t variable to an empty string (Line 48)
 +
*Call the populateLightingList(hwnd) function in populateUserDialog (Line 88)
 +
*Create the void populateLightingList(void*) function (Line 150-161)
 +
*Retrieve the selected algorithm and set its index into GF_DF_ALGO (Line 581-585)
 +
*Store the lighting description inside of the wchar_t variable (Line 594)
 +
 
 +
<b>iObject.h</b>
 +
*Declare the LightAlgorithm enum (Line 26)
 +
*Declare the get and set functions for the input variables, remove the parameter from power() (Line 43-50)
 +
 
 +
<b>Object.h</b>
 +
*Change the shine variable from float* to float (Line 41)
 +
*Add a float variable for roughness (Line 42)
 +
*Add a float variable for index of refraction (Line 43)
 +
*Add a LightAlgorithm variable that will store the index of the algorithm to be used for the object (Line 45)
 +
*Add a static iContext* variable under the protected list of variables (Line 58)
 +
*Add the void hasContext(iContext* c) function to the Object class (Line 67)
 +
*Remove the static iContext* variables from the derived classes (Line 138, 174, 196, 214)
 +
*Define the get and set functions (Line 78-85)
 +
 
 +
<b>Object.cpp</b>
 +
*Set the iContext* variable to NULL (Line 37)
 +
*Remove the iContext* variables from the derived classes (Line 389, 475, 552, 572)
 +
*Set the default values for shine, roughness and index (Line 65-67)
 +
*Call the setAlgorithm function, passing in the value of GF_DF_ALGO (Line 69)
 +
*Remove the code that initializes the shine variable's subsets, as it is no longer an array (Line 72-75)
 +
*Set roughness and index variables to NULL (Line 113-114)
 +
*Remove the conditional statement that deletes a shine array (Line 134-137)
 +
*Set the input variables and algorithm to the values from the object being copied (Line 152-154, 156)
 +
*Remove the code that instantiates shine as a new array (Line 168-172)
 +
*Remove the code that destroys the shine array (Line 282-283)
 +
 
 +
<b>Scene.cpp</b>
 +
*Pass the context to the Object class, and remove the code that passes the context to derived classes (Line 47-50)
 +
 
 +
<b>Graphic.h</b>
 +
*Add the handles to the algorithm, roughness and refraction variables (Line 58-60, 131-133)
 +
*Change the power variable in SubdividedGraphic from a FLOAT* to a FLOAT
 +
 
 +
<b>Graphic.cpp</b>
 +
*Remove the parameter from the power() function (Line 112, 343)
 +
*Get the addresses to the shader variables for the new handles (Line 121-123, 353-355)
 +
*Set the values of the shader variables (Line 166-168, 398-400)
 +
*Remove the code that initializes the power variable to an array (Line 243)
 +
*Remove the code that deletes the power array (Line 295-296)
 +
*Set the power variable to the src object's power value (Line 300)
 +
*Remove the code that sets an array of powers (Line 305)
 +
*Remove the index from the power variable (Line 397)
 +
*Remove the code that deletes a power array (Line 448-449)
 +
 
 +
<b>Design.cpp</b>
 +
*Add the Lighting Documentation comments (Line 28-113)
 +
 
 +
<b>effects.fx</b>
 +
*Overwrite the effects.fx file (take care to note that the effects.fx file is written with Solution 28 in mind, it may need modification if your solution does not support texture stages)
 +
 
 +
<b>Dialog.rc</b>
 +
*Add a drop down list box with ID IDC_LIT
 +
 
 +
<b>WindowSettings.h</b>
 +
*Define a macro IDC_LIT with the next available ID number
 +
 
 +
  ************************ Lighting Documentation v1.02 ************************
 
  * Lighting with the programmable graphics pipeline currently requires the use of
 
  * Lighting with the programmable graphics pipeline currently requires the use of
 
  * the effects framework and works on the object level. This means the algorithm
 
  * the effects framework and works on the object level. This means the algorithm
Line 18: Line 109:
 
  * accept different ranges of values from each of the variables it does use. The
 
  * accept different ranges of values from each of the variables it does use. The
 
  * lighting algorithms available for use in the framework are described below:
 
  * lighting algorithms available for use in the framework are described below:
 +
*
 +
* Functions
 +
* ---------
 +
* power(), setPower(float)
 +
* getRoughness(), setRoughness(float)
 +
* getIndexOfRefraction, setIndexOfRefraction(float)
 +
* getAlgorithm(), setAlgorithm(LightAlgorithm)
 +
*
 +
* Inputs for setAlgorithm()
 +
* PHONG
 +
* BLINN_PHONG
 +
* COOK_TORRANCE
 +
* OREN_NAYAR
 +
* WARD_ANISO
 +
* ASH_SHIRLEY
 
  *
 
  *
 
  * == Phong ==
 
  * == Phong ==
Line 23: Line 129:
 
  *
 
  *
 
  * Input                Effective Range
 
  * Input                Effective Range
  * power                0.0 -
+
  * power                0.0 - 1000
 
  *
 
  *
 
  * Makes objects look plastic
 
  * Makes objects look plastic
Line 31: Line 137:
 
  *
 
  *
 
  * Input                Effective Range
 
  * Input                Effective Range
  * power                0.0 -
+
  * power                0.0 - 1000
 
  *
 
  *
 
  * Like Phong, but uses less instructions, also gives objects a plastic look
 
  * Like Phong, but uses less instructions, also gives objects a plastic look
Line 39: Line 145:
 
  *
 
  *
 
  * Input                Effective Range
 
  * Input                Effective Range
  * roughness            0.0 -
+
  * roughness            0.0 - 15.0
  * index of refraction  0.0 -
+
  * index of refraction  0.0 - 10.0
 
  *
 
  *
 
  * Gives objects a metallic look
 
  * Gives objects a metallic look
Line 48: Line 154:
 
  *
 
  *
 
  * Input                Effective Range
 
  * Input                Effective Range
  * roughness            0.0 -
+
  * roughness            0.0 - 2.0
 
  *
 
  *
 
  * Diffuse only model, good for making objects look rough
 
  * Diffuse only model, good for making objects look rough
Line 56: Line 162:
 
  *
 
  *
 
  * Input                Effective Range
 
  * Input                Effective Range
  * roughness            0.0 - 1.0
+
  * roughness            0.0 - 2.0
  * power                0.0 - 1.0
+
  * power                0.0 - 2.0
 
  *
 
  *
 
  * Allows the manipulation of specular lobe (change its shape)
 
  * Allows the manipulation of specular lobe (change its shape)
Line 67: Line 173:
 
  * roughness            0 - 10000
 
  * roughness            0 - 10000
 
  * power                0 - 10000
 
  * power                0 - 10000
  * index of refraction  0.0 -
+
  * index of refraction  0.0 - 10.0
 
  *
 
  *
 
  * Good for making objects look metal or plastic, and can manipulate specular lobe
 
  * Good for making objects look metal or plastic, and can manipulate specular lobe
 
  * ==========================================================================
 
  * ==========================================================================
 
  *
 
  *
  * For more information on lighting, check out: http://wiki.gamedev.net/index.php/D3DBook:Lighting
+
  * For more information on lighting, check out: http://content.gpwiki.org/index.php/D3DBook:Lighting (accessed May 13, 2013)
*
 
*/
 

Latest revision as of 17:13, 13 May 2013

Contact Information

Name: Andrei Kopytov

Seneca e-mail address: akopytov@myseneca.ca

Lighting Project

NOTE: This project used the Winter 2011 version of the game framework, which has since been extensively modified. The majority of these instructions are outdated and invalid.

Instructions to incorporate advanced lighting into your game:

Download the full working solution here: Download
OR
Download just the files that have changes relevant to lighting here: Download

WARNING: This Feature has been implemented using solution 28. Modification and additional coding may be required to prior and later solutions.

Copy from the files or manually code the following:

Configuration.h

  • Increase the MAX_STR_ARRAYS macro by 1 (Line 46)
  • Add two more elements to the Integer enum: GF_NO_ALGS and GF_DF_ALGO (Line 88-89)
  • Add an element to the StrArray enum: GF_LITDESC (Line 127)
  • Create a macro called LIGHT_DESCRIPTIONS (Line 331)
  • Create an enum called LightAlgorithm (Line 389)

Context.cpp

  • Allocate memory for str array and set it to LIGHT_DESCRIPTIONS (Line 67-69)
  • Set the GF_NO_ALGS element to the number of algorithms (Line 70)

iUserDialog.h

  • Add virtual void populateLightingList(void*) = 0; to the interface (Line 29)

UserDialog.h

  • Add a wchar_t variable to store the lighting description (Line 34)
  • Add void populateLightingList(void*); to the header file (Line 54)

UserDialog.cpp

  • Set the previously created wchar_t variable to an empty string (Line 48)
  • Call the populateLightingList(hwnd) function in populateUserDialog (Line 88)
  • Create the void populateLightingList(void*) function (Line 150-161)
  • Retrieve the selected algorithm and set its index into GF_DF_ALGO (Line 581-585)
  • Store the lighting description inside of the wchar_t variable (Line 594)

iObject.h

  • Declare the LightAlgorithm enum (Line 26)
  • Declare the get and set functions for the input variables, remove the parameter from power() (Line 43-50)

Object.h

  • Change the shine variable from float* to float (Line 41)
  • Add a float variable for roughness (Line 42)
  • Add a float variable for index of refraction (Line 43)
  • Add a LightAlgorithm variable that will store the index of the algorithm to be used for the object (Line 45)
  • Add a static iContext* variable under the protected list of variables (Line 58)
  • Add the void hasContext(iContext* c) function to the Object class (Line 67)
  • Remove the static iContext* variables from the derived classes (Line 138, 174, 196, 214)
  • Define the get and set functions (Line 78-85)

Object.cpp

  • Set the iContext* variable to NULL (Line 37)
  • Remove the iContext* variables from the derived classes (Line 389, 475, 552, 572)
  • Set the default values for shine, roughness and index (Line 65-67)
  • Call the setAlgorithm function, passing in the value of GF_DF_ALGO (Line 69)
  • Remove the code that initializes the shine variable's subsets, as it is no longer an array (Line 72-75)
  • Set roughness and index variables to NULL (Line 113-114)
  • Remove the conditional statement that deletes a shine array (Line 134-137)
  • Set the input variables and algorithm to the values from the object being copied (Line 152-154, 156)
  • Remove the code that instantiates shine as a new array (Line 168-172)
  • Remove the code that destroys the shine array (Line 282-283)

Scene.cpp

  • Pass the context to the Object class, and remove the code that passes the context to derived classes (Line 47-50)

Graphic.h

  • Add the handles to the algorithm, roughness and refraction variables (Line 58-60, 131-133)
  • Change the power variable in SubdividedGraphic from a FLOAT* to a FLOAT

Graphic.cpp

  • Remove the parameter from the power() function (Line 112, 343)
  • Get the addresses to the shader variables for the new handles (Line 121-123, 353-355)
  • Set the values of the shader variables (Line 166-168, 398-400)
  • Remove the code that initializes the power variable to an array (Line 243)
  • Remove the code that deletes the power array (Line 295-296)
  • Set the power variable to the src object's power value (Line 300)
  • Remove the code that sets an array of powers (Line 305)
  • Remove the index from the power variable (Line 397)
  • Remove the code that deletes a power array (Line 448-449)

Design.cpp

  • Add the Lighting Documentation comments (Line 28-113)

effects.fx

  • Overwrite the effects.fx file (take care to note that the effects.fx file is written with Solution 28 in mind, it may need modification if your solution does not support texture stages)

Dialog.rc

  • Add a drop down list box with ID IDC_LIT

WindowSettings.h

  • Define a macro IDC_LIT with the next available ID number
************************ Lighting Documentation v1.02 ************************
* Lighting with the programmable graphics pipeline currently requires the use of
* the effects framework and works on the object level. This means the algorithm
* with which you wish to illuminate your object will work on the entire object, not
* a subset of that object. The inputs for the algorithm also work on the object level,
* meaning all subsets will use the same values.
*
* To avoid bloating the object class, three variables will be used across the various
* algorithms in different ways. It is very important to note that an algorithm may not
* necessarily use all three variables in its calculations. Also, each algorithm may
* accept different ranges of values from each of the variables it does use. The
* lighting algorithms available for use in the framework are described below:
*
* Functions
* ---------
* power(), setPower(float)
* getRoughness(), setRoughness(float)
* getIndexOfRefraction, setIndexOfRefraction(float)
* getAlgorithm(), setAlgorithm(LightAlgorithm)
*
* Inputs for setAlgorithm()
* PHONG
* BLINN_PHONG
* COOK_TORRANCE
* OREN_NAYAR
* WARD_ANISO
* ASH_SHIRLEY
*
* == Phong ==
* Isotropic
*
* Input                 Effective Range
* power                 0.0 - 1000
*
* Makes objects look plastic
* ==========================================================================
* == Blinn-Phong ==
* Isotropic
*
* Input                 Effective Range
* power                 0.0 - 1000
*
* Like Phong, but uses less instructions, also gives objects a plastic look
* ==========================================================================
* == Cook-Torrance ==
* Isotropic
*
* Input                 Effective Range
* roughness             0.0 - 15.0
* index of refraction   0.0 - 10.0
*
* Gives objects a metallic look
* ==========================================================================
* == Oren-Nayar ==
* Isotropic
*
* Input                 Effective Range
* roughness             0.0 - 2.0
*
* Diffuse only model, good for making objects look rough
* ==========================================================================
* == Ward Anisotropic ==
* Anisotropic
*
* Input                 Effective Range
* roughness             0.0 - 2.0
* power                 0.0 - 2.0
*
* Allows the manipulation of specular lobe (change its shape)
* ==========================================================================
* == Ashikhmin-Shirley ==
* Anisotropic
*
* Input                 Effective Range
* roughness             0 - 10000
* power                 0 - 10000
* index of refraction   0.0 - 10.0
*
* Good for making objects look metal or plastic, and can manipulate specular lobe
* ==========================================================================
*
* For more information on lighting, check out: http://content.gpwiki.org/index.php/D3DBook:Lighting (accessed May 13, 2013)