1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2<html xml:lang="en-US" lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
3  <head>
4    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5    <meta http-equiv="Content-Style-Type" content="text/css" />
6    <link rel="stylesheet" href="../../css/document.css" type="text/css" />
7    <title>Creating Shaders</title>
8  </head>
9  <body>
10    <h1>Creating Shaders</h1>
11    <h2>User Shaders</h2>
12    <div class="section">
13        With CTR, vertex shaders can be programmed by users.<br> Under NW4C, some registers can be used by users to customize shaders. This type of shader is called a <EM>user shader</EM>. Refer to the sample data for a user shader in <CODE>$(NW4C_ROOT)\SampleData\Graphics\Shader\UserShader</CODE>.<br> For a list of registers available for use by users, see <a href="ShaderRegister.html">Shader Register List</a>.<br> For information on switching shaders under CreativeStudio, see <a href="ShaderBind.html">Procedure for Switching Shaders</a>.
14    </div>
15    <h2>Shader Creation Tutorial</h2>
16    <div class="section">
17      This section describes the procedure up to and including creating $(NW4C_ROOT)\SampleData\Graphics\Shader\UserShader.<br> UserShader adds a feature for extending vertex coordinates in the normal vector direction and a feature for adding a particular color to the output color.<br> The features are added by limiting the number of vertex lights and hemispherical light capability.<br><br>
18      <ol>
19      	<li>Copy the default shader serving as the shader source from $(NW4C_ROOT)\sources\shaders\gfx\DefaultShader  and the header file from $(NW4C_ROOT)\sources\shaders\gfx.<br> Now, copy the files in the following table and rename them as shown.<br>
20        <table>
21          <tr><th>Files to copy</th><th>Rename as</th></tr>
22          <tr><td>gfx_DefaultShader0.vsh</td><td>gfx_UserShader0.vsh</td></tr>
23          <tr><td>gfx_DefaultShader1.vsh</td><td>gfx_UserShader1.vsh</td></tr>
24          <tr><td>gfx_DefaultShader2.vsh</td><td>gfx_UserShader2.vsh</td></tr>
25          <tr><td>gfx_DefaultShader3.vsh</td><td>gfx_UserShader3.vsh</td></tr>
26          <tr><td>TransformMatrix.vsh</td><td>UserTransformMatrix.vsh</td></tr>
27          <tr><td>CalcColor.vsh</td><td>UserCalcColor.vsh</td></tr>
28          <tr><td>CalcHemisphereLighting.vsh</td><td>No change</td></tr>
29          <tr><td>CalcQuaternion.vsh</td><td>No change</td></tr>
30          <tr><td>CalcVertexLighting.vsh</td><td>No change</td></tr>
31          <tr><td>CalcTexcoord0.vsh</td><td>No change</td></tr>
32          <tr><td>CalcTexcoord1.vsh</td><td>No change</td></tr>
33          <tr><td>CalcTexcoord2.vsh</td><td>No change</td></tr>
34          <tr><td>GenTexcoordReflection.vsh</td><td>No change</td></tr>
35          <tr><td>GenTexcoordSphereReflection.vsh</td><td>No change</td></tr>
36          <tr><td>GetTexcoordSource.vsh</td><td>No change</td></tr>
37          <tr><td>VertexShader.h</td><td>No change</td></tr>
38          <tr><td>ShaderConfig.h</td><td>No change</td></tr>
39        </table>
40      	</li>
41      	<li>Change the <a href="ShaderRegister.html">Shader Register List</a> in ShaderConfig.h.<br> First, illuminate two vertex lights (Register 12).<br> On the line, define new_user_register_start, change c60 to c48.<br> Next, for registers to be added, add c22 to extension_deform and c74 to extension_color.<br><br>
42      	</li>
43      	<li>Define all register symbols to be added to gfx_UserShader0.vsh, gfx_UserShader1.vsh, gfx_UserShader2.vsh, and gfx_UserShader3.vsh.<br> Now, define <CODE>#pragma bind_symbol(NDeform, c22, c22)</CODE> as a register for extending vertex coordinates in the normal vector direction, and add <CODE>#pragma bind_symbol(ExColor, c74, c74)</CODE>  as a register for adjusting the output color.  Also, users may use the universal register region to reduce the number of vertex lights.<br> Change <CODE>#pragma bind_symbol(UnivReg, c25, c84)</CODE> to <CODE>#pragma bind_symbol(UnivReg, c25, c73)</CODE>.<br><br>
44      	</li>
45      	<li>Add a process that uses the registers that have been added.<br> Here, we have revised UserTransformMatrix.vsh and UserCalcColor.vsh.<br><br>
46      	</li>
47      	<li>Exectue the following command to convert the shader created into a shader binary.<br> The order in which shaders are linked by ctr_VertexShaderLinker32 is the same as that when shader types are assigned when creating the shader intermediate file.
48      	<p class="notice">
49      	$(CTRSDK_ROOT)\tools\CommandLineTools\ctr_VertexShaderAssembler32.exe gfx_UserShader0.vsh<br> $(CTRSDK_ROOT)\tools\CommandLineTools\ctr_VertexShaderAssembler32.exe gfx_UserShader1.vsh<br> $(CTRSDK_ROOT)\tools\CommandLineTools\ctr_VertexShaderAssembler32.exe gfx_UserShader2.vsh<br> $(CTRSDK_ROOT)\tools\CommandLineTools\ctr_VertexShaderAssembler32.exe gfx_UserShader3.vsh<br> $(CTRSDK_ROOT)\tools\CommandLineTools\ctr_VertexShaderAssembler32.exe UserTransformMatrix.vsh<br> $(CTRSDK_ROOT)\tools\CommandLineTools\ctr_VertexShaderAssembler32.exe UserCalcColor.vsh<br> $(CTRSDK_ROOT)\tools\CommandLineTools\ctr_VertexShaderAssembler32.exe CalcHemisphereLighting.vsh<br> $(CTRSDK_ROOT)\tools\CommandLineTools\ctr_VertexShaderAssembler32.exe CalcQuaternion.vsh<br> $(CTRSDK_ROOT)\tools\CommandLineTools\ctr_VertexShaderAssembler32.exe CalcVertexLighting.vsh<br> $(CTRSDK_ROOT)\tools\CommandLineTools\ctr_VertexShaderAssembler32.exe CalcTexcoord0.vsh<br> $(CTRSDK_ROOT)\tools\CommandLineTools\ctr_VertexShaderAssembler32.exe CalcTexcoord1.vsh<br> $(CTRSDK_ROOT)\tools\CommandLineTools\ctr_VertexShaderAssembler32.exe CalcTexcoord2.vsh<br> $(CTRSDK_ROOT)\tools\CommandLineTools\ctr_VertexShaderAssembler32.exe GenTexcoordReflection.vsh<br> $(CTRSDK_ROOT)\tools\CommandLineTools\ctr_VertexShaderAssembler32.exe GenTexcoordSphereReflection.vsh<br> $(CTRSDK_ROOT)\tools\CommandLineTools\ctr_VertexShaderAssembler32.exe GetTexcoordSource.vsh<br> <br> $(CTRSDK_ROOT)\tools\CommandLineTools\ctr_VertexShaderLinker32.exe gfx_UserShader0.obj gfx_UserShader1.obj gfx_UserShader2.obj gfx_UserShader3.obj UserTransformMatrix.obj UserCalcColor.obj CalcTexcoord0.obj CalcTexcoord1.obj CalcTexcoord2.obj CalcQuaternion.obj GetTexcoordSource.obj CalcHemisphereLighting.obj CalcVertexLighting.obj GenTexcoordReflection.obj GenTexcoordSphereReflection.obj -OUserShader.shbin<br>
50      	</p>
51      	</li>
52      	<li>Create an intermediate file from UserShader.shbin using CreativeStudio.<br> For information on how to create an intermediate file, refer to the <a href="ShaderBind.html">procedure for switching shaders</a>.
53      	</li>
54      	<li>If you bind the created intermediate file to a model, check using gfxviewer.<br> In the figure below, UserSharder has been applied to human_lite_walk.<br><br> <img src="images/human_heavy_walk.png" border="0" alt="human_heavy_walk.png(41242 byte)" width="300" height="300"> <br><br>
55      	</li>
56      </ol>
57    </div>
58  <hr><p>CONFIDENTIAL</p></body>
59</html>