Bitmap 海浪实现方式

本文介绍了一种使用ActionScript 3.0 (AS3) 实现海浪效果的方法。通过利用位图数据、Perlin噪声算法及位移映射滤镜等技术,实现了动态的水面波动效果。代码中还涉及了位图的管理和更新机制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Bitmap 海浪实现方式

 

package
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.filters.DisplacementMapFilter;
	import flash.geom.Point;
	import flash.utils.getTimer;
	
	import tween.EasyTween;
	
	public class Test2 extends Sprite
	{
//		[Embed(source="_preset.png")]
		[Embed(source="sea.png")]
		public var waterBitmapCls:Class;
		
		private var refractTmpBitmap:Bitmap;
		private var refractBmData:BitmapData;
		private var refractDisplaceFilter:DisplacementMapFilter;
		private var woBitmapData:BitmapData;
		private var perlinOffsetPoint:Point = new Point();
		
		private var perlinOffset:Array = [];
		private var filterArray:Array;
		
		private var p:Point = new Point(10, 200);
		
		private var _waveLayer:Sprite;
		private var _shipLayer:Sprite;
		private var _s:AAA;
		
		public static const WATERSIZE:int = 300;
		
		public function Test2()
		{
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			
//			var bbb:BitmapData = new BitmapData(WATERSIZE, WATERSIZE);
//			bbb.perlinNoise(150, 150, 1, 50, true, true, 7, true, this.perlinOffset);
//			
//			var bb:Bitmap = new Bitmap(bbb);
//			addChild(bb);
//			return;
			
			this.refractTmpBitmap = new waterBitmapCls();
			this.refractBmData = new BitmapData(WATERSIZE, WATERSIZE);
			
			this.refractDisplaceFilter = new DisplacementMapFilter(this.refractBmData, new Point(0, 0), 1, 2, 10, 20);
			this.woBitmapData = this.refractTmpBitmap.bitmapData.clone();

			this.perlinOffsetPoint.x = 0;
			this.perlinOffsetPoint.y = 0;
			
			this.perlinOffset = [this.perlinOffsetPoint];
			this.filterArray = [this.refractDisplaceFilter];
			
			generateWater = true;
			this.addEventListener(Event.ENTER_FRAME, enterframeHandler);
			
			for(var i:int = 0; i < 4; i++)
			{
				for(var j:int = 0; j < 4; j++)
				{
					var b:Bitmap = new Bitmap(woBitmapData);
					b.x = i * WATERSIZE;
					b.y = j * WATERSIZE;
					this.addChild(b);
				}
			}
			
			_waveLayer = new Sprite();
			addChild(_waveLayer);
			_shipLayer = new Sprite();
			addChild(_shipLayer);
			
			_s = new AAA();
			_shipLayer.addChild(_s);
			
			var l:Shape = new Shape();
			l.graphics.lineStyle(1, 0xFF0000);
			l.graphics.moveTo(WATERSIZE, 100);
			l.graphics.lineTo(WATERSIZE, WATERSIZE);
			stage.addChild(l);
		}
		
		private var _t:int = getTimer();
		private var generateWater:Boolean = false;
		private var waterIndex:int = 0;
		private var waterTiles:Vector.<BitmapData> = new Vector.<BitmapData>();
		private var waterDirection:int = -1;
		
		private static var waterTileAmount:int = 32;
		
		private function enterframeHandler(e:*):void
		{
//			this.removeEventListener(Event.ENTER_FRAME, enterframeHandler);
			
			var v:Number = 2;//Math.sin(getTimer()) + 10;
			this.perlinOffsetPoint.x = this.perlinOffsetPoint.x + v;
			this.perlinOffsetPoint.y = this.perlinOffsetPoint.y - v;
			
			this.refractBmData.perlinNoise(80, 80, 1, 50, true, true, 7, true, this.perlinOffset);
			this.refractTmpBitmap.filters = this.filterArray;
			
			this.woBitmapData.lock();
			this.woBitmapData.draw(this.refractTmpBitmap);
			this.woBitmapData.unlock();
			
//			if(generateWater)
//			{
//				var v:Number = 2;//Math.sin(getTimer()) + 10;
//				this.perlinOffsetPoint.x = this.perlinOffsetPoint.x + v;
//				this.perlinOffsetPoint.y = this.perlinOffsetPoint.y - v;
//				
//				this.refractBmData.perlinNoise(80, 80, 1, 50, true, true, 7, true, this.perlinOffset);
//				this.refractTmpBitmap.filters = this.filterArray;
//				
//				this.woBitmapData.lock();
//				this.woBitmapData.draw(this.refractTmpBitmap);
//				this.woBitmapData.unlock();
//				
//				var bitmapData2:BitmapData = this.woBitmapData.clone();
//				
//				this.waterTiles[this.waterIndex] = bitmapData2;
//				waterIndex++;
//				if(waterIndex > waterTileAmount)
//				{
//					generateWater = false;
//					waterDirection = -1;
//				}
//			}
//			else
//			{
//				waterIndex += waterDirection;
//				
//				if (this.waterIndex >= waterTileAmount)
//				{
//					this.waterIndex = waterTileAmount;
//					this.waterDirection = -1;
//				}
//				else if (this.waterIndex <= 0)
//				{
//					this.waterIndex = 0;
//					this.waterDirection = 1;
//				}
//				
//				var bitmapData3:BitmapData = this.waterTiles[waterIndex];
//				this.woBitmapData.copyPixels(bitmapData3, bitmapData3.rect, new Point());
//			}
			
//			this.refractTmpBitmap.bitmapData.applyFilter(this.woBitmapData, this.woBitmapData.rect, new Point(), refractDisplaceFilter);
//			this.woBitmapData.copyPixels(this.refractTmpBitmap.bitmapData, this.refractTmpBitmap.bitmapData.rect, new Point());
		
//			var dltaT:int = getTimer() - _t;
			EasyTween.updateAll(33);
		
//			p.x += 2;
			
			_s.x = this.mouseX;
			_s.y = this.mouseY;
			Wave.playWave(_s.x, _s.y, _waveLayer);
		}
	}
}

 



 

 

