Friday, February 22, 2013

Graphics Assignment 6

This week's assignment was brutal. I'm glad that I finally got everything to work. The Maya Builder part was the easiest to do and the most rewarding, and I finished that part in a couple of hours. But the rest of the assignment was exhausting and took roughly 18 hrs to finish. I'm so exhausted I can barely type..

I had major problems with parsing Binary files ( I wasted a good 12 hrs on it), even though it is super easy and I got it to work with simple structs on a separate project. It was super annoying not being able to manually read the binary files. After some trial and error and tons of crazy errors I finally got it to work by reading each s_vertex individually, verifying it and then storing it in the vertex buffer.

Changes:
- Added the MayaExporter tool which exports my human-readable mesh format.
- MeshBuilder tool now reads the human-readable mesh file and outputs a binary file.
- Added binary file parsing to Mesh class. 
- Entities are now sorted based on effect and material.
- Vertex and Fragment shader are set only when effect changes.
- Texture and specular exponent are set only when the material changes.
- Added PIX events

Here's the assignment. Works in both Debug and Release mode.
Download Code

Oops, forgot to add a screenshot. Here it is..


Friday, February 15, 2013

Graphics Assignment 5

This assignment was really easy and I was able to whip it up in a couple of hours.


Changes:
- Changed the format of .scene file a little. You can now set the ambientLight of the scene and the attenuation factor of the point light.

- I calculate the newIntensity of light based on the attenuation factor like this:

float lightDistance = length( pointLight_position - i_position_world );
float newIntensity = saturate( pointLight_intensity - (lightDistance * attenuationFactor ) );

So the attenuation factor should be between 0 and 1. 0 being strongest and 1 being weakest i.e. no light.

- Created new fragment shader for specular lighting and made changes to the old one to add support for the attenuation factor, and created a corresponding effect file.

- Changed the format of .material file. You can now set the specularExponent of each material.

- Added a plane and some more cubes ( half of the cubes have only diffuse lighting and the rest have diffuse and specular lighting ).



Instructions:
- Move the light in the x and y plane using W,A,S,D
- Move the light forward and backward using R,F
- Move the camera using the arrow keys.


Notes:
I had no issues with this assignment but one, where the specular lighting was looking really bright and I realized that I forgot to multiply it by the light intensity.

Graphics Assignment 4


Woah, this assignment was colossal and took a lot of my time. I spent most of my time structuring my code and writing parsing code for the new file formats.


Changes:
- I have added a Scene class now, which contains the entities, light and camera. The Mesh class updates and draws itself. All the renderer does now is contain the scene and asks the scene to update and draw itself.
- I have added support for light color and intensity
- I have added 4 new file formats and this is how they look like:

Effect
technique name
{
               vs = filepath
               fs = filepath
               expectedTexture = type
}

Material
effect = filepath
texture = filepath

Entity

mesh = filepath
material = filepath

Scene
noOfEntities = n
Entities
{
               entity = filepath
               x =
               y =
               z =
               rotY =
}
{
               entity = filepath
               x =
               y =
               z =
               rotY =
}
{
               entity = filepath
               x =
               y =
               z =
               rotY =
}

Light
{
               x =
               y =
               z =
               r =
               g =
               b =
               intensity =
}
Camera
{
               x =
               y =
               z =
               rotY =
}


 Screenshots


PIX Screenshot

Instructions:
- Move the light in the x and y plane using W,A,S,D
- Move the light forward and backward using R,F
- Move the camera using the arrow keys.

Notes:
Hmm, problems I ran into..
- There was this issue when all my cubes were being drawn at the same position i.e. the position of the last updated cube. I fixed this later, I realized that I was overwriting the registers that the vertex shader uses to store its uniforms and made sure that I load the uniforms and then draw it immediately, and then load the next set of uniforms.

- I ran into this linker error on which I wasted a lot of my time. I always guard my headers but I was still getting the 'already defined' error. John helped me out with this later and it got fixed by making one of my variables extern and defining it in a seperate cpp file.


CryEngine


Friday, February 1, 2013

Graphics Assignment 3

Compared to last week, this week's assignment was really simple. It was mainly about adding textures and point lights to our project.

Here's my code
Download

Changes

- Changed the mesh file format to add support for uv coordinates and normals. Its new format is:

NoOfTriangles = n
NoOfVertices = n
NoOfIndices = n
Vertices
x , y , z  |   r , g , b, a   |  u , v  |  nX, nY, nZ
x , y , z  |   r , g , b, a   |  u , v  |  nX, nY, nZ
x , y , z  |   r , g , b, a   |  u , v  |  nX, nY, nZ
x , y , z  |   r , g , b, a   |  u , v  |  nX, nY, nZ
Indices
i1 , i2 , i3
i1 , i2 , i3

- Added a cPointLight class, which holds the point light's world position.

Instructions

- Move the light using W,A,S,D
- Move the camera using the arrow keys.

Check out my cool gameboy texture


PIX screenshot of texture


Notes
This week's assignment was simple because the concepts were really clear to me, I had dabbled with UVs and normals in an XNA project some months ago.
- The only confusing part was figuring out the right UVs for the vertices, since it's a 3D object.
- Apart from that everything went smoothly and the code runs perfectly in both Debug and Release mode. :D