Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/data_extern/programs/GLSL120/VTFInstancing.vert @ 12323

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

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

File size: 3.0 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;
18attribute vec3 tangent;
19
20//Parameters
21uniform mat4 viewProjMatrix;
22uniform sampler2D matrixTexture;
23
24#if (DEPTH_SHADOWCASTER || DEPTH_SHADOWRECEIVER)
25uniform vec4 depthRange;
26#endif
27
28#if DEPTH_SHADOWRECEIVER
29uniform mat4 texViewProjMatrix;
30#endif
31
32//Output
33#if DEPTH_SHADOWCASTER
34        varying vec2 depth;
35#else
36        varying vec2 _uv0;
37        varying vec3 oNormal;
38        varying vec3 oVPos;
39        #if DEPTH_SHADOWRECEIVER
40                varying vec4 oLightSpacePos;
41        #endif
42#endif
43
44vec3 calculateBlendPosition(vec3 position, mat2x4 blendDQ)
45{
46        vec3 blendPosition = position + 2.0*cross(blendDQ[0].yzw, cross(blendDQ[0].yzw, position) + blendDQ[0].x*position);
47        vec3 trans = 2.0*(blendDQ[0].x*blendDQ[1].yzw - blendDQ[1].x*blendDQ[0].yzw + cross(blendDQ[0].yzw, blendDQ[1].yzw));
48        blendPosition += trans;
49
50        return blendPosition;
51}
52
53vec3 calculateBlendNormal(vec3 normal, mat2x4 blendDQ)
54{
55        return normal + 2.0*cross(blendDQ[0].yzw, cross(blendDQ[0].yzw, normal) + blendDQ[0].x*normal);
56}
57
58//---------------------------------------------
59//Main Vertex Shader
60//---------------------------------------------
61void main(void)
62{
63        vec4 worldPos;
64        vec3 worldNorm;
65
66#ifdef ST_DUAL_QUATERNION
67        mat2x4 blendDQ;
68        blendDQ[0] = texture2D( matrixTexture, uv1.xy );
69        blendDQ[1] = texture2D( matrixTexture, uv1.zy );
70#ifdef BONE_TWO_WEIGHTS
71        mat2x4 blendDQ2;
72        blendDQ2[0] = texture2D( matrixTexture, uv2.xy );
73        blendDQ2[1] = texture2D( matrixTexture, uv2.zw );
74
75        //Accurate antipodality handling. For speed increase, remove the following line
76        if (dot(blendDQ[0], blendDQ2[0]) < 0.0) blendDQ2 *= -1.0;
77       
78        //Blend the dual quaternions based on the weights
79        blendDQ *= blendWeights.x;
80        blendDQ += blendWeights.y*blendDQ2;
81        //Normalize the resultant dual quaternion
82        blendDQ /= length(blendDQ[0]);
83#endif
84        worldPos = vec4(calculateBlendPosition(vertex.xyz, blendDQ), 1.0);
85        worldNorm = calculateBlendNormal(normal, blendDQ);
86#else
87        mat4 worldMatrix;
88        worldMatrix[0] = texture2D( matrixTexture, uv1.xy );
89        worldMatrix[1] = texture2D( matrixTexture, uv1.zw );
90        worldMatrix[2] = texture2D( matrixTexture, uv2.xy );
91        worldMatrix[3] = vec4( 0, 0, 0, 1 );
92
93        worldPos                = vertex * worldMatrix;
94        worldNorm               = normal * mat3(worldMatrix);
95#endif
96
97        //Transform the position
98        gl_Position                     = viewProjMatrix * worldPos;
99       
100#if DEPTH_SHADOWCASTER
101        depth.x                         = (gl_Position.z - depthRange.x) * depthRange.w;
102        depth.y                         = depthRange.w;
103#else
104        _uv0            = uv0.xy;
105        oNormal         = worldNorm;
106        oVPos           = worldPos.xyz;
107
108        #if DEPTH_SHADOWRECEIVER
109                oLightSpacePos          = texViewProjMatrix * worldPos;
110                oLightSpacePos.z        = (oLightSpacePos.z - depthRange.x) * depthRange.w;
111        #endif
112#endif
113}
Note: See TracBrowser for help on using the repository browser.