Textures

I'm required this semester to post a write-up for every assignment I complete in one of my engineering courses to a website... so here's one about Textures: how to store them, build them and use them in shaders.

Assignment 13: Texture Class & Data Files

Time Spent: 8 hrs
Git Tag: Assignment_13
Download Executable Archive here
Controls: 
Sphere Movement:
  • Up Arrow: Fwd
  • Down Arrow: Back
  • Left Arrow: Left
  • Right Arrow: Right
  • Shift: Down
  • Enter: Up
  • Space: FIRE!
Camera:
  • W: Fwd
  • A: Left
  • S: Back
  • D: Right
  • Q: Down
  • E: Up
Purpose of Assignment: 
This assignment is all about Textures! Textures of course being images which are sampled from in the fragment shader to determine the appropriate color of each pixel that is displayed. As you can see at right, games look considerably more interesting once you can texture the models within them. Textures give a sense of depth and detail not available without them. This assignment covered the addition of a few new projects to provide texture handling capabilities and the addition of texture specification in material files in the form of a string.


Readable!
So here it is, this is the human readable material file from last week, with one new element, the textureFilePath. This path points to the "authored" texture file that the user wishes to associate with the resulting material for application to in game meshes. If one were to add an additional texture for this material, they could simply give it a unique identifier:

textureFilePath2  = "Textures\\newTexture.jpg".



Less Readable!
And here again is the processed binary file for the same material as above. The top row of the file in a Hex editor shows the four floats for the color specification, in this case hex 1.0 across the board for a white, opaque object. Next comes a single byte integer that tells us the length of the upcoming effectPath string, then the path string, then a single byte integer length for the texturePath string, then the texturePath. The texture path length is not strictly necessary at the moment, but it will be necessary to have it if the user wants to add any additional paths after the texture path, just as it was necessary to add the effectPath string length to allow the addition of the texture path.


Run-Time!
And here's the code to break it back out at run-time. Two assignments back I showed a very similar bit of code for parsing out of a binary file, but instead of using char* 's I handed the pointer to a string. This causes an unnecessary copy operation which is eliminated here by simply setting a char* to point into the memory of the binary file and passing that on for parsing. Note that I determine where the effectFilePath ends by first extracting its length parameter, and that I do the same for the texture path although it is currently unused (but would be if any additional paths were added to the material file).


Game Progress
I'm going for an underwater environment to surround everything in my game, mostly just because it is visually interesting. The addition of new textures and a change to the clear color starts me moving that direction, but I would still like to add some additional details like swaying seaweed and possibly a moving refraction effect on the floor. Other than that I did some work to clean up my materials and effects, and that's about it for now.

No comments:

Post a Comment