SUIMONO Water System是Unity互动式水系统,专门为我们提供了先进且深度可定制的海洋和水分效应,需要Unity 5.0.0或更高版本。 现实的水渲染 – Suimono 2.0为我们的Unity项目带来先进而现实的水和海洋渲染 高级FX – 具有镶嵌(dx11),泡沫渲染,动态反射,折射和屏幕转换 场景交互 – 设置任何游戏对象,用于交互式效果,如飞溅,折射波纹,声音和高级浮力效果 水下FX – 自动水下渲染,包括深度雾化,高级焦散,模糊和屏幕折射 定制 – 可以控制水景观和行为的各个方面 SUIMONO Water System v2.1.6更新日志: 2.1.6 (当前)已发布 2018年8月16日 WHAT’S NEW: – Added ‘Clear Mode’ option to camera tools. Allows override of clear flag inheritance on reflection camera. CHANGES: – Raised default Buoyancy activation range to 5000. – Added Mesh Collider to farplane surface prefab. Helps prevent Buoyancy detection fail. – Underwater camera component is no longer added if underwater rendering is turned off on module. BUG FIXES: – Fixed shader errors under PS4 that were preventing build completion (Lerp/Dot ambiguity). – Fixed Depthmask2 shader over-bright error. – Fixed object editor issue when expanding tabs. – Fixed bug where editor was showing wrong skin color (dark/pro skin vs light skin). – Reflection Color setting now affects underwater reflection as well. – Adjusted Caustic lighting code so it doesn’t reduce to 0 intensity. – Removed buoyancy frustum occlusion code causing strange buoyancy errors. – Fixed screen uv edge smearing underwater and with water droplet effects. – Fixed Underwater surface flickering error. – Fixed underwater transparency over-bright error. – Fixed Reflection over-bright error. – Darkened underwater fog color matching.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值