Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/Shader_HS18/programs/Example/GLSLES/HW_VTFInstancing.vert @ 12091

Last change on this file since 12091 was 12091, checked in by wiesep, 5 years ago

Updated programs and adjusted Material to work with GLSL>150

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