1// --------------------------------------------------------------------------- 2// Project: NintendoWare 3// File: UserRenderCommandShader.vsh 4// 5// Copyright (C)2009-2011 Nintendo Co., Ltd. All rights reserved. 6// 7// These coded instructions, statements, and computer programs contain 8// proprietary information of Nintendo of America Inc. and/or Nintendo 9// Company Ltd., and are protected by Federal copyright law. They may 10// not be disclosed to third parties or copied or duplicated in any form, 11// in whole or in part, without the prior written consent of Nintendo. 12// 13// $Revision:$ 14// --------------------------------------------------------------------------- 15 16 17// Input registers map 18#define InputPos v0 19#define InputColor v1 20#define InputNormal v2 21 22// Output registers map 23#define OutputPosition o0 24#define OutputColor o1 25#define OutputQuaternion o2 26#define OutputView o3 27 28// Constant registers map 29#define WRLD_MAT c8 30#define PROJ_MAT c86 31#define VIEW_MAT c90 32 33#define TEMP_VEC1 r10 34#define TEMP_VEC2 r11 35#define TEMP_SRC_Z r12 36#define TEMP_QUATE r13 37#define TEMP_POS r14 38#define TEMP_VIEW r15 39 40#define ConstVec c93 41#define ConstZero ConstVec.xxxx 42#define ConstHalf ConstVec.yyyy 43#define ConstOne ConstVec.zzzz 44#define ConstInit ConstVec.xxxz 45 46// Constant registers 47def ConstVec, 0.0, 0.5, 1.0, 3.0 48 49// uniform 50#pragma bind_symbol(world, c8, c10) 51 52// 以下の 2 つのユニフォームは NintendoWare のレジスタ番号と一致させる必要があります 53#pragma bind_symbol(proj, c86, c89) 54#pragma bind_symbol(view, c90, c92) 55 56// input 57#pragma bind_symbol(Position.xyz, v0,v0) 58#pragma bind_symbol(Color.xyzw, v1,v1) 59#pragma bind_symbol(Normal, v2,v2) 60 61// output 62#pragma output_map (position, o0) 63#pragma output_map (color, o1) 64#pragma output_map (quaternion, o2 ) 65#pragma output_map (view, o3 ) 66 67main: 68 mov TEMP_POS, ConstInit 69 mov TEMP_VIEW, ConstInit 70 mov TEMP_POS.xyz, InputPos.xyz 71 m4x3 TEMP_VIEW.xyz, TEMP_POS, WRLD_MAT 72 m4x3 TEMP_POS.xyz, TEMP_VIEW, VIEW_MAT 73 m4x4 OutputPosition, TEMP_POS, PROJ_MAT 74 mov OutputView, -TEMP_POS 75 76 m3x3 TEMP_VIEW.xyz, InputNormal, WRLD_MAT 77 m3x3 TEMP_SRC_Z.xyz, TEMP_VIEW.xyz, VIEW_MAT 78 79 mov OutputColor, InputColor 80 81 dp3 r0.x, TEMP_SRC_Z, TEMP_SRC_Z 82 rsq r0.x, r0.x 83 mul TEMP_SRC_Z.xyz, TEMP_SRC_Z.xyz, r0.x 84 85 mov TEMP_QUATE, ConstZero 86 cmp 0, 0, TEMP_SRC_Z.z, -ConstOne // z == -1.0 87 ifc 0, 1, 2 88 add TEMP_VEC1, TEMP_SRC_Z.z, ConstOne // normal.z + 1.0 89 mul TEMP_VEC1, TEMP_VEC1, ConstHalf // 0.5 * (normal.z + 1.0) 90 rsq TEMP_VEC1, TEMP_VEC1.z // 1 / sqrt(0.5*(normal.z + 1.0)) 91 mul TEMP_VEC2.xy, TEMP_SRC_Z, ConstHalf // 0.5 * normal 92 rcp TEMP_QUATE.z, TEMP_VEC1.z // sqrt(0.5*(normal.z + 1.0)) 93 mul TEMP_QUATE.xy, TEMP_VEC2.xy, TEMP_VEC1.x // 0.5*normal / quaternion.z (クォータニオンからの展開時にきちんと、nrm = (mtx.31, mtx.32, mtx33) になる) 94 else 95 mov TEMP_QUATE.x, ConstOne // これで展開時に 0, 0, -1 になる 96 endif 97 98 mov OutputQuaternion, TEMP_QUATE 99 end 100endmain: 101