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

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file postDeferredF.glsl
  3.  *
  4.  * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
  5.  * $License$
  6.  */
  7.  
  8. #extension GL_ARB_texture_rectangle : enable
  9. uniform sampler2DRect diffuseRect;
  10. uniform sampler2DRect specularRect;
  11. uniform sampler2DRect localLightMap;
  12. uniform sampler2DRect sunLightMap;
  13. uniform sampler2DRect giLightMap;
  14. uniform sampler2DRect edgeMap;
  15. uniform sampler2D   luminanceMap;
  16. uniform sampler2DRect lightMap;
  17. uniform sampler2D   lightFunc;
  18. uniform sampler2D   noiseMap;
  19. uniform float sun_lum_scale;
  20. uniform float sun_lum_offset;
  21. uniform float lum_scale;
  22. uniform float lum_lod;
  23. uniform vec4 ambient;
  24. uniform float gi_brightness;
  25. uniform float gi_luminance;
  26. uniform vec4 sunlight_color;
  27. uniform vec2 screen_res;
  28. varying vec2 vary_fragcoord;
  29. void main() 
  30. {
  31. vec2 tc = vary_fragcoord.xy;
  32. vec4 lcol = texture2DLod(luminanceMap, vec2(0.5, 0.5), lum_lod);
  33. vec3 gi_col = texture2DRect(giLightMap, vary_fragcoord.xy).rgb;
  34. vec4 sun_col = texture2DRect(sunLightMap, vary_fragcoord.xy);
  35. vec3 local_col = texture2DRect(localLightMap, vary_fragcoord.xy).rgb;
  36. float scol = texture2DRect(lightMap, vary_fragcoord.xy).r;
  37. vec3 diff = texture2DRect(diffuseRect, vary_fragcoord.xy).rgb;
  38. vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy);
  39. gi_col = gi_col*(diff.rgb+spec.rgb*spec.a);
  40. float lum = 1.0-clamp(pow(lcol.r, gi_brightness)+sun_lum_offset, 0.0, 1.0);
  41. lum *= sun_lum_scale;
  42. sun_col *= 1.0+(lum*lum_scale*scol);
  43.   
  44. vec4 col;
  45. col.rgb = gi_col+sun_col.rgb+local_col;
  46. col.a = sun_col.a;
  47. vec3 bcol = vec3(0,0,0);
  48. float tweight = 0.0;
  49. for (int i = 0; i < 16; i++)
  50. {
  51. float weight = (float(i)+1.0)/2.0;
  52. bcol += texture2DLod(luminanceMap, vary_fragcoord.xy/screen_res, weight).rgb*weight*weight*weight;
  53. tweight += weight*weight;
  54. }
  55. bcol /= tweight;
  56. bcol *= gi_luminance;
  57. col.rgb += bcol*lum;
  58. gl_FragColor = col;
  59. //gl_FragColor.rgb = texture2DRect(giLightMap, vary_fragcoord.xy).rgb;
  60. }