Upload
kamin
View
80
Download
0
Embed Size (px)
DESCRIPTION
GPU Gems3 Chapter 2. Animated Crowd Rendering. http://www.kindnap.pe.kr http://cafe.naver.com/shader. introduction. Shader 4.0 버전을 이용한 Skinned Hardware Instancing 을 구현해본다 . A Crowd of Characters Animated Using Skinned Instancing. Hardware Instancing?. 모아 찍는 기술. 오버해드의 원인 캐시 미스 - PowerPoint PPT Presentation
Citation preview
GPU Gems3Chapter 2. Animated
Crowd Rendering
http://www.kindnap.pe.krhttp://cafe.naver.com/shader
introductionShader 4.0 버전을 이용한 Skinned Hardware
Instancing 을 구현해본다 .
A Crowd of Characters Animated Using Skinned In-stancing
Hardware Instancing?모아 찍는 기술
오버해드의 원인캐시 미스
Render StateTexture
풀 , 나무 , 배경에 적용되는간단한 Mesh
리소스의 공유(Texture, VB,
IB)단지 위치 , 회전혹은 칼러값 차이
Hardware Instancing?하나의 버퍼에 몰아 , Draw Call 을 최적화이점
Reduce :: Draw CallReduce :: Cache MissReduce :: SetRenderStateReduce :: SetTexture
더 자세한 내용은 http://www.storyq.net/boxes/1841
Hardware Instancing Dx9 사용법
In HLSL
#define MAX_UNIT_INSTANCING 75 //상수 레지스터의 제한으로 인한 한번을 DP call시 그릴 수 있는 수의 한계를 둠Float4x3 g_mWorldMatrixArrayInstancing[MAX_UNIT_INSTANCING] : WORLDMA-TRIXARRAY; //각 인스턴스의 월드행렬 정보의 저장struct VS_INPUT{
float4 vPos : POSITION;float2 vTexCoord0 : TEXCOORD0;
float fWorldMatrixIndex : TEXCOORD1;//버퍼중 인스턴스의 아이디를 직접 알 수 있는 버퍼의 존재
} Vertex;
Hardware Instancing Dx9 In VS
int iMatrixIndex = i.fWorldMatrixIndex; // 버택스 Input 에서 현제 아이드를 참조함
vWorldPos = mul( i.vPos, g_mWorldMatrixArrayInstancing[iMatrixIndex] );// 포지션 개산시 해당 월드행렬의 참조o.vPos = mul( float4( vWorldPos, 1.0f ), g_mShadowViewProj );// 이후 일반 연산과 동일한 과정
Hardware Instancing Dx9In C Code
D3DDevice()->SetStreamSourceFreq( uiStreamNumber, uiFrequencyParam );의 호출
Hardware Instancing Dx9한계점
협소한 상수레지스터 (256) 의 보유로 많은 수를 In-stancing 처리할 수 없음Shader 2.0 버전 기준으로 Vs 에서 택스쳐를 샘플링 할 수 없으므로 Skinned Instancing 구현 시 상수 레지스터가 더욱 모자라게 됨
In Article Technique (Use DX10 – shader 4.0)DX10 을 이용한다면 현실적으로 적용하며 효율적인
Skinned animated instancing 이 구현가능Animation 정보를 택스쳐에 기입
// shader 3.0 이상 사용시 vs 에서 샘플링 가능상수 레지스터에 기존방법에 + Animation info
( 참조 에니매이션 , 프레임정보… )
Technique Cpu프로그램의 로직을 실행- ( 각종 업데이트 , AI, 그에따른 ani 진행 )
각 인스턴스에 대한 LOD 그룹화- 결정된 LOD 그룹에서 매쉬별로 그룹화LOD 그룹기준으로 각 그룹에 대하여동일 매쉬를 사용한다면DrawInstanced();
Technique Gpu
VSLoad Instance dataLoad bone matrix(in tex)ani 연산
PS 여타와 같은 행위
Technique Constants – Based
Shader 4.0 기준 상수 레지스터는 4096 (3.0 / 256)위와 같은 방법으로 연산시 한번에 Dp call 당800 개의 instance 를 랜더링 가능10000 여기의 오브젝트를 랜더링시 13 번의 Dp Call 이면 랜더링이 가능함
Technique Constants – Based HLSL strucestruct PerInstanceData { float4 world1; float4 world2; float4 world3; float4 color; uint4 animationData; }; cbuffer cInstanceData {
PerInstanceData g_Instances[MAX_INSTANCE_CONSTANTS]; }
Technique Constants – Based C Structstruct InstanceDataElement { D3DXVECTOR4 world1; D3DXVECTOR4 world2; D3DXVECTOR4 world3; D3DXCOLOR color;
// Offset in vectors (texels) into the whole data stream // for the start of the animation playing
UINT animationIndex; // Offset in vectors (texels) into the animation stream // for the start of the frame playing UINT frameOffset; UINT unused1; // pad UINT unused2; // pad };
Palette Skinning Using an Animation Texture
Conditional branchingfloat4x4 finalMatrix;// Load the first and most influential bone weightfinalMatrix = input.vWeights.x *loadBoneMatrix(animationData,input.vBones.x);
// Conditionally apply subsequent bone matrices if the weight is > 0if(input.vWeights.y > 0){
finalMatrix += input.vWeights.y *loadBoneMatrix(animationData,input.vBones.y);if(input.vWeights.z > 0){finalMatrix += input.vWeights.z *loadBoneMatrix(animationData,input.vBones.z);if(input.vWeights.w > 0)finalMatrix += input.vWeights.w *loadBoneMatrix(animationData,input.vBones.w);}
}
Geometry Variations같은 ani 를 참조하고 있지만 , 캐릭터의 장비를 다양하게 줄 수 있다 .
하지만 장작된 장비기준으로만 인스턴싱 그룹이 된다 .
자동화를 위하여 익스포터시 모든 장비를 장착한체 익스포터 시키고 프로그램 상에서 특정 장비를 선택하게 하는 방식으로 구현할수 있다 .
Geometry Variations
The Level-of-Detail System거리 기준으로 정렬거리 기준으로 정렬된 데이터를 매쉬별로 정렬ANIMATION 데이터 또한 LOD 별로 제작되 있음
Other ConsiderationsColor Variations베이스가 되는 칼라값 또한 인스턴스 정보에 넣어주어 효과를 줄 수 있으며 기존 app 에 적용되어 있다 .
(LOD 설정 정도의 표시 기능 )
Performance8600 회사똥컴
24frame / 9547 characters if no instancing16frame / 9547 characters
8800 Gtx34frame / 9547 characters
ConclusionInstancing 사용합시다 . 끝 !