1
1. De a n C a lve r Direct3D ShaderX: &. DirectX 9 (stream).. Dire c tx 9 1.1.... 3.0,
1. 49.. DirectX 8., ( ). DirectX 8 (D3DDEVCAPS2_STREAMOFFSET ), DirectX 9. DirectX 7, FVF.,, DirectX 9, D3DDEVCAPS2_VERTEXELEMENTSCANSHARESTREAMOFFSET. DWORD (4 ). DirectX 9..,.,. N o t e DirectX 9 2.0..,. 2.0 (ATI ).
50 1 DirectX 8 (signed), (unsigned), (normalized),.. D3DCOLOR 4 32 8 [0,1] N a UBYTE4 4 32 8 [0,255] Y UBYTE4N 4 32 8 [0,1] Y UDEC3 3 32 10 [0,1024] Y b DEC3N 3 32 10 [-1,1] Y b SHORT2 2 32 16 [-32768,32767] N SHORT4 4 64 16 [-32768,3276z7] N USHORT2N 2 32 16 [0,1] Y USHORT4N 4 64 16 [0,1] Y SHORT2N 2 32 16 [-1,1] Y SHORT4N 4 64 16 [-6.55e4,6.55e4] Y FLOA16_2 2 32 16 [-6.55e4,6.55e4] Y c FLOAT16_4 4 64 16 [-3.45e38,3.48e38] Y c FLOAT1 1 32 32 [-3.48e38,3.48e38] N d FLOAT2 2 64 32 [-3.48e38,3.48e38] N d FLOAT3 3 96 32 [-3.48e38,3.48e38] N d FLOAT4 4 128 32 [-3.48e38,3.48e38] N d a) D3DCOLOR. ARGB RGBA. b) 2. c) float16 OpenEXR, nvidia PIXAR. D3DXFLOAT16 ( OpenEXR SDK ). d) float C IEEE754.
1. 51 32 (DEC3 ). D3DCAPS9.DeclType, D3DTCAPS_datatype, D3DDECLTYPE_datatype ( datatype ). DEC3N UDEC3, (,, ). ( ). A B C D 2 10 10 10 D2DDECLTYPE UDEC3 D2DDECLTYPE UBYTE4 X B X (D&0x0ff) Y C Y (C&0x03f) (D&0x300)>>8) Z D Z (B&0x00F) ((C&0x3c0)>>6) W 1 W (A<<6) ((B&0x3f0)>>4 [ 1-1 ] UDEC3 ( ).
52 1 NORMAL0 UDEC3 NORMAL1 UBYTE4. D3DVERTEXELEMENT9 decl[] = }; / /, ' ' UDEC3 0, / / 0, / / D3DDECLTYPE_UDEC3, / / D3DDECLMETHOD_DEFAULT, / /. D3DDECLUSAGE_NORMAL, / / ( ) 0 / / (n. ) }, / /, UBYTE4 0, / /,. 0, / /,. D3DDECLTYPE_UBYTE4, / / D3DDECLMETHOD_DEFAULT, / /. D3DDECLUSAGE_NORMAL, / / ( ) 1 / / (n. ) }, D3DDECL END( ), 2^6(64) (floor)., 0 3. (mova ). st r uct VS_I NPUT f l oat 4 normal : NORMAL0, f l oat 4 enc2bi t : NORMAL1 }; voi d mai n( VS_I NPUT i nput )
1. 53 } / /. f l oat 3 normal = i nput. normal ; / / 2. (0-3) f l oat t wo bi t s = f l oor (i nput.enc2bi t.w / 64.0) ; DEC3N 10, 10, 12. (Direct3D ShaderX., (eigen),. ). (dominant) (, )., 64 (SHORT4) 32., z. st r uct VS I NPUT f l oat 4 posi t i on : POSITION0, f l oat 4 enc2bi t : POSITION1 }; voi d mai n( VS_I NPUT i nput ) / / 10, 10, 10. f l oat 3 cpos = i nput. posi t i on; / / 2. (0-3) f l oat t wo_bi t s = f l oor (i nput.enc2bi t.w / 64.0) ; / / 0-1. cpos. z = (cpos. z + t wo_bi t s ) * 0.25;
54 1 } / /. f l oat 4 pos = mul ( f l oat 4 (cpos, 1), I nvcompressi ontransf orm ) ;. Tom Forsyth.,, (subdivision surfaces). (tessellation), CPU,. ( ( ), ).,., (barycentric),.. :.,. :.,... Mike Dogget Tom Forsyth [2]., Tom
1. 55 Forsyth [1]. 1D. Direct3D ShaderX... CPU,.,,,. (FLOAT1),. 8, UBYTE4.,. N o t e, DirectX 9 GPU. API, DirectX 9 ( ). Mike Doggett OpenGL (uber-buffer) renderto-vertex-array GPU. (p re - filte ring ).., ( ) ( ).
56 1,. UBYTE4,. ( / )...,.,,., (barycentric) (, (areal) ) (., ). ( ).., (k i j ).....
1. 57 / / HLSL f l oat 3 Vert expos [3 * NUMBASE TRIANGLE] ; voi d mai n(f l oat 3 vert exst ream : POSITION0) f l oat i = vert exst ream.x; f l oat j = vert exst ream.y f l oat k = 1.0 i j ; f l oat basei ndex = vert exst ream. z * 256; / /. f l oat 3 pos = i *Vert expos [ (basei ndex*3) + 0 ] + j *Vert expos [ (basei ndex*3) + 1 ] + k*vert expos [ (basei ndex*3) + 2 ] ; } N- N- ( PN [3]) (bicubic). N-,,..,.,. GPU, PC CPU. CPU ( N-, 39 18 ), CPU. f l oat 3 Vert expos [3 * NUM_BASE_TRIANGLE] ; f l oat 3 Vert exnormal s [3 * NUM_BASE_TRIANGLE] ; / / f l oat 3 b300, b030, b003, b210, b120, b021, b201, b102, b012, b111;
58 1 f l oat 3 n200, n020, n002 ; voi d generat econt rol Poi nt swi t hli nearnormal s (f l oat basei ndex) ; f l oat 3 v0 = Vert expos [ (basei ndex*3) + 0 ] ; f l oat 3 v1 = Vert expos [ (basei ndex*3) + 1 ] ; f l oat 3 v2 = Vert expos [ (basei ndex*3) + 2 ] ; f l oat 3 n0 = Vert exnormal [ (basei ndex*3) + 0 ] ; f l oat 3 n1 = Vert exnormal [ (basei ndex*3) + 1 ] ; f l oat 3 n2 = Vert exnormal [ (basei ndex*3) + 2 ] ; / /. / / CD/ ATI PN [3]. f l oat 3 edge = v1 - v0; / / E - (E.N)N f l oat 3 t angent 1 = edge ; f l oat t mpf = dot ( t angent 1, n0 ) ; t angent 1 -= n0 * t mpf ; b210 = v0 + (t angent 1 * rcp3) ; } voi d eval uat enpat chli nearnormal (f l oat i, f l oat j, out f l oat 3 pos, out f l oat 3 norm) f l oat k = 1 - i - j ; f l oat k2 = k * k; f l oat k3 = k2 * k; f l oat i 2 = i * I ; f l oat i 3 = i 2 * i ; f l oat j 2 = j * j ; f l oat j 3 = j 2 * j ; / / pos = (b300*k3) + (b030*u3) + (b003*v3) + (b210*3*k2*i ) + (b120*3*k*i 2) + (b201*3*k2*j ) + (b021*3*i 2*j ) + (b102*3*k*j 2) + (b012*3*i 2*j ) + (b111*6*k*i *j ) ; } / / norm = (w * n200) + (i * n020) + (j * n002) ; voi d mai n(f l oat 3 vert exst ream : POSITION0)
1. 59 f l oat i = vert exst ream.x; f l oat j = vert exst ream.y f l oat basei ndex = vert exst ream. z * 256; f l oat 3 pos, norm; } generat econt rol Poi nt swi t hli nearnormal s (basei ndex) ; eval uat enpat chli nearnormal (i, j, pos, norm) ; N-.,.,.. ( ),. ( ).,.,.. / / HLSL f l oat MAX_DISPLACEMENT_HEIGHT = 100; / /. f l oat 3 Vert expos [NUM_BASE_VERTICES] ; f l oat 3 Vert exnormal [NUM_BASE_VERTICES] ; f l oat 2 Vert exuv[numbase_vertices] ; st r uct VS_I N f l oat 2 barycent r i c ; f l oat 3 i ndi ces ; f l oat di spl acement ;
60 1 }; voi d mai n( VS_I N i nput ) f l oat i = i nput. barycent r i c.x; f l oat j = i nput. barycent r i c.y f l oat k = 1.0 i j ; f l oat i 0 = i nput. i ndi ces.x * 256; f l oat i 1 = i nput. i ndi ces.y * 256; f l oat i 2 = i nput. i ndi ces. z * 256; f l oat 3 pos = i *Vert expos [i 0] + j *Vert expos [i 1] + k*vert expos [i 2] ; f l oat 3 normal = i * Vert exnormal [i 0] + j * Vert exnormal [i 1] + k* Vert exnormal [i 2] ; f l oat 2 uv = i * Vert exuv[i 0] + j * Vert exuv[i 1] + k* Vert exuv[i 2] ; } normal = normal i ze ( normal ) ; pos = pos + i nput.di spl acement * normal * MAX DISPLACEMENT HEIGHT; [0, 1]. 256 ( 256 ).., 1 + 1 8 ( ), 3 + 1 8 ( )... (perturbed),..,.
1. 61,.,.., ( )., ( )..,.,.,. ( [2] ),. [1] Forsyth, Tom, Displacement Mapping, ShaderX 2 : Shader Programming Tips & Tricks with DirectX 9, Wolfgang Engel, Wordware Publishing, Inc., 2004, pp. 73-86. 1 7.. [2] Doggett, Mike Tom Forsyth, Displacement Mapping, GDC 2003. [3] Vlachos, A. J. Peters, C. Boyd, J. Mitchell, Curved PN Triangles, http://www.ati.com/developer/curvedpntriangles.pdf.