PageRenderTime 111ms CodeModel.GetById 5ms RepoModel.GetById 0ms app.codeStats 0ms

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

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