// --------------------------------------------------------------------------- // Project: NintendoWare // File: UserRenderCommandShader.vsh // // Copyright (C)2009-2011 Nintendo Co., Ltd. All rights reserved. // // These coded instructions, statements, and computer programs contain // proprietary information of Nintendo of America Inc. and/or Nintendo // Company Ltd., and are protected by Federal copyright law. They may // not be disclosed to third parties or copied or duplicated in any form, // in whole or in part, without the prior written consent of Nintendo. // // $Revision:$ // --------------------------------------------------------------------------- // Input registers map #define InputPos v0 #define InputColor v1 #define InputNormal v2 // Output registers map #define OutputPosition o0 #define OutputColor o1 #define OutputQuaternion o2 #define OutputView o3 // Constant registers map #define WRLD_MAT c8 #define PROJ_MAT c86 #define VIEW_MAT c90 #define TEMP_VEC1 r10 #define TEMP_VEC2 r11 #define TEMP_SRC_Z r12 #define TEMP_QUATE r13 #define TEMP_POS r14 #define TEMP_VIEW r15 #define ConstVec c93 #define ConstZero ConstVec.xxxx #define ConstHalf ConstVec.yyyy #define ConstOne ConstVec.zzzz #define ConstInit ConstVec.xxxz // Constant registers def ConstVec, 0.0, 0.5, 1.0, 3.0 // uniform #pragma bind_symbol(world, c8, c10) // 以下の 2 つのユニフォームは NintendoWare のレジスタ番号と一致させる必要があります #pragma bind_symbol(proj, c86, c89) #pragma bind_symbol(view, c90, c92) // input #pragma bind_symbol(Position.xyz, v0,v0) #pragma bind_symbol(Color.xyzw, v1,v1) #pragma bind_symbol(Normal, v2,v2) // output #pragma output_map (position, o0) #pragma output_map (color, o1) #pragma output_map (quaternion, o2 ) #pragma output_map (view, o3 ) main: mov TEMP_POS, ConstInit mov TEMP_VIEW, ConstInit mov TEMP_POS.xyz, InputPos.xyz m4x3 TEMP_VIEW.xyz, TEMP_POS, WRLD_MAT m4x3 TEMP_POS.xyz, TEMP_VIEW, VIEW_MAT m4x4 OutputPosition, TEMP_POS, PROJ_MAT mov OutputView, -TEMP_POS m3x3 TEMP_VIEW.xyz, InputNormal, WRLD_MAT m3x3 TEMP_SRC_Z.xyz, TEMP_VIEW.xyz, VIEW_MAT mov OutputColor, InputColor dp3 r0.x, TEMP_SRC_Z, TEMP_SRC_Z rsq r0.x, r0.x mul TEMP_SRC_Z.xyz, TEMP_SRC_Z.xyz, r0.x mov TEMP_QUATE, ConstZero cmp 0, 0, TEMP_SRC_Z.z, -ConstOne // z == -1.0 ifc 0, 1, 2 add TEMP_VEC1, TEMP_SRC_Z.z, ConstOne // normal.z + 1.0 mul TEMP_VEC1, TEMP_VEC1, ConstHalf // 0.5 * (normal.z + 1.0) rsq TEMP_VEC1, TEMP_VEC1.z // 1 / sqrt(0.5*(normal.z + 1.0)) mul TEMP_VEC2.xy, TEMP_SRC_Z, ConstHalf // 0.5 * normal rcp TEMP_QUATE.z, TEMP_VEC1.z // sqrt(0.5*(normal.z + 1.0)) mul TEMP_QUATE.xy, TEMP_VEC2.xy, TEMP_VEC1.x // 0.5*normal / quaternion.z (クォータニオンからの展開時にきちんと、nrm = (mtx.31, mtx.32, mtx33) になる) else mov TEMP_QUATE.x, ConstOne // これで展開時に 0, 0, -1 になる endif mov OutputQuaternion, TEMP_QUATE end endmain: