Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/Shader_HS18/programs/Cg/VTFInstancing.cg @ 12202

Last change on this file since 12202 was 12115, checked in by wiesep, 6 years ago

Changed folder structure, deletet some unused files and cleaned up code

File size: 3.3 KB
Line 
1//---------------------------------------------------------------------------
2//These materials/shaders are part of the NEW InstanceManager implementation
3//Written by Matias N. Goldberg ("dark_sylinc")
4//---------------------------------------------------------------------------
5
6//---------------------------------------------
7//Vertex Shader Input
8//---------------------------------------------
9struct VS_INPUT
10{
11        float4 Position :       POSITION;
12        float3 Normal   :       NORMAL;
13        float3 Tangent  :       TANGENT;
14#ifdef BONE_TWO_WEIGHTS
15        float4 weights          :       BLENDWEIGHT;
16#endif
17        float2 uv0              :       TEXCOORD0;
18
19        float4 m01              :       TEXCOORD1;
20        float4 m23              :       TEXCOORD2;
21};
22
23#include "InstancingVertexInterpolators.cg"
24#ifdef ST_DUAL_QUATERNION
25#include "DualQuaternionSkinning_Shadow.cg"
26#endif
27
28//---------------------------------------------
29//Main Vertex Shader
30//---------------------------------------------
31VS_OUTPUT main_vs( in VS_INPUT input,
32                                   uniform float4x4 viewProjMatrix,
33                                   
34#ifdef DEPTH_SHADOWCASTER
35                                   uniform sampler2D matrixTexture : register(s0)
36#else
37                                   uniform sampler2D matrixTexture : register(s2)
38#endif
39
40#if defined( DEPTH_SHADOWCASTER ) || defined( DEPTH_SHADOWRECEIVER )
41                                ,  uniform float4 depthRange
42#endif
43#ifdef DEPTH_SHADOWRECEIVER
44                                ,  uniform float4x4 texViewProjMatrix
45#endif
46                                )
47{
48        VS_OUTPUT output;
49
50        float4 worldPos  = 0;
51        float3 worldNorm = 0;
52
53#ifdef ST_DUAL_QUATERNION
54        float2x4 blendDQ;       
55        blendDQ[0] = tex2D( matrixTexture, input.m01.xy );
56        blendDQ[1] = tex2D( matrixTexture, input.m01.zw );
57#ifdef BONE_TWO_WEIGHTS
58        float2x4 blendDQ2;
59        //Use the empty parts of m03, z and w, for the second dual quaternion
60        blendDQ2[0] = tex2D( matrixTexture, input.m23.xy );
61        blendDQ2[1] = tex2D( matrixTexture, input.m23.zw );
62       
63        //Accurate antipodality handling. For speed increase, remove the following line
64        if (dot(blendDQ[0], blendDQ2[0]) < 0.0) blendDQ2 *= -1.0;
65       
66        //Blend the dual quaternions based on the weights
67        blendDQ *= input.weights.x;
68        blendDQ += input.weights.y*blendDQ2;
69        //Normalize the resultant dual quaternion
70        blendDQ /= length(blendDQ[0]);
71#endif
72        //Only dealing with one weight so normalization of the dual quaternion and weighting are unnecessary
73        worldPos = float4(calculateBlendPosition(input.Position, blendDQ), 1.0);
74        worldNorm = calculateBlendNormal(input.Normal.xyz, blendDQ);
75#else
76        float3x4 worldMatrix;
77        worldMatrix[0] = tex2D( matrixTexture, input.m01.xy );
78        worldMatrix[1] = tex2D( matrixTexture, input.m01.zw );
79        worldMatrix[2] = tex2D( matrixTexture, input.m23.xy );
80
81        worldPos = float4( mul( worldMatrix, input.Position ).xyz, 1.0f );
82        worldNorm= mul( (float3x3)(worldMatrix), input.Normal );
83#endif
84
85        //Transform the position
86        output.Position         = mul( viewProjMatrix, worldPos );
87
88#ifdef DEPTH_SHADOWCASTER
89        output.ps.unused        = float3( 0 );
90        output.ps.depth         = (output.Position.z - depthRange.x + SHADOW_BIAS) * depthRange.w;
91#else
92        output.ps.uv0           = input.uv0;
93
94        //Pass Normal and position for Blinn Phong lighting
95        output.ps.Normal        = normalize(worldNorm);
96        output.ps.vPos          = worldPos.xyz;
97       
98        #ifdef DEPTH_SHADOWRECEIVER
99                // Calculate the position of vertex in light space to do shadows
100                output.ps.lightSpacePos = mul( texViewProjMatrix, worldPos );
101                // make linear
102                output.ps.lightSpacePos.z = (output.ps.lightSpacePos.z - depthRange.x) * depthRange.w;
103        #endif
104#endif
105
106        return output;
107}
Note: See TracBrowser for help on using the repository browser.