gam531 dps931 – week 11 render state. the render state render state buffersshaderssamplers...
TRANSCRIPT
GAM531DPS931 – Week 11Render State
The Render State
Render State
Buffers Shaders Samplers
Rasterizer State
Blend State
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
Context Shader Blend State
What The Blend State Does
Blending On
Blending Off
Color Model
Unsigned CharMin: 0Max: 255
Float
Min: 0.0Max: 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]
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
The Blend StateBlend State
Color Operation
Source Color
Destination Color
Alpha Operation
Source Alpha
Destination Alpha
ColorOperation: AddSource: OneDest: One
AlphaOperation: AddSource: OneDest: Zero
[255,0,0,255]
[0,255,0,255]
+ =
Programming Blend State
_glBlend t;
t.index = rt; //The render targett.enableFunc = //proxy function (Emperor code)t.blendOp = //Blend operationt.blendOpAlpha = //Blend operationt.destBlend = //Destination Colort.destBlendAlpha = //Destination Alphat.srcBlend = //Source Colort.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 falsebsd.RenderTarget[rt].BlendOp = //Blend operationbsd.RenderTarget[rt].BlendOpAlpha = //Blend operationbsd.RenderTarget[rt].DestBlend = //Destination colorbsd.RenderTarget[rt].DestBlendAlpha = //Dest alphabsd.RenderTarget[rt].RenderTargetWriteMask = 0x0f;bsd.RenderTarget[rt].SrcBlend = //Source Colorbsd.RenderTarget[rt].SrcBlendAlpha = //Source Alpha
bsd.IndependentBlendEnable = //true or falsebsd.AlphaToCoverageEnable = //true or false
dev->CreateBlendState(&bsd, &bs));
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 functionsglEnablei(GL_BLEND, index); //if enabled is true//orglDisablei(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
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
Context Shader Blend State
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
targetPrimitive Assembler / Geometry Shader
Rasterizer State Fragment Shader
Tranforms Vertices into homogenous clip
space (and other processing)
Vertex Shader
What Does The Rasterizer Do?
One Primitive Many
Fragments
Rasterizer Parameters
Face Culling
Vs
None
Back Face
Winding Order
Front
Vs
Front
Fill Mode
Vs
Solid
Wireframe
Anti-Aliasing
Vs
Depth Processing
Z Fighting
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();
Programming Rasterizer State
//No creation code for GL, only Emperor specific code//See binding
D3D11_RASTERIZER_DESC d;
d.AntialiasedLineEnable = //true or falsed.CullMode = //face cull mode, none, front, or backd.DepthBias = //The depth biasd.DepthBiasClamp = //The maximum depth biasd.DepthClipEnable = //true or false, clips far planed.FillMode = //wireframe or solidd.FrontCounterClockwise = //true or false, wind orderd.MultisampleEnable = //true or false, anti-aliasingd.ScissorEnable = //true or false, scissor cullingd.SlopeScaledDepthBias = //sloped depth bias
dev->CreateRasterizerState(&d, &rasterState);
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 eitherglEnable(a);//orglDisable(a);
con->RSSetState(rasterState);
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
Context Shader Blend State
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
targetPrimitive Assembler / Geometry Shader
Rasterizer State Fragment Shader
Tranforms Vertices into homogenous clip
space (and other processing)
Vertex Shader
To Do• Continue work on engine enhancement
• Read this week’s lab
• Read this week’s notes
• Re-implement OpenGL Render State functions