Presentation is loading. Please wait.

Presentation is loading. Please wait.

GAM531 DPS931 – Week 11 Render State. The Render State Render State BuffersShadersSamplers Rasterizer State Blend State.

Similar presentations


Presentation on theme: "GAM531 DPS931 – Week 11 Render State. The Render State Render State BuffersShadersSamplers Rasterizer State Blend State."— Presentation transcript:

1 GAM531 DPS931 – Week 11 Render State

2 The Render State Render State BuffersShadersSamplers Rasterizer State Blend State

3 The Render Process Clear Buffer Update Graphic Context (per object) Draw Object (per object) Merge Output With Buffer (per object) Flip Back Buffer 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 ContextShaderBlend State

4 What The Blend State Does Blending On Blending Off

5 Color Model Unsigned Char Min: 0 Max: 255 Float Min: 0.0 Max: 1.0 Non-Alpha Color 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 Operation Sources Factors (Source vs Destination) Add (D = S + D) Subtract (D = S – D) Reverse Subtract (D = D – S) Min (D = S < D ? S : D) Max (D = S > D ? S : D) Const Zero Const One Source Color Inverse Source Color Destination Color Inverse Destination Color

7 The Blend State Blend State Color Operation Source Color Destination Color Alpha Operation Source Alpha Destination Alpha 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 _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 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));

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 Clear Buffer Update Graphic Context (per object) Draw Object (per object) Merge Output With Buffer (per object) Flip Back Buffer 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 ContextShaderBlend State

11 The Shader Pipeline Vertex Processing Primitive Assembly / Processing Rasterization Fragment Processing Pixel Output 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 Rasterizer State Fragment Shader Tranforms Vertices into homogenous clip space (and other processing) Vertex Shader

12 What Does The Rasterizer Do? One Primitive Many Fragments

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

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

15 Programming Rasterizer State //No creation code for GL, only Emperor specific code //See binding 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);

16 Binding Rasterizer State 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 Clear Buffer Update Graphic Context (per object) Draw Object (per object) Merge Output With Buffer (per object) Flip Back Buffer 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 ContextShaderBlend State

18 The Shader Pipeline Vertex Processing Primitive Assembly / Processing Rasterization Fragment Process Pixel Output 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 Rasterizer State Fragment Shader Tranforms Vertices into homogenous clip space (and other processing) Vertex 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


Download ppt "GAM531 DPS931 – Week 11 Render State. The Render State Render State BuffersShadersSamplers Rasterizer State Blend State."

Similar presentations


Ads by Google