Showing posts from June, 2010

Depth Bias

To solve Z fighting issue: use depth bias. An application can help ensure that coplanar polygons are rendered properly by adding a bias to the z-values that the system uses when rendering the sets of coplanar polygons. To add a z-bias to a set of polygons, call the IDirect3DDevice9::SetRenderState method just before rendering them, setting the State parameter to D3DRS_DEPTHBIAS, and the Value parameter to a value between 0-16 inclusive. A higher z-bias value increases the likelihood that the polygons you render will be visible when displayed with other coplanar polygons. Offset = m * D3DRS_SLOPESCALEDEPTHBIAS + D3DRS_DEPTHBIAS where m is the maximum depth slope of the triangle being rendered. m = max(abs(delta z / delta x), abs(delta z / delta y))  reference:                                                  Z Slope Scale = 0.0, Depth Bias = 0.0                                         

Occlusion Culling Using Direct3D 9.0

In the view frustum culling scenario, the culling-in objects like the bottom figure shows: But in the practical view looks like the bottom figure, we just need to render three objects: red, purple, and blue one. The green and yellow one are hidden. In this condition, we can adopt GPU hardware support. Direct3D provides Occlusion Query to calculate number of pixel visible. If the number is zero, meaning it is fully occluded, else is greater than zero  the pixel is visible by the viewer. The IDirect3DQuery9 process is presented below: Render every object's bounding mesh For every object: Begin query Re-render the bounding mesh End query Retrieve occlusion query data. If the pixels visible are greater than zero, the object should be rendered. Otherwise, the object should be occluded from rendering. In the first step, we need to decide the bounding mesh. Use bounding box? sphere?...The suit way is using lower vertex count mesh to instead of bounding box or spher

Shadow Application In A Soccer Game

Maybe you will wonder in this snapshot how to present so many shadows in one frame. There is some tricky, because the gorgeous shadow result doesn't appear always. In the often gameplay situation, it only looks like the bottom snapshot . In this snapshot, doesn't have any self-shadow result. The shadow approach looks like planar shadow. When in the replay clips, Planar shadow and shadow map are used together. In the planar shadow phases, all shadows are rendered to a target, and then preparing shadow map uses another render target(using sizeof 1024x2048, cause what?, now I still don't understand.). At the rendering pass, planar shadow can use a rectangle to mapping the render target. With regard to shadow map, fetch the shadow texel in each object's pixel shader .

Order-Independent Transparency

Depth sorting alpha blended objects Order Independent Transparency with Dual Depth Peeling Interactive Order-Independent Transparency Alpha blending without sorting Depth-sort based Alpha Blending Sort-Indenpency Alpha Blending Order-indenpendent transparency

Current shadow map method

Switch render target. Keep the current pass color surface and depth surface, set the shadow map color surface and depth surface in order to get the frame buffer data into the screen space texture - shadow map. We use the R32 color map to store shadow texture, size of 1024x1024. Because dx 9.0 can't be valid for modify depth texture, but graphics card vendor support get depth texture approach, it may has something warning in dx 9.0 runtime .( Nvidia : hardware shadow map, pcf 2x2. ATI : fetch4) If we can fetch depth info. as texture then disable color write, use depth bias to solve depth fighting. The process of shadow map will decrease cost effectively. In the second rendering pass, fetch the shadow map, and adopt PCF 2x2 to blur the aliasing.

Matrix multiple in HLSL

In HLSL , We could use constant float to transit the value into shader code. There is a confusing problem to me, in row-major and column major rule will have the same result? When we use setConstantF to the register, shader's assembly use vector to record them. At processing time, these vector use dot product operator with you variable. So when you use mul ( pos , WorldMtx ); WorldMtx is: { _00, _01, _02, _03, _10, _11, _12, _13, _20, _21, _22, _23, _30, _31, _32, _33 } the WorldMtx need to be transpose at software, and the process is: Output.x = dot( vector( pos . xyz , 1.0f), vector(_00,_10,_20,_30) ); Output.y = dot( vector( pos . xyz , 1.0f), vector(_01,_11,_21,_31) ); Output.z = dot( vector( pos . xyz , 1.0f), vector(_02,_12,_22,_32) ); Or you also can use mul ( WoldMtx , pos ); , and don't transpose WorldMtx . The result is: Output.x = mul ( vector(_00,_01,_02,_03), pos . x ) + mul (_30, 1.0f); Output.y = mul ( vector(_10,_11,_12,_13), pos . y ) + mul (_31, 1.0f)



SSAO - Screen Space Ambient Occlusion

About SSAO approach can reference here

Hardware Occlusion Queries

GPU provides query mode to test pixel whether or not would be draw. In the previous frame, render model only its bounding box, and query if success in the view indeed . Furthermore, we just render objects the bounding box is in the clip space . But sometimes this method will have more drawcalls , and need to wait some frames. It will have overcome. Fast and Simple Occlusion Culling using Hardware-Based. pdf Occlusion Culling Using DirectX 9

Website introduce shader

HLSL Shaders Introduction to Shader Programming