;---------------------------------------------------------------------------- ; NUMERICAL DESIGN LIMITED PROPRIETARY INFORMATION ; ; This software is supplied under the terms of a license agreement or ; nondisclosure agreement with Numerical Design Limited and may not ; be copied or disclosed except in accordance with the terms of that ; agreement. ; ; Copyright (c) 1996-2001 Numerical Design Limited. ; All Rights Reserved. ; ; Numerical Design Limited, Chapel Hill, North Carolina 27514 ; http://www.ndl.com ;---------------------------------------------------------------------------- ; Vertex shader to perform index palette skinning ; This is a sample only; not part of the NetImmerse rendering library. ;---------------------------------------------------------------------------- ; VertexShader Version ; MUST BE 1.1 - since we use the a0 register! vs.1.1 ;---------------------------------------------------------------------------- ; This samples assumes that the partitioning will be done with 8 bones per ; partition, and 4 bones per vertex. This is a condition of the vertex shader ; which will need to be enforced in the ShaderDeclaration associated with the ; partitioning. ; The options for dealing with this are writing a single shader which handles ; the maximum number of bones you will partition your objects with. ; ; One of the issues with indexed palette skinning via the vertex shader ; pipeline is lighting. For this sample, we are using a known light. Ideally, ; you would search through the effects for active lights and pass them down ; to the shader. ; ; Constants specified by the app ; c0 = constants0 ( 1.0f,-1.0f, 0.0f, 1020.01f); ; c1 = temp ; c2 = // Object Color ; c3 = // Line Color ; c4 = // Line Size ; c5 = light direction ; c10 = matView * matProj ; c14 = matBone0 ; c18 = matBone1 ; c22 = matBone2 ; c26 = matBone3 ; c30 = matBone4 ; c34 = matBone5 ; c38 = matBone6 ; c42 = matBone7 ; c46 = matBone8 ; c50 = matBone9 ; c54 = matBone10 ; c58 = matBone11 ; c62 = matBone12 ; c66 = matBone13 ; c70 = matBone14 ; c74 = matBone15 ; c78 = matBone16 ; c82 = matBone17 ; c86 = matBone18 ; c90 = matBone19 ; c94 = ; ; Vertex components (as specified in the vertex DECL) ; v0 = pVertex[i].position ; v1 = pVertex[i].blendweights ; v2 = pVertex[i].blendindices ; v3 = pVertex[i].normal ; v5 = pVertex[i].texturecoords0 ; v6 = pVertex[i].texturecoords1 ; ;---------------------------------------------------------------------------- dcl_position v0 dcl_blendweight v1 dcl_blendindices v2 dcl_normal v3 dcl_texcoord0 v5 dcl_texcoord1 v6 ;---------------------------------------------------------------------------- ; Determine the last blending weight ;---------------------------------------------------------------------------- mov r0.xyz, v1.xyz ; r0.xyz = w0, w1, w2 dp3 r0.w, v1.xyz, c0.xxxx ; r0.w = w0 + w1 + w2 add r0.w, -r0.w, c0.x ; r0.w = 1 - (w0 + w1 + w2) = w3 ;---------------------------------------------------------------------------- ; Decode the index - PBYTE is supported on Xbox ; On XBOX, use the unswizzled input. ; On DX8, use the swizzled input - dues to the usage of D3DCOLOR for ; packing the indices... ;---------------------------------------------------------------------------- ;mul r1, v2.xyzw, c0.wwww ; r1 = indices w/ offset (XBOX) mul r1, v2.zyxw, c0.wwww ; r1 = indices w/ offset (DX8) ;---------------------------------------------------------------------------- ; Transform the position and normal for each bone ; v0 = position ; v3 = normal ;---------------------------------------------------------------------------- ; Get the index of the bone matrix [0] mov a0.x, r1.x ; Transform position and normal m4x3 r5, v0, c[a0.x + 14] m3x3 r6, v3, c[a0.x + 14] ; Blend them mul r5.xyz, r5.xyz, r0.xxx mul r6.xyz, r6.xyz, r0.xxx ; Get the index of the bone matrix [1] mov a0.x, r1.y ; Transform position and normal m4x3 r2, v0, c[a0.x + 14] m3x3 r3, v3, c[a0.x + 14] ; Blend them mad r5.xyz, r2.xyz, r0.yyy, r5.xyz mad r6.xyz, r3.xyz, r0.yyy, r6.xyz ; Get the index of the bone matrix [2] mov a0.x, r1.z ; Transform position and normal m4x3 r2, v0, c[a0.x + 14] m3x3 r3, v3, c[a0.x + 14] ; Blend them mad r5.xyz, r2.xyz, r0.zzz, r5.xyz mad r6.xyz, r3.xyz, r0.zzz, r6.xyz ; Get the index of the bone matrix [3] mov a0.x, r1.w ; Transform position and normal m4x3 r2, v0, c[a0.x + 14] m3x3 r3, v3, c[a0.x + 14] ; Blend them mad r5.xyz, r2, r0.wwww, r5 mad r6.xyz, r3, r0.wwww, r6 ;---------------------------------------------------------------------------- ; Transform the resulting position for the world ;---------------------------------------------------------------------------- mov r5.w, c0.x m4x4 oPos, r5, c10 ;---------------------------------------------------------------------------- ; Normalize the normal ;---------------------------------------------------------------------------- dp3 r11.x, r6.xyz, r6.xyz ; r11.x = length of normal rsq r11.xyz, r11.x ; r11.xyz = 1/sqrt(length of normal) mul r6.xyz, r6.xyz, r11.xyz ; r6 = normalized normal ;---------------------------------------------------------------------------- ; Lighting based on a SINGLE LIGHT!!!! ;---------------------------------------------------------------------------- mov oD0.xyzw, c2 ; Output color ;---------------------------------------------------------------------------- ; Just pass texture coordinates through ;---------------------------------------------------------------------------- mov oT0.xy, v5.xy dp3 r6.x , r6.xyz , c5.xyz max r6.x , r6.x , c0.z mov oT1.x, r6.x mov oT1.y, c0.y