Post by olganix on Aug 9, 2016 18:35:12 GMT
Hi.
Let me explain you how to create a new Shader witch will work in game.
It's a little bit complex if you don't know about shaders.
if you don't know about shaders's coding, may be you should try to do some on Unity, Ogre, or another engine. Prefer training about Hlsl or Cg shader in our case.
Here my test with a pixelShader witch display direction of normal by using rgb = xyz.
First I have to check you have all needed background informations
a) In Character folder :
-emd files is meshes , with submeshes with each a material referenced into emm file.
-emm file could be converted into xml with LibXenoverse Tools : emmXml.exe. so you have something like that :
=> so you have the name of material, the name of the "shader" definition, and values of some of shader parameters, with X Y Z W for float4, and RGBA for colors.
-emb files are a pack of texture. could be decompressed with embpack.exe
-dyt.emb are map for switching color on the same character (depend of the version position of a character into the select character's menu).
-in emd file, you have information about the texture used (not for dyt.emb version) see xenoversemods.com/forums/topic/how-to-load-multiple-textures-from-a-single-emb/
b) into adam_shader folder :
-you have shader_age_ps.emz and shader_age_vs.emz. This files could be decompressed with emzpack.exe. That give a emb file, witch you could depack with embpack.exe. So you have xpu file for pixelShader, and xvu file for vertexShader, and you could use hlslasm.exe to have a "readeable" version in asm.
by ex, TOON_UNIF_STAIN2_DFD_W_VS.xvu.asm :
if, you have the force with you, you could try to understand all the shader (also as I have done of only one (2 days) using the links :
msdn.microsoft.com/en-us/library/windows/desktop/bb172963(v=vs.85).aspx
msdn.microsoft.com/en-us/library/windows/desktop/bb172920(v=vs.85).aspx
msdn.microsoft.com/en-us/library/windows/desktop/bb172938(v=vs.85).aspx
msdn.microsoft.com/en-us/library/windows/desktop/bb219845%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396 )
But it could be very long to read and modify this.
The only thing we could notice, that the declaration of shader parameters. we could see there is :
float4x4 g_mWVP_VS : is the World View Projection matrix. to have the final position vertex on the screen
float4x3 g_mMatrixPalette_VS[24] : is a array of matrix in world (or object) space (may be worldview). to move vertex in case of HardwareSkinning (not this case in Xenoviewer, just a question of performance)
float4 g_vEyePos_VS : position of the camera for light calculations.
This 3 parameters are only knowed by the game. With doing a list on all current shader (may be also on others games), we could have all possiblities of input.
-you also have technique_age_sds.emz. if you use emzpack.exe, with the current version, you will have "technique_age_sds.uncompressed", just rename extension ".sds". I have done a sdsXml.exe to make it readeable (xenoversemods.com/mods/sdsxml/). so you have something like this :
=> So you have the link of "shader" name from emm file , and the real vertexShader and pixelShader.
you also have some declaration of some parameter decalred into emm file (if you not take care of X , Y , Z , W , R, G ,B, A components).
So, to resume : Emd use material , witch use "shader" definition, with use vertex and pixel Shaders. There is a link done by the game between parameters definition into emm and sds files, and shaders files.
Note : I will made a programs witch analyze all material/sds/shaders to list unique names and try to link some of them to have a beautiful list of all possiblities of parameters in game.
2) The new shader
The goal is to make some new shader with the constraint of the game (like parameters names).
For my test, I only make a new pixelShader and use it into a "shader" definition (into sds file) to replace another pixelShader. But, if you want you could make a new material in emm file, add a new definition into sds file, and made a new vertex and pixel shader (and also apply the new material on a emd part with blender)
So first, I have made a new file, name "normal_ps.hlsl" :
I know by looking on Vertex Shader TOON_UNIF_STAIN2_DFD_W_VS.xvu.asm, that TEXCOORD1 is for normal direction BUT if you also made your own vertexShader, you will do what you want.
So I just have to use xyz information from normal as the final color. the (x+1) / 2.0 is for change the range [-1, 1] => [0,1], because color is about this last range.
In a second time, we have to compile it. For that, i use the tool fxc.exe. this tools is in DirectX SKD (june 2010), but also in Windows SDK for people witch are on Windows 8 or 10.
so I use the command :
C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Utilities\bin\x86>fxc.exe /T ps_3_0 /E normal_ps /Od /Fc D:\Tests\DragonBall_Xenoverse\normal_ps.xpu.asm D:\Tests\DragonBall_Xenoverse\normal_ps.hlsl
ps_3_0 is the version of the shader, don't change it please. or just vs_3_0 for vertexshader case.
normal_ps is the name of the fonction (it's when you have more than one shader in the file. it's use "main" if it's not defined)
It will made a file "normal_ps.xpu.asm". So you just have to convert it into xpu file by using hlslsasm.exe, and put him into shader_age_ps.emz pack.
Ok, we have the new shader. great. Now we have to use it. We just replace the use of a pixelShader for the test :
open technique_age_sds.sds.xml (keep the original, by copy/paste) , search for TOON_UNIF_STAIN2_DFD_W_VS, the name of the vertexShader with the good ouput for our pixelShader.
for all line founded : replace the pixelShader_name by "normal_ps".
So you just have to repack in technique_age_sds.sds, and after in technique_age_sds.emz, and test in game.
I will add in few hours another sample, a little bit more complex, witch use texture.
Hope the possiblity of modify shaders could motivate someone to do some look and feel modification.
I can't wait the guy witch will do realistic shading like this : images.google.fr/imgres?imgurl=http%3A%2F%2Fi.imgur.com%2FXFQPngH.jpg&imgrefurl=http%3A%2F%2Fwww.kanzenshuu.com%2Fforum%2Fviewtopic.php%3Ft%3D27405&h=1024&w=723&tbnid=dm2Gie44_hLhzM%3A&docid=bQTOlGXtcRm2ZM&ei=7BmqV9qoLcyya-zut_gN&tbm=isch&iact=rc&uact=3&dur=2170&page=1&start=0&ndsp=39&ved=0ahUKEwjaztLQ9LTOAhVM2RoKHWz3Dd8QMwgsKAcwBw&bih=927&biw=1298
Let me explain you how to create a new Shader witch will work in game.
It's a little bit complex if you don't know about shaders.
if you don't know about shaders's coding, may be you should try to do some on Unity, Ogre, or another engine. Prefer training about Hlsl or Cg shader in our case.
Here my test with a pixelShader witch display direction of normal by using rgb = xyz.
First I have to check you have all needed background informations
a) In Character folder :
-emd files is meshes , with submeshes with each a material referenced into emm file.
-emm file could be converted into xml with LibXenoverse Tools : emmXml.exe. so you have something like that :
<EMMMaterial name="bootsB_B" shader_name="TOON_UNIF_STAIN2_DFD">
<EMMParameter name="MatCol0R" type="0" value="0" />
<EMMParameter name="MatCol0G" type="0" value="0" />
<EMMParameter name="MatCol0B" type="0" value="0" />
.....
=> so you have the name of material, the name of the "shader" definition, and values of some of shader parameters, with X Y Z W for float4, and RGBA for colors.
-emb files are a pack of texture. could be decompressed with embpack.exe
-dyt.emb are map for switching color on the same character (depend of the version position of a character into the select character's menu).
-in emd file, you have information about the texture used (not for dyt.emb version) see xenoversemods.com/forums/topic/how-to-load-multiple-textures-from-a-single-emb/
b) into adam_shader folder :
-you have shader_age_ps.emz and shader_age_vs.emz. This files could be decompressed with emzpack.exe. That give a emb file, witch you could depack with embpack.exe. So you have xpu file for pixelShader, and xvu file for vertexShader, and you could use hlslasm.exe to have a "readeable" version in asm.
by ex, TOON_UNIF_STAIN2_DFD_W_VS.xvu.asm :
//
// Generated by Microsoft (R) D3DX9 Shader Compiler 9.15.779.0000
//
// Parameters:
//
// bool g_bSkinning_VS;
// float4x3 g_mMatrixPalette_VS[24];
// float4x4 g_mWVP_VS;
// float4 g_vEyePos_VS;
//
//
// Registers:
//
// Name Reg Size
// ------------------- ----- ----
// g_bSkinning_VS b0 1
// g_mWVP_VS c0 4
// g_vEyePos_VS c72 1
// g_mMatrixPalette_VS c104 72
//
vs_3_0
def c4, 3, 1, 0, 0
dcl_position v0
dcl_normal v1
dcl_texcoord v2
dcl_blendindices v3
dcl_blendweight v4
dcl_position o0
dcl_texcoord o1.xy
dcl_texcoord1 o2.xyz
dcl_texcoord2 o3.xyz
dcl_texcoord4 o4.xyz
dcl_texcoord6 o5
mov o1.xy, v2
if b0
mul r0, c4.x, v3
mova a0, r0
add r1.w, v4.y, v4.x
mul r0, c106[a0.y], v4.y
add r1.w, r1.w, v4.z
mad r0, c106[a0.x], v4.x, r0
add r2.w, -r1.w, c4.y
mad r0, c106[a0.z], v4.z, r0
mad r1, c106[a0.w], r2.w, r0
dp3 o2.z, v1, r1
mad r0, v0.xyzx, c4.yyyz, c4.zzzy
dp4 r2.z, r0, r1
mul r1, c104[a0.y], v4.y
mad r3, c104[a0.x], v4.x, r1
mul r1, c105[a0.y], v4.y
mad r3, c104[a0.z], v4.z, r3
mad r1, c105[a0.x], v4.x, r1
mad r3, c104[a0.w], r2.w, r3
mad r1, c105[a0.z], v4.z, r1
dp3 o2.x, v1, r3
mad r1, c105[a0.w], r2.w, r1
dp4 r2.x, r0, r3
dp3 o2.y, v1, r1
dp4 r2.y, r0, r1
mov r2.w, c4.y
mov r1.xyz, r2
dp4 r0.w, r2, c3
dp4 r0.x, r2, c0
dp4 r0.y, r2, c1
dp4 r0.z, r2, c2
else
mad r1, v0.xyzx, c4.yyyz, c4.zzzy
mov o2.xyz, v1
dp4 r0.w, r1, c3
dp4 r0.x, r1, c0
dp4 r0.y, r1, c1
dp4 r0.z, r1, c2
mov r1.xyz, v0
endif
mov o5, r0
mov o4.xyz, r1
add o3.xyz, -r1, c72
mov o0, r0
// approximately 47 instruction slots used
if, you have the force with you, you could try to understand all the shader (also as I have done of only one (2 days) using the links :
msdn.microsoft.com/en-us/library/windows/desktop/bb172963(v=vs.85).aspx
msdn.microsoft.com/en-us/library/windows/desktop/bb172920(v=vs.85).aspx
msdn.microsoft.com/en-us/library/windows/desktop/bb172938(v=vs.85).aspx
msdn.microsoft.com/en-us/library/windows/desktop/bb219845%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396 )
But it could be very long to read and modify this.
The only thing we could notice, that the declaration of shader parameters. we could see there is :
float4x4 g_mWVP_VS : is the World View Projection matrix. to have the final position vertex on the screen
float4x3 g_mMatrixPalette_VS[24] : is a array of matrix in world (or object) space (may be worldview). to move vertex in case of HardwareSkinning (not this case in Xenoviewer, just a question of performance)
float4 g_vEyePos_VS : position of the camera for light calculations.
This 3 parameters are only knowed by the game. With doing a list on all current shader (may be also on others games), we could have all possiblities of input.
-you also have technique_age_sds.emz. if you use emzpack.exe, with the current version, you will have "technique_age_sds.uncompressed", just rename extension ".sds". I have done a sdsXml.exe to make it readeable (xenoversemods.com/mods/sdsxml/). so you have something like this :
<SDSShaderProgram name="TOON_UNIF_STAIN2_DFD" vertexShader_name="TOON_UNIF_STAIN2_DFD_W_VS" pixelShader_name="TOON_UNIF_STAIN2_DFD_PS">
<SDSParameter name="WVP" type="MtxP" />
<SDSParameter name="EyePos_VS" type="GblP" />
<SDSParameter name="FadeColor" type="GblP" />
<SDSParameter name="LightVec0_PS" type="GblP" />
<SDSParameter name="SkinningEnable" type="GblP" />
<SDSParameter name="MatCol0_PS" type="PsP" />
<SDSParameter name="MatCol1_PS" type="PsP" />
<SDSParameter name="MatCol3_PS" type="PsP" />
<SDSParameter name="MatScale0_PS" type="PsP" />
<SDSParameter name="MatScale1_PS" type="PsP" />
</SDSShaderProgram>
=> So you have the link of "shader" name from emm file , and the real vertexShader and pixelShader.
you also have some declaration of some parameter decalred into emm file (if you not take care of X , Y , Z , W , R, G ,B, A components).
So, to resume : Emd use material , witch use "shader" definition, with use vertex and pixel Shaders. There is a link done by the game between parameters definition into emm and sds files, and shaders files.
Note : I will made a programs witch analyze all material/sds/shaders to list unique names and try to link some of them to have a beautiful list of all possiblities of parameters in game.
2) The new shader
The goal is to make some new shader with the constraint of the game (like parameters names).
For my test, I only make a new pixelShader and use it into a "shader" definition (into sds file) to replace another pixelShader. But, if you want you could make a new material in emm file, add a new definition into sds file, and made a new vertex and pixel shader (and also apply the new material on a emd part with blender)
So first, I have made a new file, name "normal_ps.hlsl" :
void normal_ps( float4 sPosition : SV_Position,
float3 texcoord : TEXCOORD0,
float3 normal : TEXCOORD1,
out float4 color : SV_Target
)
{
color.xyz = (normal.xyz + float3(1,1,1)) / 2.0;
color.w = 1;
}
I know by looking on Vertex Shader TOON_UNIF_STAIN2_DFD_W_VS.xvu.asm, that TEXCOORD1 is for normal direction BUT if you also made your own vertexShader, you will do what you want.
So I just have to use xyz information from normal as the final color. the (x+1) / 2.0 is for change the range [-1, 1] => [0,1], because color is about this last range.
In a second time, we have to compile it. For that, i use the tool fxc.exe. this tools is in DirectX SKD (june 2010), but also in Windows SDK for people witch are on Windows 8 or 10.
so I use the command :
C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Utilities\bin\x86>fxc.exe /T ps_3_0 /E normal_ps /Od /Fc D:\Tests\DragonBall_Xenoverse\normal_ps.xpu.asm D:\Tests\DragonBall_Xenoverse\normal_ps.hlsl
ps_3_0 is the version of the shader, don't change it please. or just vs_3_0 for vertexshader case.
normal_ps is the name of the fonction (it's when you have more than one shader in the file. it's use "main" if it's not defined)
It will made a file "normal_ps.xpu.asm". So you just have to convert it into xpu file by using hlslsasm.exe, and put him into shader_age_ps.emz pack.
Ok, we have the new shader. great. Now we have to use it. We just replace the use of a pixelShader for the test :
open technique_age_sds.sds.xml (keep the original, by copy/paste) , search for TOON_UNIF_STAIN2_DFD_W_VS, the name of the vertexShader with the good ouput for our pixelShader.
for all line founded : replace the pixelShader_name by "normal_ps".
So you just have to repack in technique_age_sds.sds, and after in technique_age_sds.emz, and test in game.
I will add in few hours another sample, a little bit more complex, witch use texture.
Hope the possiblity of modify shaders could motivate someone to do some look and feel modification.
I can't wait the guy witch will do realistic shading like this : images.google.fr/imgres?imgurl=http%3A%2F%2Fi.imgur.com%2FXFQPngH.jpg&imgrefurl=http%3A%2F%2Fwww.kanzenshuu.com%2Fforum%2Fviewtopic.php%3Ft%3D27405&h=1024&w=723&tbnid=dm2Gie44_hLhzM%3A&docid=bQTOlGXtcRm2ZM&ei=7BmqV9qoLcyya-zut_gN&tbm=isch&iact=rc&uact=3&dur=2170&page=1&start=0&ndsp=39&ved=0ahUKEwjaztLQ9LTOAhVM2RoKHWz3Dd8QMwgsKAcwBw&bih=927&biw=1298