Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/Shader_HS18/programs/GLSL120/skinningTwoWeightsVp.glsl @ 12115

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

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

File size: 1.5 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;
16uniform vec4 diffuse;
17
18void main()
19{
20        vec3 blendPos = vec3(0.0, 0.0, 0.0);
21        vec3 blendNorm = vec3(0.0, 0.0, 0.0);
22
23        for (int bone = 0; bone < 2; ++bone)
24        {
25        // ATI GLSL compiler can't handle indexing an array within an array so calculate the inner index first
26                int idx = int(blendIndices[bone]);
27
28                // now weight this into final
29                float weight = blendWeights[bone];
30                blendPos += worldMatrix3x4Array[idx]* vertex * weight;
31
32                mat3 worldRotMatrix = mat3(worldMatrix3x4Array[idx]);
33                blendNorm += (worldRotMatrix * normal) * weight;
34        }
35
36        blendNorm = normalize(blendNorm);
37
38        // apply view / projection to position
39        gl_Position = viewProjectionMatrix * vec4(blendPos, 1.0);
40
41        // simple vertex lighting model
42        vec3 lightDir0 = normalize(
43                lightPos[0].xyz -  (blendPos * lightPos[0].w));
44        vec3 lightDir1 = normalize(
45                lightPos[1].xyz -  (blendPos * lightPos[1].w));
46
47        gl_FrontColor = gl_FrontMaterial.diffuse * (ambient + (clamp(dot(lightDir0, blendNorm), 0.0, 1.0) * lightDiffuseColour[0]) +
48                (clamp(dot(lightDir1, blendNorm), 0.0, 1.0) * lightDiffuseColour[1]));
49
50        gl_TexCoord[0] = uv0;
51}
Note: See TracBrowser for help on using the repository browser.