Wrote the Skinned.fx shader for Dx10, Dx11 and Metro (the class however is not yet implemented)

This commit is contained in:
SND\AstrorEnales_cp 2012-09-09 19:59:18 +00:00
parent 9b842c7fd8
commit 0251a7a2e7
15 changed files with 30801 additions and 8630 deletions

View File

@ -48,7 +48,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DX10", "DX10", "{CCB4679D-1
shader\DX10\EnvironmentMap.fx = shader\DX10\EnvironmentMap.fx
shader\DX10\Skinned.fx = shader\DX10\Skinned.fx
shader\DX10\SpriteBatch.fx = shader\DX10\SpriteBatch.fx
shader\DX10\Structures.fxh = shader\DX10\Structures.fxh
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "GL3", "GL3", "{E4FFD875-95FC-48F2-8B6D-8483D0B71666}"
@ -113,6 +112,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DX11", "DX11", "{6285F3EF-07DB-49C9-8CDE-A9092789FE4F}"
ProjectSection(SolutionItems) = preProject
shader\DX11\AlphaTest.fx = shader\DX11\AlphaTest.fx
shader\DX11\BasicEffect.fx = shader\DX11\BasicEffect.fx
shader\DX11\build.xml = shader\DX11\build.xml
shader\DX11\DualTexture.fx = shader\DX11\DualTexture.fx
shader\DX11\EnvironmentMap.fx = shader\DX11\EnvironmentMap.fx
@ -167,6 +167,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Metro", "Metro", "{32B91ACB
shader\Metro\build.xml = shader\Metro\build.xml
shader\Metro\DualTexture.fx = shader\Metro\DualTexture.fx
shader\Metro\EnvironmentMap.fx = shader\Metro\EnvironmentMap.fx
shader\Metro\Skinned.fx = shader\Metro\Skinned.fx
shader\Metro\SpriteBatch.fx = shader\Metro\SpriteBatch.fx
EndProjectSection
EndProject

View File

@ -48,7 +48,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DX10", "DX10", "{CCB4679D-1
shader\DX10\EnvironmentMap.fx = shader\DX10\EnvironmentMap.fx
shader\DX10\Skinned.fx = shader\DX10\Skinned.fx
shader\DX10\SpriteBatch.fx = shader\DX10\SpriteBatch.fx
shader\DX10\Structures.fxh = shader\DX10\Structures.fxh
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "GL3", "GL3", "{E4FFD875-95FC-48F2-8B6D-8483D0B71666}"
@ -113,6 +112,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DX11", "DX11", "{6285F3EF-07DB-49C9-8CDE-A9092789FE4F}"
ProjectSection(SolutionItems) = preProject
shader\DX11\AlphaTest.fx = shader\DX11\AlphaTest.fx
shader\DX11\BasicEffect.fx = shader\DX11\BasicEffect.fx
shader\DX11\build.xml = shader\DX11\build.xml
shader\DX11\DualTexture.fx = shader\DX11\DualTexture.fx
shader\DX11\EnvironmentMap.fx = shader\DX11\EnvironmentMap.fx
@ -167,6 +167,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Metro", "Metro", "{32B91ACB
shader\Metro\build.xml = shader\Metro\build.xml
shader\Metro\DualTexture.fx = shader\Metro\DualTexture.fx
shader\Metro\EnvironmentMap.fx = shader\Metro\EnvironmentMap.fx
shader\Metro\Skinned.fx = shader\Metro\Skinned.fx
shader\Metro\SpriteBatch.fx = shader\Metro\SpriteBatch.fx
EndProjectSection
EndProject

View File

@ -48,7 +48,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DX10", "DX10", "{CCB4679D-1
shader\DX10\EnvironmentMap.fx = shader\DX10\EnvironmentMap.fx
shader\DX10\Skinned.fx = shader\DX10\Skinned.fx
shader\DX10\SpriteBatch.fx = shader\DX10\SpriteBatch.fx
shader\DX10\Structures.fxh = shader\DX10\Structures.fxh
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "GL3", "GL3", "{E4FFD875-95FC-48F2-8B6D-8483D0B71666}"
@ -113,6 +112,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DX11", "DX11", "{6285F3EF-07DB-49C9-8CDE-A9092789FE4F}"
ProjectSection(SolutionItems) = preProject
shader\DX11\AlphaTest.fx = shader\DX11\AlphaTest.fx
shader\DX11\BasicEffect.fx = shader\DX11\BasicEffect.fx
shader\DX11\build.xml = shader\DX11\build.xml
shader\DX11\DualTexture.fx = shader\DX11\DualTexture.fx
shader\DX11\EnvironmentMap.fx = shader\DX11\EnvironmentMap.fx
@ -167,6 +167,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Metro", "Metro", "{32B91ACB
shader\Metro\build.xml = shader\Metro\build.xml
shader\Metro\DualTexture.fx = shader\Metro\DualTexture.fx
shader\Metro\EnvironmentMap.fx = shader\Metro\EnvironmentMap.fx
shader\Metro\Skinned.fx = shader\Metro\Skinned.fx
shader\Metro\SpriteBatch.fx = shader\Metro\SpriteBatch.fx
EndProjectSection
EndProject

View File

@ -48,7 +48,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DX10", "DX10", "{CCB4679D-1
shader\DX10\EnvironmentMap.fx = shader\DX10\EnvironmentMap.fx
shader\DX10\Skinned.fx = shader\DX10\Skinned.fx
shader\DX10\SpriteBatch.fx = shader\DX10\SpriteBatch.fx
shader\DX10\Structures.fxh = shader\DX10\Structures.fxh
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "GL3", "GL3", "{E4FFD875-95FC-48F2-8B6D-8483D0B71666}"
@ -113,6 +112,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DX11", "DX11", "{6285F3EF-07DB-49C9-8CDE-A9092789FE4F}"
ProjectSection(SolutionItems) = preProject
shader\DX11\AlphaTest.fx = shader\DX11\AlphaTest.fx
shader\DX11\BasicEffect.fx = shader\DX11\BasicEffect.fx
shader\DX11\build.xml = shader\DX11\build.xml
shader\DX11\DualTexture.fx = shader\DX11\DualTexture.fx
shader\DX11\EnvironmentMap.fx = shader\DX11\EnvironmentMap.fx
@ -167,6 +167,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Metro", "Metro", "{32B91ACB
shader\Metro\build.xml = shader\Metro\build.xml
shader\Metro\DualTexture.fx = shader\Metro\DualTexture.fx
shader\Metro\EnvironmentMap.fx = shader\Metro\EnvironmentMap.fx
shader\Metro\Skinned.fx = shader\Metro\Skinned.fx
shader\Metro\SpriteBatch.fx = shader\Metro\SpriteBatch.fx
EndProjectSection
EndProject

View File

@ -144,23 +144,24 @@ namespace ANX.RenderSystem.Windows.DX10
public byte[] GetShaderByteCode(PreDefinedShader type)
{
PreventSystemChange();
switch (type)
{
case PreDefinedShader.SpriteBatch:
return ShaderByteCode.SpriteBatchByteCode;
case PreDefinedShader.AlphaTestEffect:
return ShaderByteCode.AlphaTestEffectByteCode;
case PreDefinedShader.BasicEffect:
return ShaderByteCode.BasicEffectByteCode;
case PreDefinedShader.DualTextureEffect:
return ShaderByteCode.DualTextureEffectByteCode;
case PreDefinedShader.AlphaTestEffect:
return ShaderByteCode.AlphaTestEffectByteCode;
case PreDefinedShader.EnvironmentMapEffect:
return ShaderByteCode.EnvironmentMapEffectByteCode;
case PreDefinedShader.BasicEffect:
return ShaderByteCode.BasicEffectByteCode;
case PreDefinedShader.SkinnedEffect:
return ShaderByteCode.SkinnedEffectByteCode;
}
throw new NotImplementedException("ByteCode for '" + type + "' is not yet available");
throw new NotImplementedException("ByteCode for built-in effect '" + type + "' is not yet available.");
}
#endregion

File diff suppressed because it is too large Load Diff

View File

@ -135,32 +135,23 @@ namespace ANX.RenderSystem.Windows.DX11
{
PreventSystemChange();
if (type == PreDefinedShader.SpriteBatch)
switch (type)
{
return ShaderByteCode.SpriteBatchByteCode;
}
else if (type == PreDefinedShader.AlphaTestEffect)
{
return ShaderByteCode.AlphaTestEffectByteCode;
}
else if (type == PreDefinedShader.BasicEffect)
{
return ShaderByteCode.BasicEffectByteCode;
}
else if (type == PreDefinedShader.DualTextureEffect)
{
return ShaderByteCode.DualTextureEffectByteCode;
}
else if (type == PreDefinedShader.EnvironmentMapEffect)
{
return ShaderByteCode.EnvironmentMapEffectByteCode;
}
else if (type == PreDefinedShader.SkinnedEffect)
{
return ShaderByteCode.SkinnedEffectByteCode;
case PreDefinedShader.SpriteBatch:
return ShaderByteCode.SpriteBatchByteCode;
case PreDefinedShader.DualTextureEffect:
return ShaderByteCode.DualTextureEffectByteCode;
case PreDefinedShader.AlphaTestEffect:
return ShaderByteCode.AlphaTestEffectByteCode;
case PreDefinedShader.EnvironmentMapEffect:
return ShaderByteCode.EnvironmentMapEffectByteCode;
case PreDefinedShader.BasicEffect:
return ShaderByteCode.BasicEffectByteCode;
case PreDefinedShader.SkinnedEffect:
return ShaderByteCode.SkinnedEffectByteCode;
}
throw new NotImplementedException("ByteCode for '" + type + "' is not yet available");
throw new NotImplementedException("ByteCode for built-in effect '" + type + "' is not yet available.");
}
#endregion

File diff suppressed because it is too large Load Diff

View File

@ -40,76 +40,64 @@ namespace ANX.RenderSystem.Windows.Metro
#endregion
#region CreateGraphicsDevice
public INativeGraphicsDevice CreateGraphicsDevice(
PresentationParameters presentationParameters)
public INativeGraphicsDevice CreateGraphicsDevice(PresentationParameters presentationParameters)
{
PreventSystemChange();
return new GraphicsDeviceWindowsMetro(presentationParameters);
}
#endregion
#region CreateIndexBuffer
public INativeIndexBuffer CreateIndexBuffer(GraphicsDevice graphics,
IndexBuffer managedBuffer, IndexElementSize size, int indexCount,
BufferUsage usage)
public INativeIndexBuffer CreateIndexBuffer(GraphicsDevice graphics, IndexBuffer managedBuffer, IndexElementSize size,
int indexCount, BufferUsage usage)
{
PreventSystemChange();
return new IndexBuffer_Metro(graphics, size, indexCount, usage);
}
#endregion
#region CreateVertexBuffer
public INativeVertexBuffer CreateVertexBuffer(GraphicsDevice graphics,
VertexBuffer managedBuffer, VertexDeclaration vertexDeclaration,
int vertexCount, BufferUsage usage)
public INativeVertexBuffer CreateVertexBuffer(GraphicsDevice graphics, VertexBuffer managedBuffer,
VertexDeclaration vertexDeclaration, int vertexCount, BufferUsage usage)
{
PreventSystemChange();
return new VertexBuffer_Metro(graphics, vertexDeclaration, vertexCount, usage);
}
#endregion
#if XNAEXT
#region CreateConstantBuffer
public INativeConstantBuffer CreateConstantBuffer(GraphicsDevice graphics, ConstantBuffer managedBuffer, BufferUsage usage)
{
public INativeConstantBuffer CreateConstantBuffer(GraphicsDevice graphics, ConstantBuffer managedBuffer,
BufferUsage usage)
{
PreventSystemChange();
throw new NotImplementedException();
}
#endregion
#endif
#region CreateEffect
public INativeEffect CreateEffect(GraphicsDevice graphics,
Effect managedEffect, Stream vertexShaderByteCode, Stream pixelShaderByteCode)
public INativeEffect CreateEffect(GraphicsDevice graphics, Effect managedEffect, Stream vertexShaderByteCode,
Stream pixelShaderByteCode)
{
return new Effect_Metro(graphics, managedEffect,
vertexShaderByteCode, pixelShaderByteCode);
PreventSystemChange();
return new Effect_Metro(graphics, managedEffect, vertexShaderByteCode, pixelShaderByteCode);
}
#endregion
#region CreateEffect
public INativeEffect CreateEffect(GraphicsDevice graphics,
Effect managedEffect, System.IO.Stream byteCode)
public INativeEffect CreateEffect(GraphicsDevice graphics, Effect managedEffect, Stream byteCode)
{
PreventSystemChange();
return new Effect_Metro(graphics, managedEffect, byteCode);
}
#endregion
#region CreateTexture (TODO)
public Texture2D CreateTexture(GraphicsDevice graphics, string fileName)
{
//TODO: implement
throw new NotImplementedException();
//GraphicsDeviceWindowsDX10 graphicsDX10 = graphics.NativeDevice as GraphicsDeviceWindowsDX10;
//Dx11.Texture2D nativeTexture = Dx11.Texture2D.FromFile<Dx11.Texture2D>(graphicsDX10.NativeDevice, fileName);
//Texture2D_DX10 texture = new Texture2D_DX10(graphics, nativeTexture.Description.Width, nativeTexture.Description.Height, FormatConverter.Translate(nativeTexture.Description.Format), nativeTexture.Description.MipLevels);
//texture.NativeTexture = nativeTexture;
//return texture;
}
#endregion
#region CreateTexture
public INativeTexture2D CreateTexture(GraphicsDevice graphics,
SurfaceFormat surfaceFormat, int width, int height, int mipCount)
public INativeTexture2D CreateTexture(GraphicsDevice graphics, SurfaceFormat surfaceFormat, int width, int height,
int mipCount)
{
PreventSystemChange();
return new Texture2D_Metro(graphics, width, height, surfaceFormat, mipCount);
}
#endregion
@ -117,6 +105,7 @@ namespace ANX.RenderSystem.Windows.Metro
#region CreateBlendState
public INativeBlendState CreateBlendState()
{
PreventSystemChange();
return new BlendState_Metro();
}
#endregion
@ -124,6 +113,7 @@ namespace ANX.RenderSystem.Windows.Metro
#region CreateRasterizerState
public INativeRasterizerState CreateRasterizerState()
{
PreventSystemChange();
return new RasterizerState_Metro();
}
#endregion
@ -131,6 +121,7 @@ namespace ANX.RenderSystem.Windows.Metro
#region CreateDepthStencilState
public INativeDepthStencilState CreateDepthStencilState()
{
PreventSystemChange();
return new DepthStencilState_Metro();
}
#endregion
@ -138,6 +129,7 @@ namespace ANX.RenderSystem.Windows.Metro
#region CreateSamplerState
public INativeSamplerState CreateSamplerState()
{
PreventSystemChange();
return new SamplerState_Metro();
}
#endregion
@ -145,6 +137,8 @@ namespace ANX.RenderSystem.Windows.Metro
#region GetShaderByteCode
public byte[] GetShaderByteCode(PreDefinedShader type)
{
PreventSystemChange();
switch (type)
{
case PreDefinedShader.SpriteBatch:
@ -157,12 +151,11 @@ namespace ANX.RenderSystem.Windows.Metro
return ShaderByteCode.EnvironmentMapEffectByteCode;
case PreDefinedShader.BasicEffect:
return ShaderByteCode.BasicEffectByteCode;
// TODO
//case PreDefinedShader.SkinnedEffect:
// return ShaderByteCode.SkinnedEffectByteCode;
case PreDefinedShader.SkinnedEffect:
return ShaderByteCode.SkinnedEffectByteCode;
}
throw new NotImplementedException("ByteCode for '" + type + "' is not yet available");
throw new NotImplementedException("ByteCode for built-in effect '" + type + "' is not yet available.");
}
#endregion
@ -244,18 +237,20 @@ namespace ANX.RenderSystem.Windows.Metro
#endregion
#region CreateRenderTarget
public INativeRenderTarget2D CreateRenderTarget(GraphicsDevice graphics,
int width, int height, bool mipMap, SurfaceFormat preferredFormat,
DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage)
public INativeRenderTarget2D CreateRenderTarget(GraphicsDevice graphics, int width, int height, bool mipMap,
SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount,
RenderTargetUsage usage)
{
return new RenderTarget2D_Metro(graphics, width, height, mipMap,
preferredFormat, preferredDepthFormat, preferredMultiSampleCount, usage);
PreventSystemChange();
return new RenderTarget2D_Metro(graphics, width, height, mipMap, preferredFormat, preferredDepthFormat,
preferredMultiSampleCount, usage);
}
#endregion
#region CreateOcclusionQuery (TODO)
public IOcclusionQuery CreateOcclusionQuery()
{
PreventSystemChange();
throw new NotImplementedException();
}
#endregion
@ -270,8 +265,16 @@ namespace ANX.RenderSystem.Windows.Metro
#region SetTextureSampler (TODO)
public void SetTextureSampler(int index, Texture value)
{
PreventSystemChange();
throw new NotImplementedException();
}
#endregion
#region PreventSystemChange
private void PreventSystemChange()
{
AddInSystemFactory.Instance.PreventSystemChange(AddInType.RenderSystem);
}
#endregion
}
}

File diff suppressed because it is too large Load Diff

View File

@ -2,49 +2,459 @@
// "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license
//TODO: dummy implementation / placeholder
uniform extern float4x4 WorldViewProj;
uniform extern float4x4 MatrixTransform;
uniform extern float4 DiffuseColor;
uniform extern float3 EmissiveColor;
uniform extern float3 SpecularColor;
uniform extern float SpecularPower;
uniform extern float3 DirLight0Direction;
uniform extern float3 DirLight0DiffuseColor;
uniform extern float3 DirLight0SpecularColor;
uniform extern float3 DirLight1Direction;
uniform extern float3 DirLight1DiffuseColor;
uniform extern float3 DirLight1SpecularColor;
uniform extern float3 DirLight2Direction;
uniform extern float3 DirLight2DiffuseColor;
uniform extern float3 DirLight2SpecularColor;
uniform extern float3 EyePosition;
uniform extern float3 FogColor;
uniform extern float4 FogVector;
uniform extern float4x4 World;
uniform extern float3x3 WorldInverseTranspose;
uniform extern float4x3 Bones[72];
Texture2D<float4> Texture : register(t0);
sampler TextureSampler : register(s0);
sampler TextureSampler : register(s0);
struct VertexShaderInput
struct VSInputNmTxWeights
{
float4 pos : POSITION;
float4 col : COLOR;
float2 tex : TEXCOORD0;
float4 Position : POSITION;
float3 Normal : NORMAL;
float2 TexCoord : TEXCOORD0;
int4 Indices : BLENDINDICES0;
float4 Weights : BLENDWEIGHT0;
};
struct PixelShaderInput
struct VSOutputTx
{
float4 pos : SV_POSITION;
float4 col : COLOR;
float2 tex : TEXCOORD0;
float4 Diffuse : COLOR0;
float4 Specular : COLOR1;
float2 TexCoord : TEXCOORD0;
float4 PositionPS : SV_Position;
};
PixelShaderInput AlphaTestVertexShader( VertexShaderInput input )
struct VSOutputPixelLightingTx
{
PixelShaderInput output = (PixelShaderInput)0;
float2 TexCoord : TEXCOORD0;
float4 PositionWS : TEXCOORD1;
float3 NormalWS : TEXCOORD2;
float4 Diffuse : COLOR0;
float4 PositionPS : SV_Position;
};
struct PSInputTx
{
float4 Diffuse : COLOR0;
float4 Specular : COLOR1;
float2 TexCoord : TEXCOORD0;
};
struct PSInputPixelLightingTx
{
float2 TexCoord : TEXCOORD0;
float4 PositionWS : TEXCOORD1;
float3 NormalWS : TEXCOORD2;
float4 Diffuse : COLOR0;
};
struct ColorPair
{
float3 Diffuse;
float3 Specular;
};
void Skin(inout VSInputNmTxWeights input, uniform int boneCount)
{
float4x3 skinning = 0;
[unroll]
for (int i = 0; i < boneCount; i++)
{
skinning += Bones[input.Indices[i]] * input.Weights[i];
}
input.Position.xyz = mul(input.Position, skinning);
input.Normal = mul(input.Normal, (float3x3)skinning);
}
ColorPair ComputeLights(float3 eyeVector, float3 worldNormal, uniform int numLights)
{
float3x3 lightDirections = 0;
float3x3 lightDiffuse = 0;
float3x3 lightSpecular = 0;
float3x3 halfVectors = 0;
[unroll]
for (int i = 0; i < numLights; i++)
{
lightDirections[i] = float3x3(DirLight0Direction, DirLight1Direction, DirLight2Direction) [i];
lightDiffuse[i] = float3x3(DirLight0DiffuseColor, DirLight1DiffuseColor, DirLight2DiffuseColor) [i];
lightSpecular[i] = float3x3(DirLight0SpecularColor, DirLight1SpecularColor, DirLight2SpecularColor)[i];
halfVectors[i] = normalize(eyeVector - lightDirections[i]);
}
float3 dotL = mul(-lightDirections, worldNormal);
float3 dotH = mul(halfVectors, worldNormal);
float3 zeroL = step(0, dotL);
float3 diffuse = zeroL * dotL;
float3 specular = pow(max(dotH, 0) * zeroL, SpecularPower);
ColorPair result;
result.Diffuse = mul(diffuse, lightDiffuse) * DiffuseColor.rgb + EmissiveColor;
result.Specular = mul(specular, lightSpecular) * SpecularColor;
return result;
}
VSOutputTx VSSkinnedVertexLightingOneBone(VSInputNmTxWeights input)
{
VSOutputTx output;
Skin(input, 1);
float4 pos_ws = mul(input.Position, World);
float3 eyeVector = normalize(EyePosition - pos_ws.xyz);
float3 worldNormal = normalize(mul(input.Normal, WorldInverseTranspose));
ColorPair lightResult = ComputeLights(eyeVector, worldNormal, 3);
output.PositionPS = mul(input.Position, WorldViewProj);
output.Diffuse = float4(lightResult.Diffuse, DiffuseColor.a);
output.Specular = float4(lightResult.Specular, saturate(dot(input.Position, FogVector)));
output.TexCoord = input.TexCoord;
return output;
}
VSOutputTx VSSkinnedVertexLightingTwoBones(VSInputNmTxWeights input)
{
VSOutputTx output;
Skin(input, 2);
float4 pos_ws = mul(input.Position, World);
float3 eyeVector = normalize(EyePosition - pos_ws.xyz);
float3 worldNormal = normalize(mul(input.Normal, WorldInverseTranspose));
ColorPair lightResult = ComputeLights(eyeVector, worldNormal, 3);
output.PositionPS = mul(input.Position, WorldViewProj);
output.Diffuse = float4(lightResult.Diffuse, DiffuseColor.a);
output.Specular = float4(lightResult.Specular, saturate(dot(input.Position, FogVector)));
output.TexCoord = input.TexCoord;
return output;
}
VSOutputTx VSSkinnedVertexLightingFourBones(VSInputNmTxWeights input)
{
VSOutputTx output;
Skin(input, 4);
float4 pos_ws = mul(input.Position, World);
float3 eyeVector = normalize(EyePosition - pos_ws.xyz);
float3 worldNormal = normalize(mul(input.Normal, WorldInverseTranspose));
ColorPair lightResult = ComputeLights(eyeVector, worldNormal, 3);
output.PositionPS = mul(input.Position, WorldViewProj);
output.Diffuse = float4(lightResult.Diffuse, DiffuseColor.a);
output.Specular = float4(lightResult.Specular, saturate(dot(input.Position, FogVector)));
output.TexCoord = input.TexCoord;
return output;
}
VSOutputTx VSSkinnedOneLightOneBone(VSInputNmTxWeights input)
{
VSOutputTx output;
Skin(input, 1);
output.pos = mul(input.pos, MatrixTransform);
output.col = input.col;
output.tex = input.tex;
float4 pos_ws = mul(input.Position, World);
float3 eyeVector = normalize(EyePosition - pos_ws.xyz);
float3 worldNormal = normalize(mul(input.Normal, WorldInverseTranspose));
ColorPair lightResult = ComputeLights(eyeVector, worldNormal, 1);
return output;
output.PositionPS = mul(input.Position, WorldViewProj);
output.Diffuse = float4(lightResult.Diffuse, DiffuseColor.a);
output.Specular = float4(lightResult.Specular, saturate(dot(input.Position, FogVector)));
output.TexCoord = input.TexCoord;
return output;
}
float4 AlphaTestPixelShader( PixelShaderInput input ) : SV_Target
VSOutputTx VSSkinnedOneLightTwoBones(VSInputNmTxWeights input)
{
return Texture.Sample(TextureSampler, input.tex) * input.col;
VSOutputTx output;
Skin(input, 2);
float4 pos_ws = mul(input.Position, World);
float3 eyeVector = normalize(EyePosition - pos_ws.xyz);
float3 worldNormal = normalize(mul(input.Normal, WorldInverseTranspose));
ColorPair lightResult = ComputeLights(eyeVector, worldNormal, 1);
output.PositionPS = mul(input.Position, WorldViewProj);
output.Diffuse = float4(lightResult.Diffuse, DiffuseColor.a);
output.Specular = float4(lightResult.Specular, saturate(dot(input.Position, FogVector)));
output.TexCoord = input.TexCoord;
return output;
}
technique10 AlphaTest
VSOutputTx VSSkinnedOneLightFourBones(VSInputNmTxWeights input)
{
pass AlphaTestPass
VSOutputTx output;
Skin(input, 4);
float4 pos_ws = mul(input.Position, World);
float3 eyeVector = normalize(EyePosition - pos_ws.xyz);
float3 worldNormal = normalize(mul(input.Normal, WorldInverseTranspose));
ColorPair lightResult = ComputeLights(eyeVector, worldNormal, 1);
output.PositionPS = mul(input.Position, WorldViewProj);
output.Diffuse = float4(lightResult.Diffuse, DiffuseColor.a);
output.Specular = float4(lightResult.Specular, saturate(dot(input.Position, FogVector)));
output.TexCoord = input.TexCoord;
return output;
}
VSOutputPixelLightingTx VSSkinnedPixelLightingOneBone(VSInputNmTxWeights input)
{
VSOutputPixelLightingTx output;
Skin(input, 1);
output.PositionPS = mul(input.Position, WorldViewProj);
output.PositionWS = float4(mul(input.Position, World).xyz, saturate(dot(input.Position, FogVector)));
output.NormalWS = normalize(mul(input.Normal, WorldInverseTranspose));
output.Diffuse = float4(1, 1, 1, DiffuseColor.a);
output.TexCoord = input.TexCoord;
return output;
}
VSOutputPixelLightingTx VSSkinnedPixelLightingTwoBones(VSInputNmTxWeights input)
{
VSOutputPixelLightingTx output;
Skin(input, 2);
output.PositionPS = mul(input.Position, WorldViewProj);
output.PositionWS = float4(mul(input.Position, World).xyz, saturate(dot(input.Position, FogVector)));
output.NormalWS = normalize(mul(input.Normal, WorldInverseTranspose));
output.Diffuse = float4(1, 1, 1, DiffuseColor.a);
output.TexCoord = input.TexCoord;
return output;
}
VSOutputPixelLightingTx VSSkinnedPixelLightingFourBones(VSInputNmTxWeights input)
{
VSOutputPixelLightingTx output;
Skin(input, 4);
output.PositionPS = mul(input.Position, WorldViewProj);
output.PositionWS = float4(mul(input.Position, World).xyz, saturate(dot(input.Position, FogVector)));
output.NormalWS = normalize(mul(input.Normal, WorldInverseTranspose));
output.Diffuse = float4(1, 1, 1, DiffuseColor.a);
output.TexCoord = input.TexCoord;
return output;
}
float4 PSSkinnedVertexLighting(PSInputTx input) : SV_Target0
{
float4 color = Texture.Sample(TextureSampler, input.TexCoord) * input.Diffuse;
color.rgb += input.Specular.rgb * color.a;
color.rgb = lerp(color.rgb, FogColor * color.a, input.Specular.w);
return color;
}
float4 PSSkinnedVertexLightingNoFog(PSInputTx input) : SV_Target0
{
float4 color = Texture.Sample(TextureSampler, input.TexCoord) * input.Diffuse;
color.rgb += input.Specular.rgb * color.a;
return color;
}
float4 PSSkinnedPixelLighting(PSInputPixelLightingTx input) : SV_Target0
{
float4 color = Texture.Sample(TextureSampler, input.TexCoord) * input.Diffuse;
float3 eyeVector = normalize(EyePosition - input.PositionWS.xyz);
float3 worldNormal = normalize(input.NormalWS);
ColorPair lightResult = ComputeLights(eyeVector, worldNormal, 3);
color.rgb *= lightResult.Diffuse;
color.rgb += lightResult.Specular * color.a;
color.rgb = lerp(color.rgb, FogColor * color.a, input.PositionWS.w);
return color;
}
technique10 OneBoneVertexLighting
{
pass Skinned
{
SetGeometryShader( 0 );
SetVertexShader( CompileShader( vs_4_0, AlphaTestVertexShader() ) );
SetPixelShader( CompileShader( ps_4_0, AlphaTestPixelShader() ) );
SetVertexShader(CompileShader(vs_4_0, VSSkinnedVertexLightingOneBone()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedVertexLighting()));
}
}
technique10 OneBoneVertexLightingNoFog
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedVertexLightingOneBone()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedVertexLightingNoFog()));
}
}
technique10 TwoBonesVertexLighting
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedVertexLightingTwoBones()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedVertexLighting()));
}
}
technique10 TwoBonesVertexLightingNoFog
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedVertexLightingTwoBones()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedVertexLightingNoFog()));
}
}
technique10 FourBonesVertexLighting
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedVertexLightingFourBones()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedVertexLighting()));
}
}
technique10 FourBonesVertexLightingNoFog
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedVertexLightingFourBones()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedVertexLightingNoFog()));
}
}
technique10 OneBoneOneLight
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedOneLightOneBone()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedVertexLighting()));
}
}
technique10 OneBoneOneLightNoFog
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedOneLightOneBone()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedVertexLightingNoFog()));
}
}
technique10 TwoBonesOneLight
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedOneLightTwoBones()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedVertexLighting()));
}
}
technique10 TwoBonesOneLightNoFog
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedOneLightTwoBones()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedVertexLightingNoFog()));
}
}
technique10 FourBonesOneLight
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedOneLightFourBones()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedVertexLighting()));
}
}
technique10 FourBonesOneLightNoFog
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedOneLightFourBones()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedVertexLightingNoFog()));
}
}
technique10 OneBonePixelLighting
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedPixelLightingOneBone()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedPixelLighting()));
}
}
technique10 OneBonePixelLightingNoFog
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedPixelLightingOneBone()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedPixelLighting()));
}
}
technique10 TwoBonesPixelLighting
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedPixelLightingTwoBones()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedPixelLighting()));
}
}
technique10 TwoBonesPixelLightingNoFog
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedPixelLightingTwoBones()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedPixelLighting()));
}
}
technique10 FourBonesPixelLighting
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedPixelLightingFourBones()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedPixelLighting()));
}
}
technique10 FourBonesPixelLightingNoFog
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedPixelLightingFourBones()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedPixelLighting()));
}
}

