本页内容

PointLight QML Type

在场景中定义一个点光源。更多...

Import Statement: import QtQuick3D
Inherits:

Light

属性

详细说明

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

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

默认情况下,点光的强度会按照反平方定律衰减。不过,可以通过constantFade 、linearFade 和quadraticFade 属性来控制衰减(及范围)。光线衰减的计算公式如下: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
}

此处的白色点光源(PointLight)沿 Z 轴移动,使其位于摄像机与场景中心之间的中点。与DirectionalLight 不同,点光源的旋转方向无关紧要,但其位置却至关重要。此处可见光强逐渐减弱,尤其是在背景中的矩形网格上。

一个带有黑色边框的绿色渐变圆,背景为深灰色渐变,展示了点光源的衰减

更多用法示例,请参阅《Qt Quick 3D - 光源示例》。

另请参阅 DirectionalLight 、SpotLight 以及Shadow Mapping。

属性文档

constantFade : real

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

linearFade : real

此属性会根据光源的距离,成比例地加快灯光效果的变暗速率。默认值为0.0 ,这意味着灯光不具有线性淡出效果。此处的数值在用于计算光线衰减之前,会先乘以0.01 。

quadraticFade : real

此属性会根据反平方定律,增加灯光效果调暗灯光的速度。 默认值为 1.0,这意味着点光源的衰减完全遵循反平方定律,即当与物体的距离加倍时,光强会减小至原来的 1/4。此处的数值在用于计算光衰减之前,会乘以 `0.0001 `。

© 2026 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.