PageRenderTime 109ms CodeModel.GetById 93ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaV.glsl

https://bitbucket.org/lindenlab/viewer-beta/
Unknown | 147 lines | 109 code | 38 blank | 0 comment | 0 complexity | eb676bc0b00ed7faac2fbd88804e4016 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file avatarAlphaV.glsl
  3. *
  4. * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  5. * Second Life Viewer Source Code
  6. * Copyright (C) 2007, Linden Research, Inc.
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation;
  11. * version 2.1 of the License only.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. *
  22. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  23. * $/LicenseInfo$
  24. */
  25. uniform mat4 projection_matrix;
  26. ATTRIBUTE vec3 position;
  27. ATTRIBUTE vec3 normal;
  28. ATTRIBUTE vec2 texcoord0;
  29. vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseCol);
  30. mat4 getSkinnedTransform();
  31. void calcAtmospherics(vec3 inPositionEye);
  32. float calcDirectionalLight(vec3 n, vec3 l);
  33. float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float is_pointlight);
  34. vec3 atmosAmbient(vec3 light);
  35. vec3 atmosAffectDirectionalLight(float lightIntensity);
  36. vec3 scaleDownLight(vec3 light);
  37. vec3 scaleUpLight(vec3 light);
  38. VARYING vec3 vary_position;
  39. VARYING vec3 vary_ambient;
  40. VARYING vec3 vary_directional;
  41. VARYING vec3 vary_fragcoord;
  42. VARYING vec3 vary_pointlight_col;
  43. VARYING vec4 vertex_color;
  44. VARYING vec2 vary_texcoord0;
  45. uniform float near_clip;
  46. uniform vec4 color;
  47. uniform vec4 light_position[8];
  48. uniform vec3 light_direction[8];
  49. uniform vec3 light_attenuation[8];
  50. uniform vec3 light_diffuse[8];
  51. float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight)
  52. {
  53. //get light vector
  54. vec3 lv = lp.xyz-v;
  55. //get distance
  56. float d = length(lv);
  57. float da = 0.0;
  58. if (d > 0.0 && la > 0.0 && fa > 0.0)
  59. {
  60. //normalize light vector
  61. lv *= 1.0/d;
  62. //distance attenuation
  63. float dist2 = d*d/(la*la);
  64. da = clamp(1.0-(dist2-1.0*(1.0-fa))/fa, 0.0, 1.0);
  65. // spotlight coefficient.
  66. float spot = max(dot(-ln, lv), is_pointlight);
  67. da *= spot*spot; // GL_SPOT_EXPONENT=2
  68. //angular attenuation
  69. da *= calcDirectionalLight(n, lv);
  70. }
  71. return da;
  72. }
  73. void main()
  74. {
  75. vary_texcoord0 = texcoord0;
  76. vec4 pos;
  77. vec3 norm;
  78. mat4 trans = getSkinnedTransform();
  79. vec4 pos_in = vec4(position.xyz, 1.0);
  80. pos.x = dot(trans[0], pos_in);
  81. pos.y = dot(trans[1], pos_in);
  82. pos.z = dot(trans[2], pos_in);
  83. pos.w = 1.0;
  84. norm.x = dot(trans[0].xyz, normal);
  85. norm.y = dot(trans[1].xyz, normal);
  86. norm.z = dot(trans[2].xyz, normal);
  87. norm = normalize(norm);
  88. vec4 frag_pos = projection_matrix * pos;
  89. gl_Position = frag_pos;
  90. vary_position = pos.xyz;
  91. calcAtmospherics(pos.xyz);
  92. vec4 col = vec4(0.0, 0.0, 0.0, 1.0);
  93. // Collect normal lights
  94. col.rgb += light_diffuse[2].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[2], light_direction[2], light_attenuation[2].x, light_attenuation[2].y, light_attenuation[2].z);
  95. col.rgb += light_diffuse[3].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[3], light_direction[3], light_attenuation[3].x, light_attenuation[3].y, light_attenuation[3].z);
  96. col.rgb += light_diffuse[4].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[4], light_direction[4], light_attenuation[4].x, light_attenuation[4].y, light_attenuation[4].z);
  97. col.rgb += light_diffuse[5].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[5], light_direction[5], light_attenuation[5].x, light_attenuation[5].y, light_attenuation[5].z);
  98. col.rgb += light_diffuse[6].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[6], light_direction[6], light_attenuation[6].x, light_attenuation[6].y, light_attenuation[6].z);
  99. col.rgb += light_diffuse[7].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[7], light_direction[7], light_attenuation[7].x, light_attenuation[7].y, light_attenuation[7].z);
  100. vary_pointlight_col = col.rgb*color.rgb;
  101. col.rgb = vec3(0,0,0);
  102. // Add windlight lights
  103. col.rgb = atmosAmbient(vec3(0.));
  104. vary_ambient = col.rgb*color.rgb;
  105. vary_directional = color.rgb*atmosAffectDirectionalLight(max(calcDirectionalLight(norm, light_position[0].xyz), 0.0));
  106. col.rgb = col.rgb * color.rgb;
  107. vertex_color = col;
  108. vary_fragcoord.xyz = frag_pos.xyz + vec3(0,0,near_clip);
  109. }