avatarAlphaV.glsl
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:3k
源码类别:

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file avatarAlphaV.glsl
  3.  *
  4.  * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
  5.  * $License$
  6.  */
  7. vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseCol);
  8. mat4 getSkinnedTransform();
  9. void calcAtmospherics(vec3 inPositionEye);
  10. float calcDirectionalLight(vec3 n, vec3 l);
  11. float calcPointLight(vec3 v, vec3 n, vec4 lp, float la);
  12. vec3 atmosAmbient(vec3 light);
  13. vec3 atmosAffectDirectionalLight(float lightIntensity);
  14. vec3 scaleDownLight(vec3 light);
  15. vec3 scaleUpLight(vec3 light);
  16. varying vec3 vary_position;
  17. varying vec3 vary_ambient;
  18. varying vec3 vary_directional;
  19. varying vec3 vary_normal;
  20. uniform float near_clip;
  21. uniform float shadow_offset;
  22. uniform float shadow_bias;
  23. void main()
  24. {
  25. gl_TexCoord[0] = gl_MultiTexCoord0;
  26. vec4 pos;
  27. vec3 norm;
  28. mat4 trans = getSkinnedTransform();
  29. pos.x = dot(trans[0], gl_Vertex);
  30. pos.y = dot(trans[1], gl_Vertex);
  31. pos.z = dot(trans[2], gl_Vertex);
  32. pos.w = 1.0;
  33. norm.x = dot(trans[0].xyz, gl_Normal);
  34. norm.y = dot(trans[1].xyz, gl_Normal);
  35. norm.z = dot(trans[2].xyz, gl_Normal);
  36. norm = normalize(norm);
  37. gl_Position = gl_ProjectionMatrix * pos;
  38. float dp_directional_light = max(0.0, dot(norm, gl_LightSource[0].position.xyz));
  39. vary_position = pos.xyz + gl_LightSource[0].position.xyz * (1.0-dp_directional_light)*shadow_offset;
  40. vary_normal = norm;
  41. calcAtmospherics(pos.xyz);
  42. //vec4 color = calcLighting(pos.xyz, norm, gl_Color, vec4(0.));
  43. vec4 col;
  44. col.a = gl_Color.a;
  45. // Add windlight lights
  46. col.rgb = atmosAmbient(vec3(0.));
  47. col.rgb = scaleUpLight(col.rgb);
  48. // Collect normal lights (need to be divided by two, as we later multiply by 2)
  49. col.rgb += gl_LightSource[2].diffuse.rgb*calcPointLight(pos.xyz, norm, gl_LightSource[2].position, gl_LightSource[2].linearAttenuation);
  50. col.rgb += gl_LightSource[3].diffuse.rgb*calcPointLight(pos.xyz, norm, gl_LightSource[3].position, gl_LightSource[3].linearAttenuation);
  51. col.rgb += gl_LightSource[4].diffuse.rgb*calcPointLight(pos.xyz, norm, gl_LightSource[4].position, gl_LightSource[4].linearAttenuation);
  52. col.rgb += gl_LightSource[5].diffuse.rgb*calcPointLight(pos.xyz, norm, gl_LightSource[5].position, gl_LightSource[5].linearAttenuation);
  53.   col.rgb += gl_LightSource[6].diffuse.rgb*calcPointLight(pos.xyz, norm, gl_LightSource[6].position, gl_LightSource[6].linearAttenuation);
  54.   col.rgb += gl_LightSource[7].diffuse.rgb*calcPointLight(pos.xyz, norm, gl_LightSource[7].position, gl_LightSource[7].linearAttenuation);
  55. col.rgb += gl_LightSource[1].diffuse.rgb*calcDirectionalLight(norm, gl_LightSource[1].position.xyz);
  56. col.rgb = scaleDownLight(col.rgb);
  57. vary_ambient = col.rgb*gl_Color.rgb;
  58. vary_directional = gl_Color.rgb*atmosAffectDirectionalLight(max(calcDirectionalLight(norm, gl_LightSource[0].position.xyz), (1.0-gl_Color.a)*(1.0-gl_Color.a)));
  59. col.rgb = min(col.rgb*gl_Color.rgb, 1.0);
  60. gl_FrontColor = col;
  61. gl_FogFragCoord = pos.z;
  62. }