190 likes | 352 Views
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.
E N D
GAM531DPS931 – Week 11 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 Combine the 2D output with the back buffer / render target
What The Blend State Does Blending Off Blending On
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]
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
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] = +
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
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
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
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
What Does The Rasterizer Do? One Primitive Many Fragments
Rasterizer Parameters Face Culling Anti-Aliasing Winding Order Fill Mode Solid None Front Vs Vs Vs Vs Wireframe Back Face Front
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
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
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);
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
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
To Do • Continue work on engine enhancement • Read this week’s lab • Read this week’s notes • Re-implement OpenGL Render State functions