Light Source Tutorial: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "\{\{GameCategory *\| *arma3 *\| +" to "{{GameCategory|arma3|")
(Add #lightreflector commands and other intel)
 
(9 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{TOC|side}}
{{TOC|side}}
{{GVI|arma1|1.00}}
== Basics ==
== Basics ==


A lightpoint (glowing light source) is a non-physical object that shines a light. Unlike projectors or vehicle headlights, this light type cannot be directed into a beam and can only glow uniformously. The glowing does not cast shadows (only the sun or the moon can) and can go through walls.
A '''light source''' is a non-physical object that shines a light. Its light does not cast shadows (only the sun or the moon can) and can go through walls. It can be of one of these two types:
* A '''light point''' (glowing light source) is an all-directional light source, like a floating lightbulb, that emits light all around it.
* A '''light reflector''', much like projectors or vehicle headlights, is a beam-shaped light that was introduced in {{GVI|arma3|2.06|size= 0.75}} (see {{Link|#Heli Spotlight|this example below}}).


{{Feature | Informative | Lightpoint notions and commands were introduced in {{arma1}}, some commands were later added in {{arma3}} (e.g [[setLightIntensity]], flare commands).}}
Such light source is '''[[Multiplayer Scripting#Locality|local]]''' to the computer where the script has been called; one player could see a light in the dark while another would not have such light "object" created.
 
A lightpoint is '''[[local]]''' to the computer where the script has been called; one player could see a light in the dark while another would not have such light "object" created.


<div class="float-right" style="margin-top: 1em"><!-- little trick to keep Flare's thumbnail aligned -->
[[File:lightpoint_redColor_blueAmbient.jpg|thumb|left|200px|Lightpoint with {{Color|darkred|red}} colour, and {{Color|blue|blue}} ambient.
[[File:lightpoint_redColor_blueAmbient.jpg|thumb|left|200px|Lightpoint with {{Color|darkred|red}} colour, and {{Color|blue|blue}} ambient.
Note how the {{Color|darkred|red}} and {{Color|blue|blue}} hues mix to create {{Color|purple|purple}}.]]
Note how the {{Color|darkred|red}} and {{Color|blue|blue}} hues mix to create {{Color|purple|purple}}.]]
</div>
=== Colour ===
=== Colour ===


Line 16: Line 19:
=== Ambient ===
=== Ambient ===


Colour set ''via'' [[setLightAmbient]] determines the outer colour shone by the lightpoint.
Colour set ''via'' [[setLightAmbient]] determines the outer colour shone by the light source.
{{Feature | important | Light colour does not affect AI, but ambient '''does'''.}}
{{Feature|important|Light colour does not affect AI spotting ability, but ambient '''does'''.}}


=== Flare ===
=== Flare ===


The flare is the "colour point" centre that emits light. It can be visible or invisible (set by [[setLightUseFlare]]).
The flare is the "colour point" centre that emits light. It can be visible or invisible (set by [[setLightUseFlare]]).
{{Feature | Informative | Flare is '''not''' visible by day, even using [[setLightDayLight]].}}
{{Feature|informative|Flare is '''not''' visible by day, even using [[setLightDayLight]].}}




== How to ==
== How To ==


The list of all lightpoint commands can be found in the [[:Category:Command Group: Lights|Lights command group]] category.
The list of all light source commands can be found in the [[:Category:Command Group: Lights|Lights command group]] category.


=== Create a lightpoint ===
=== Create a Light Source ===


[[private]] _lightpoint = '''"#lightpoint"''' [[createVehicleLocal]] [[player]] [[modelToWorld]] [0,2,1.5];
<sqf>
private _lightSource = "#lightpoint" createVehicleLocal player modelToWorld [0, 2, 1.5];
// alternatively, a light reflector (cone) can be created since {{arma3}} v2.06
private _lightSource = "#lightreflector" createVehicleLocal player modelToWorld [0, 2, 1.5];
</sqf>


{{Feature | Informative | A lightpoint is '''local''' (and all the lightpoint commands take a local argument too), hence [[createVehicleLocal]] usage.}}
{{Feature|informative|A light source is '''local''' (and all the light commands take a local argument too), hence [[createVehicleLocal]]'s usage.}}


=== Set light colour ===
=== Set Light Colour ===


==== Colour ====
==== Colour ====
_lightpoint [[setLightColor]] [0.25, 1, 1]; {{cc|also defines [[#Set flare|Flare]] colour}}
<sqf>_lightSource setLightColor [0.25, 1, 1]; // also defines Flare colour</sqf>


==== Ambient Colour ====
==== Ambient Colour ====
_lightpoint [[setLightAmbient]] [1, 1, 1]; {{cc|sets the colour applied to the surroundings}}
<sqf>_lightSource setLightAmbient [1, 1, 1]; // sets the colour applied to the surroundings</sqf>
 
=== Set Flare ===
 
{{Feature|informative|For the flare to be visible, all the following values (use flare, size, visibility) must be defined and light colour [[#Colour_2|set by]] [[setLightColor]] must not be [0,0,0].}}


=== Set flare ===
{{ArgTitle|4|Enable Flare|{{GVI|arma3|0.50}}}}
<sqf>_lightSource setLightUseFlare true;</sqf>


{{Feature | Informative | For the flare to be visible, all the following values (use flare, size, visibility) must be defined and light colour [[#Colour_2|set by]] [[setLightColor]] must not be [0,0,0].}}
{{ArgTitle|4|Set Flare Size|{{GVI|arma3|0.50}}}}
<sqf>_lightSource setLightFlareSize 1; // in metre</sqf>


{{ArgTitle|Enable flare|4|{{GVI|arma3|0.50}}}}
{{ArgTitle|4|Set Flare Visibility|{{GVI|arma3|0.50}}}}
_lightpoint [[setLightUseFlare]] [[true]];
<sqf>_lightSource setLightFlareMaxDistance 100; // in metre</sqf>


{{ArgTitle|Set flare size|4|{{GVI|arma3|0.50}}}}
=== Set Light Brightness ===
_lightpoint [[setLightFlareSize]] 1; {{cc|in meter}}


{{ArgTitle|Set flare visibility|4|{{GVI|arma3|0.50}}}}
==== Set Brightness ====
_lightpoint [[setLightFlareMaxDistance]] 100; {{cc|in meter}}
<sqf>_lightSource setLightBrightness 8;</sqf>
{{Feature|important|Does '''not''' work with {{hl|#lightreflector}} - use {{Link|#Set Intensity|setLightIntensity}} instead.}}


=== Set light brightness ===
{{ArgTitle|4|Set Intensity|{{GVI|arma3|0.50}}}}
<sqf>_lightSource setLightIntensity 3000;</sqf>


==== Set brightness ====
{{ArgTitle|4|Set Attenuation|{{GVI|arma3|0.50}}}}
_lightpoint [[setLightBrightness]] 8;
<sqf>_lightSource setLightAttenuation [0, 2, 4, 4, 0, 9, 10]; // [start, constant, linear, quadratic, hardLimitStart, hardLimitEnd]</sqf>
{{Feature|informative|Formula is {{hl|1 / (constant + linear &times; dist + quadratic &times; dist &times; dist)}} - see [[setLightAttenuation]] for more information.}}


{{ArgTitle|Set intensity|4|{{GVI|arma3|0.50}}}}
{{ArgTitle|3|Make Light Visible by Day|{{GVI|arma3|0.50}}}}
_lightpoint [[setLightIntensity]] 3000;


{{ArgTitle|Set attenuation|4|{{GVI|arma3|0.50}}}}
<sqf>_lightSource setLightDayLight true; // only for the light itself, not the flare</sqf>
_lightpoint [[setLightAttenuation]] [0, 2, 4, 4, 0, 9, 10]; {{cc|[start, constant, linear, quadratic, hardLimitStart, hardLimitEnd]}}
{{Feature | Informative | Formula is {{ic|1 / (constant + linear × dist + quadratic × dist × dist)}} - see [[setLightAttenuation]] for more information.}}


{{ArgTitle|Make light visible by day|3|{{GVI|arma3|0.50}}}}
{{ArgTitle|3|Set IR|{{GVI|arma3|2.06}}}}


_lightpoint [[setLightDayLight]] [[true]]; {{cc|only for the light itself, not the flare}}
<sqf>_lightSource setLightIR true;</sqf>


=== Delete lightpoint ===
{{ArgTitle|3|Set Reflector Angles|{{GVI|arma3|2.06}}}}


[[deleteVehicle]] _lightpoint; {{cc|as simple as that}}
==== Set Cone Parameters ====
<sqf>_lightReflector setLightConePars [90, 45, 1];</sqf>


== Full examples ==
==== Set Reflector Volume Shape ====
<sqf>_lightReflector setLightVolumeShape ["a3\data_f\VolumeLightFlashlight.p3d", [1, 1, 1]];</sqf>
 
=== Delete Light Source ===
 
<sqf>deleteVehicle _lightSource; // as simple as that</sqf>
 
 
== Examples ==


=== Dark Souls ===
=== Dark Souls ===


[[skipTime]] -[[daytime]];
<sqf>
skipTime -dayTime;
_lightpoint = "#lightpoint" [[createVehicleLocal]] [0,0,0];
 
_lightpoint [[attachTo]] [<nowiki/>[[player]], [0, 0, 1.5]];
_lightSource = "#lightpoint" createVehicleLocal [0,0,0];
_lightpoint [[setLightColor]] [0,0,0];
_lightSource attachTo [player, [0, 0, 1.5]];
_lightpoint [[setLightAmbient]] [1,0.8, 0.25];
_lightSource setLightColor [0,0,0];
_lightpoint [[setLightBrightness]] 0.15;
_lightSource setLightAmbient [1,0.8, 0.25];
_lightSource setLightBrightness 0.15;
</sqf>


=== Contact ===
=== Contact ===


[[skipTime]] -[[daytime]];
<sqf>
skipTime -dayTime;
[[private]] _position = [[player]] [[modelToWorld]] [0, 20, 1.5];
 
[[private]] _lightpoint = "#lightpoint" [[createVehicleLocal]] _position;
private _position = player modelToWorld [0, 20, 1.5];
_lightpoint [[setLightColor]] [0,1,1];
private _lightSource = "#lightpoint" createVehicleLocal _position;
_lightpoint [[setLightAmbient]] [0.2,0.0,0.3];
_lightSource setLightColor [0,1,1];
_lightpoint [[setLightUseFlare]] [[true]];
_lightSource setLightAmbient [0.2,0.0,0.3];
_lightpoint [[setLightFlareSize]] 3;
_lightSource setLightUseFlare true;
_lightpoint [[setLightFlareMaxDistance]] 3.5;
_lightSource setLightFlareSize 3;
_lightpoint [[setLightBrightness]] 4;
_lightSource setLightFlareMaxDistance 3.5;
_lightpoint [[setLightDayLight]] [[true]];
_lightSource setLightBrightness 4;
_lightSource setLightDayLight true;
_lightpoint [[spawn]] {
 
[[while]] { sleep 0.05; [[player]] [[distance]] [[Magic Variables#this|_this]] > 2 } [[do]]
_lightSource spawn {
{
while { sleep 0.05; player distance _this > 2 } do
[[Magic Variables#this|_this]] [[setLightBrightness]] 4 [[max]] (40 / ([[player]] [[distance]] [[Magic Variables#this|_this]]));
{
};
_this setLightBrightness 4 max (40 / (player distance _this));
[[deleteVehicle]] [[Magic Variables#this|_this]];
};
};
deleteVehicle _this;
};
</sqf>
 
=== Heli Spotlight ===
 
<sqf>
private _reflector = "#lightreflector" createVehicleLocal [0, 0, 0];
_reflector attachTo [myHeliVariable, [0, 0, 0], "light_l"];
_reflector setLightColor [1, 1, 1];
_reflector setLightAmbient [1, 1, 1];
_reflector setLightIntensity 1e6;
_reflector setLightConePars [60, 10, 1];
private _vector3D = [[[0, 1, 0], [0, 0, 1]], 0, -45, 0] call BIS_fnc_transformVectorDirAndUp;
_reflector setVectorDirAndUp _vector3D;
 
private _light = "#lightpoint" createVehicleLocal [0, 0, 0];
_light attachTo [myHeliVariable, [0, 0, 0], "light_l"];
_light setLightColor [1, 1, 1];
_light setLightAmbient [1, 1, 1];
_light setLightUseFlare true;
_light setLightFlareSize 5;
_light setLightFlareMaxDistance 500;
_light setLightBrightness 1000;
_light setLightIntensity 10;
</sqf>




== See also ==
== See Also ==


* [[:Category:Command Group: Lights|Command Group: Lights]]
* [[:Category:Command Group: Lights|Command Group: Lights]]
Line 117: Line 165:


[[Category:Arma Scripting Tutorials]]
[[Category:Arma Scripting Tutorials]]
{{GameCategory|arma1|Tutorials}}
{{GameCategory|arma2|Tutorials}}
{{GameCategory|arma2|Tutorials}}
{{GameCategory|arma3|Tutorials}}
{{GameCategory|arma3|Tutorials}}

Latest revision as of 01:01, 4 March 2024

Logo A1 black.png1.00

Basics

A light source is a non-physical object that shines a light. Its light does not cast shadows (only the sun or the moon can) and can go through walls. It can be of one of these two types:

  • A light point (glowing light source) is an all-directional light source, like a floating lightbulb, that emits light all around it.
  • A light reflector, much like projectors or vehicle headlights, is a beam-shaped light that was introduced in Arma 3 logo black.png2.06 (see this example below).

Such light source is local to the computer where the script has been called; one player could see a light in the dark while another would not have such light "object" created.

Lightpoint with red colour, and blue ambient. Note how the red and blue hues mix to create purple.

Colour

Colour set via setLightColor determines the lens flare effect colour, as well as light's first colour.

Ambient

Colour set via setLightAmbient determines the outer colour shone by the light source.

Light colour does not affect AI spotting ability, but ambient does.

Flare

The flare is the "colour point" centre that emits light. It can be visible or invisible (set by setLightUseFlare).

Flare is not visible by day, even using setLightDayLight.


How To

The list of all light source commands can be found in the Lights command group category.

Create a Light Source

private _lightSource = "#lightpoint" createVehicleLocal player modelToWorld [0, 2, 1.5]; // alternatively, a light reflector (cone) can be created since Arma 3 v2.06 private _lightSource = "#lightreflector" createVehicleLocal player modelToWorld [0, 2, 1.5];

A light source is local (and all the light commands take a local argument too), hence createVehicleLocal's usage.

Set Light Colour

Colour

_lightSource setLightColor [0.25, 1, 1]; // also defines Flare colour

Ambient Colour

_lightSource setLightAmbient [1, 1, 1]; // sets the colour applied to the surroundings

Set Flare

For the flare to be visible, all the following values (use flare, size, visibility) must be defined and light colour set by setLightColor must not be [0,0,0].

Enable Flare

_lightSource setLightUseFlare true;

Set Flare Size

_lightSource setLightFlareSize 1; // in metre

Set Flare Visibility

_lightSource setLightFlareMaxDistance 100; // in metre

Set Light Brightness

Set Brightness

_lightSource setLightBrightness 8;

Does not work with #lightreflector - use setLightIntensity instead.

Set Intensity

_lightSource setLightIntensity 3000;

Set Attenuation

_lightSource setLightAttenuation [0, 2, 4, 4, 0, 9, 10]; // [start, constant, linear, quadratic, hardLimitStart, hardLimitEnd]

Formula is 1 / (constant + linear × dist + quadratic × dist × dist) - see setLightAttenuation for more information.

Make Light Visible by Day

_lightSource setLightDayLight true; // only for the light itself, not the flare

Set IR

_lightSource setLightIR true;

Set Reflector Angles

Set Cone Parameters

_lightReflector setLightConePars [90, 45, 1];

Set Reflector Volume Shape

_lightReflector setLightVolumeShape ["a3\data_f\VolumeLightFlashlight.p3d", [1, 1, 1]];

Delete Light Source

deleteVehicle _lightSource; // as simple as that


Examples

Dark Souls

skipTime -dayTime; _lightSource = "#lightpoint" createVehicleLocal [0,0,0]; _lightSource attachTo [player, [0, 0, 1.5]]; _lightSource setLightColor [0,0,0]; _lightSource setLightAmbient [1,0.8, 0.25]; _lightSource setLightBrightness 0.15;

Contact

skipTime -dayTime; private _position = player modelToWorld [0, 20, 1.5]; private _lightSource = "#lightpoint" createVehicleLocal _position; _lightSource setLightColor [0,1,1]; _lightSource setLightAmbient [0.2,0.0,0.3]; _lightSource setLightUseFlare true; _lightSource setLightFlareSize 3; _lightSource setLightFlareMaxDistance 3.5; _lightSource setLightBrightness 4; _lightSource setLightDayLight true; _lightSource spawn { while { sleep 0.05; player distance _this > 2 } do { _this setLightBrightness 4 max (40 / (player distance _this)); }; deleteVehicle _this; };

Heli Spotlight

private _reflector = "#lightreflector" createVehicleLocal [0, 0, 0]; _reflector attachTo [myHeliVariable, [0, 0, 0], "light_l"]; _reflector setLightColor [1, 1, 1]; _reflector setLightAmbient [1, 1, 1]; _reflector setLightIntensity 1e6; _reflector setLightConePars [60, 10, 1]; private _vector3D = [[[0, 1, 0], [0, 0, 1]], 0, -45, 0] call BIS_fnc_transformVectorDirAndUp; _reflector setVectorDirAndUp _vector3D; private _light = "#lightpoint" createVehicleLocal [0, 0, 0]; _light attachTo [myHeliVariable, [0, 0, 0], "light_l"]; _light setLightColor [1, 1, 1]; _light setLightAmbient [1, 1, 1]; _light setLightUseFlare true; _light setLightFlareSize 5; _light setLightFlareMaxDistance 500; _light setLightBrightness 1000; _light setLightIntensity 10;


See Also