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 vec4 vary_position;
  17. varying vec3 vary_ambient;
  18. varying vec3 vary_directional;
  19. varying vec3 vary_normal;
  20. void main()
  21. {
  22. gl_TexCoord[0] = gl_MultiTexCoord0;
  23. vec4 pos;
  24. vec3 norm;
  25. mat4 trans = getSkinnedTransform();
  26. pos.x = dot(trans[0], gl_Vertex);
  27. pos.y = dot(trans[1], gl_Vertex);
  28. pos.z = dot(trans[2], gl_Vertex);
  29. pos.w = 1.0;
  30. norm.x = dot(trans[0].xyz, gl_Normal);
  31. norm.y = dot(trans[1].xyz, gl_Normal);
  32. norm.z = dot(trans[2].xyz, gl_Normal);
  33. norm = normalize(norm);
  34. gl_Position = gl_ProjectionMatrix * pos;
  35. vary_position = pos;
  36. vary_normal = norm;
  37. calcAtmospherics(pos.xyz);
  38. //vec4 color = calcLighting(pos.xyz, norm, gl_Color, vec4(0.));
  39. vec4 col;
  40. col.a = gl_Color.a;
  41. // Add windlight lights
  42. col.rgb = atmosAmbient(vec3(0.));
  43. col.rgb = scaleUpLight(col.rgb);
  44. // Collect normal lights (need to be divided by two, as we later multiply by 2)
  45. col.rgb += gl_LightSource[2].diffuse.rgb*calcPointLight(pos.xyz, norm, gl_LightSource[2].position, gl_LightSource[2].linearAttenuation);
  46. col.rgb += gl_LightSource[3].diffuse.rgb*calcPointLight(pos.xyz, norm, gl_LightSource[3].position, gl_LightSource[3].linearAttenuation);
  47. col.rgb += gl_LightSource[4].diffuse.rgb*calcPointLight(pos.xyz, norm, gl_LightSource[4].position, gl_LightSource[4].linearAttenuation);
  48. col.rgb += gl_LightSource[5].diffuse.rgb*calcPointLight(pos.xyz, norm, gl_LightSource[5].position, gl_LightSource[5].linearAttenuation);
  49.   col.rgb += gl_LightSource[6].diffuse.rgb*calcPointLight(pos.xyz, norm, gl_LightSource[6].position, gl_LightSource[6].linearAttenuation);
  50.   col.rgb += gl_LightSource[7].diffuse.rgb*calcPointLight(pos.xyz, norm, gl_LightSource[7].position, gl_LightSource[7].linearAttenuation);
  51. col.rgb += gl_LightSource[1].diffuse.rgb*calcDirectionalLight(norm, gl_LightSource[1].position.xyz);
  52. col.rgb = scaleDownLight(col.rgb);
  53. vary_ambient = col.rgb*gl_Color.rgb;
  54. vary_directional = gl_Color.rgb*atmosAffectDirectionalLight(max(calcDirectionalLight(norm, gl_LightSource[0].position.xyz), (1.0-gl_Color.a)*(1.0-gl_Color.a)));
  55. col.rgb = min(col.rgb*gl_Color.rgb, 1.0);
  56. gl_FrontColor = col;
  57. gl_FogFragCoord = pos.z;
  58. }