float4x3 World; float4x3 PrevWorld; float4x3 View; float4x4 ViewProj; float4x4 PrevViewProj; static float InvDetailSize0 = 0.008f; static float InvDetailSize1 = 0.0008f; float3 CamPos; #define NOMOTION #include "dcSuperShader_Data.HLSL" float4x3 WorldArray[30]; float4x3 PrevWorldArray[30]; 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 float BlendIndices : BLENDINDICES; #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 World = WorldArray[Input.BlendIndices]; float4x3 PrevWorld = PrevWorldArray[Input.BlendIndices]; #endif #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 VS_OUTPUT Out; Out.Pos = mul(float4(Pos, 1), ViewProj); #ifdef BASEUV Out.Data.Tex = Input.Tex; #endif #ifdef DETAILUV0 Out.Data.DetailTex0 = Pos.xz * InvDetailSize0; #endif #ifdef DETAILUV1 Out.Data.DetailTex1 = Pos.xz * InvDetailSize1; #endif #ifdef FACENORMAL float3x3 WorldView = mul((float3x3)World, (float3x3)View); // Optimize this float3 N = mul(Input.Normal, WorldView); #ifdef SKINNING N = normalize(N); // FIX!!! #endif Out.Data.Normal = N; #ifdef REFLECTIVE float3 RN = mul(Input.Normal, (float3x3)World); float3 V = CamPos - Pos; Out.Data.R = 2 * dot(RN, V) * RN - V; #endif #endif #ifdef NORMALMAP float3x3 WorldView = mul((float3x3)World, (float3x3)View); // Optimize this #ifdef TANGENTSPACE float3x3 Tangent; Tangent[0] = Input.Binormal; Tangent[1] = Input.Tangent; Tangent[2] = Input.Normal; Out.Data.NormalMatrix = mul(Tangent, WorldView); #else Out.Data.NormalMatrix = WorldView; #endif #endif Out.Data.V = CamPos - Pos; return Out; }