diff options
author | Jacek Antonelli | 2008-08-15 23:45:34 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:45:34 -0500 |
commit | cd17687f01420952712a500107e0f93e7ab8d5f8 (patch) | |
tree | ce48c2b706f2c1176290e39fb555fbdf6648ce01 /linden/indra/newview/app_settings/shaders/class3/avatar | |
parent | Second Life viewer sources 1.19.0.5 (diff) | |
download | meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.zip meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.gz meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.bz2 meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.xz |
Second Life viewer sources 1.19.1.0
Diffstat (limited to 'linden/indra/newview/app_settings/shaders/class3/avatar')
-rw-r--r-- | linden/indra/newview/app_settings/shaders/class3/avatar/avatarV.glsl | 112 |
1 files changed, 47 insertions, 65 deletions
diff --git a/linden/indra/newview/app_settings/shaders/class3/avatar/avatarV.glsl b/linden/indra/newview/app_settings/shaders/class3/avatar/avatarV.glsl index 2505afe..04c1053 100644 --- a/linden/indra/newview/app_settings/shaders/class3/avatar/avatarV.glsl +++ b/linden/indra/newview/app_settings/shaders/class3/avatar/avatarV.glsl | |||
@@ -1,10 +1,14 @@ | |||
1 | vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec3 baseCol); | 1 | /** |
2 | mat4 getSkinnedTransform(); | 2 | * @file avatarV.glsl |
3 | void default_scatter(vec3 viewVec, vec3 lightDir); | 3 | * |
4 | * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc. | ||
5 | * $License$ | ||
6 | */ | ||
4 | 7 | ||
5 | attribute vec4 materialColor; //2 | 8 | vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseCol); |
9 | mat4 getSkinnedTransform(); | ||
10 | void calcAtmospherics(vec3 inPositionEye); | ||
6 | 11 | ||
7 | attribute vec4 binormal; //6 | ||
8 | attribute vec4 clothing; //4 | 12 | attribute vec4 clothing; //4 |
9 | 13 | ||
10 | attribute vec4 gWindDir; //7 | 14 | attribute vec4 gWindDir; //7 |
@@ -27,102 +31,80 @@ void main() | |||
27 | norm.z = dot(trans[2].xyz, gl_Normal); | 31 | norm.z = dot(trans[2].xyz, gl_Normal); |
28 | norm = normalize(norm); | 32 | norm = normalize(norm); |
29 | 33 | ||
30 | vec3 binorm; | ||
31 | binorm.x = dot(trans[0].xyz, binormal.xyz); | ||
32 | binorm.y = dot(trans[1].xyz, binormal.xyz); | ||
33 | binorm.z = dot(trans[2].xyz, binormal.xyz); | ||
34 | norm = normalize(norm); | ||
35 | |||
36 | //wind | 34 | //wind |
37 | vec4 windEffect; | 35 | vec4 windEffect; |
38 | windEffect = vec4(dot(norm, gWindDir.xyz)); // DP3 windEffect, blendNorm, gWindDir; | 36 | windEffect = vec4(dot(norm, gWindDir.xyz)); |
39 | pos.x = dot(trans[2].xyz, gl_Vertex.xyz); // DP3 blendPos.x, blendMatZ, iPos; | 37 | pos.x = dot(trans[2].xyz, gl_Vertex.xyz); |
40 | windEffect.xyz = pos.x * vec3(0.015, 0.015, 0.015) | 38 | windEffect.xyz = pos.x * vec3(0.015, 0.015, 0.015) |
41 | + windEffect.xyz; // MAD windEffect.xyz, blendPos.x, {0.015, 0.015, 0.015, 0}, windEffect; | 39 | + windEffect.xyz; |
42 | windEffect.w = windEffect.w * 2.0 + 1.0; // MAD windEffect.w, windEffect, {0, 0, 0, 2}, {0, 0, 0, 1}; # move wind offset value to [-1, 3] | 40 | windEffect.w = windEffect.w * 2.0 + 1.0; // move wind offset value to [-1, 3] |
43 | windEffect.w = windEffect.w*gWindDir.w; // MUL windEffect.w, windEffect, gWindDir; # modulate wind strength | 41 | windEffect.w = windEffect.w*gWindDir.w; // modulate wind strength |
44 | 42 | ||
45 | windEffect.xyz = windEffect.xyz*gSinWaveParams.xyz | 43 | windEffect.xyz = windEffect.xyz*gSinWaveParams.xyz |
46 | +vec3(gSinWaveParams.w); // MAD windEffect.xyz, windEffect, gSinWaveParams, gSinWaveParams.w; # use sin wave params to scale and offset input | 44 | +vec3(gSinWaveParams.w); // use sin wave params to scale and offset input |
47 | 45 | ||
48 | 46 | ||
49 | //reduce to period of 2 PI | 47 | //reduce to period of 2 PI |
50 | vec4 temp1, temp0, temp2, offsetPos; | 48 | vec4 temp1, temp0, temp2, offsetPos; |
51 | temp1.xyz = windEffect.xyz * gPiConstants.x; // MUL temp1.xyz, windEffect, gPiConstants.x; # change input as multiple of [0-2PI] to [0-1] | 49 | temp1.xyz = windEffect.xyz * gPiConstants.x; // change input as multiple of [0-2PI] to [0-1] |
52 | temp0.y = mod(temp1.x,1.0); // EXP temp0, temp1.x; # find mod(x, 1) | 50 | temp0.y = mod(temp1.x,1.0); |
53 | windEffect.x = temp0.y * gPiConstants.y; // MUL windEffect.x, temp0.y, gPiConstants.y; # scale from [0,1] to [0, 2PI] | 51 | windEffect.x = temp0.y * gPiConstants.y; // scale from [0,1] to [0, 2PI] |
54 | temp1.z = temp1.z - gPiConstants.w; // ADD temp1.z, temp1.z, -gPiConstants.w; # shift normal oscillation by PI/2 | 52 | temp1.z = temp1.z - gPiConstants.w; // shift normal oscillation by PI/2 |
55 | temp0.y = mod(temp1.z,1.0); // EXP temp0, temp1.z; # find mod(x, 1) | 53 | temp0.y = mod(temp1.z,1.0); |
56 | 54 | ||
57 | windEffect.z = temp0.y * gPiConstants.y; // MUL windEffect.z, temp0.y, gPiConstants.y; # scale from [0,1] to [0, 2PI] | 55 | windEffect.z = temp0.y * gPiConstants.y; // scale from [0,1] to [0, 2PI] |
58 | windEffect.xyz = windEffect.xyz + vec3(-3.141592); // # offset to [-PI, PI] | 56 | windEffect.xyz = windEffect.xyz + vec3(-3.141592); // offset to [-PI, PI] |
59 | // ADD windEffect.xyz, windEffect, {-3.141592, -3.141592, -3.141592, -3.141592}; | 57 | |
60 | 58 | ||
61 | //calculate sinusoid | 59 | //calculate sinusoid |
62 | vec4 sinWave; | 60 | vec4 sinWave; |
63 | temp1 = windEffect*windEffect; // MUL temp1, windEffect, windEffect; # x^2 | 61 | temp1 = windEffect*windEffect; |
64 | sinWave = -temp1 * gMinMaxConstants.w | 62 | sinWave = -temp1 * gMinMaxConstants.w |
65 | + vec4(gMinMaxConstants.z); // MAD sinWave, -temp1, gMinMaxConstants.w, gMinMaxConstants.z; # y = -(x^2)/7! + 1/5! | 63 | + vec4(gMinMaxConstants.z); // y = -(x^2)/7! + 1/5! |
66 | sinWave = sinWave * -temp1 + vec4(gMinMaxConstants.y); // MAD sinWave, sinWave, -temp1, gMinMaxConstants.y; # y = -(x^2) * (-(x^2)/7! + 1/5!) + 1/3! | 64 | sinWave = sinWave * -temp1 + vec4(gMinMaxConstants.y); // y = -(x^2) * (-(x^2)/7! + 1/5!) + 1/3! |
67 | sinWave = sinWave * -temp1 + vec4(gMinMaxConstants.x); // MAD sinWave, sinWave, -temp1, gMinMaxConstants.x; # y = -(x^2) * (-(x^2) * (-(x^2)/7! + 1/5!) + 1/3!) + 1 | 65 | sinWave = sinWave * -temp1 + vec4(gMinMaxConstants.x); // y = -(x^2) * (-(x^2) * (-(x^2)/7! + 1/5!) + 1/3!) + 1 |
68 | sinWave = sinWave * windEffect; // MUL sinWave, sinWave, windEffect; # y = x * (-(x^2) * (-(x^2) * (-(x^2)/7! + 1/5!) + 1/3!) + 1) | 66 | sinWave = sinWave * windEffect; // y = x * (-(x^2) * (-(x^2) * (-(x^2)/7! + 1/5!) + 1/3!) + 1) |
69 | 67 | ||
70 | // sinWave.x holds sin(norm . wind_direction) with primary frequency | 68 | // sinWave.x holds sin(norm . wind_direction) with primary frequency |
71 | // sinWave.y holds sin(norm . wind_direction) with secondary frequency | 69 | // sinWave.y holds sin(norm . wind_direction) with secondary frequency |
72 | // sinWave.z hold cos(norm . wind_direction) with primary frequency | 70 | // sinWave.z hold cos(norm . wind_direction) with primary frequency |
73 | sinWave.xyz = sinWave.xyz * gWindDir.w | 71 | sinWave.xyz = sinWave.xyz * gWindDir.w |
74 | + vec3(windEffect.w); // MAD sinWave.xyz, sinWave, gWindDir.w, windEffect.w; # multiply by wind strength in gWindDir.w [-wind, wind] | 72 | + vec3(windEffect.w); // multiply by wind strength in gWindDir.w [-wind, wind] |
75 | 73 | ||
76 | // add normal facing bias offset [-wind,wind] -> [-wind - .25, wind + 1] | 74 | // add normal facing bias offset [-wind,wind] -> [-wind - .25, wind + 1] |
77 | temp1 = vec4(dot(norm, gGravity.xyz)); // DP3 temp1, blendNorm, gGravity; # how much is this normal facing in direction of gGravity? | 75 | temp1 = vec4(dot(norm, gGravity.xyz)); // how much is this normal facing in direction of gGravity? |
78 | temp1 = min(temp1, vec4(0.2,0.0,0.0,0.0)); // MIN temp1, temp1, {0.2, 0, 0, 0}; # clamp [-1, 1] to [-1, 0.2] | 76 | temp1 = min(temp1, vec4(0.2,0.0,0.0,0.0)); // clamp [-1, 1] to [-1, 0.2] |
79 | temp1 = temp1*vec4(1.5,0.0,0.0,0.0); // MUL temp1, temp1, {1.5, 0, 0, 0}; # scale from [-1,0.2] to [-1.5, 0.3] | 77 | temp1 = temp1*vec4(1.5,0.0,0.0,0.0); // scale from [-1,0.2] to [-1.5, 0.3] |
80 | sinWave.x = sinWave.x + temp1.x; // ADD sinWave.x, sinWave, temp1; # add gGravity effect to sinwave (only primary frequency) | 78 | sinWave.x = sinWave.x + temp1.x; // add gGravity effect to sinwave (only primary frequency) |
81 | sinWave.xyz = sinWave.xyz * clothing.w; // MUL sinWave.xyz, sinWave, iClothing.w; # modulate by clothing coverage | 79 | sinWave.xyz = sinWave.xyz * clothing.w; // modulate by clothing coverage |
82 | 80 | ||
83 | sinWave.xyz = max(sinWave.xyz, vec3(-1.0, -1.0, -1.0)); // MAX sinWave.xyz, sinWave, {-1, -1, -1, -1}; # clamp to underlying body shape | 81 | sinWave.xyz = max(sinWave.xyz, vec3(-1.0, -1.0, -1.0)); // clamp to underlying body shape |
84 | offsetPos = clothing * sinWave.x; // MUL offsetPos, iClothing, sinWave.x; # multiply wind effect times clothing displacement | 82 | offsetPos = clothing * sinWave.x; // multiply wind effect times clothing displacement |
85 | temp2 = gWindDir*sinWave.z + vec4(norm,0); // MAD temp2, gWindDir, sinWave.z, blendNorm; # calculate normal offset due to wind oscillation | 83 | temp2 = gWindDir*sinWave.z + vec4(norm,0); // calculate normal offset due to wind oscillation |
86 | offsetPos = vec4(1.0,1.0,1.0,0.0)*offsetPos+gl_Vertex; // MAD offsetPos, {1.0, 1.0, 1.0, 0.0}, offsetPos, iPos; # add to offset vertex position, and zero out effect from w | 84 | offsetPos = vec4(1.0,1.0,1.0,0.0)*offsetPos+gl_Vertex; // add to offset vertex position, and zero out effect from w |
87 | norm += temp2.xyz*2.0; // MAD blendNorm, temp2, {2, 2, 2, 2}, blendNorm; # add sin wave effect on normals (exaggerated) | 85 | norm += temp2.xyz*2.0; // add sin wave effect on normals (exaggerated) |
88 | 86 | ||
89 | //add "backlighting" effect | 87 | //add "backlighting" effect |
90 | float colorAcc; | 88 | float colorAcc; |
91 | colorAcc = 1.0 - clothing.w; // SUB colorAcc, {1, 1, 1, 1}, iClothing; | 89 | colorAcc = 1.0 - clothing.w; |
92 | norm.z -= colorAcc * 0.2; // MAD blendNorm, colorAcc.w, {0, 0, -0.2, 0}, blendNorm; | 90 | norm.z -= colorAcc * 0.2; |
93 | 91 | ||
94 | //renormalize normal (again) | 92 | //renormalize normal (again) |
95 | norm = normalize(norm); // DP3 divisor.w, blendNorm, blendNorm; | 93 | norm = normalize(norm); |
96 | // RSQ divisor.xyz, divisor.w; | ||
97 | // MUL blendNorm.xyz, blendNorm, divisor; | ||
98 | |||
99 | //project binormal to normal plane to ensure orthogonality | ||
100 | temp2 = vec4(dot(norm, binorm)); // DP3 temp2, blendNorm, blendBinorm; | ||
101 | binorm = binorm - temp2.xyz; // SUB blendBinorm, blendBinorm, temp2; | ||
102 | |||
103 | //renormalize binormal | ||
104 | binorm = normalize(binorm); // DP3 divisor.w, blendBinorm, blendBinorm; | ||
105 | // RSQ divisor.xyz, divisor.w; | ||
106 | // MUL blendBinorm.xyz, blendBinorm, divisor; | ||
107 | 94 | ||
108 | pos.x = dot(trans[0], offsetPos); | 95 | pos.x = dot(trans[0], offsetPos); |
109 | pos.y = dot(trans[1], offsetPos); | 96 | pos.y = dot(trans[1], offsetPos); |
110 | pos.z = dot(trans[2], offsetPos); | 97 | pos.z = dot(trans[2], offsetPos); |
111 | pos.w = 1.0; | 98 | pos.w = 1.0; |
99 | |||
100 | calcAtmospherics(pos.xyz); | ||
112 | 101 | ||
113 | vec4 color = calcLighting(pos.xyz, norm, materialColor, gl_Color.rgb); | 102 | vec4 color = calcLighting(pos.xyz, norm, gl_Color, vec4(0.0)); |
114 | gl_FrontColor = color; | 103 | gl_FrontColor = color; |
115 | 104 | ||
116 | gl_Position = gl_ProjectionMatrix * pos; | 105 | gl_Position = gl_ProjectionMatrix * pos; |
117 | 106 | ||
118 | vec3 N = norm; | ||
119 | vec3 B = binorm; | ||
120 | vec3 T = cross(N,B); | ||
121 | 107 | ||
122 | //gl_TexCoord[1].xy = gl_MultiTexCoord0.xy + 1.0/512.0 * vec2(dot(T,gl_LightSource[0].position.xyz), | ||
123 | // dot(B,gl_LightSource[0].position.xyz)); | ||
124 | |||
125 | gl_TexCoord[2] = vec4(pos.xyz, 1.0); | 108 | gl_TexCoord[2] = vec4(pos.xyz, 1.0); |
126 | default_scatter(pos.xyz, gl_LightSource[0].position.xyz); | 109 | |
127 | 110 | } | |
128 | } \ No newline at end of file | ||