View File

@ -5,7 +5,7 @@
uniform extern float4x4 MatrixTransform;
Texture2D<float4> Texture : register(t0);
sampler TextureSampler : register(s0);
sampler TextureSampler : register(s0);
struct VertexShaderInput
{
@ -21,18 +21,16 @@ struct PixelShaderInput
float2 tex : TEXCOORD0;
};
PixelShaderInput SpriteVertexShader( VertexShaderInput input )
PixelShaderInput SpriteVertexShader(VertexShaderInput input)
{
PixelShaderInput output = (PixelShaderInput)0;
PixelShaderInput output;
output.pos = mul(input.pos, MatrixTransform);
output.col = input.col;
output.tex = input.tex;
return output;
}
float4 SpritePixelShader( PixelShaderInput input ) : SV_Target
float4 SpritePixelShader(PixelShaderInput input) : SV_Target
{
return Texture.Sample(TextureSampler, input.tex) * input.col;
}
@ -41,8 +39,7 @@ technique10 SpriteTechnique
{
pass SpriteColorPass
{
SetGeometryShader( 0 );
SetVertexShader( CompileShader( vs_4_0, SpriteVertexShader() ) );
SetPixelShader( CompileShader( ps_4_0, SpritePixelShader() ) );
SetVertexShader(CompileShader(vs_4_0, SpriteVertexShader()));
SetPixelShader(CompileShader(ps_4_0, SpritePixelShader()));
}
}

