Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/Shader_HS18/programs/Example/GLSL120/skinningTwoWeightsVp.glsl @ 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: 1.4 KB
Line 
1#version 120
2// Example GLSL program for skinning with two bone weights per vertex
3
4attribute vec4 vertex;
5attribute vec3 normal;
6attribute vec4 uv0;
7attribute vec4 blendIndices;
8attribute vec4 blendWeights;
9
10// ogre <> glsl notation is transposed
11uniform mat4x3 worldMatrix3x4Array[24];
12uniform mat4 viewProjectionMatrix;
13uniform vec4 lightPos[2];
14uniform vec4 lightDiffuseColour[2];
15uniform vec4 ambient;
16
17void main()
18{
19        vec3 blendPos = vec3(0.0, 0.0, 0.0);
20        vec3 blendNorm = vec3(0.0, 0.0, 0.0);
21
22        for (int bone = 0; bone < 2; ++bone)
23        {
24        // ATI GLSL compiler can't handle indexing an array within an array so calculate the inner index first
25                int idx = int(blendIndices[bone]);
26
27                // now weight this into final
28                float weight = blendWeights[bone];
29                blendPos += worldMatrix3x4Array[idx]* vertex * weight;
30
31                mat3 worldRotMatrix = mat3(worldMatrix3x4Array[idx]);
32                blendNorm += (worldRotMatrix * normal) * weight;
33        }
34
35        blendNorm = normalize(blendNorm);
36
37        // apply view / projection to position
38        gl_Position = viewProjectionMatrix * vec4(blendPos, 1.0);
39
40        // simple vertex lighting model
41        vec3 lightDir0 = normalize(
42                lightPos[0].xyz -  (blendPos * lightPos[0].w));
43        vec3 lightDir1 = normalize(
44                lightPos[1].xyz -  (blendPos * lightPos[1].w));
45
46        gl_FrontColor = gl_FrontMaterial.diffuse * (ambient + (clamp(dot(lightDir0, blendNorm), 0.0, 1.0) * lightDiffuseColour[0]) +
47                (clamp(dot(lightDir1, blendNorm), 0.0, 1.0) * lightDiffuseColour[1]));
48
49        gl_TexCoord[0] = uv0;
50}
Note: See TracBrowser for help on using the repository browser.