Advertisement
waffr

Volumetric Cloud For Seus 10.1 Final

Dec 18th, 2014
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.36 KB | None | 0 0
  1. Uncomment= Remove the //
  2. Comment= Put in the //
  3. EX. Comment= //CalculateClouds
  4. Uncomment= CalculateClouds
  5.  
  6. Open composite.fsh
  7.  
  8. Copy this from line 1422 to line 1637 or until it says
  9. //color.rgb = mix(color.rgb, cloudSum.rgb, vec3(min(1.0f, cloudSum.a * 20.0f)));
  10. //color.rgb = cloudSum.rgb;
  11. }
  12.  
  13. //##Copy Below##//
  14. vec4 CloudColor(in vec4 worldPosition, in float sunglow, in vec3 worldLightVector)
  15. {
  16.  
  17. float cloudHeight = 460.0f;
  18. float cloudDepth = 170.0f;
  19. float cloudUpperHeight = cloudHeight + (cloudDepth / 2.0f);
  20. float cloudLowerHeight = cloudHeight - (cloudDepth / 2.0f);
  21.  
  22. if (worldPosition.y < cloudLowerHeight || worldPosition.y > cloudUpperHeight)
  23. return vec4(0.0f);
  24. else
  25. {
  26.  
  27. vec3 p = worldPosition.xyz / 185.0f;
  28.  
  29.  
  30.  
  31. float t = frameTimeCounter * .1f;
  32. //t *= 0.001;
  33. p.x -= t * 0.2f;
  34.  
  35. p += (Get3DNoise(p * 1.0f + vec3(0.021f, t * 0.001f, 0.051f)) * 1.0f - 1.0f) * 0.4f;
  36.  
  37. vec3 p1 = p * vec3(1.0f, 0.5f, 1.0f) + vec3(0.01f, t * 0.001f, 0.01f);
  38. float noise = Get3DNoise(p * vec3(1f, 1f, 1f) + vec3(0.5f, t * 0.0001f, 0.01f)); p *= 3.0f; p.x -= t * 0.07f; vec3 p2 = p;
  39. noise += (1.0f - abs(Get3DNoise(p) * 1.0f - 0.5f)) * 0.45f; p *= 3.0f; p.xz -= t * .3f; vec3 p3 = p;
  40. noise += (1.0f - abs(Get3DNoise(p) * 3.0f - 1.5f)) * 0.065f; p *= 3.0f; p.xz -= t * .5f;
  41. noise += (1.0f - abs(Get3DNoise(p) * 3.0f - 1.0f)) * 0.022f;
  42. noise /= 1.875f;
  43.  
  44.  
  45.  
  46. const float lightOffset = 0.35f;
  47.  
  48.  
  49. float heightGradient = clamp(( - (cloudLowerHeight - worldPosition.y) / (cloudDepth * 1.0f)), 0.0f, 1.0f);
  50. float heightGradient2 = clamp(( - (cloudLowerHeight - (worldPosition.y + worldLightVector.y * lightOffset * 30.0f)) / (cloudDepth * 1.0f)), 0.0f, 1.0f);
  51.  
  52. float cloudAltitudeWeight = 1.0f - clamp(distance(worldPosition.y, cloudHeight) / (cloudDepth / 2.0f), 0.0f, 1.0f);
  53. cloudAltitudeWeight = pow(cloudAltitudeWeight, mix(0.2f, 0.6f, rainStrength));
  54. cloudAltitudeWeight *= 1.0f - heightGradient;
  55.  
  56. float cloudAltitudeWeight2 = 1.0f - clamp(distance(worldPosition.y + worldLightVector.y * lightOffset * 30.0f, cloudHeight) / (cloudDepth / 2.0f), 0.0f, 1.0f);
  57. cloudAltitudeWeight2 = pow(cloudAltitudeWeight2, mix(0.2f, 0.6f, rainStrength));
  58. cloudAltitudeWeight2 *= 1.0f - heightGradient2;
  59.  
  60. noise *= cloudAltitudeWeight;
  61.  
  62. //cloud edge
  63. float coverage = .73f;
  64. coverage = mix(coverage, 0.77f, rainStrength);
  65. float density = .4f;
  66. //noise = clamp(noise - (1.0f - coverage), 0.0f, 1.0f - density) / (1.0f - density);
  67. noise = GetCoverage(coverage, density, noise) / (density, noise - (1.04f - coverage));
  68.  
  69. float sunProximity = pow(sunglow, 1f);
  70. float propigation = mix(15.0f, 9.0f, sunProximity);
  71.  
  72.  
  73. // float directLightFalloff = pow(heightGradient, propigation);
  74. // directLightFalloff += pow(heightGradient, propigation / 2.0f);
  75. // directLightFalloff /= 2.0f;
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82. //float sundiff = -Get3DNoise(p1 + worldLightVector.xyz * lightOffset) * cloudAltitudeWeight2;
  83. //sundiff += -(1.0f - abs(Get3DNoise(p2 + worldLightVector.xyz * lightOffset) * 1.0f - 0.5f)) * 0.4f * cloudAltitudeWeight2;
  84. //sundiff += -(1.0f - abs(Get3DNoise(p3 + worldLightVector.xyz * lightOffset) * 3.0f - 1.0f)) * 0.035f * cloudAltitudeWeight2;
  85. float sundiff = Get3DNoise(p1 + worldLightVector.xyz * lightOffset);
  86. sundiff += (1.0f - abs(Get3DNoise(p2 + worldLightVector.xyz * lightOffset) * 1.0f - 0.5f)) * 0.4f;
  87. sundiff *= 1.0f;
  88. sundiff *= cloudAltitudeWeight2;
  89. //sundiff += (1.0f - abs(Get3DNoise(p3 + worldLightVector.xyz * lightOffset) * 3.0f - 1.0f)) * 0.075f * cloudAltitudeWeight2;
  90. sundiff = -GetCoverage(coverage * 1.0f, 0.0f, sundiff);
  91. float firstOrder = pow(clamp(sundiff * 1.0f + 1.1f, 0.0f, 1.0f), 56.0f);
  92. //firstOrder *= pow(clamp(1.3f - noise, 0.0f, 1.0f), 12.0f);
  93. float secondOrder = pow(clamp(sundiff * 1.0f + 1.1f, 0.0f, 1.0f), 11.0f);
  94.  
  95. //directLightFalloff *= mix( clamp(pow(noise, 1.2f) * 1.0f, 0.0f, 1.0f), clamp(pow(1.0f - noise, 10.3f), 0.0f, 0.5f), pow(sunglow, 1.2f));
  96.  
  97.  
  98.  
  99.  
  100. float directLightFalloff = mix(firstOrder, secondOrder, 0.5f);
  101. //float directLightFalloff = firstOrder;
  102. float anisoBackFactor = mix(clamp(pow(noise, 1.6f) * 2.5f, 0.0f, 1.0f), 1.0f, pow(sunglow, 1.0f));
  103.  
  104. directLightFalloff *= anisoBackFactor;
  105. directLightFalloff *= mix(11.5f, 1.0f, pow(sunglow, 0.5f));
  106.  
  107.  
  108.  
  109.  
  110. vec3 colorDirect = colorSunlight * .35f;
  111. colorDirect = mix(colorDirect, colorDirect * vec3(0.6f, 0.8f, 1.1f), timeMidnight);
  112. //colorDirect *= 1.0f + pow(sunglow, 10.0f) * 0.0f * pow(directLightFalloff, 1.0f);
  113. colorDirect *= 1.0f + pow(sunglow, 2.0f) * 100.0f * pow(directLightFalloff, 1.1f) * (1.0f - rainStrength);
  114. //colorDirect *= mix(1.0f, (clamp(pow(1.1f - noise, 50.09f) * 1.0f, 0.0f, 1.0f)) * 5.0f + 1.0f, pow(sunglow, 1.5f));
  115.  
  116.  
  117. vec3 colorAmbient = mix(colorSkylight, colorSunlight * 2.0f, vec3(heightGradient * 0.0f)) * 0.03f;
  118. colorAmbient *= vec3(0.5f, 0.7f, 1.0f);
  119. colorAmbient *= mix(1.0f, 0.3f, timeMidnight);
  120. colorAmbient = mix(colorAmbient, colorAmbient * 3.0f + colorSunlight * 0.05f, vec3(clamp(pow(1.0f - noise, 12.0f) * 1.0f, 0.0f, 1.0f)));
  121. colorAmbient *= heightGradient * heightGradient + 0.1f;
  122.  
  123. vec3 colorBounced = colorBouncedSunlight * 0.1f;
  124. colorBounced *= pow((1.0f - heightGradient), 8.0f);
  125.  
  126.  
  127. directLightFalloff *= 1.0f - rainStrength * 0.7;
  128.  
  129. // //cloud shadows
  130. //vec4 shadowPosition = shadowModelView * (worldPosition - vec4(cameraPosition, 0.0f));
  131. //shadowPosition = shadowProjection * shadowPosition;
  132. //shadowPosition /= shadowPosition.w;
  133.  
  134. //float dist = sqrt(shadowPosition.x * shadowPosition.x + shadowPosition.y * shadowPosition.y);
  135. //float distortFactor = (1.0f - SHADOW_MAP_BIAS) + dist * SHADOW_MAP_BIAS;
  136. //shadowPosition.xy *= 1.0f / distortFactor;
  137. //shadowPosition = shadowPosition * 0.5f + 0.5f;
  138.  
  139. //float sunlightVisibility = shadow2D(shadow, vec3(shadowPosition.st, shadowPosition.z)).x;
  140. //directLightFalloff *= sunlightVisibility;
  141.  
  142. vec3 color = mix(colorAmbient, colorDirect, vec3(min(1.0f, directLightFalloff)));
  143. //color += colorBounced;
  144. //color = colorAmbient;
  145. //color = colorDirect * directLightFalloff;
  146. //color *= clamp(pow(noise, 0.1f), 0.0f, 1.0f);
  147.  
  148. color *= 1.0f;
  149.  
  150. //color *= mix(1.0f, 0.4f, timeMidnight);
  151.  
  152. vec4 result = vec4(color.rgb, noise);
  153.  
  154. return result;
  155. }
  156. }
  157.  
  158. void CalculateClouds (inout vec3 color, inout SurfaceStruct surface)
  159. {
  160. //if (texcoord.s < 0.5f && texcoord.t < 0.5f)
  161. //{
  162. surface.cloudAlpha = 0.0f;
  163.  
  164. vec2 coord = texcoord.st * 2.0f;
  165.  
  166. vec4 worldPosition = gbufferModelViewInverse * surface.screenSpacePosition;
  167. worldPosition.xyz += cameraPosition.xyz;
  168.  
  169. float cloudHeight = 350.0f;
  170. float cloudDepth = 50.0f;
  171. float cloudDensity = .35f;
  172.  
  173. float startingRayDepth = far - 1.0f;
  174.  
  175. float rayDepth = startingRayDepth;
  176. rayDepth += CalculateDitherPattern1() * 0.0001f;
  177. //rayDepth += texture2D(noisetex, texcoord.st * (viewWidth / noiseTextureResolution, viewHeight / noiseTextureResolution)).x * 0.1f;
  178. rayDepth += CalculateDitherPattern2() * 0.09f;
  179. float rayIncrement = far / 40f;
  180.  
  181. rayDepth += CalculateDitherPattern1() * rayIncrement;
  182. rayDepth += CalculateDitherPattern2() / rayIncrement;
  183.  
  184. int i = 0;
  185.  
  186. vec3 cloudColor = colorSunlight;
  187. vec4 cloudSum = vec4(0.0f);
  188. cloudSum.rgb = colorSkylight * 0.2f;
  189. cloudSum.rgb = color.rgb;
  190.  
  191. float sunglow = CalculateSunglow(surface);
  192.  
  193. float cloudDistanceMult = 1500.0f / far;
  194.  
  195.  
  196. float surfaceDistance = length(worldPosition.xyz - cameraPosition.xyz);
  197.  
  198. while (rayDepth > 0.0f)
  199. {
  200. //determine worldspace ray position
  201. vec4 rayPosition = GetCloudSpacePosition(texcoord.st, rayDepth, cloudDistanceMult);
  202.  
  203. float rayDistance = length((rayPosition.xyz - cameraPosition.xyz) / cloudDistanceMult);
  204.  
  205. vec4 proximity = CloudColor(rayPosition, sunglow, surface.worldLightVector);
  206. proximity.a *= cloudDensity;
  207.  
  208. //proximity.a *= clamp(surfaceDistance - rayDistance, 0.0f, 1.0f);
  209. if (surfaceDistance < rayDistance * cloudDistanceMult && !surface.mask.sky)
  210. proximity.a = 0.0f;
  211.  
  212. //cloudSum.rgb = mix( cloudSum.rgb, proximity.rgb, vec3(min(1.0f, proximity.a * cloudDensity)) );
  213. //cloudSum.a += proximity.a * cloudDensity;
  214. color.rgb = mix(color.rgb, proximity.rgb, vec3(min(1.0f, proximity.a * cloudDensity)));
  215.  
  216. surface.cloudAlpha += proximity.a;
  217.  
  218. //Increment ray
  219. rayDepth -= rayIncrement;
  220. i++;
  221.  
  222. // if (rayDepth * cloudDistanceMult < ((cloudHeight - (cloudDepth * 0.5)) - cameraPosition.y))
  223. // {
  224. // break;
  225. // }
  226. }
  227.  
  228. //color.rgb = mix(color.rgb, cloudSum.rgb, vec3(min(1.0f, cloudSum.a * 20.0f)));
  229. //color.rgb = cloudSum.rgb;
  230. }
  231. //##END DO NOT COPY!##//
  232.  
  233. Then GOTO line 2256. Uncomment CalculateClouds
  234.  
  235. Next, GOTO composite1.fsh
  236. GOTO line 1234 and make sure "CloudPlane" is not commented
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement