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 CTR vertex shaders can be programmed by users.<br/> Using 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 in <CODE>$(NW4C_ROOT)\SampleData\Graphics\Shader\UserShader</CODE> or <CODE>$(NW4C_ROOT)\SampleData\Graphics\Shader\JShader</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 <CODE>$(NW4C_ROOT)\SampleData\Graphics\Shader\UserShader</CODE>.<br/> <CODE>UserShader</CODE> 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 to customize and the header file from the <CODE>$(NW4C_ROOT)\sources\shaders\gfx\DefaultShader</CODE> directory. 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><CODE>gfx_DefaultShader0.vsh</CODE></td><td><CODE>gfx_UserShader.vsh</CODE></td></tr> 23 <tr><td><CODE>TransformMatrix.vsh</CODE></td><td><CODE>UserTransformMatrix.vsh</CODE></td></tr> 24 <tr><td><CODE>CalcColor.vsh</CODE></td><td><CODE>UserCalcColor.vsh</CODE></td></tr> 25 <tr><td><CODE>ShaderConfig.h</CODE></td><td>Do not change (must be copied for each shader)</td></tr> 26 </table> 27 </li> 28 <li>Change the <a href="ShaderRegister.html">Shader Register List</a> in <CODE>ShaderConfig.h</CODE>.<br/> First, eliminate two vertex lights (Register 12).<br/> Change the line <CODE>define new_user_register_start</CODE> from a value of <CODE>c60</CODE> to a value of <CODE>c48</CODE>.<br/> Next, add register <CODE>c22</CODE> to <CODE>extension_deform</CODE> and <CODE>c74</CODE> to <CODE>extension_color</CODE>.<br/><br/> 29 </li> 30 <li>Define symbols for the registers to add in the <CODE>gfx_UserShader.vsh</CODE> file.<br/> Now, define <CODE>#pragma bind_symbol(NDeform, c22, c22)</CODE> as a register for extending a vertex in the normal vector direction, and add <CODE>#pragma bind_symbol(ExColor, c74, c74)</CODE> as a register for adjusting the output color. You can also reduce the number of vertex lights to make the universal register region available for users.<br/> Change <CODE>#pragma bind_symbol(UnivReg, c25, c84)</CODE> to <CODE>#pragma bind_symbol(UnivReg, c25, c73)</CODE>.<br/><br/> 31 </li> 32 <li>Add a process that uses the registers that have been added.<br/> In this tutorial, we have revised <CODE>UserTransformMatrix.vsh</CODE> and <CODE>UserCalcColor.vsh</CODE>.<br/><br/> 33 </li> 34 <li>Execute the following commands to convert the shader created into a shader binary.<br/> In this tutorial, files that are not customized are referenced from environmental variables.<br/> The order in which <CODE>ctr_VertexShaderLinker32</CODE> links shaders is the same as when shader types are assigned when creating the shader intermediate file.<br/><br/> 35 <p class="notice"> 36 <CODE>$(CTRSDK_ROOT)\tools\CommandLineTools\ctr_VertexShaderAssembler32.exe gfx_UserShader.vsh -I$(NW4C_ROOT)\sources\shaders\gfx<br/> $(CTRSDK_ROOT)\tools\CommandLineTools\ctr_VertexShaderAssembler32.exe UserTransformMatrix.vsh -I$(NW4C_ROOT)\sources\shaders\gfx<br/> $(CTRSDK_ROOT)\tools\CommandLineTools\ctr_VertexShaderAssembler32.exe UserCalcColor.vsh -I$(NW4C_ROOT)\sources\shaders\gfx<br/> $(CTRSDK_ROOT)\tools\CommandLineTools\ctr_VertexShaderAssembler32.exe $(NW4C_ROOT)\sources\shaders\gfx\DefaultShader\CalcTexcoord0.vsh -I$(NW4C_ROOT)\sources\shaders\gfx<br/> $(CTRSDK_ROOT)\tools\CommandLineTools\ctr_VertexShaderAssembler32.exe $(NW4C_ROOT)\sources\shaders\gfx\DefaultShader\CalcTexcoord1.vsh -I$(NW4C_ROOT)\sources\shaders\gfx<br/> $(CTRSDK_ROOT)\tools\CommandLineTools\ctr_VertexShaderAssembler32.exe $(NW4C_ROOT)\sources\shaders\gfx\DefaultShader\CalcTexcoord2.vsh -I$(NW4C_ROOT)\sources\shaders\gfx<br/> $(CTRSDK_ROOT)\tools\CommandLineTools\ctr_VertexShaderAssembler32.exe $(NW4C_ROOT)\sources\shaders\gfx\DefaultShader\CalcQuaternion.vsh -I$(NW4C_ROOT)\sources\shaders\gfx<br/> $(CTRSDK_ROOT)\tools\CommandLineTools\ctr_VertexShaderAssembler32.exe $(NW4C_ROOT)\sources\shaders\gfx\DefaultShader\GetTexcoordSource.vsh -I$(NW4C_ROOT)\sources\shaders\gfx<br/> $(CTRSDK_ROOT)\tools\CommandLineTools\ctr_VertexShaderAssembler32.exe $(NW4C_ROOT)\sources\shaders\gfx\DefaultShader\CalcVertexLighting.vsh -I$(NW4C_ROOT)\sources\shaders\gfx<br/> $(CTRSDK_ROOT)\tools\CommandLineTools\ctr_VertexShaderAssembler32.exe $(NW4C_ROOT)\sources\shaders\gfx\DefaultShader\CalcHemisphereLighting.vsh -I$(NW4C_ROOT)\sources\shaders\gfx<br/> $(CTRSDK_ROOT)\tools\CommandLineTools\ctr_VertexShaderAssembler32.exe $(NW4C_ROOT)\sources\shaders\gfx\DefaultShader\GenTexcoordReflection.vsh -I$(NW4C_ROOT)\sources\shaders\gfx<br/> $(CTRSDK_ROOT)\tools\CommandLineTools\ctr_VertexShaderAssembler32.exe $(NW4C_ROOT)\sources\shaders\gfx\DefaultShader\GenTexcoordSphereReflection.vsh -I$(NW4C_ROOT)\sources\shaders\gfx<br/> <br/> $(CTRSDK_ROOT)\tools\CommandLineTools\ctr_VertexShaderLinker32.exe gfx_UserShader.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/></CODE> 37 </p> 38 </li> 39 <li>Use CreativeStudio to create an intermediate file from <CODE>UserShader.shbin</CODE>.<br/> For information on how to create an intermediate file, refer to the <a href="ShaderBind.html">Procedure for Switching Shaders</a>. 40 </li> 41 <li>Bind the created intermediate file to a model and check using <CODE>Viewer</CODE> or another tool.<br/> The figure below shows the results of applying <CODE>UserShader</CODE> to <CODE>Male</CODE>.<br/><br/> <img src="images/male_with_shader.png" border="0" width="400" height="240"/> <br/><br/> 42 </li> 43 </ol> 44 </div> 45 <hr><p>CONFIDENTIAL</p></body> 46</html> 47