Skip to content

Commit 7b7bd1d

Browse files
committed
Add AreaLight3D
1 parent ee713cc commit 7b7bd1d

82 files changed

Lines changed: 4621 additions & 260 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

doc/classes/AreaLight3D.xml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<class name="AreaLight3D" inherits="Light3D" api_type="core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
3+
<brief_description>
4+
An area light, such as a neon light tube or a screen.
5+
</brief_description>
6+
<description>
7+
An area light is a type of [Light3D] node that emits light over a two-dimensional area, in the shape of a rectangle. The light is attenuated throughout the distance. This attenuation can be configured by changing the energy, [member area_attenuation], and [member area_range].
8+
Light is emitted in the -Z direction of the node's global basis. For an unrotated light, this means that the light is emitted forwards, illuminating the front side of a 3D model (see [constant Vector3.FORWARD] and [constant Vector3.MODEL_FRONT]).
9+
Area lights can cast soft shadows using PCSS, which you can control by tweaking the size parameter. The shadow map is drawn from the center of the light.
10+
[b]Note:[/b] Area lights have limited support in the Mobile and Compatibility renderers. In the Mobile renderer, the size of the penumbra doesn't vary as it should with PCSS. In Compatibility, area lights cannot cast shadows.
11+
</description>
12+
<tutorials>
13+
</tutorials>
14+
<members>
15+
<member name="area_attenuation" type="float" setter="set_param" getter="get_param" default="1.0">
16+
Controls the distance attenuation function for this area light.
17+
A value of [code]0.0[/code] will maintain a constant brightness through most of the range, but will smoothly attenuate the light at the edge of the range. Use a value of [code]2.0[/code] for physically accurate lights as it results in the proper inverse square attenuation.
18+
[b]Note:[/b] Setting attenuation to [code]2.0[/code] or higher may result in distant objects receiving minimal light, even when within range. For example, with a range of [code]4096[/code], an object at [code]100[/code] units is attenuated by a factor of [code]0.0001[/code]. With a default brightness of [code]1[/code], the light would not be visible at that distance.
19+
[b]Note:[/b] Using negative values or values higher than [code]10.0[/code] may lead to unexpected results.
20+
</member>
21+
<member name="area_normalize_energy" type="bool" setter="set_area_normalize_energy" getter="is_area_normalizing_energy" default="true">
22+
Defines whether the energy is normalized (divided) by the surface area of the light. If set to [code]true[/code], changing the size does not affect the total energy output, and does not dramatically alter the brightness of the scene.
23+
</member>
24+
<member name="area_range" type="float" setter="set_param" getter="get_param" default="5.0">
25+
The range of the area in meters. This determines the maximum distance from any point on the area at which the area can still emit light.
26+
</member>
27+
<member name="area_size" type="Vector2" setter="set_area_size" getter="get_area_size" default="Vector2(1, 1)">
28+
The extents (width and height) of the area in meters.
29+
</member>
30+
<member name="area_texture" type="Texture2D" setter="set_area_texture" getter="get_area_texture">
31+
An optional texture to use as a light source. Changing the texture at runtime might impact performance, as it needs to be drawn to the area light atlas with filtered mipmaps.
32+
If no texture is assigned, the area light emits uniform light across its surface.
33+
[b]Note:[/b] Area light textures are only supported in the Forward+ and Mobile rendering methods, not Compatibility. To reduce the performance impact of switching textures at runtime, make sure each dimension of an area texture is either a multiple of 128 pixels, or a power of two. This removes the need for a scaling pass, which slows down texture changes. The textures don't necessarily have to be square to be optimal. Examples of optimal texture sizes include 32x64, 128x128, and 256x384.
34+
</member>
35+
<member name="light_size" type="float" setter="set_param" getter="get_param" overrides="Light3D" default="0.5" />
36+
<member name="shadow_normal_bias" type="float" setter="set_param" getter="get_param" overrides="Light3D" default="1.0" />
37+
</members>
38+
</class>

