Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/Shader_HS18/programs/GLSL120/HW_VTFInstancing.vert @ 12302

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

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

File size: 3.5 KB
Line 
1//---------------------------------------------------------------------------
2//These materials/shaders are part of the NEW InstanceManager implementation
3//Written by Matias N. Goldberg ("dark_sylinc")
4//---------------------------------------------------------------------------
5#version 120
6
7//Vertex input
8attribute vec4 vertex;
9attribute vec3 normal;
10
11#ifdef BONE_TWO_WEIGHTS
12        attribute vec4 blendWeights;
13#endif
14
15attribute vec4 uv0;
16attribute vec4 uv1;
17attribute vec4 uv2;
18       
19#if BONE_MATRIX_LUT
20        attribute vec4 uv3;
21        attribute vec4 uv4;
22        attribute vec4 uv5;
23#endif
24
25attribute vec3 tangent;
26
27//Parameters
28uniform mat4 viewProjMatrix;
29uniform sampler2D matrixTexture;
30
31#if (DEPTH_SHADOWCASTER || DEPTH_SHADOWRECEIVER)
32uniform vec4 depthRange;
33#endif
34
35#if DEPTH_SHADOWRECEIVER
36uniform mat4 texViewProjMatrix;
37#endif
38
39//Output
40#if DEPTH_SHADOWCASTER
41        varying vec2 depth;
42#else
43        varying vec2 _uv0;
44        varying vec3 oNormal;
45        varying vec3 oVPos;
46        #if DEPTH_SHADOWRECEIVER
47                varying vec4 oLightSpacePos;
48        #endif
49#endif
50
51vec3 calculateBlendPosition(vec3 position, mat2x4 blendDQ)
52{
53        vec3 blendPosition = position + 2.0*cross(blendDQ[0].yzw, cross(blendDQ[0].yzw, position) + blendDQ[0].x*position);
54        vec3 trans = 2.0*(blendDQ[0].x*blendDQ[1].yzw - blendDQ[1].x*blendDQ[0].yzw + cross(blendDQ[0].yzw, blendDQ[1].yzw));
55        blendPosition += trans;
56
57        return blendPosition;
58}
59
60vec3 calculateBlendNormal(vec3 normal, mat2x4 blendDQ)
61{
62        return normal + 2.0*cross(blendDQ[0].yzw, cross(blendDQ[0].yzw, normal) + blendDQ[0].x*normal);
63}
64
65//---------------------------------------------
66//Main Vertex Shader
67//---------------------------------------------
68void main(void)
69{
70        vec4 worldPos;
71        vec3 worldNorm;
72
73#ifdef ST_DUAL_QUATERNION
74        mat2x4 blendDQ;
75        blendDQ[0] = texture2D( matrixTexture, vec2(uv1.x, 0.0) + uv2.xy );
76        blendDQ[1] = texture2D( matrixTexture, vec2(uv1.y, 0.0) + uv2.xy );
77#ifdef BONE_TWO_WEIGHTS
78        mat2x4 blendDQ2;
79        blendDQ2[0] = texture2D( matrixTexture, vec2(uv1.z, 0.0) + uv2.xy );
80        blendDQ2[1] = texture2D( matrixTexture, vec2(uv1.w, 0.0) + uv2.xy );
81
82        //Accurate antipodality handling. For speed increase, remove the following line
83        if (dot(blendDQ[0], blendDQ2[0]) < 0.0) blendDQ2 *= -1.0;
84       
85        //Blend the dual quaternions based on the weights
86        blendDQ *= blendWeights.x;
87        blendDQ += blendWeights.y*blendDQ2;
88        //Normalize the resultant dual quaternion
89        blendDQ /= length(blendDQ[0]);
90#endif
91        worldPos = vec4(calculateBlendPosition(vertex.xyz, blendDQ), 1.0);
92        worldNorm = calculateBlendNormal(normal, blendDQ);
93#else
94        mat4 worldMatrix;
95        worldMatrix[0] = texture2D( matrixTexture, uv1.xw + uv2.xy );
96        worldMatrix[1] = texture2D( matrixTexture, uv1.yw + uv2.xy );
97        worldMatrix[2] = texture2D( matrixTexture, uv1.zw + uv2.xy );
98        worldMatrix[3] = vec4( 0, 0, 0, 1 );
99
100        worldPos                = vertex * worldMatrix;
101        worldNorm               = normal * mat3(worldMatrix);
102#endif
103
104#if BONE_MATRIX_LUT
105        mat4 worldCompMatrix;
106        worldCompMatrix[0] = uv3;
107        worldCompMatrix[1] = uv4;
108        worldCompMatrix[2] = uv5;
109        worldCompMatrix[3] = vec4( 0, 0, 0, 1 );
110       
111        worldPos =  worldPos * worldCompMatrix;
112        worldNorm = worldNorm * mat3(worldCompMatrix);
113#endif
114
115        //Transform the position
116        gl_Position                     = viewProjMatrix * worldPos;
117       
118#if DEPTH_SHADOWCASTER
119        depth.x                         = (gl_Position.z - depthRange.x) * depthRange.w;
120        depth.y                         = depthRange.w;
121#else
122        _uv0            = uv0.xy;
123        oNormal         = worldNorm;
124        oVPos           = worldPos.xyz;
125
126        #if DEPTH_SHADOWRECEIVER
127                oLightSpacePos          = texViewProjMatrix * worldPos;
128                oLightSpacePos.z        = (oLightSpacePos.z - depthRange.x) * depthRange.w;
129        #endif
130#endif
131}
Note: See TracBrowser for help on using the repository browser.