away3d 4.1 贴图总结

TextureMaterial(texture:Texture2DBase = null, smooth:Boolean = true, repeat:Boolean = false, mipmap:Boolean = true)//贴图,平滑,重复,启用mipmap贴图
Creates a new TextureMaterial.

 1.贴图相关

在三维计算机图形的贴图渲染中有一个常用的技术被称为Mipmapping。为了加快渲染速度和减少图像锯齿,贴图被处理成由一系列被预先计算和优化过的图片组成的文件,这样的贴图被称为 MIP map 或者 mipmap。这个技术在三维游戏中被非常广泛的使用。“MIP”来自于拉丁语 multum in parvo 的首字母,意思是“放置很多东西的小空间”。Mipmap 需要占用一定的内存空间,同时也遵循小波压缩规则 (wavelet compression)。

var floorMapTexture:BitmapTexture = new BitmapTexture(new this.FloorMapAsset().bitmapData); 

var floorMap:TextureMaterial = new TextureMaterial(floorMapTexture, true, true);
floorMap.specular = 1;//反射
floorMap.lightPicker = new StaticLightPicker([param1]);//拾取灯光
floorMap.diffuseMethod = new TerrainDiffuseMethod([floorMapTexture], new BitmapTexture(new this.FloorShadowMapAsset().bitmapData), [10]);//三维里面称之为凹凸贴图方法

  this.floorMesh = new Mesh(new PlaneGeometry(3800, 3800), floorMap);//创建地面面片,贴上上面生成的地面贴图

一般贴图思路:

1.制作各种贴图 ,如 :反射贴图,凹凸贴图,等  

2场景里的灯光用lightPicker把灯光打到贴图

3.把效果的贴图 添加到贴图上 

4.生成一个面片mesh  ,把贴图放到面片上

加载模型上贴图 

  var garageLoader:Loader3D = new Loader3D();//实例模型加载器
        garageLoader.addEventListener(AssetEvent.ASSET_COMPLETE, this.complete);
        garageLoader.loadData(new this.GarageAsset(), null, null);
        super.addChildren(this.floorMesh, this.floorShadowMesh);

    private function complete(event:AssetEvent):void
    {
        if (event.asset.assetType == AssetType.MESH)
        {
            garageMesh = event.asset as Mesh;//将模型转换成面片
            garageMesh.material = new TextureMaterial(new BitmapTexture(new this.GarageMapAsset().bitmapData), true);//为加载进来的模型上贴图
            garageMesh.roll(180);
            garageMesh.geometry.scale(3);
            super.addChild(this.garageMesh);
            super.y = 188;
        }
    }

Method类的用法有两种,一种是通过DefaultMaterialBase的子类(如ColorMaterial,BitmapMaterial等)的addMethod()方法进行设置,
如:

var cubeMaterial:ColorMaterial = new ColorMaterial();
cubeMaterial.addMethod(new OutlineMethod());

另一种是通过DefaultMaterialBase子类的指定方法进行设置,
如:

var cubeMaterial:ColorMaterial = new ColorMaterial();
cubeMaterial.diffuseMethod = new SubsurfaceScatteringDiffuseMethod();
cubeMaterial.specularMethod = new FresnelSpecularMethod();
cubeMaterial.shadowMethod = new DitheredShadowMapMethod();

其实这两种设置方式的区别仅在于渲染时的执行优先级,如果对哪个Method被先执行没有特殊要求的话,完全可以使用第一种方式来添加所有的Method

渲染时的执行优先级依次为:
normalMethod>ambientMethod>shadowMethod>diffuseMethod>specularMethod>colorTransform>其它通过addMethod()方法添加的Method


一些常用的Method:

EnvMapMethod
环境贴图方法,想要物体表面能反射周围环境(如不锈钢,有机玻璃材质)