View File

@ -2,49 +2,459 @@
// "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license
//TODO: dummy implementation / placeholder
uniform extern float4x4 WorldViewProj;
uniform extern float4x4 MatrixTransform;
uniform extern float4 DiffuseColor;
uniform extern float3 EmissiveColor;
uniform extern float3 SpecularColor;
uniform extern float SpecularPower;
uniform extern float3 DirLight0Direction;
uniform extern float3 DirLight0DiffuseColor;
uniform extern float3 DirLight0SpecularColor;
uniform extern float3 DirLight1Direction;
uniform extern float3 DirLight1DiffuseColor;
uniform extern float3 DirLight1SpecularColor;
uniform extern float3 DirLight2Direction;
uniform extern float3 DirLight2DiffuseColor;
uniform extern float3 DirLight2SpecularColor;
uniform extern float3 EyePosition;
uniform extern float3 FogColor;
uniform extern float4 FogVector;
uniform extern float4x4 World;
uniform extern float3x3 WorldInverseTranspose;
uniform extern float4x3 Bones[72];
Texture2D<float4> Texture : register(t0);
sampler TextureSampler : register(s0);
sampler TextureSampler : register(s0);
struct VertexShaderInput
struct VSInputNmTxWeights
{
float4 pos : POSITION;
float4 col : COLOR;
float2 tex : TEXCOORD0;
float4 Position : POSITION;
float3 Normal : NORMAL;
float2 TexCoord : TEXCOORD0;
int4 Indices : BLENDINDICES0;
float4 Weights : BLENDWEIGHT0;
};
struct PixelShaderInput
struct VSOutputTx
{
float4 pos : SV_POSITION;
float4 col : COLOR;
float2 tex : TEXCOORD0;
float4 Diffuse : COLOR0;
float4 Specular : COLOR1;
float2 TexCoord : TEXCOORD0;
float4 PositionPS : SV_Position;
};
PixelShaderInput AlphaTestVertexShader( VertexShaderInput input )
struct VSOutputPixelLightingTx
{
PixelShaderInput output = (PixelShaderInput)0;
float2 TexCoord : TEXCOORD0;
float4 PositionWS : TEXCOORD1;
float3 NormalWS : TEXCOORD2;
float4 Diffuse : COLOR0;
float4 PositionPS : SV_Position;
};
struct PSInputTx
{
float4 Diffuse : COLOR0;
float4 Specular : COLOR1;
float2 TexCoord : TEXCOORD0;
};
struct PSInputPixelLightingTx
{
float2 TexCoord : TEXCOORD0;
float4 PositionWS : TEXCOORD1;
float3 NormalWS : TEXCOORD2;
float4 Diffuse : COLOR0;
};
struct ColorPair
{
float3 Diffuse;
float3 Specular;
};
void Skin(inout VSInputNmTxWeights input, uniform int boneCount)
{
float4x3 skinning = 0;
[unroll]
for (int i = 0; i < boneCount; i++)
{
skinning += Bones[input.Indices[i]] * input.Weights[i];
}
input.Position.xyz = mul(input.Position, skinning);
input.Normal = mul(input.Normal, (float3x3)skinning);
}
ColorPair ComputeLights(float3 eyeVector, float3 worldNormal, uniform int numLights)
{
float3x3 lightDirections = 0;
float3x3 lightDiffuse = 0;
float3x3 lightSpecular = 0;
float3x3 halfVectors = 0;
[unroll]
for (int i = 0; i < numLights; i++)
{
lightDirections[i] = float3x3(DirLight0Direction, DirLight1Direction, DirLight2Direction) [i];
lightDiffuse[i] = float3x3(DirLight0DiffuseColor, DirLight1DiffuseColor, DirLight2DiffuseColor) [i];
lightSpecular[i] = float3x3(DirLight0SpecularColor, DirLight1SpecularColor, DirLight2SpecularColor)[i];
halfVectors[i] = normalize(eyeVector - lightDirections[i]);
}
float3 dotL = mul(-lightDirections, worldNormal);
float3 dotH = mul(halfVectors, worldNormal);
float3 zeroL = step(0, dotL);
float3 diffuse = zeroL * dotL;
float3 specular = pow(max(dotH, 0) * zeroL, SpecularPower);
ColorPair result;
result.Diffuse = mul(diffuse, lightDiffuse) * DiffuseColor.rgb + EmissiveColor;
result.Specular = mul(specular, lightSpecular) * SpecularColor;
return result;
}
VSOutputTx VSSkinnedVertexLightingOneBone(VSInputNmTxWeights input)
{
VSOutputTx output;
Skin(input, 1);
float4 pos_ws = mul(input.Position, World);
float3 eyeVector = normalize(EyePosition - pos_ws.xyz);
float3 worldNormal = normalize(mul(input.Normal, WorldInverseTranspose));
ColorPair lightResult = ComputeLights(eyeVector, worldNormal, 3);
output.PositionPS = mul(input.Position, WorldViewProj);
output.Diffuse = float4(lightResult.Diffuse, DiffuseColor.a);
output.Specular = float4(lightResult.Specular, saturate(dot(input.Position, FogVector)));
output.TexCoord = input.TexCoord;
return output;
}
VSOutputTx VSSkinnedVertexLightingTwoBones(VSInputNmTxWeights input)
{
VSOutputTx output;
Skin(input, 2);
float4 pos_ws = mul(input.Position, World);
float3 eyeVector = normalize(EyePosition - pos_ws.xyz);
float3 worldNormal = normalize(mul(input.Normal, WorldInverseTranspose));
ColorPair lightResult = ComputeLights(eyeVector, worldNormal, 3);
output.PositionPS = mul(input.Position, WorldViewProj);
output.Diffuse = float4(lightResult.Diffuse, DiffuseColor.a);
output.Specular = float4(lightResult.Specular, saturate(dot(input.Position, FogVector)));
output.TexCoord = input.TexCoord;
return output;
}
VSOutputTx VSSkinnedVertexLightingFourBones(VSInputNmTxWeights input)
{
VSOutputTx output;
Skin(input, 4);
float4 pos_ws = mul(input.Position, World);
float3 eyeVector = normalize(EyePosition - pos_ws.xyz);
float3 worldNormal = normalize(mul(input.Normal, WorldInverseTranspose));
ColorPair lightResult = ComputeLights(eyeVector, worldNormal, 3);
output.PositionPS = mul(input.Position, WorldViewProj);
output.Diffuse = float4(lightResult.Diffuse, DiffuseColor.a);
output.Specular = float4(lightResult.Specular, saturate(dot(input.Position, FogVector)));
output.TexCoord = input.TexCoord;
return output;
}
VSOutputTx VSSkinnedOneLightOneBone(VSInputNmTxWeights input)
{
VSOutputTx output;
Skin(input, 1);
output.pos = mul(input.pos, MatrixTransform);
output.col = input.col;
output.tex = input.tex;
float4 pos_ws = mul(input.Position, World);
float3 eyeVector = normalize(EyePosition - pos_ws.xyz);
float3 worldNormal = normalize(mul(input.Normal, WorldInverseTranspose));
ColorPair lightResult = ComputeLights(eyeVector, worldNormal, 1);
return output;
output.PositionPS = mul(input.Position, WorldViewProj);
output.Diffuse = float4(lightResult.Diffuse, DiffuseColor.a);
output.Specular = float4(lightResult.Specular, saturate(dot(input.Position, FogVector)));
output.TexCoord = input.TexCoord;
return output;
}
float4 AlphaTestPixelShader( PixelShaderInput input ) : SV_Target
VSOutputTx VSSkinnedOneLightTwoBones(VSInputNmTxWeights input)
{
return Texture.Sample(TextureSampler, input.tex) * input.col;
VSOutputTx output;
Skin(input, 2);
float4 pos_ws = mul(input.Position, World);
float3 eyeVector = normalize(EyePosition - pos_ws.xyz);
float3 worldNormal = normalize(mul(input.Normal, WorldInverseTranspose));
ColorPair lightResult = ComputeLights(eyeVector, worldNormal, 1);
output.PositionPS = mul(input.Position, WorldViewProj);
output.Diffuse = float4(lightResult.Diffuse, DiffuseColor.a);
output.Specular = float4(lightResult.Specular, saturate(dot(input.Position, FogVector)));
output.TexCoord = input.TexCoord;
return output;
}
technique10 AlphaTest
VSOutputTx VSSkinnedOneLightFourBones(VSInputNmTxWeights input)
{
pass AlphaTestPass
VSOutputTx output;
Skin(input, 4);
float4 pos_ws = mul(input.Position, World);
float3 eyeVector = normalize(EyePosition - pos_ws.xyz);
float3 worldNormal = normalize(mul(input.Normal, WorldInverseTranspose));
ColorPair lightResult = ComputeLights(eyeVector, worldNormal, 1);
output.PositionPS = mul(input.Position, WorldViewProj);
output.Diffuse = float4(lightResult.Diffuse, DiffuseColor.a);
output.Specular = float4(lightResult.Specular, saturate(dot(input.Position, FogVector)));
output.TexCoord = input.TexCoord;
return output;
}
VSOutputPixelLightingTx VSSkinnedPixelLightingOneBone(VSInputNmTxWeights input)
{
VSOutputPixelLightingTx output;
Skin(input, 1);
output.PositionPS = mul(input.Position, WorldViewProj);
output.PositionWS = float4(mul(input.Position, World).xyz, saturate(dot(input.Position, FogVector)));
output.NormalWS = normalize(mul(input.Normal, WorldInverseTranspose));
output.Diffuse = float4(1, 1, 1, DiffuseColor.a);
output.TexCoord = input.TexCoord;
return output;
}
VSOutputPixelLightingTx VSSkinnedPixelLightingTwoBones(VSInputNmTxWeights input)
{
VSOutputPixelLightingTx output;
Skin(input, 2);
output.PositionPS = mul(input.Position, WorldViewProj);
output.PositionWS = float4(mul(input.Position, World).xyz, saturate(dot(input.Position, FogVector)));
output.NormalWS = normalize(mul(input.Normal, WorldInverseTranspose));
output.Diffuse = float4(1, 1, 1, DiffuseColor.a);
output.TexCoord = input.TexCoord;
return output;
}
VSOutputPixelLightingTx VSSkinnedPixelLightingFourBones(VSInputNmTxWeights input)
{
VSOutputPixelLightingTx output;
Skin(input, 4);
output.PositionPS = mul(input.Position, WorldViewProj);
output.PositionWS = float4(mul(input.Position, World).xyz, saturate(dot(input.Position, FogVector)));
output.NormalWS = normalize(mul(input.Normal, WorldInverseTranspose));
output.Diffuse = float4(1, 1, 1, DiffuseColor.a);
output.TexCoord = input.TexCoord;
return output;
}
float4 PSSkinnedVertexLighting(PSInputTx input) : SV_Target0
{
float4 color = Texture.Sample(TextureSampler, input.TexCoord) * input.Diffuse;
color.rgb += input.Specular.rgb * color.a;
color.rgb = lerp(color.rgb, FogColor * color.a, input.Specular.w);
return color;
}
float4 PSSkinnedVertexLightingNoFog(PSInputTx input) : SV_Target0
{
float4 color = Texture.Sample(TextureSampler, input.TexCoord) * input.Diffuse;
color.rgb += input.Specular.rgb * color.a;
return color;
}
float4 PSSkinnedPixelLighting(PSInputPixelLightingTx input) : SV_Target0
{
float4 color = Texture.Sample(TextureSampler, input.TexCoord) * input.Diffuse;
float3 eyeVector = normalize(EyePosition - input.PositionWS.xyz);
float3 worldNormal = normalize(input.NormalWS);
ColorPair lightResult = ComputeLights(eyeVector, worldNormal, 3);
color.rgb *= lightResult.Diffuse;
color.rgb += lightResult.Specular * color.a;
color.rgb = lerp(color.rgb, FogColor * color.a, input.PositionWS.w);
return color;
}
technique10 OneBoneVertexLighting
{
pass Skinned
{
SetGeometryShader( 0 );
SetVertexShader( CompileShader( vs_4_0, AlphaTestVertexShader() ) );
SetPixelShader( CompileShader( ps_4_0, AlphaTestPixelShader() ) );
SetVertexShader(CompileShader(vs_4_0, VSSkinnedVertexLightingOneBone()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedVertexLighting()));
}
}
technique10 OneBoneVertexLightingNoFog
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedVertexLightingOneBone()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedVertexLightingNoFog()));
}
}
technique10 TwoBonesVertexLighting
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedVertexLightingTwoBones()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedVertexLighting()));
}
}
technique10 TwoBonesVertexLightingNoFog
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedVertexLightingTwoBones()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedVertexLightingNoFog()));
}
}
technique10 FourBonesVertexLighting
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedVertexLightingFourBones()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedVertexLighting()));
}
}
technique10 FourBonesVertexLightingNoFog
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedVertexLightingFourBones()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedVertexLightingNoFog()));
}
}
technique10 OneBoneOneLight
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedOneLightOneBone()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedVertexLighting()));
}
}
technique10 OneBoneOneLightNoFog
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedOneLightOneBone()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedVertexLightingNoFog()));
}
}
technique10 TwoBonesOneLight
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedOneLightTwoBones()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedVertexLighting()));
}
}
technique10 TwoBonesOneLightNoFog
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedOneLightTwoBones()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedVertexLightingNoFog()));
}
}
technique10 FourBonesOneLight
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedOneLightFourBones()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedVertexLighting()));
}
}
technique10 FourBonesOneLightNoFog
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedOneLightFourBones()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedVertexLightingNoFog()));
}
}
technique10 OneBonePixelLighting
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedPixelLightingOneBone()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedPixelLighting()));
}
}
technique10 OneBonePixelLightingNoFog
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedPixelLightingOneBone()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedPixelLighting()));
}
}
technique10 TwoBonesPixelLighting
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedPixelLightingTwoBones()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedPixelLighting()));
}
}
technique10 TwoBonesPixelLightingNoFog
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedPixelLightingTwoBones()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedPixelLighting()));
}
}
technique10 FourBonesPixelLighting
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedPixelLightingFourBones()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedPixelLighting()));
}
}
technique10 FourBonesPixelLightingNoFog
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedPixelLightingFourBones()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedPixelLighting()));
}
}

