Sunday, 10 March 2013

Environment map and render target as texture

This week assignment was really about graphics! There were almost no data processing required. The only new data needed to be added is the environment map. However, since I had a nice system which make it easy to add or subtract one data, it was not a big deal at all. Again, this proved my half-XML parser is a nice system. ^__^

The first part of the assignment, environment map, was not a big challenge. All I need to do was added new environment texture into my scene then use this texture to change the reflected light.

I downloaded my environment map from internet and changed it into dds format with DirectX Texture tool. This is my original environment map.


My original environment map


On creating my environment map, I learnt that the orientation of the environment map was important. At first I just cut and crop the environment map to get the +/-X, +/-Y, and +/-Z map for the cube map. The result was of course incorrect. I could still see the border line between the face of the cube map. Then Derek, when he saw my new scene, pointed out that I should rotate my environment map. The final result is...


My sphere with galaxy environment map

This is exactly what it should look like!! My ball looks so shiny in spite of the environment map was only 0.5 + 0.5 * fresnel modifier. The reason is my ball was textured with black majority texture! With this starry galaxy, my floor looks sparkling ^^


New scene

Oh, I changed the background colour into black since I don't like the darkness of the black background.

The second part of this assignment is using render target as texture. At the beginning I wanted to create magnifying effect however I couldn't find one. Btw,while searching for magnifying trick that I wanted in my render target effect, I found a good website about the graphics pipeline and the transformation matrix which was always stressed in class: http://www.directxtutorial.com/Lesson.aspx?lessonid=9-4-5. In the end I used Lissajous curve  with a = 1 and b = 2.


A screenshot of Lissajous effect render target
 





This is the texture it used from Pix
 
As usual, this is my note from class:
  • View dependent: different angle, different RGB value
  • View independent: different angle, same RGB value
  • In game the specular effect of light is not really representing the specular light in real world. We hack the calculation because it's expensive. Unfortunately, with this hack, there is one thing that we couldn't do - the differences between real world and game, i.e. we can't make our specular spot view dependent!
  • In the real world all kind of surfaces behave like mirror: what reflected will be sent back like mirror. The less light get reflected, the more we can see the object. The more light gets reflected (the higher the reflectivity), the more the object act like mirror. However, in specular highlight, the light is more feasible than the specular reflection because of the light brightness. For this reason we can hack how the specular light work in game. (By seeking out the light in the scene and ignoring anything else that get reflected, find the position of light and calculate how much that light get reflected.)
  • To get the reflection of the surrounding light, we need to seek out the reflection. Doing the real calculation in graphics is, again, expensive. We need to put camera on every surface that behave like a mirror. Therefore, the mirror reflection in game is also a hack. As long as we get the general idea, then it is good enough. If a clock face in game doesn't reflect the room it's located, no one care. That's why all the mirrors in game world always look dusty and cloudy. If the mirror looks shiny, it will be obvious that it was hacked (the character is not reflection in the mirror).
  • The diffuse light, however, in game graphics acts exactly like the real world.
  • The basic idea of hacking mirror reflection: create another map called environment map. When we wanted to see reflection, we can say do something with this map, that would be our environment. Instead of using how close the surface to light, we are going to use it as reflection. It's close enough that no one will notice. The best use of this in game if we want something looks like metal.
  • This environment map is also known as cube map. It has 6 sides of cube which gives 3 dimensional representation that we can use a vector to look up at any direction. Given three dimensional vector, the first thing we have to decide is what texture we are looking at and the next thing is to decide what 2 dimensional texture we are looking at in that texture.
 
Cube map orientation
  • If the result relies on different pixel, use render-target texture.
  • If the result relies on the previous pixel (same pixel of current pixel), use hardware transparency.

I found bug in my code:
- I updated my light position every entity. Actually I just need to update it every fragment.
- Did I ever mention that I fixed my bug with binary file reading last week so I can have sphere on my scene? Anyway, it is bug-free now.
Oh, after I submitted this assignment early this week, JP suggested me to do linear texture filtering to make my floor less pixely and this is the result:
New glossy and shiny floor

No comments:

Post a Comment