GARIN R. K. RICHARDS
  • HOME
  • WORK
  • RESUME
  • ABOUT

DEV-LOG

Assignment 14 - Going Clearer

12/2/2017

0 Comments

 
Picture
Picture

Being Transparent!

Recall back to when we first implemented three dimensional graphics in our game engine in week 9's post. One of the challenges we hypothesized was that of depth. As in, who is in front of whom? Well, we're fortunate that for those opaque meshes, the GPU is in charge of who is in front of what based on their world position and just overwrites that pixel with the pixel that is in the front. But what about transparent objects? 

Because an object is transparent, we must know what is behind it. This order is very important, and we'll keep in mind the logic of drawing from front to back. Or perhaps more simply, we must first "draw" the pixels that are behind the transparent objects before we draw the transparent objects with their effect. This is crucial as the opaque object's must be on screen in order for the alpha blending to occur properly within the transparent meshes.

Previously in both our application and rendering threads, we had a vector that held the Meshes that would be rendered on screen. But how do we impose order within these structures? We'll have to sort them based on their Z position. We could have approached this by adding the transparent meshes to the same structures that held the rest of the meshes, but for simplicity, we'll just go ahead and make a separate structure that is sorted that only holds transparent meshes. We'll just make sure that these are sorted correctly based on their position's Z value, and that they are the ones drawn last.

Specifically, we do the following:
  • Calculate the Z position of the objects, in camera space
    • This is so we know where the objects are in relation to the camera to draw them in the appropriate order
  • Draw our opaque meshes first
    • The GPU will handle who goes in front of what then.
  • Sort our submitted transparent meshes based on their position in the world
  • Draw our transparent meshes in this sorted order.

In the screenshots above you can see two cube meshes that use our transparent fragment shader, placed in front of one another to be able to see their transparencies with an opaque mesh in the background.

​Controls

​The Camera: [Key : Action]​​​

[W : Move Forwards]
[A : Move to the Left]
[S : Move to the Right]
[D: Move Backwards]
[Space: Move UP]
[Left / Right Ctrl: Move DOWN]

The Brain: [Key : Action]

​[Arrow UP : Move Forwards]
[Arrow LEFT: Move to the Left]
[Arrow RIGHT : Move to the Right]
[Arrow DOWN: Move Backwards]
[Page UP: Move UP]
[Page DOWN: Move DOWN]

Downloads

You can try out these games via the below links. The only difference is that Direct3D will be used in the x64 version, with OpenGL in the other. They have been built and verified to work on Windows.
assign14_garinrk_x64.zip
File Size: 863 kb
File Type: zip
Download File

assign14_garinrk_x86.zip
File Size: 855 kb
File Type: zip
Download File

0 Comments

Your comment will be posted after it is approved.


Leave a Reply.

    Categories

    All
    Engines
    Programming

    RSS Feed

Powered by Create your own unique website with customizable templates.
  • HOME
  • WORK
  • RESUME
  • ABOUT