460
shader/Metro/Skinned.fx Normal file
View File

@ -0,0 +1,460 @@
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license
uniform extern float4x4 WorldViewProj;
uniform extern float4 DiffuseColor;
uniform extern float3 EmissiveColor;
uniform extern float3 SpecularColor;
uniform extern float SpecularPower;
uniform extern float3 DirLight0Direction;
uniform extern float3 DirLight0DiffuseColor;
uniform extern float3 DirLight0SpecularColor;
uniform extern float3 DirLight1Direction;
uniform extern float3 DirLight1DiffuseColor;
uniform extern float3 DirLight1SpecularColor;
uniform extern float3 DirLight2Direction;
uniform extern float3 DirLight2DiffuseColor;
uniform extern float3 DirLight2SpecularColor;
uniform extern float3 EyePosition;
uniform extern float3 FogColor;
uniform extern float4 FogVector;
uniform extern float4x4 World;
uniform extern float3x3 WorldInverseTranspose;
uniform extern float4x3 Bones[72];
Texture2D<float4> Texture : register(t0);
sampler TextureSampler : register(s0);
struct VSInputNmTxWeights
{
float4 Position : POSITION;
float3 Normal : NORMAL;
float2 TexCoord : TEXCOORD0;
int4 Indices : BLENDINDICES0;
float4 Weights : BLENDWEIGHT0;
};
struct VSOutputTx
{
float4 Diffuse : COLOR0;
float4 Specular : COLOR1;
float2 TexCoord : TEXCOORD0;
float4 PositionPS : SV_Position;
};
struct VSOutputPixelLightingTx
{
float2 TexCoord : TEXCOORD0;
float4 PositionWS : TEXCOORD1;
float3 NormalWS : TEXCOORD2;
float4 Diffuse : COLOR0;
float4 PositionPS : SV_Position;
};
struct PSInputTx
{
float4 Diffuse : COLOR0;
float4 Specular : COLOR1;
float2 TexCoord : TEXCOORD0;
};
struct PSInputPixelLightingTx
{
float2 TexCoord : TEXCOORD0;
float4 PositionWS : TEXCOORD1;
float3 NormalWS : TEXCOORD2;
float4 Diffuse : COLOR0;
};
struct ColorPair
{
float3 Diffuse;
float3 Specular;
};
void Skin(inout VSInputNmTxWeights input, uniform int boneCount)
{
float4x3 skinning = 0;
[unroll]
for (int i = 0; i < boneCount; i++)
{
skinning += Bones[input.Indices[i]] * input.Weights[i];
}
input.Position.xyz = mul(input.Position, skinning);
input.Normal = mul(input.Normal, (float3x3)skinning);
}
ColorPair ComputeLights(float3 eyeVector, float3 worldNormal, uniform int numLights)
{
float3x3 lightDirections = 0;
float3x3 lightDiffuse = 0;
float3x3 lightSpecular = 0;
float3x3 halfVectors = 0;
[unroll]
for (int i = 0; i < numLights; i++)
{
lightDirections[i] = float3x3(DirLight0Direction, DirLight1Direction, DirLight2Direction) [i];
lightDiffuse[i] = float3x3(DirLight0DiffuseColor, DirLight1DiffuseColor, DirLight2DiffuseColor) [i];
lightSpecular[i] = float3x3(DirLight0SpecularColor, DirLight1SpecularColor, DirLight2SpecularColor)[i];
halfVectors[i] = normalize(eyeVector - lightDirections[i]);
}
float3 dotL = mul(-lightDirections, worldNormal);
float3 dotH = mul(halfVectors, worldNormal);
float3 zeroL = step(0, dotL);
float3 diffuse = zeroL * dotL;
float3 specular = pow(max(dotH, 0) * zeroL, SpecularPower);
ColorPair result;
result.Diffuse = mul(diffuse, lightDiffuse) * DiffuseColor.rgb + EmissiveColor;
result.Specular = mul(specular, lightSpecular) * SpecularColor;
return result;
}
VSOutputTx VSSkinnedVertexLightingOneBone(VSInputNmTxWeights input)
{
VSOutputTx output;
Skin(input, 1);
float4 pos_ws = mul(input.Position, World);
float3 eyeVector = normalize(EyePosition - pos_ws.xyz);
float3 worldNormal = normalize(mul(input.Normal, WorldInverseTranspose));
ColorPair lightResult = ComputeLights(eyeVector, worldNormal, 3);
output.PositionPS = mul(input.Position, WorldViewProj);
output.Diffuse = float4(lightResult.Diffuse, DiffuseColor.a);
output.Specular = float4(lightResult.Specular, saturate(dot(input.Position, FogVector)));
output.TexCoord = input.TexCoord;
return output;
}
VSOutputTx VSSkinnedVertexLightingTwoBones(VSInputNmTxWeights input)
{
VSOutputTx output;
Skin(input, 2);
float4 pos_ws = mul(input.Position, World);
float3 eyeVector = normalize(EyePosition - pos_ws.xyz);
float3 worldNormal = normalize(mul(input.Normal, WorldInverseTranspose));
ColorPair lightResult = ComputeLights(eyeVector, worldNormal, 3);
output.PositionPS = mul(input.Position, WorldViewProj);
output.Diffuse = float4(lightResult.Diffuse, DiffuseColor.a);
output.Specular = float4(lightResult.Specular, saturate(dot(input.Position, FogVector)));
output.TexCoord = input.TexCoord;
return output;
}
VSOutputTx VSSkinnedVertexLightingFourBones(VSInputNmTxWeights input)
{
VSOutputTx output;
Skin(input, 4);
float4 pos_ws = mul(input.Position, World);
float3 eyeVector = normalize(EyePosition - pos_ws.xyz);
float3 worldNormal = normalize(mul(input.Normal, WorldInverseTranspose));
ColorPair lightResult = ComputeLights(eyeVector, worldNormal, 3);
output.PositionPS = mul(input.Position, WorldViewProj);
output.Diffuse = float4(lightResult.Diffuse, DiffuseColor.a);
output.Specular = float4(lightResult.Specular, saturate(dot(input.Position, FogVector)));
output.TexCoord = input.TexCoord;
return output;
}
VSOutputTx VSSkinnedOneLightOneBone(VSInputNmTxWeights input)
{
VSOutputTx output;
Skin(input, 1);
float4 pos_ws = mul(input.Position, World);
float3 eyeVector = normalize(EyePosition - pos_ws.xyz);
float3 worldNormal = normalize(mul(input.Normal, WorldInverseTranspose));
ColorPair lightResult = ComputeLights(eyeVector, worldNormal, 1);
output.PositionPS = mul(input.Position, WorldViewProj);
output.Diffuse = float4(lightResult.Diffuse, DiffuseColor.a);
output.Specular = float4(lightResult.Specular, saturate(dot(input.Position, FogVector)));
output.TexCoord = input.TexCoord;
return output;
}
VSOutputTx VSSkinnedOneLightTwoBones(VSInputNmTxWeights input)
{
VSOutputTx output;
Skin(input, 2);
float4 pos_ws = mul(input.Position, World);
float3 eyeVector = normalize(EyePosition - pos_ws.xyz);
float3 worldNormal = normalize(mul(input.Normal, WorldInverseTranspose));
ColorPair lightResult = ComputeLights(eyeVector, worldNormal, 1);
output.PositionPS = mul(input.Position, WorldViewProj);
output.Diffuse = float4(lightResult.Diffuse, DiffuseColor.a);
output.Specular = float4(lightResult.Specular, saturate(dot(input.Position, FogVector)));
output.TexCoord = input.TexCoord;
return output;
}
VSOutputTx VSSkinnedOneLightFourBones(VSInputNmTxWeights input)
{
VSOutputTx output;
Skin(input, 4);
float4 pos_ws = mul(input.Position, World);
float3 eyeVector = normalize(EyePosition - pos_ws.xyz);
float3 worldNormal = normalize(mul(input.Normal, WorldInverseTranspose));
ColorPair lightResult = ComputeLights(eyeVector, worldNormal, 1);
output.PositionPS = mul(input.Position, WorldViewProj);
output.Diffuse = float4(lightResult.Diffuse, DiffuseColor.a);
output.Specular = float4(lightResult.Specular, saturate(dot(input.Position, FogVector)));
output.TexCoord = input.TexCoord;
return output;
}
VSOutputPixelLightingTx VSSkinnedPixelLightingOneBone(VSInputNmTxWeights input)
{
VSOutputPixelLightingTx output;
Skin(input, 1);
output.PositionPS = mul(input.Position, WorldViewProj);
output.PositionWS = float4(mul(input.Position, World).xyz, saturate(dot(input.Position, FogVector)));
output.NormalWS = normalize(mul(input.Normal, WorldInverseTranspose));
output.Diffuse = float4(1, 1, 1, DiffuseColor.a);
output.TexCoord = input.TexCoord;
return output;
}
VSOutputPixelLightingTx VSSkinnedPixelLightingTwoBones(VSInputNmTxWeights input)
{
VSOutputPixelLightingTx output;
Skin(input, 2);
output.PositionPS = mul(input.Position, WorldViewProj);
output.PositionWS = float4(mul(input.Position, World).xyz, saturate(dot(input.Position, FogVector)));
output.NormalWS = normalize(mul(input.Normal, WorldInverseTranspose));
output.Diffuse = float4(1, 1, 1, DiffuseColor.a);
output.TexCoord = input.TexCoord;
return output;
}
VSOutputPixelLightingTx VSSkinnedPixelLightingFourBones(VSInputNmTxWeights input)
{
VSOutputPixelLightingTx output;
Skin(input, 4);
output.PositionPS = mul(input.Position, WorldViewProj);
output.PositionWS = float4(mul(input.Position, World).xyz, saturate(dot(input.Position, FogVector)));
output.NormalWS = normalize(mul(input.Normal, WorldInverseTranspose));
output.Diffuse = float4(1, 1, 1, DiffuseColor.a);
output.TexCoord = input.TexCoord;
return output;
}
float4 PSSkinnedVertexLighting(PSInputTx input) : SV_Target0
{
float4 color = Texture.Sample(TextureSampler, input.TexCoord) * input.Diffuse;
color.rgb += input.Specular.rgb * color.a;
color.rgb = lerp(color.rgb, FogColor * color.a, input.Specular.w);
return color;
}
float4 PSSkinnedVertexLightingNoFog(PSInputTx input) : SV_Target0
{
float4 color = Texture.Sample(TextureSampler, input.TexCoord) * input.Diffuse;
color.rgb += input.Specular.rgb * color.a;
return color;
}
float4 PSSkinnedPixelLighting(PSInputPixelLightingTx input) : SV_Target0
{
float4 color = Texture.Sample(TextureSampler, input.TexCoord) * input.Diffuse;
float3 eyeVector = normalize(EyePosition - input.PositionWS.xyz);
float3 worldNormal = normalize(input.NormalWS);
ColorPair lightResult = ComputeLights(eyeVector, worldNormal, 3);
color.rgb *= lightResult.Diffuse;
color.rgb += lightResult.Specular * color.a;
color.rgb = lerp(color.rgb, FogColor * color.a, input.PositionWS.w);
return color;
}
technique10 OneBoneVertexLighting
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedVertexLightingOneBone()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedVertexLighting()));
}
}
technique10 OneBoneVertexLightingNoFog
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedVertexLightingOneBone()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedVertexLightingNoFog()));
}
}
technique10 TwoBonesVertexLighting
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedVertexLightingTwoBones()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedVertexLighting()));
}
}
technique10 TwoBonesVertexLightingNoFog
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedVertexLightingTwoBones()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedVertexLightingNoFog()));
}
}
technique10 FourBonesVertexLighting
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedVertexLightingFourBones()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedVertexLighting()));
}
}
technique10 FourBonesVertexLightingNoFog
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedVertexLightingFourBones()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedVertexLightingNoFog()));
}
}
technique10 OneBoneOneLight
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedOneLightOneBone()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedVertexLighting()));
}
}
technique10 OneBoneOneLightNoFog
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedOneLightOneBone()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedVertexLightingNoFog()));
}
}
technique10 TwoBonesOneLight
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedOneLightTwoBones()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedVertexLighting()));
}
}
technique10 TwoBonesOneLightNoFog
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedOneLightTwoBones()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedVertexLightingNoFog()));
}
}
technique10 FourBonesOneLight
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedOneLightFourBones()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedVertexLighting()));
}
}
technique10 FourBonesOneLightNoFog
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedOneLightFourBones()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedVertexLightingNoFog()));
}
}
technique10 OneBonePixelLighting
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedPixelLightingOneBone()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedPixelLighting()));
}
}
technique10 OneBonePixelLightingNoFog
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedPixelLightingOneBone()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedPixelLighting()));
}
}
technique10 TwoBonesPixelLighting
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedPixelLightingTwoBones()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedPixelLighting()));
}
}
technique10 TwoBonesPixelLightingNoFog
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedPixelLightingTwoBones()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedPixelLighting()));
}
}
technique10 FourBonesPixelLighting
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedPixelLightingFourBones()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedPixelLighting()));
}
}
technique10 FourBonesPixelLightingNoFog
{
pass Skinned
{
SetVertexShader(CompileShader(vs_4_0, VSSkinnedPixelLightingFourBones()));
SetPixelShader(CompileShader(ps_4_0, PSSkinnedPixelLighting()));
}
}

View File

@ -7,4 +7,5 @@
<Shader Type="AlphaTestEffect" Source="../Shader/Metro/AlphaTest.fx" RenderSystem="ANX.RenderSystem.Windows.Metro" />
<Shader Type="EnvironmentMapEffect" Source="../Shader/Metro/EnvironmentMap.fx" RenderSystem="ANX.RenderSystem.Windows.Metro" />
<Shader Type="BasicEffect" Source="../Shader/Metro/BasicEffect.fx" RenderSystem="ANX.RenderSystem.Windows.Metro" />
<Shader Type="SkinnedEffect" Source="../Shader/Metro/Skinned.fx" RenderSystem="ANX.RenderSystem.Windows.Metro" />
</Build>