1 / 21

GAM532 DPS932 – Week 6

GAM532 DPS932 – Week 6. Render Targets and Post Processing. The Back Buffer & Depth Buffer. Buffer Flipping. Frame Buffer. Render. Back Buffer. Depth Buffer. Buffer Description. Back Buffer. Depth Buffer. Type. 2D Texture. 2D Texture. 1440 x 900. 1440 x 900. Resolution.

glenda
Download Presentation

GAM532 DPS932 – Week 6

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. GAM532DPS932 – Week 6 Render Targets and Post Processing

  2. The Back Buffer & Depth Buffer Buffer Flipping Frame Buffer Render Back Buffer Depth Buffer

  3. Buffer Description Back Buffer Depth Buffer Type 2D Texture 2D Texture 1440 x 900 1440 x 900 Resolution Pixel Format D24 S8 R8 G8 B8 A8 Colors to be display on the monitor Depth of each pixel for depth testing Purpose

  4. What is a Render Target? Target Objects Target Types Bound To Color Target Back Buffer Monitor Color Texture Shader Resource Render Depth Target Depth Buffer System Reserve Depth Texture Shader Resource

  5. How to use Render Targets Pre-Render Camera Color Target Material Scene 2 Renders= 1 Frame Main Camera Actor

  6. Initializing Color Render Targets //First, make a 2D texture we’ll use for the target D3D11_TEXTURE2D_DESC desc; desc.BindFlags= D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET; desc.CPUAccessFlags= 0; desc.Format= //Texture format desc.MipLevels= 1; desc.MiscFlags = 0; desc.Usage = D3D11_USAGE_DEFAULT; //Fill in remainder of struct dev->CreateTexture2D(&desc, 0, &tex2d); dev->CreateShaderResourceView(tex2d, 0, &texture); //Make the render target and bind it to the texture D3D11_RENDER_TARGET_VIEW_DESC rDesc; rDesc.Format= desc.Format; rDesc.ViewDimension= D3D11_RTV_DIMENSION_TEXTURE2D; rDesc.Texture2D.MipSlice = 0; dev->CreateRenderTargetView(tex2d, &rDesc, &rend); //Create and initialize the texture glGenTextures(1, &textureID); glBindTexture(dim, textureID); glTexStorage2D(dim, 1, iFormat, width, height); //Create the render target and bind it to the texture glGenFramebuffers(1, &framebuffer); glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,textureID, 0); //Unbind when done glBindTexture(dim, 0); glBindFramebuffer(GL_FRAMEBUFFER, 0);

  7. Binding Color Render Targets //Clear before binding con->ClearRenderTargetView(targetView, D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f)); //Bind it as the system’s render target con->OMSetRenderTargets(1, &targetView, 0); //Adjust the view port to for the dimensions of //the new render target D3D11_VIEWPORT v; v.TopLeftX= left; v.TopLeftY= top; v.MinDepth= 0.0f; v.MaxDepth= 1.0f; v.Width= targetWidth; v.Height= targetHeight; con->RSSetViewports(1, &v); glBindFramebuffer(GL_FRAMEBUFFER, targetView); //Clear before using glClear(GL_COLOR_BUFFER_BIT); //Indicate the buffer will output a color GLenumdrawBuffer[1] = {GL_COLOR_ATTACHMENT0}; glDrawBuffers(1, drawBuffer); //Adjust the view port to for the dimensions of //the new render target glViewport(left, top, targetWidth, targetHeight);

  8. Unbinding & Deleting Color Render Targets //To unbind a color target, rebind the system’s //back buffer con->OMSetRenderTargets(1, &backbuffer, 0); //don’t forget to reset the view ports! //Delete the texture and color target rend->release(); texture->release(); //Unbind the color target glBindFramebuffer(GL_FRAMEBUFFER, 0); //don’t forget to reset the view ports! //Delete the texture and color target glDeleteFramebuffers(1, &framebuffer); glDeleteTextures(1, &textureID);

  9. Target Depth Binding DX vs GL DX Context GL Context Color Target(glFramebuffer) Depth Buffer Color Target Depth Target Color Texture Color Texture Depth Texture Depth Texture

  10. Initializing Depth Render Targets D3D11_TEXTURE2D_DESC desc; desc.BindFlags= D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_SHADER_RESOURCE; desc.Format= DXGI_FORMAT_R32_TYPELESS; //fill in rest of struct dev->CreateTexture2D(&desc, 0, &tex2d); D3D11_SHADER_RESOURCE_VIEW_DESC desc2; desc2.ViewDimension= D3D11_SRV_DIMENSION_TEXTURE2D; desc2.Format = textureFormat;//single channel //fill in rest of struct dev->CreateShaderResourceView(tex2d, &desc2, &texture); D3D11_DEPTH_STENCIL_VIEW_DESC descDSV; descDSV.Format= depthFormat; descDSV.ViewDimension=D3D11_DSV_DIMENSION_TEXTURE2D;//fill in rest of struct dev->CreateDepthStencilView(tex2d,&descDSV,&dsv); glGenTextures(1, &textureID); glBindTexture(dim, textureID); glTexStorage2D(dim, 1, iFormat, width, height); glGenRenderbuffers(1, &depthBuffer); glBindRenderbuffer(GL_RENDERBUFFER, depthBuffer); glRenderbufferStorage(GL_RENDERBUFFER, iFormat, width, height); glBindRenderbuffer(GL_RENDERBUFFER, 0); glBindTexture(dim, 0);

  11. Binding Depth Render Targets //Bind the buffer to the color target glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthTarget); //Bind the texture to the color target glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthTexture, 0); //Clear before using glClear(GL_DEPTH_BUFFER_BIT); //Since color and depth targets should match in //when bound together, viewport is only set once //Clear before binding con->ClearDepthStencilView(depthTarget, D3D11_CLEAR_DEPTH, 1.0f, 0); //Bind it as the system’s render target //(also binds the render target) con->OMSetRenderTargets(1, colorTarget, depthTarget); //Since color and depth targets should match in //when bound together, viewport is only set once

  12. Unbinding & Deleting Color Render Targets //Unbind the depth target/texture from color target glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, 0, 0); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0); //Delete the texture and color target glDeleteRenderbuffers(1, &depthBuffer); glDeleteTextures(1, &textureID); //To unbind a depth target, set it to zero //Alternative, set it back to the system’s buffer con->OMSetRenderTargets(1, &backbuffer, depthbuffer); //Delete the texture and color target dsv->release(); texture->release();

  13. Uses of Render Targets Dynamic Mirrors Post Processing Effects Shadows

  14. Setting Up Dynamically Rear View Rear View Main Camera

  15. Setting Up a Dynamic Mirror Main Camera Mirror Camera Actors

  16. Fragment Isolation Fragments Processed Concurrently Limited Scope, no adjacency data Following effects are difficult: Motion Blur Glow

  17. Post Processing 1 Fragment Render Camera Color Target Can sample from Post Processing Camera Any number of Texels Back Buffer Screen Space Quad (100%)

  18. Basic Post Processing Effects

  19. Storing Post Processing Data Hiding Data in Color Alternatively… Color for Frame Buffer RedGreenBlue Alpha 1st Color Target 2nd Color Target Often unused Use the 2nd color target to store post processing data which you use to manipulate the colors in the 1st Color for Color Target (Post Processing) RedGreenBlue Luminosity Make use of unused variables to store data for post processing

  20. Post Processing Effects God Rays Screen Distortion Motion Blur

  21. To Do • Read over Lab 5 • Finish Proposal Documents and Prepare to Submit • Research your engine enhancement

More Related