zoukankan      html  css  js  c++  java
  • Away3D那些贴图的Method

    在away3d.materials.methods目录下有很多以Method结尾的类,相信大家都已经知道了吧?
    ok,我们今天就来说说这些Method

    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
    环境贴图方法,想要物体表面能反射周围环境(如不锈钢,有机玻璃材质)?用这个就对啦....Wahahaha.....我到底在笑什么?....= =!

    //创建一个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满散射方式),玩3D软件的应该都知道这是什么了吧?...heihei
    这个方法用来模拟光在半透明物体内的折射效果(如人的皮肤,葡萄,蜡烛等)

    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

    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
    抖动阴影方法

  • 相关阅读:
    前沿技术解密——VirtualDOM
    Ques核心思想——CSS Namespace
    Unix Pipes to Javascript Pipes
    Road to the future——伪MVVM库Q.js
    聊聊CSS postproccessors
    【译】十款性能最佳的压缩算法
    Kafka Streams开发入门(9)
    Kafka Streams开发入门(8)
    【译】Kafka Producer Sticky Partitioner
    【译】99th Percentile Latency at Scale with Apache Kafka
  • 原文地址:https://www.cnblogs.com/njflash/p/2886960.html
Copyright © 2011-2022 走看看