In assignment 3 we combined our GLSL and HLSL shaders into a single file but it wasn’t really platform independent, we used ugly preprocessor define blocks to separate the HLSL and GLSL parts of the code. In this assignment we fix that by using preprocessor directives to our advantage, creating a platform independent interface through which we access platform specific APIs and data types. I used the Shaders.inc file where Professor JP had already setup some code for platform independent data types and constant buffer declaration. Using these as a base I setup a common definition for the Texture and Sampler (which resolves to a dummy variable in OpenGL because it doesn’t use it) and a common definition for sampling the texture. With the new improvements, the new texture declaration looks like this.
The texture sampling interface looks like this.
GLSL does this thing where you don’t need to declare a variable to output the position from the vertex shader which conflicts with the way HLSL does it. GLSL uses a default variable called gl_Position, I used this as the name of the output variable in HLSL so that there is consistency in naming and I could keep the main function body platform independent.
And as proof that nothing has change in the program, here’s a gif of it running.