1 / 19

GAM531 DPS931 – Week 11

GAM531 DPS931 – Week 11. Render State. The Render State. The Render Process. Context. Shader. Blend State. Send object’s position, camera’s projection etc to the graphics card. Transform 3D object representations into 2D textures.

tucker
Download Presentation

GAM531 DPS931 – Week 11

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. GAM531DPS931 – Week 11 Render State

  2. The Render State

  3. The Render Process Context Shader Blend State Send object’s position, camera’s projection etc to the graphics card Transform 3D object representations into 2D textures Combine the 2D output with the back buffer / render target

  4. What The Blend State Does Blending Off Blending On

  5. Color Model Non-Alpha Color Unsigned Char Float Min: 0 Max: 255 Min: 0.0 Max: 1.0 Red | Green | Blue Alpha Color Red | Green | Blue | Alpha [255,0,0] [0,50,0] [255,0,255] [255,255,255] [0,0,0] [1.0,0,0,1.0] [0.5,0.5,0,1.0] [1.0,1.0,0,0.5] [0,0,0,0.5]

  6. Blending Parameters Sources Factors(Source vs Destination) Operation Add (D = S + D) Const Zero Subtract (D = S – D) Const One Reverse Subtract (D = D – S) Source Color Min (D = S < D ? S : D) Inverse Source Color Max (D = S > D ? S : D) Destination Color Inverse Destination Color

  7. The Blend State Color Operation: Add Source: One Dest: One Alpha Operation: Add Source: One Dest: Zero [255,0,0,255] [0,255,0,255] = +

  8. Programming Blend State D3D11_BLEND_DESC bsd; ZeroMemory(&bsd, sizeof(D3D11_BLEND_DESC)); bsd.RenderTarget[rt].BlendEnable= //true or false bsd.RenderTarget[rt].BlendOp = //Blend operation bsd.RenderTarget[rt].BlendOpAlpha = //Blend operation bsd.RenderTarget[rt].DestBlend= //Destination color bsd.RenderTarget[rt].DestBlendAlpha= //Dest alpha bsd.RenderTarget[rt].RenderTargetWriteMask = 0x0f; bsd.RenderTarget[rt].SrcBlend = //Source Color bsd.RenderTarget[rt].SrcBlendAlpha = //Source Alpha bsd.IndependentBlendEnable = //true or false bsd.AlphaToCoverageEnable= //true or false dev->CreateBlendState(&bsd, &bs)); _glBlend t; t.index= rt; //The render target t.enableFunc= //proxy function (Emperor code) t.blendOp= //Blend operation t.blendOpAlpha= //Blend operation t.destBlend= //Destination Color t.destBlendAlpha= //Destination Alpha t.srcBlend= //Source Color t.srcBlendAlpha = //Source Alpha //Nothing to be created, the device will be set with this struct

  9. Binding Blend State t->enableFunc(t->index); glBlendEquationSeparatei(t->index, t->blendOp, t->blendOpAlpha); glBlendFuncSeparatei(in, t->srcBlend, t->destBlend, t->srcBlendAlpha, t->destBlendAlpha); //enable function activates one of two functions glEnablei(GL_BLEND, index);//if enabled is true //or glDisablei(GL_BLEND, index); //if enabled is false con->OMSetBlendState(bs, Vector4(0,0,0,0).data, 0xffffffff); //blend state, blend factor, sample mask

  10. The Render Process Context Shader Blend State Send object’s position, camera’s projection etc to the graphics card Transform 3D object representations into 2D textures Combine the 2D output with the back buffer / render target

  11. The Shader Pipeline Vertex Shader Tranforms Vertices into homogenous clip space (and other processing) Fragment Shader Rasterizer State Creates 2D primitives (triangles, lines, points) from transformed vertices Divides 2D primitives into many pixel sized fragments Processes each fragment and returns a color to be displayed on the render target Primitive Assembler / Geometry Shader

  12. What Does The Rasterizer Do? One Primitive Many Fragments

  13. Rasterizer Parameters Face Culling Anti-Aliasing Winding Order Fill Mode Solid None Front Vs Vs Vs Vs Wireframe Back Face Front

  14. Depth Processing New Fragment Depth ~= Old Fragment Depth 0.100001111121 ~= 0.100001111111 Floating point precision will cause inconsistent state if( oldDepth >= newDepth) OverwriteFragment(); Depth Bias if(oldDepth >= newDepth + DepthBias) OverwriteFragment(); Z Fighting

  15. Programming Rasterizer State D3D11_RASTERIZER_DESC d; d.AntialiasedLineEnable= //true or false d.CullMode= //face cull mode, none, front, or back d.DepthBias= //The depth bias d.DepthBiasClamp= //The maximum depth bias d.DepthClipEnable= //true or false, clips far plane d.FillMode= //wireframe or solid d.FrontCounterClockwise= //true or false, wind order d.MultisampleEnable= //true or false, anti-aliasing d.ScissorEnable= //true or false, scissor culling d.SlopeScaledDepthBias= //sloped depth bias dev->CreateRasterizerState(&d, &rasterState); //No creation code for GL, only Emperor specific code //See binding

  16. Binding RasterizerState aaLine(GL_LINE_SMOOTH); cullFace(GL_CULL_FACE); glCullFace(cullDir); glPolygonOffset(depthClamp, (GLfloat)depthBias); glPolygonMode(GL_FRONT_AND_BACK, fillMode); glFrontFace(windOrder); multiSample(GL_MULTISAMPLE); scissorTest(GL_SCISSOR_TEST); depthClip(GL_DEPTH_CLAMP); //Anything not starting with gl is a function pointer //to either glEnable(a); //or glDisable(a); con->RSSetState(rasterState);

  17. The Render Process Context Shader Blend State Send object’s position, camera’s projection etc to the graphics card Transform 3D object representations into 2D textures Combine the 2D output with the back buffer / render target

  18. The Shader Pipeline Vertex Shader Tranforms Vertices into homogenous clip space (and other processing) Fragment Shader Rasterizer State Creates 2D primitives (triangles, lines, points) from transformed vertices Divides 2D primitives into many pixel sized fragments Processes each fragment and returns a color to be displayed on the render target Primitive Assembler / Geometry Shader

  19. To Do • Continue work on engine enhancement • Read this week’s lab • Read this week’s notes • Re-implement OpenGL Render State functions

More Related