PointLight QML Type

定义场景中的点光源。更多

Import Statement: import QtQuick3D
Inherits:

Light

属性

详细说明

点光源可以描述为一个球体,从光源中心向各个方向发出强度相等的光。这与灯泡的发光方式类似。

旋转或缩放点光源不会产生任何影响。移动点光源会改变光线发射的位置。

默认情况下,点光源的强度会根据反平方定律逐渐减弱。不过,可以使用constantFadelinearFadequadraticFade 属性来控制衰减(和范围)。光衰减的计算公式为 constantFade +distance * (linearFade * 0.01) +distance^2 * (quadraticFade * 0.0001)

一个简单的例子:用三种不同的方法为一个球体着色

在一个场景中,背景是一个按比例放大的矩形,前面有一个球体。PrincipledMaterial 矩形的默认基色为白色。

在没有任何灯光并禁用两个网格的灯光相关着色的情况下,我们会得到以下结果:

import QtQuick
import QtQuick3D
View3D {
    anchors.fill: parent

    PerspectiveCamera { z: 600 }

    Model {
        source: "#Rectangle"
        scale: Qt.vector3d(10, 10, 10)
        z: -100
        materials: PrincipledMaterial {
            lighting: PrincipledMaterial.NoLighting
        }
    }

    Model {
        source: "#Sphere"
        scale: Qt.vector3d(2, 2, 2)
        materials: PrincipledMaterial {
            lighting: PrincipledMaterial.NoLighting
            baseColor: "#40c060"
            roughness: 0.1
        }
    }
}

添加一个方向光,默认情况下沿着 Z 轴向下发射,结果如下:

import QtQuick
import QtQuick3D
View3D {
    anchors.fill: parent

    PerspectiveCamera { z: 600 }

    DirectionalLight { }

    Model {
        source: "#Rectangle"
        scale: Qt.vector3d(10, 10, 10)
        z: -100
        materials: PrincipledMaterial { }
    }

    Model {
        source: "#Sphere"
        scale: Qt.vector3d(2, 2, 2)
        materials: PrincipledMaterial {
            baseColor: "#40c060"
            roughness: 0.1
        }
    }
}

如果我们将DirectionalLight 替换为

PointLight {
    z: 300
}

这里的白色点光源在 Z 轴上移动,使其位于摄像机和场景中心的中间位置。与DirectionalLight 不同,PointLight 的旋转并不重要,但它的位置却很重要。在这里可以看到光强的减弱,尤其是在背景的矩形网格上。

更多使用示例,请参见Qt Quick 3D - 灯光示例

另请参阅 DirectionalLight,SpotLight阴影贴图

属性文档

constantFade : real

该属性是灯光衰减项的常数因子。默认值为 1.0。


linearFade : real

该属性可提高灯光效果根据与灯光的距离成比例地使灯光变暗的速率。默认值为0.0 ,表示灯光没有线性衰减。此处使用的值会先乘以0.01 ,然后再用于计算灯光衰减。


quadraticFade : real

该属性根据平方反比定律增加灯光效果的光线衰减速度。默认值为 1.0,这意味着点光源的衰减完全遵循平方反比定律,即当物体距离增加一倍时,光照强度减弱为原来的四分之一。这里使用的值会乘以0.0001 ,然后用于计算光衰减。


© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.