_Water

用来实现水的渲染效果 全部展开

属性展开

  • + alpha : number

    水波1和水波2的混合因子。默认值为0.5。

    • 示例

       water.alpha = 0.5
  • + color : uint

    水的颜色。

    • 示例

       water.color = _Color.Blue
  • + depth : number

    水的深度。默认值为0。

    • 示例

       water.depth = 5
  • + direction1 : _Vector2

    水波1的流动方向。

    • 示例

       water.direction1 = _Vector2.new(1, 0)
  • + direction2 : _Vector2

    水波2的流动方向。

    • 示例

       water.direction2 = _Vector2.new(0, 1)
  • + distort : number

    水波的扭曲程度。默认值为1。

    • 示例

       water.distort = 1
  • + environmentMap : string

    水波的流光贴图资源名。

    • 示例

       water.environmentMap = 'environment.jpg'
  • + height : number

    水平面的高度

    • 示例

       water.height = 1
  • + isWireframe : bool

    是否现况模式。

    • 示例

       water.isWireframe = true
  • + lightColor : uint

    水波光照的颜色值。

    • 示例

       water.lightColor  = 0xffffffff
  • + lightDir : _Vector3

    水波光照的方向。

    • 示例

       water.lightDir = _Vector3.new(-1, -1, -1)
  • + lightShine : number

    水波光照的强度。

    • 示例

       water.lightShine = 200
  • + mode : number

    水的模式,Lighting, Fresnel,Refract,Reflect四种

  • + name : string

    水的逻辑名

    • 示例

       water.name = 'water1'
  • + normalMap : string

    水波的法线贴图资源名。

    • 示例

       water.normalMap = 'normal.jpg'
  • + reflectColor : uint

    水反射颜色值,仅在没有天空盒反射区域的反射颜色值。

    • 示例

       water.reflectColor = 0xffffffff
  • + speed1 : number

    水波1流动的速度。默认值为1。

    • 示例

       water.speed1 = 2
  • + speed2 : number

    水波2流动的速度。默认值为1。

    • 示例

       water.speed2 = 2
  • + transparency : number

    透明度。

    • 示例

       water.transparency = 1
  • + waves : uint

    波纹数量。默认值为4。

    • 示例

       water.waves = 5
  • + x1 : number

    水区域左上坐标的x值

    • 示例

       water.x1 = 0
  • + x2 : number

    水区域右下坐标的x值

    • 示例

       water.x2 = 10
  • + y1 : number

    水区域左上坐标的y值

    • 示例

       water.y1 = 0
  • + y2 : number

    水区域右下坐标的y值

    • 示例

       water.y2 = 10

构造方法展开

  • + function _Water() : _Water

公共方法展开

  • + function draw()

    渲染水。

    • 示例

       water:draw()
  • + function reflectionBegin()

    开始渲染反射的物体。与配对使用。在与之间渲染的物体会受到水的反射效果。

    • 示例

       water:reflectionBegin()
  • + function reflectionEnd()

    结束渲染反射的物体。与配对使用。在与之间渲染的物体会受到水的反射效果。

    • 示例

       water:reflectionEnd()
  • + function refractionBegin()

    开始渲染折射的物体。与配对使用。在与之间渲染的物体会受到水的折射效果。

    • 示例

       water:refractionBegin()
  • + function refractionEnd()

    结束渲染折射的物体。与配对使用。在与之间渲染的物体会受到水的折射效果。

    • 示例

       water:refractionEnd()

代码示例

    _sys:addPath('res')
    _dofile('cameracontrol.lua')
    amblight = _AmbientLight.new()
    skylight = _SkyLight.new()
    skylight.direction = _Vector3.new(-1, -1, -1)

    sky = _SkyDome.new()
    sky:setSkyMap('X+.bmp|X-.bmp|Y+.bmp|Y-.bmp|Z+.bmp|Z-.bmp')
    sen = _Scene.new('water-scene.sen')

    water = _Water.new()
    water.x1 = -1250
    water.x2 = 1250
    water.y1 = -1250
    water.y2 = 1250

    water.depth = 50.0
    water.height = 1.5
    water.normalMap = 'normal.jpg'
    water.color = 0x88002233
    water.lightColor = _Color.Green
    water.lightDir = _Vector3.new(-1, -1, -1)

    water.reflectColor = 0xFF00FF00
    water.lightShine = 200
    water.alpha = 0.7

    water.direction1 = _Vector2.new(1,-1)
    water.speed1 = 4.0
    water.direction2 = _Vector2.new(1,1)
    water.speed2 = 5.0
    water.waves = 0.50
    water.distort = 50
    water.mode = _Water.Lighting + _Water.Fresnel

    teapot = _mf:createTeapot()

    mat1 = _Matrix3D.new():setScaling(20, 20, 20):mulTranslationRight(0, 0, 20)
    mat2 = _Matrix3D.new():setTranslation(0, 0, -10)

    _rd.camera.eye = _Vector3.new(100, 100, 100)

    function render_obj()
        _rd:useLight(amblight)
        _rd:useLight(skylight)
        _rd:pushMatrix3D(mat1)
            teapot:drawMesh()
        _rd:popMatrix3D()
        _rd:popLight()
        _rd:popLight()
    end

    function render_scene()
        _rd:pushMatrix3D(mat2)
            sen.terrain:draw()
        _rd:popMatrix3D(mat2)
    end

    _app:onIdle(function(e)
        if water:refractionBegin() then
            render_scene()
            water:refractionEnd()
        end

        if water:reflectionBegin() then
            sky:draw()
            render_obj()
            render_scene()
            water:reflectionEnd()
        end

        render_obj()
        render_scene()

        sky:draw()
        water:draw()
    end)
问题反馈(登录才可以发表哦!)