doc/classes/Light3D.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
[b]Note:[/b] Light projector textures are only supported in the Forward+ and Mobile rendering methods, not Compatibility.
9696
</member>
9797
<member name="light_size" type="float" setter="set_param" getter="get_param" default="0.0" keywords="pcss">
98-
The size of the light in Godot units. Only available for [OmniLight3D]s and [SpotLight3D]s. Increasing this value will make the light fade out slower and shadows appear blurrier (also called percentage-closer soft shadows, or PCSS). This can be used to simulate area lights to an extent. Increasing this value above [code]0.0[/code] for lights with shadows enabled will have a noticeable performance cost due to PCSS.
98+
The simulated size of the light in Godot units, affecting shading and shadows. For [OmniLight3D]s and [SpotLight3D]s, increasing this value simulates a spherical area light, expanding the size of specular highlights. If shadows are enabled, a penumbra is rendered, making shadows appear blurrier. For [AreaLight3D]s, only the shadows are affected. Penumbras are simulated with percentage-closer soft shadows, or PCSS, which has a noticeable performance cost for values above [code]0.0[/code].
9999
[b]Note:[/b] [member light_size] is not affected by [member Node3D.scale] (the light's scale or its parent's scale).
100100
[b]Note:[/b] PCSS for positional lights is only supported in the Forward+ and Mobile rendering methods, not Compatibility.
101101
</member>

doc/classes/RenderingServer.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@
1818
<link title="Optimization using Servers">$DOCS_URL/tutorials/performance/using_servers.html</link>
1919
</tutorials>
2020
<methods>
21+
<method name="area_light_create">
22+
<return type="RID" />
23+
<description>
24+
Creates a new area light and adds it to the RenderingServer. It can be accessed with the RID that is returned. This RID can be used in most [code]light_*[/code] RenderingServer functions.
25+
Once finished with your RID, you will want to free the RID using the RenderingServer's [method free_rid] method.
26+
To place in a scene, attach this area light to an instance using [method instance_set_base] using the returned RID.
27+
[b]Note:[/b] The equivalent node is [AreaLight3D].
28+
</description>
29+
</method>
2130
<method name="bake_render_uv2">
2231
<return type="Image[]" />
2332
<param index="0" name="base" type="RID" />
@@ -2104,6 +2113,22 @@
21042113
Returns [code]true[/code] if our code is currently executing on the rendering thread.
21052114
</description>
21062115
</method>
2116+
<method name="light_area_set_normalize_energy">
2117+
<return type="void" />
2118+
<param index="0" name="light" type="RID" />
2119+
<param index="1" name="enable" type="bool" />
2120+
<description>
2121+
Defines whether the energy of an [AreaLight3D] is normalized (divided) by its area. If set to [code]true[/code], changing the size does not affect the total energy output. Equivalent to [member AreaLight3D.area_normalize_energy].
2122+
</description>
2123+
</method>
2124+
<method name="light_area_set_size">
2125+
<return type="void" />
2126+
<param index="0" name="light" type="RID" />
2127+
<param index="1" name="size" type="Vector2" />
2128+
<description>
2129+
Sets the extents (width and height) in meters for this area light. Equivalent to [member AreaLight3D.area_size].
2130+
</description>
2131+
</method>
21072132
<method name="light_directional_set_blend_splits">
21082133
<return type="void" />
21092134
<param index="0" name="light" type="RID" />
@@ -5009,6 +5034,9 @@
50095034
<constant name="LIGHT_SPOT" value="2" enum="LightType">
50105035
Spot light (see [SpotLight3D]).
50115036
</constant>
5037+
<constant name="LIGHT_AREA" value="3" enum="LightType">
5038+
Area light (see [AreaLight3D]).
5039+
</constant>
50125040
<constant name="LIGHT_PARAM_ENERGY" value="0" enum="LightParam">
50135041
The light's energy multiplier.
50145042
</constant>

doc/classes/Viewport.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,14 @@
758758
Draws the internal resolution buffer of the scene in linear colorspace before tonemapping or post-processing is applied.
759759
[b]Note:[/b] Only supported when using the Forward+ or Mobile rendering methods.
760760
</constant>
761+
<constant name="DEBUG_DRAW_CLUSTER_AREA_LIGHTS" value="27" enum="DebugDraw">
762+
Draws the cluster used by [AreaLight3D] nodes to optimize light rendering.
763+
[b]Note:[/b] Only supported when using the Forward+ rendering method.
764+
</constant>
765+
<constant name="DEBUG_DRAW_AREA_LIGHT_ATLAS" value="28" enum="DebugDraw">
766+
Draws the atlas used by [AreaLight3D] nodes in the upper left quadrant of the [Viewport].
767+
[b]Note:[/b] Only supported when using the Forward+ or Mobile rendering method.
768+
</constant>
761769
<constant name="DEFAULT_CANVAS_ITEM_TEXTURE_FILTER_NEAREST" value="0" enum="DefaultCanvasItemTextureFilter">
762770
The texture filter reads from the nearest pixel only. This makes the texture look pixelated from up close, and grainy from a distance (due to mipmaps not being sampled).
763771
</constant>

0 commit comments

Comments
 (0)