//创建一个skybox,6块贴图大家自己找,官方demo里有
var cubeTexture:BitmapCubeTexture = new BitmapCubeTexture("6块贴图")
scene.addChild(new SkyBox(cubeTexture));
//创建一个宽高长均为500的方块
var cubeGeometry:CubeGeometry = new CubeGeometry(500, 500, 500);
var cubeMaterial:ColorMaterial = new ColorMaterial();
cubeMaterial.specular = 0.8;
cubeMaterial.alpha = 0.5;
//因为要反射skybox的环境,所以共用skybox的贴图材质
//如果你想反射别的东西,也可以使用别的材质
cubeMaterial.addMethod(new EnvMapMethod(cubeTexture));
var cubeMesh:Mesh = new Mesh(cubeGeometry, cubeMaterial);
scene.addChild(cubeMesh);

FresnelSpecularMethod
菲涅尔镜面贴图方法,我不想把这东西解释的太复杂,下面有一段摘录自百度百科的内容,相信大家一看就能明白....
(我们站在湖边的时候,低头看脚下的水,水是透明的,反射不是特别强烈;远处的湖面,你会发现水并不是透明的,并且反射非常强烈。这就是“菲涅尔效应”....摘自百度百科)
说白了就是把光线反射变得更柔和,可以使用在湖面材质上,也可以配合SSS散射方式使用在皮肤材质上

FresnelEnvMapMethod
菲涅尔环境贴图方法

SubsurfaceScatteringDiffuseMethod
次表面满散射方式(SSS满散射方式)
这个方法用来模拟光在半透明物体内的折射效果(如人的皮肤,葡萄,蜡烛等)

var subsurfaceMethod:SubsurfaceScatteringDiffuseMethod = new SubsurfaceScatteringDiffuseMethod(2048, 2);
subsurfaceMethod.scatterColor = 0xff7733;
subsurfaceMethod.scattering = .05;
subsurfaceMethod.translucency = 4;
bodyMaterial.diffuseMethod = subsurfaceMethod;

WrapDiffuseMethod
包裹散射方式,接近于SSS满散射方式,但更粗糙一些

ColorTransformMethod
颜色转换方法,效果与直接设置material.colorTransform一样,在执行顺序上会晚于material.colorTransform的设置
一般情况下不推荐使用,请直接使用material.colorTransform,除非你需要解决一些特殊的问题或Bug

var m:ColorTransformMethod = new ColorTransformMethod();
m.colorTransform = new ColorTransform(1,0,0);
bodyMaterial.addMethod(m);

ColorMatrixMethod
颜色矩阵转换方法,想换贴图的颜色?也可以用它....
但你得具备一些ColorMatrixFilter的知识...

var matrix:Array = new Array();
matrix = matrix.concat([1, 0, 0, 0, 0]); // red
matrix = matrix.concat([0, 0, 0, 0, 0]); // green
matrix = matrix.concat([0, 0, 0, 0, 0]); // blue
matrix = matrix.concat([0, 0, 0, 1, 0]); // alpha
var filter:ColorMatrixFilter = new ColorMatrixFilter(matrix);
var m:ColorMatrixMethod = new ColorMatrixMethod();
m.colorMatrixFilter = filter;
bodyMaterial.addMethod(m);

OutlineMethod
轮廓方法,如果材质图某些地方是透明的,但你又想知道整个mesh的形状,可以使用此方法(此方法不受贴图影响,有效边界为geometry边界)

RimLightMethod
轮廓发光方法(有效边界为贴图可视边界,透明部分不受此方法影响)

bodyMaterial.addMethod(new RimLightMethod(0xff0000));

ProjectiveTextureMethod
投射材质方法,想像一下阳光透过彩色的窗玻璃,这些玻璃上的色彩投射在墙上的效果
或者....heihei.....如果你有一个球体,想再贴一张照片在这球体上....heihei.....

var projector:TextureProjector = new TextureProjector(photoBitmapData);
projector..position = new Vector3D(0,100,0);
bodyMaterial.addMethod(new ProjectiveTextureMethod(projector));

话说....这货有个bug....不支持透明图片....希望下个版本能修复吧....

SimpleWaterNormalMethod
想要一些简单的水波效果?用它,就是用它!

SoftShadowMapMethod
想看到物体的阴影被映射在墙角时的弯折效果?就是这个了

DitheredShadowMapMethod
抖动阴影方法

原文地址:https://www.cnblogs.com/bulolo/p/2797675.html