Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/Shader_HS18/programs/Example/GLSL150/DualQuaternion_TwoPhase.glsl @ 12083

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

Reorganised shader programs

File size: 2.6 KB
Line 
1#version 150
2
3mat2x4 blendTwoWeightsAntipod(vec4 blendWgt, vec4 blendIdx, mat2x4 dualQuaternions[24]);
4vec3 calculateBlendPosition(vec3 position, mat2x4 blendDQ);
5vec3 calculateBlendNormal(vec3 normal, mat2x4 blendDQ);
6
7mat3 adjointTransposeMatrix(mat3 M)
8{
9        mat3 atM;
10        atM[0][0] = M[2][2] * M[1][1] - M[2][1] * M[1][2];
11        atM[1][0] = M[2][1] * M[0][2] - M[0][1] * M[2][2];
12        atM[2][0] = M[0][1] * M[1][2] - M[0][2] * M[1][1];
13
14        atM[0][1] = M[2][0] * M[1][2] - M[2][2] * M[1][0];
15        atM[1][1] = M[2][2] * M[0][0] - M[2][0] * M[0][2];
16        atM[2][1] = M[0][2] * M[1][0] - M[0][0] * M[1][2];
17
18        atM[0][2] = M[2][1] * M[1][0] - M[2][0] * M[1][1];
19        atM[1][2] = M[0][1] * M[2][0] - M[2][1] * M[0][0];
20        atM[2][2] = M[0][0] * M[1][1] - M[0][1] * M[1][0];
21
22        return atM;
23}
24
25uniform vec4 worldDualQuaternion2x4Array[24];
26uniform vec4 scaleM[72];
27uniform mat4 viewProjectionMatrix;
28uniform vec4 lightPos[2];
29uniform vec4 lightDiffuseColour[2];
30uniform vec4 ambient;
31
32in vec4 vertex;
33in vec3 normal;
34in vec4 blendIndices;
35in vec4 blendWeights;
36in vec4 uv0;
37
38out vec4 oUv0;
39out vec4 ambientColour;
40
41void main()
42{       
43        //First phase - applies scaling and shearing:
44        int blendIndicesX = int(blendIndices.x) * 3;
45        int blendIndicesY = int(blendIndices.y) * 3;
46       
47        mat3x4 blendS = blendWeights.x*mat3x4(scaleM[blendIndicesX], 
48                scaleM[blendIndicesX + 1], scaleM[blendIndicesX + 2]);
49       
50        blendS += blendWeights.y*mat3x4(scaleM[blendIndicesY],
51                    scaleM[blendIndicesY + 1], scaleM[blendIndicesY + 2]);
52
53        mat4x3 blendF = transpose(blendS);
54
55        vec3 pass1_position = blendF * vertex;
56
57        mat3x3 blendSrotAT = adjointTransposeMatrix(mat3x3(blendF));
58        vec3 pass1_normal = normalize(blendSrotAT * normal);
59
60        //Second phase
61        mat2x4 blendDQ = blendTwoWeightsAntipod(blendWeights, blendIndices, worldDualQuaternion2x4Array);
62
63        blendDQ /= length(blendDQ[0]);
64
65        vec3 blendPosition = calculateBlendPosition(pass1_position, blendDQ);
66
67        //No need to normalize, the magnitude of the normal is preserved because only rotation is performed
68        vec3 blendNormal = calculateBlendNormal(pass1_normal, blendDQ);
69       
70        gl_Position =  viewProjectionMatrix * vec4(blendPosition, 1.0);
71
72        // Lighting - support point and directional
73        vec3 lightDir0 = normalize(lightPos[0].xyz - (blendPosition * lightPos[0].w));
74        vec3 lightDir1 = normalize(lightPos[1].xyz - (blendPosition * lightPos[1].w));
75
76        oUv0 = uv0;
77
78        ambientColour = /*gl_FrontMaterial.diffuse **/ (ambient + (clamp(dot(lightDir0, blendNormal), 0.0, 1.0) * lightDiffuseColour[0]) + 
79                (clamp(dot(lightDir1, blendNormal), 0.0, 1.0) * lightDiffuseColour[1]));                       
80}
81
Note: See TracBrowser for help on using the repository browser.