float4x3 World; float4x3 PrevWorld; float4x3 View; float4x4 ViewProj; float4x4 PrevViewProj; float InvDetailSize; float InvNormalMapSize; #ifndef INVDETAIL2SIZE #define INVDETAIL2SIZE 1 #endif #ifndef INVDETAIL3SIZE #define INVDETAIL3SIZE 1 #endif //#define DEFORM static float InvDetail2Size = INVDETAIL2SIZE; static float InvDetail3Size = INVDETAIL3SIZE; float3 CamPos; //#undef NORMALMAP #include "dcSuperShader_Data.HLSL" float4x3 WorldArray[40]; float4x3 PrevWorldArray[40]; #ifdef WIN32 static float MatrixOffset = 0.5f; static float MatrixScale = 2; #endif #ifdef XBOX static float MatrixOffset = 0; static float MatrixScale = 1; #endif struct XDeform{ float4 Pos; float4 Dir; }; XDeform Deforms[32]; float DeformCount; float Deform; float4x3 Model; // Model transform struct VS_OUTPUT{ float4 Pos : POSITION; dcShaderData Data : TEXCOORD0; }; struct VS_INPUT{ float4 Pos : POSITION; #ifdef SKINNING int4 BlendIndices : BLENDINDICES; float4 BlendWeights : BLENDWEIGHT; #endif #ifdef FACENORMAL float3 Normal : NORMAL; #endif #ifdef NORMALMAP #ifdef TANGENTSPACE float3 Normal : NORMAL; float3 Binormal : BINORMAL; float3 Tangent : TANGENT; #endif #endif #ifdef BASEUV float2 Tex : TEXCOORD0; #endif #ifdef INSTANCED float4x3 World : TEXCOORD1; #endif }; VS_OUTPUT main(const VS_INPUT Input){ #ifdef INSTANCED float4x3 World = Input.World; float4x3 PrevWorld = Input.World; #endif #ifdef SKINNING float4x3 SkinWorld[4]; float4x3 SkinPrevWorld[4]; for (int i = 0; i < 4; i++){ SkinWorld[i] = WorldArray[Input.BlendIndices[i]]; SkinPrevWorld[i] = PrevWorldArray[Input.BlendIndices[i]]; } // Fix later float4x3 World = WorldArray[Input.BlendIndices[0]]; float4x3 PrevWorld = PrevWorldArray[Input.BlendIndices[0]]; #endif #ifdef BILLBOARD float3 Dir = CamPos - InstancePos; Dir.y = 0; Dir = normalize(Dir); float4x3 Matrix; Matrix[0] = cross(float3(0, 1, 0), Dir); Matrix[1] = float3(0, 1, 0); Matrix[2] = Dir; Matrix[3] = World[3]; World = Matrix; #endif #ifndef SKINNING #ifdef INSTANCED float3 Pos = mul(Input.Pos, World); float3 PrevPos = mul(Input.Pos, PrevWorld); #else float3 LocalPos = mul(Input.Pos, Model); float3 PosOffset = 0; for (int i = 0; i < DeformCount; i++){ float3 Diff = (Deforms[i].Pos.xyz - LocalPos); float DistSq = dot(Diff, Diff); float Strength = 1 - clamp((DistSq - Deforms[i].Pos.w) * Deforms[i].Dir.w, 0, 1); PosOffset += Deforms[i].Dir.xyz * Strength; } LocalPos += PosOffset * Deform; float3 Pos = mul(float4(LocalPos, 1), World); float3 PrevPos = mul(float4(LocalPos, 1), PrevWorld); #endif #else float TotalWeight = 0; float3 Pos = 0; float3 PrevPos = 0; for (int i = 0; i < 4; i++){ TotalWeight += Input.BlendWeights[i]; Pos += mul(Input.Pos, SkinWorld[i]) * Input.BlendWeights[i]; PrevPos += mul(Input.Pos, SkinPrevWorld[i]) * Input.BlendWeights[i]; } Pos /= TotalWeight; PrevPos /= TotalWeight; #endif VS_OUTPUT Out = (VS_OUTPUT)0; Out.Pos = mul(float4(Pos, 1), ViewProj); #ifdef BASEUV Out.Data.Tex = Input.Tex; #endif #ifdef DETAILUV0 Out.Data.DetailTex01.xy = Pos.xz * InvDetailSize; #endif #ifdef DETAILUV1 Out.Data.DetailTex01.zw = Pos.xz * InvNormalMapSize; #endif #ifdef DETAILUV2 Out.Data.DetailTex23.xy = Pos.xz * InvDetail2Size; #endif #ifdef DETAILUV3 Out.Data.DetailTex23.zw = Pos.xz * InvDetail3Size; #endif #ifdef FACENORMAL #if defined(INSTANCED) || defined(SKINNING) float3 N = mul((Input.Normal - MatrixOffset) * MatrixScale, (float3x3)World); #else float3 N = mul(Input.Normal, (float3x3)World); #endif #ifdef SKINNING N = normalize(N); // FIX!!! #endif Out.Data.Normal = N; #ifdef REFLECTIVE float3 V = CamPos - Pos; Out.Data.R = 2 * dot(N, V) * N - V; #endif #endif #ifdef NORMALMAP #ifdef TANGENTSPACE float3x3 Tangent; #ifndef TANGENTFIX Tangent[0] = (Input.Binormal - MatrixOffset) * MatrixScale; Tangent[1] = (Input.Tangent - MatrixOffset) * MatrixScale; Tangent[2] = (Input.Normal - MatrixOffset) * MatrixScale; #else Tangent[2] = (Input.Normal - MatrixOffset) * MatrixScale; Tangent[0] = normalize(cross(float3(0, 1, 0), Tangent[2])); Tangent[1] = normalize(cross(Tangent[2], Tangent[0])); #endif Out.Data.NormalMatrix = mul(Tangent, (float3x3)World); #else Out.Data.NormalMatrix = (float3x3)World; #endif #endif Out.Data.V = CamPos - Pos; #ifndef NOMOTION Out.Data.CurPos = mul(float4(Pos, 1), ViewProj); Out.Data.PrevPos = mul(float4(PrevPos, 1), PrevViewProj); Out.Data.CurPos.xy = (Out.Data.CurPos.xy * float2(0.5f, -0.5f)) + float2(0.5f, 0.5f); Out.Data.PrevPos.xy = (Out.Data.PrevPos.xy * float2(0.5f, -0.5f)) + float2(0.5f, 0.5f); #endif return Out; }