From 21b66bda2968cd73b370e826ee1154acdc6e3569 Mon Sep 17 00:00:00 2001 From: wangyawei <1796609990@qq.com> Date: 星期五, 18 四月 2025 20:28:27 +0800 Subject: [PATCH] 修改雨的效果 --- src/utils/rain.js | 25 +++++++++++++++++++------ 1 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/utils/rain.js b/src/utils/rain.js index a7499e5..2be1717 100644 --- a/src/utils/rain.js +++ b/src/utils/rain.js @@ -6,6 +6,7 @@ this.tiltAngle = Cesium.defaultValue(options.tiltAngle, -0.6); this.rainSize = Cesium.defaultValue(options.rainSize, 0.3); this.rainSpeed = Cesium.defaultValue(options.rainSpeed, 60.0); + this.rainDensity = Cesium.defaultValue(options.rainSpeed, 30.0); this.color = Cesium.defaultValue(options.color, new Cesium.Color(0.6, 0.7, 0.8, 1.0)); this.viewer = viewer; this.init(); @@ -28,6 +29,9 @@ rainSpeed: () => { return this.rainSpeed; }, + rainDensity: () => { + return this.rainDensity; + }, }, }); this.viewer.scene.postProcessStages.add(this.rainStage); @@ -49,7 +53,6 @@ show(visible) { this.rainStage.enabled = visible; } - rain() { return "uniform sampler2D colorTexture;\n\ in vec2 v_textureCoordinates;\n\ @@ -57,6 +60,7 @@ uniform vec4 rainColor;\n\ uniform float rainSize;\n\ uniform float rainSpeed;\n\ + uniform float rainDensity;\n\ float hash(float x) {\n\ return fract(sin(x * 133.3) * 13.13);\n\ }\n\ @@ -69,11 +73,20 @@ float a = tiltAngle;\n\ float si = sin(a), co = cos(a);\n\ uv *= mat2(co, -si, si, co);\n\ - uv *= length(uv + vec2(0, 4.9)) / (rainSize * 3.0 + 0.1) + 0.5;\n\ - float v = 1. - sin(hash(floor(uv.x * 100.)) * 2.);\n\ - float b = clamp(abs(sin(20. * time * v + uv.y * (5. / (2. + v)))) - .95, 0., 1.) * 20.;\n\ - c *= v * b;\n\ - fragColor = mix(texture(colorTexture, v_textureCoordinates), vec4(c, 1), .5);\n\ + uv *= length(uv + vec2(0, 4.9)) / (rainSize * 3.0 + 0.1) + 0.5;\n\ + // 闄愬埗鏈�澶у瘑搴﹀�硷紝浣跨敤瀵规暟鍑芥暟鏉ュ帇缂╅珮瀵嗗害鑼冨洿\n\ + float cappedDensity = min(rainDensity, 30.0 + (rainDensity - 30.0) * 0.1);\n\ + float densityScale = pow(cappedDensity / 200.0, 0.4); // 浣跨敤0.4娆″箓杩涗竴姝ュ帇缂‐n\ + // 鍑忓皯鍩虹闆ㄦ淮鏁伴噺\n\ + float v = 1. - sin(hash(floor(uv.x * (25.0 + densityScale * 50.0))) * 2.);\n\ + // 浣跨敤鏇翠弗鏍肩殑闃堝�煎嚱鏁帮紝璁╅珮瀵嗗害鏃跺鍔犳洿灏戠殑闆╘n\ + float densityThreshold = 0.96 - (0.15 * log(1.0 + cappedDensity / 50.0));\n\ + float b = clamp(abs(sin(20. * time * v + uv.y * (5. / (2. + v)))) - densityThreshold, 0., 1.) * 20.;\n\ + // 璁$畻闆ㄦ淮棰滆壊\n\ + vec3 finalColor = rainColor.rgb * v * b;\n\ + // 璋冩暣娣峰悎绯绘暟\n\ + float mixFactor = min(b * 0.05, 0.5);\n\ + fragColor = mix(texture(colorTexture, v_textureCoordinates), vec4(finalColor, 1), mixFactor);\n\ }\n\ "; } -- Gitblit v1.9.3