mc光影吧 关注:8,595贴子:130,405

【教程】在SEUS renewed加入con1.3的体积云

只看楼主收藏回复

之前eplor的e2云其实很不错 但是因为renewed1.0.0的TAA导致漫天拖影 关掉又满天噪点 所以我就发布一个con1.3的云,个人认为这个云还是不错的


来自iPhone客户端1楼2019-02-15 13:53回复
    第一步 进入composite2.fsh


    2楼2019-02-15 13:54
    回复
      2025-06-14 12:06:09
      广告
      第二步如图


      来自iPhone客户端4楼2019-02-15 13:55
      收起回复
        第三步,在171行加入
        varying vec3 colorBouncedSunlight;


        5楼2019-02-15 13:55
        回复
          第三步如图


          来自iPhone客户端6楼2019-02-15 13:56
          回复
            第四步 在325行加入
            float LinearToExpDepth(float depth)
            {
            return (far * (depth - near)) / (depth * (far - near));
            }
            float CalculateDitherPattern1() {
            const int[16] ditherPattern = int[16] (0 , 8 , 2 , 10,
            12, 4 , 14, 6 ,
            3 , 11, 1, 9 ,
            15, 7 , 13, 5 );
            vec2 count = vec2(0.0f);
            count.x = floor(mod(texcoord.s * viewWidth, 4.0f));
            count.y = floor(mod(texcoord.t * viewHeight, 4.0f));
            int dither = ditherPattern[int(count.x) + int(count.y) * 4];
            return float(dither) / 16.0f;
            }
            float CalculateDitherPattern2() {
            const int[64] ditherPattern = int[64] ( 1, 49, 13, 61, 4, 52, 16, 64,
            33, 17, 45, 29, 36, 20, 48, 32,
            9, 57, 5, 53, 12, 60, 8, 56,
            41, 25, 37, 21, 44, 28, 40, 24,
            3, 51, 15, 63, 2, 50, 14, 62,
            35, 19, 47, 31, 34, 18, 46, 30,
            11, 59, 7, 55, 10, 58, 6, 54,
            43, 27, 39, 23, 42, 26, 38, 22);
            vec2 count = vec2(0.0f);
            count.x = floor(mod(texcoord.s * viewWidth, 8.0f));
            count.y = floor(mod(texcoord.t * viewHeight, 8.0f));
            int dither = ditherPattern[int(count.x) + int(count.y) * 8];
            return float(dither) / 64.0f;
            }
            vec4 GetCloudPosition(vec2 coord, float depth, float distanceMult)
            {
            // depth *= 30.0f;
            //Convert texture coordinates and depth into view space
            vec4 viewPos = gbufferProjectionInverse * vec4(coord.s * 2.0f - 1.0f, coord.t * 2.0f - 1.0f, 2.0f * depth - 1.0f, 1.0f);
            viewPos /= viewPos.w;
            //Convert from view space to world space
            vec4 worldPos = gbufferModelViewInverse * viewPos;
            worldPos.xyz *= distanceMult;
            worldPos.xyz += cameraPosition.xyz;
            return worldPos;
            }


            7楼2019-02-15 13:59
            回复
              第四步图片:


              来自iPhone客户端8楼2019-02-15 14:00
              回复
                第五步如图


                来自iPhone客户端10楼2019-02-15 14:01
                回复
                  2025-06-14 12:00:09
                  广告
                  第六步来到1840行
                  加入
                  vec4 CloudColor3(vec4 worldPosition, float sunglow, vec3 worldLightVector)
                  {
                  float cloudHeight = Cloud3Height;
                  float cloudDepth = 150.0f;
                  float cloudUpperHeight = cloudHeight + (cloudDepth / 2.0f);
                  float cloudLowerHeight = cloudHeight - (cloudDepth / 2.0f);
                  if (worldPosition.y < cloudLowerHeight || worldPosition.y > cloudUpperHeight)
                  return vec4(0.0f);
                  else
                  {
                  vec3 p = worldPosition.xyz / 150.0f;
                  float t = frameTimeCounter * VOLUMETRIC_CLOUD_SPEED ;
                  #ifdef Volumetric_Cloud_Type
                  p.x -= t * 0.02f;
                  vec3 p1 = p * vec3(1.0f, 0.5f, 1.0f) + vec3(0.0f, t * 0.01f, 0.0f);
                  float noise = Get3DNoise2(p) * 1.0f;p *= 4.0f;p.x += t * 0.02f; vec3 p2 = p;
                  noise += (1.0f - abs(Get3DNoise2(p) * 3.0f - 1.0f)) * 0.20f;p *= 3.0f;p.xz += t * 0.05f;
                  noise += (1.0f - abs(Get3DNoise2(p) * 3.0f - 1.5f)-0.2) * 0.065f;p.xz -=t * 0.165f;p.xz += t * 0.05f;
                  noise += (1.0f - abs(Get3DNoise2(p) * 3.0f - 1.0f)) * 0.05f;p *= 2.0f;
                  noise += (1.0 - abs(Get3DNoise3(p) * 2.0 - 1.0)) * 0.015f;
                  noise /= 1.2f;
                  #else
                  t *= 0.0095;
                  p.x *= 0.5f;
                  p.x -= t * 0.01f;
                  vec3 p1 = p * vec3(1.0f, 0.5f, 1.0f) + vec3(0.0f, t * 0.01f, 0.0f);
                  float noise = Get3DNoise1(p * vec3(1.0f, 0.5f, 1.0f) + vec3(0.0f, t * 0.01f, 0.0f)) * 1.3;p *= 2.0f;p.x -= t * 0.557f;vec3 p2 = p;
                  noise += (2.0f - abs(Get3DNoise1(p) * 2.0f - 0.0f)) * (0.35f);p *= 3.0f;p.xz -= t * 0.905f;p.x *= 2.0f;vec3 p3 = p; float largeNoise = noise;
                  noise += (3.0f - abs(Get3DNoise1(p) * 3.0f - 0.0f)) * (0.085f);p *= 3.0f;p.xz -= t * 3.905f;vec3 p4 = p;
                  noise += (3.0f - abs(Get3DNoise1(p) * 3.0f - 0.0f)) * (0.035f);p *= 3.0f;p.xz -= t * 3.905f;
                  noise += ((Get3DNoise1(p))) * (0.04f);p *= 3.0f;
                  noise /= 2.375f;
                  #endif
                  const float lightOffset = 0.3f;
                  float heightGradient = clamp(( - (cloudLowerHeight - worldPosition.y) / (cloudDepth * 1.0f)), 0.0f, 1.0f);
                  float heightGradient2 = clamp(( - (cloudLowerHeight - (worldPosition.y + worldLightVector.y * lightOffset * 150.0f)) / (cloudDepth * 1.0f)), 0.0f, 1.0f);
                  float cloudAltitudeWeight = 1.0f - clamp(distance(worldPosition.y, cloudHeight) / (cloudDepth / 2.0f), 0.0f, 1.0f);
                  cloudAltitudeWeight = (-cos(cloudAltitudeWeight * 3.1415f)) * 0.5 + 0.5;
                  cloudAltitudeWeight = pow(cloudAltitudeWeight, mix(0.33f, 0.8f, rainStrength));
                  float cloudAltitudeWeight2 = 1.0f - clamp(distance(worldPosition.y + worldLightVector.y * lightOffset * 150.0f, cloudHeight) / (cloudDepth / 2.0f), 0.0f, 1.0f);
                  cloudAltitudeWeight2 = (-cos(cloudAltitudeWeight2 * 3.1415f)) * 0.5 + 0.5;
                  cloudAltitudeWeight2 = pow(cloudAltitudeWeight2, mix(0.33f, 0.8f, rainStrength));
                  noise *= cloudAltitudeWeight;
                  //cloud edge
                  float rainy = mix(wetness, 1.0f, rainStrength);
                  float coverage = Vol_Cloud_Coverage + rainy * 0.335;
                  coverage = mix(coverage, 0.77f, rainStrength);
                  float dist = length(worldPosition.xz - cameraPosition.xz);
                  coverage *= max(0.0f, 1.0f - dist / 40000.0f);
                  float density = 0.90f;
                  noise = GetCoverage(coverage, density, noise);
                  noise = pow(noise, 1.5);
                  if (noise <= 0.001f)
                  {
                  return vec4(0.0f, 0.0f, 0.0f, 0.0f);
                  }
                  float sundiff = Get3DNoise3(p1 + worldLightVector.xyz * lightOffset);
                  sundiff += (1.0 - abs(Get3DNoise3(p2 + worldLightVector.xyz * lightOffset / 2.0f) * 1.0f - 0.5f) - 0.1) * 0.55f;
                  sundiff *= 0.955f;
                  sundiff *= cloudAltitudeWeight2;
                  float preCoverage = sundiff;
                  sundiff = -GetCoverage(coverage * 1.0f, density * 0.5, sundiff);
                  float sundiff2 = -GetCoverage(coverage * 1.0f, 0.0, preCoverage);
                  float firstOrder = pow(clamp(sundiff * 1.2f + 1.7f, 0.0f, 1.0f), 8.0f);
                  float secondOrder = pow(clamp(sundiff2 * 1.2f + 1.1f, 0.0f, 1.0f), 4.0f);
                  float anisoBackFactor = mix(clamp(pow(noise, 1.6f) * 2.5f, 0.0f, 1.0f), 1.0f, pow(sunglow, 1.0f));
                  firstOrder *= anisoBackFactor * 0.99 + 0.01;
                  secondOrder *= anisoBackFactor * 1.19 + 0.9;
                  float directLightFalloff = clamp(pow(-(cloudLowerHeight - worldPosition.y) / cloudDepth, 3.5f), 0.0f, 1.0f);
                  directLightFalloff *= mix(clamp(pow(noise, 0.9f), 0.0f, 1.0f), clamp(pow(1.0f - noise, 10.3f), 0.0f, 0.5f), pow(sunglow, 1.2f));
                  vec3 colorDirect = colorSunlight * 4.5f;
                  colorDirect = mix(colorDirect, colorDirect * vec3(0.1f, 0.2f, 0.3f)*2, timeMidnight);
                  colorDirect = mix(colorDirect, colorDirect * vec3(0.2f, 0.2f, 0.2f), rainStrength);
                  colorDirect *= 1.0f + pow(sunglow, 4.0f) * 100.0f;
                  vec3 colorAmbient = mix(colorSkylight, colorSunlight, 0.15f) * 0.10965f;
                  colorAmbient = mix(colorAmbient, vec3(0.04) * Luminance(colorSkylight), vec3(rainStrength));
                  colorAmbient *= mix(1.0f, 0.3f, timeMidnight);
                  vec3 colorBounced = colorBouncedSunlight * 0.35f;
                  colorBounced *= pow((1.0f - heightGradient), 8.0f);
                  colorBounced *= anisoBackFactor + 0.5;
                  colorBounced *= 1.0 - rainStrength;
                  vec3 color = mix(colorAmbient, colorDirect, vec3(directLightFalloff));
                  color += colorBounced;
                  color *= 8.0f;
                  vec4 result = vec4(color.rgb, noise);
                  return result;
                  }
                  }
                  void CalculateClouds (inout vec3 color, inout float cloudAlpha, vec4 worldPos, vec3 viewDir, MaterialMask mask, vec3 worldLightVector, vec3 lightVector)
                  {
                  vec2 coord = texcoord.st * 2.0f;
                  float cloudHeight = 150.0f;
                  float cloudDepth = 140.0f;
                  float cloudDensity = 0.89f;
                  float startingRayDepth = far - 5.0f;
                  float rayDepth = startingRayDepth;
                  float rayIncrement = far / CLOUD_DISPERSE;
                  #ifdef SOFT_FLUFFY_CLOUDS
                  rayDepth += CalculateDitherPattern1() * rayIncrement;
                  #else
                  rayDepth += CalculateDitherPattern2() * rayIncrement;
                  #endif
                  int i = 0;
                  vec3 cloudColor3 = colorSunlight;
                  vec4 cloudSum = vec4(0.0f);
                  cloudSum.rgb = color.rgb;
                  float sunglow = min(CalculateSunglow(viewDir, lightVector), 2.0);
                  float cloudDistanceMult = 400.0f / far;
                  float surfaceDistance = length(worldPos);
                  while (rayDepth > 0.0f) {
                  //determine worldspace ray position
                  vec4 rayPosition = GetCloudPosition(texcoord.st, LinearToExpDepth(rayDepth), cloudDistanceMult);
                  float rayDistance = length((rayPosition.xyz - cameraPosition.xyz) / cloudDistanceMult);
                  vec4 proximity = CloudColor3(rayPosition, sunglow/1.2, worldLightVector);
                  proximity.a *= cloudDensity;
                  if (surfaceDistance < rayDistance * cloudDistanceMult && mask.sky == 0.0)
                  proximity.a = 0.0f;
                  cloudSum.rgb = mix( cloudSum.rgb, proximity.rgb, vec3(min(1.0f, proximity.a * cloudDensity)) );
                  cloudSum.a += proximity.a * cloudDensity;
                  cloudAlpha += proximity.a;
                  //Increment ray
                  rayDepth -= rayIncrement;
                  i++;
                  }
                  color.rgb = mix(color.rgb, cloudSum.rgb, vec3(min(1.0f, cloudSum.a * 50.0f)));
                  if (cloudSum.a > 0.00f)
                  {
                  //materialMask.volumeCloud = 1.0;
                  }
                  }


                  11楼2019-02-15 14:01
                  回复
                    老规矩 图片


                    来自iPhone客户端12楼2019-02-15 14:02
                    回复
                      第七步。大概在2317的位置加入
                      float cloudAlpha = 0.0;
                      #ifdef Volumetric_Clouds
                      CalculateClouds (finalComposite, cloudAlpha, worldPos, viewDir, materialMask, worldLightVector, lightVector);
                      #endif


                      13楼2019-02-15 14:03
                      回复
                        加在这里!


                        来自iPhone客户端14楼2019-02-15 14:03
                        回复
                          第八步
                          然后到2348,用这行代码替换原来的代码
                          gl_FragData[1] = vec4(finalComposite.rgb, cloudAlpha);


                          15楼2019-02-15 14:04
                          回复
                            过程


                            来自iPhone客户端16楼2019-02-15 14:05
                            回复
                              2025-06-14 11:54:09
                              广告
                              这时体积云其实已经加好了 可是还没有平滑噪点 所以进入游戏你会看到


                              来自iPhone客户端17楼2019-02-15 14:05
                              回复