Advertisement
Guest User

Untitled

a guest
Apr 29th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.24 KB | None | 0 0
  1. #version 120
  2.  
  3. #define SKY_DESATURATION 0.0f
  4.  
  5. varying vec4 texcoord;
  6.  
  7. uniform vec3 sunPosition;
  8. uniform vec3 moonPosition;
  9. uniform vec3 upPosition;
  10. uniform float rainStrength;
  11. uniform vec3 skyColor;
  12. uniform float sunAngle;
  13.  
  14. uniform int worldTime;
  15.  
  16. varying vec3 lightVector;
  17. varying vec3 upVector;
  18.  
  19. varying float timeSunriseSunset;
  20. varying float timeNoon;
  21. varying float timeMidnight;
  22. varying float timeSkyDark;
  23.  
  24. varying vec3 colorSunlight;
  25. varying vec3 colorSkylight;
  26. varying vec3 colorSunglow;
  27. varying vec3 colorBouncedSunlight;
  28. varying vec3 colorScatteredSunlight;
  29. varying vec3 colorTorchlight;
  30. varying vec3 colorWaterMurk;
  31. varying vec3 colorWaterBlue;
  32. varying vec3 colorSkyTint;
  33.  
  34.  
  35. float CubicSmooth(in float x)
  36. {
  37. return x * x * (3.0f - 2.0f * x);
  38. }
  39.  
  40. float clamp01(float x)
  41. {
  42. return clamp(x, 0.0, 1.0);
  43. }
  44.  
  45.  
  46. void main() {
  47. gl_Position = ftransform();
  48.  
  49. texcoord = gl_MultiTexCoord0;
  50.  
  51. if (sunAngle < 0.5f) {
  52. lightVector = normalize(sunPosition);
  53. } else {
  54. lightVector = normalize(moonPosition);
  55. }
  56.  
  57. vec3 sunVector = normalize(sunPosition);
  58.  
  59. upVector = normalize(upPosition);
  60.  
  61.  
  62. float timePow = 4.0f;
  63.  
  64. float LdotUp = dot(upVector, sunVector);
  65. float LdotDown = dot(-upVector, sunVector);
  66.  
  67. timeNoon = 1.0 - pow(1.0 - clamp01(LdotUp), timePow);
  68. timeSunriseSunset = 1.0 - timeNoon;
  69. timeMidnight = CubicSmooth(CubicSmooth(clamp01(LdotDown * 20.0f + 0.4)));
  70. timeMidnight = 1.0 - pow(1.0 - timeMidnight, 2.0);
  71. timeSunriseSunset *= 1.0 - timeMidnight;
  72. timeNoon *= 1.0 - timeMidnight;
  73.  
  74. // timeSkyDark = clamp01(LdotDown);
  75. // timeSkyDark = pow(timeSkyDark, 3.0f);
  76. timeSkyDark = 0.0f;
  77.  
  78.  
  79. float horizonTime = CubicSmooth(clamp01((1.0 - abs(LdotUp)) * 4.0f - 3.0f));
  80. horizonTime = 1.0 - pow(1.0 - horizonTime, 3.0);
  81.  
  82. const float rayleigh = 0.00f;
  83.  
  84.  
  85. colorWaterMurk = vec3(0.2f, 0.5f, 0.95f);
  86. colorWaterBlue = vec3(0.2f, 0.5f, 0.95f);
  87. colorWaterBlue = mix(colorWaterBlue, vec3(1.0f), vec3(0.5f));
  88.  
  89. //colors for shadows/sunlight and sky
  90.  
  91. vec3 sunrise_sun;
  92. sunrise_sun.r = 1.00;
  93. sunrise_sun.g = 0.58;
  94. sunrise_sun.b = 0.00;
  95. sunrise_sun *= 0.65f;
  96.  
  97. vec3 sunrise_amb;
  98. sunrise_amb.r = 0.30 ;
  99. sunrise_amb.g = 0.595;
  100. sunrise_amb.b = 0.70 ;
  101. sunrise_amb *= 1.0f;
  102.  
  103.  
  104. vec3 noon_sun;
  105. noon_sun.r = mix(1.00, 1.00, rayleigh);
  106. noon_sun.g = mix(1.00, 0.75, rayleigh);
  107. noon_sun.b = mix(1.00, 0.00, rayleigh);
  108.  
  109. vec3 noon_amb;
  110. noon_amb.r = 0.00 ;
  111. noon_amb.g = 0.3 ;
  112. noon_amb.b = 0.999;
  113.  
  114. // vec3 sunset_sun;
  115. // sunset_sun.r = 1.0 ;
  116. // sunset_sun.g = 0.58;
  117. // sunset_sun.b = 0.0 ;
  118. // sunset_sun *= 0.65f;
  119.  
  120. // vec3 sunset_amb;
  121. // sunset_amb.r = 1.0;
  122. // sunset_amb.g = 0.0;
  123. // sunset_amb.b = 0.0;
  124. // sunset_amb *= 1.0f;
  125.  
  126. vec3 midnight_sun;
  127. midnight_sun.r = 1.0;
  128. midnight_sun.g = 1.0;
  129. midnight_sun.b = 1.0;
  130.  
  131. vec3 midnight_amb;
  132. midnight_amb.r = 0.0 ;
  133. midnight_amb.g = 0.23;
  134. midnight_amb.b = 0.99;
  135.  
  136.  
  137. colorSunlight = sunrise_sun * timeSunriseSunset + noon_sun * timeNoon + midnight_sun * timeMidnight;
  138.  
  139.  
  140.  
  141. sunrise_amb = vec3(0.19f, 0.35f, 0.7f) * 0.15f;
  142. noon_amb = vec3(0.15f, 0.29f, 0.99f);
  143. midnight_amb = vec3(0.005f, 0.01f, 0.02f) * 0.025f;
  144.  
  145. colorSkylight = sunrise_amb * timeSunriseSunset + noon_amb * timeNoon + midnight_amb * timeMidnight;
  146.  
  147. vec3 colorSunglow_sunrise;
  148. colorSunglow_sunrise.r = 1.00f * timeSunriseSunset;
  149. colorSunglow_sunrise.g = 0.46f * timeSunriseSunset;
  150. colorSunglow_sunrise.b = 0.00f * timeSunriseSunset;
  151.  
  152. vec3 colorSunglow_noon;
  153. colorSunglow_noon.r = 1.0f * timeNoon;
  154. colorSunglow_noon.g = 1.0f * timeNoon;
  155. colorSunglow_noon.b = 1.0f * timeNoon;
  156.  
  157. vec3 colorSunglow_midnight;
  158. colorSunglow_midnight.r = 0.05f * 0.8f * 0.0055f * timeMidnight;
  159. colorSunglow_midnight.g = 0.20f * 0.8f * 0.0055f * timeMidnight;
  160. colorSunglow_midnight.b = 0.90f * 0.8f * 0.0055f * timeMidnight;
  161.  
  162. colorSunglow = colorSunglow_sunrise + colorSunglow_noon + colorSunglow_midnight;
  163.  
  164.  
  165.  
  166.  
  167. //colorBouncedSunlight = mix(vec3(0.64f, 0.73f, 0.34f), colorBouncedSunlight, 0.5f);
  168. //colorBouncedSunlight = colorSunlight;
  169.  
  170. //colorSkylight.g *= 0.95f;
  171.  
  172. //colorSkylight = mix(colorSkylight, vec3(dot(colorSkylight, vec3(1.0))), SKY_DESATURATION);
  173.  
  174. float sun_fill = 0.0;
  175.  
  176. //colorSkylight = mix(colorSkylight, colorSunlight, sun_fill);
  177. vec3 colorSkylight_rain = vec3(2.0, 2.0, 2.38) * 0.25f * (1.0f - timeMidnight * 0.9995f); //rain
  178. colorSkylight = mix(colorSkylight, colorSkylight_rain, rainStrength); //rain
  179.  
  180.  
  181.  
  182. //Saturate sunlight colors
  183. colorSunlight = pow(colorSunlight, vec3(4.2f));
  184.  
  185. colorSunlight *= 1.0f - horizonTime;
  186.  
  187.  
  188. colorBouncedSunlight = mix(colorSunlight, colorSkylight, 0.15f);
  189.  
  190. colorScatteredSunlight = mix(colorSunlight, colorSkylight, 0.15f);
  191.  
  192. colorSunglow = pow(colorSunglow, vec3(2.5f));
  193.  
  194. //colorSunlight = vec3(1.0f, 0.5f, 0.0f);
  195.  
  196. //Make ambient light darker when not day time
  197. // colorSkylight = mix(colorSkylight, colorSkylight * 0.03f, timeSunrise);
  198. // colorSkylight = mix(colorSkylight, colorSkylight * 1.0f, timeNoon);
  199. // colorSkylight = mix(colorSkylight, colorSkylight * 0.3f, timeSunset);
  200. // colorSkylight = mix(colorSkylight, colorSkylight * 0.0080f, timeMidnight);
  201. // colorSkylight *= mix(1.0f, 0.001f, timeMidnightLin);
  202. // colorSkylight *= mix(1.0f, 0.001f, timeSunriseLin);
  203. //colorSkylight = vec3(0.3f) * vec3(0.17f, 0.37f, 0.8f);
  204.  
  205. // colorSkylight = vec3(0.0f, 0.0f, 1.0f);
  206. // colorSunlight = vec3(1.0f, 1.0f, 0.0f); //fuf
  207.  
  208. //Make sunlight darker when not day time
  209. colorSunlight = mix(colorSunlight, colorSunlight * 0.5f, timeSunriseSunset);
  210. colorSunlight = mix(colorSunlight, colorSunlight * 1.0f, timeNoon);
  211. colorSunlight = mix(colorSunlight, colorSunlight * 0.00020f, timeMidnight);
  212.  
  213. //Make reflected light darker when not day time
  214. colorBouncedSunlight = mix(colorBouncedSunlight, colorBouncedSunlight * 0.5f, timeSunriseSunset);
  215. colorBouncedSunlight = mix(colorBouncedSunlight, colorBouncedSunlight * 1.0f, timeNoon);
  216. colorBouncedSunlight = mix(colorBouncedSunlight, colorBouncedSunlight * 0.000015f, timeMidnight);
  217.  
  218. //Make scattered light darker when not day time
  219. colorScatteredSunlight = mix(colorScatteredSunlight, colorScatteredSunlight * 0.5f, timeSunriseSunset);
  220. colorScatteredSunlight = mix(colorScatteredSunlight, colorScatteredSunlight * 1.0f, timeNoon);
  221. colorScatteredSunlight = mix(colorScatteredSunlight, colorScatteredSunlight * 0.000015f, timeMidnight);
  222.  
  223. //Make scattered light darker when not day time
  224. // colorSkyTint = mix(colorSkyTint, colorSkyTint * 0.5f, timeSunrise);
  225. // colorSkyTint = mix(colorSkyTint, colorSkyTint * 1.0f, timeNoon);
  226. // colorSkyTint = mix(colorSkyTint, colorSkyTint * 0.5f, timeSunset);
  227. // colorSkyTint = mix(colorSkyTint, colorSkyTint * 0.0045f, timeMidnight);
  228.  
  229.  
  230.  
  231. float colorSunlightLum = colorSunlight.r + colorSunlight.g + colorSunlight.b;
  232. colorSunlightLum /= 3.0f;
  233.  
  234. colorSunlight = mix(colorSunlight, vec3(colorSunlightLum), vec3(rainStrength));
  235.  
  236.  
  237. //Torchlight color
  238. float torchWhiteBalance = 0.015f;
  239. colorTorchlight = vec3(0.28f, 0.42f, 0.4f);
  240. colorTorchlight = mix(colorTorchlight, vec3(1.0f), vec3(torchWhiteBalance));
  241.  
  242. colorTorchlight = pow(colorTorchlight, vec3(0.99f));
  243.  
  244.  
  245. //colorSkylight = vec3(0.1f);
  246.  
  247. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement