Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/Shader_HS18/programs/Example/GLSLES/skinningTwoWeightsVp.glsles @ 12091

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

Updated programs and adjusted Material to work with GLSL>150

File size: 1.8 KB
Line 
1#version 100
2
3precision highp int;
4precision highp float;
5
6// Example GLSL ES program for skinning with two bone weights per vertex
7
8attribute vec4 vertex;
9attribute vec4 uv0;
10attribute vec3 normal;
11attribute vec4 blendIndices;
12attribute vec4 blendWeights;
13
14varying vec4 colour;
15varying vec4 uv;
16
17// 3x4 matrix, passed as vec4's for compatibility with GL ES 2.0
18// Support 24 bones ie 24*3, but use 72 since our parser can pick that out for sizing
19uniform vec4 worldMatrix3x4Array[72];
20uniform mat4 viewProjectionMatrix;
21uniform vec4 lightPos[2];
22uniform vec4 lightDiffuseColour[2];
23uniform vec4 ambient;
24uniform vec4 diffuse;
25
26void main()
27{
28        vec3 blendPos = vec3(0.0);
29        vec3 blendNorm = vec3(0.0);
30       
31        for (int bone = 0; bone < 2; ++bone)
32        {
33                // perform matrix multiplication manually since no 3x4 matrices
34            int idx = int(blendIndices[bone]) * 3;
35
36                mat4 worldMatrix;
37                worldMatrix[0] = worldMatrix3x4Array[idx];
38                worldMatrix[1] = worldMatrix3x4Array[idx + 1];
39                worldMatrix[2] = worldMatrix3x4Array[idx + 2];
40                worldMatrix[3] = vec4(0.0);
41                // now weight this into final
42            float weight = blendWeights[bone];
43                blendPos += (vertex * worldMatrix).xyz * weight;
44
45                mat3 worldRotMatrix = mat3(worldMatrix[0].xyz, worldMatrix[1].xyz, worldMatrix[2].xyz);
46                blendNorm += (normal * worldRotMatrix) * weight;
47        }
48
49        // apply view / projection to position
50        gl_Position = viewProjectionMatrix * vec4(blendPos, 1.0);
51
52        // simple vertex lighting model
53        vec3 lightDir0 = normalize(
54                lightPos[0].xyz -  (blendPos.xyz * lightPos[0].w));
55        vec3 lightDir1 = normalize(
56                lightPos[1].xyz -  (blendPos.xyz * lightPos[1].w));
57
58 
59        colour = diffuse * (ambient
60                + clamp(dot(lightDir0, blendNorm), 0.0, 1.0) * lightDiffuseColour[0]
61                + clamp(dot(lightDir1, blendNorm), 0.0, 1.0) * lightDiffuseColour[1]);
62    uv = uv0;
63}
Note: See TracBrowser for help on using the repository browser.