Write Up 07


Press Escape to quit the application.


Press the right arrow key to switch the texture of the two largest sprites.


The main objective of Assignment07 was to make the shader files platform independent. To do this the shaders.inc file was included in the vertex and fragment shaders in order to define platform specific macros that alter the definitions of variables and functions for Direct3D and OpenGL. I started by using the DeclareConstantBuffer() macro to declare the constant buffers for each platform. This macro handles the differences between the definitions of the variable and register types.


I then proceeded to make the main functions of each shader platform independent by adding platform macros to the declaration of the main function. However, the definition of the main function is platform independent in each.

To make the texture of the shaders platform independent, I made a macro called DeclareColorTexture() which calls the texture creation function for the platform is it running on. The parameters it requires is the name of the texture variable and the register id number.




Direct3D requires a sampler state for which I created the macro DeclareSamplerState().The parameters it requires is the name of the samplerState variable and the register id number.



To make sampling color from a texture platform independent, I created the macro CalculateSampledColor()which calls the texture sampling function for the platform it is running on. The parameters it requires is the name of the texture variable, the name of the sampler state and the name of the uv.


CalculateSampledColor(g_color_texture,g_color_samplerState, i_uv );


To make the reserved gl_Position variable not require code duplication for OpenGL, I added a #define in shaders.inc to make the output position be defined as glPosition on OpenGL. I did not add any additional lines to the macros of Direct3D in this file because that platform does not use any reserved variables.


#define o_position gl_Position


The changes I made to the vertex shader were also made in the vertex input layout shader in order to make it more platform independent.


I also added a new texture that has alpha transparency as an optional challenge. The effect used for the sprite of this texture has eae6320::Graphics::RenderStates::AlphaTransparency as its render state value.

The time it took me to complete this assignment was 3 hours.