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

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file alphaV.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. void calcAtmospherics(vec3 inPositionEye);
  9. float calcDirectionalLight(vec3 n, vec3 l);
  10. float calcPointLight(vec3 v, vec3 n, vec4 lp, float la);
  11. vec3 atmosAmbient(vec3 light);
  12. vec3 atmosAffectDirectionalLight(float lightIntensity);
  13. vec3 scaleDownLight(vec3 light);
  14. vec3 scaleUpLight(vec3 light);
  15. varying vec3 vary_ambient;
  16. varying vec3 vary_directional;
  17. varying vec3 vary_fragcoord;
  18. varying vec3 vary_position;
  19. varying vec3 vary_light;
  20. uniform float near_clip;
  21. uniform float shadow_offset;
  22. uniform float shadow_bias;
  23. void main()
  24. {
  25. //transform vertex
  26. gl_Position = ftransform(); 
  27. gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
  28. vec4 pos = (gl_ModelViewMatrix * gl_Vertex);
  29. vec3 norm = normalize(gl_NormalMatrix * gl_Normal);
  30. float dp_directional_light = max(0.0, dot(norm, gl_LightSource[0].position.xyz));
  31. vary_position = pos.xyz + gl_LightSource[0].position.xyz * (1.0-dp_directional_light)*shadow_offset;
  32. calcAtmospherics(pos.xyz);
  33. //vec4 color = calcLighting(pos.xyz, norm, gl_Color, vec4(0.));
  34. vec4 col;
  35. col.a = gl_Color.a;
  36. // Add windlight lights
  37. col.rgb = atmosAmbient(vec3(0.));
  38. col.rgb = scaleUpLight(col.rgb);
  39. // Collect normal lights (need to be divided by two, as we later multiply by 2)
  40. col.rgb += gl_LightSource[2].diffuse.rgb*calcPointLight(pos.xyz, norm, gl_LightSource[2].position, gl_LightSource[2].linearAttenuation);
  41. col.rgb += gl_LightSource[3].diffuse.rgb*calcPointLight(pos.xyz, norm, gl_LightSource[3].position, gl_LightSource[3].linearAttenuation);
  42. col.rgb += gl_LightSource[4].diffuse.rgb*calcPointLight(pos.xyz, norm, gl_LightSource[4].position, gl_LightSource[4].linearAttenuation);
  43. col.rgb += gl_LightSource[5].diffuse.rgb*calcPointLight(pos.xyz, norm, gl_LightSource[5].position, gl_LightSource[5].linearAttenuation);
  44.   col.rgb += gl_LightSource[6].diffuse.rgb*calcPointLight(pos.xyz, norm, gl_LightSource[6].position, gl_LightSource[6].linearAttenuation);
  45.   col.rgb += gl_LightSource[7].diffuse.rgb*calcPointLight(pos.xyz, norm, gl_LightSource[7].position, gl_LightSource[7].linearAttenuation);
  46. col.rgb += gl_LightSource[1].diffuse.rgb*calcDirectionalLight(norm, gl_LightSource[1].position.xyz);
  47. col.rgb = scaleDownLight(col.rgb);
  48. vary_light = gl_LightSource[0].position.xyz;
  49. vary_ambient = col.rgb*gl_Color.rgb;
  50. vary_directional.rgb = gl_Color.rgb*atmosAffectDirectionalLight(max(calcDirectionalLight(norm, gl_LightSource[0].position.xyz), (1.0-gl_Color.a)*(1.0-gl_Color.a)));
  51. col.rgb = min(col.rgb*gl_Color.rgb, 1.0);
  52. gl_FrontColor = col;
  53. gl_FogFragCoord = pos.z;
  54. pos = gl_ModelViewProjectionMatrix * gl_Vertex;
  55. vary_fragcoord.xyz = pos.xyz + vec3(0,0,near_clip);
  56. }