User Tools

Site Tools


dragengine:modules:dragonscript:behavior_light

ECBehaviorLight

Behavior element behavior adding custom color support.

Custom colors are typically used to allow players to customize the look of their player actor by altering the color of individual body parts. This behavior allows to define custom color slots the player or artist can manipulate. This behavior does not define how custom colors are applied. This is left for other behaviors or game scripts to do.

Custom colors compose of a display name and the currently assigned color. This color can be null to use the assigned default color. An optional list of colors can be used to restrict the colors the player can select. If the list is empty the player can choose the color unrestricted. In addition a display description can be added in case the game developer would like to communicate additional information about the custom color.

Instance Counts

This behavior can be used multiple times on an element to add multiple custom colors to mainpulate. Use the behavior identifier to tell them apart.

Element Class Properties

Element class properties have the prefix light. or light({id}). if id is not empty.

type

Set light type.

  • Full name: light.type or light({id}).type
  • Type: enumeration
  • Allowed Values:

    ValueDescription
    pointPoint light.
    spotSpot light.
    projectorProjector light.
  • Default Value: point
  • Example (*.deeclass)
    <string name='light.type'>spot</string>

color

Set light color.

  • Full name: light.color or light({id}).color
  • Type: 3-component color
  • Default Value: (1,1,1)
  • Example (*.deeclass)
    <color name='light.color' r='0.8' g='0.6' b='0.4'/>

intensity

Set value.

  • Full name: light.intensity or light({id}).intensity
  • Type: float
  • Default Value: 1
  • Restriction: At least 0
  • Example (*.deeclass)
    <float name='light.intensity'>2.5</float>

ambientRatio

Set ambient ratio. Percentage of total light to use as ambient light.

  • Full name: light.ambientRatio or light({id}).ambientRatio
  • Type: float
  • Default Value: 0
  • Restriction: At least 0 and at most 1.
  • Example (*.deeclass)
    <float name='light.ambientRatio'>0.2</float>

range

Set range im meters. Beyond this range light has no effect.

  • Full name: light.range or light({id}).range
  • Type: float
  • Default Value: 10
  • Restriction: At least 0
  • Example (*.deeclass)
    <float name='light.range'>2.5</float>

halfIntensityDistance

Set half intensity distance relative to range. At this position the light dropped to 50% strength. Allows to shape fall-off curve. A value of 0.1 is natural fall-off. Values larger than 0.1 make light fall off faster near the light source. Values smaller than 0.1 make light fall off faster near the light range.

  • Full name: light.halfIntensityDistance or light({id}).halfIntensityDistance
  • Type: float
  • Default Value: 0.1
  • Restriction: At least 0 and at most 1.
  • Example (*.deeclass)
    <float name='light.halfIntensityDistance'>0.2</float>

spotAngle

Set spot angle in degrees (opening angle).

  • Full name: light.spotAngle or light({id}).spotAngle
  • Type: float
  • Default Value: 30
  • Restriction: At least 0 and at most 179.
  • Example (*.deeclass)
    <float name='light.spotAngle'>45</float>

spotRatio

Set spot ratio as height divided by width. Hence this is the aspect ratio of the spot light.

  • Full name: light.spotRatio or light({id}).spotRatio
  • Type: float
  • Default Value: 1
  • Restriction: At least 0
  • Example (*.deeclass)
    <float name='light.spotRatio'>1.5</float>

spotSmoothness

Set spot smoothness. Percentage distance from border to center where light fall-off begins. A value of 0 produces constant light intensity across the entire spot cone. A value of 1 produces linear fade across the entire spot cone.

  • Full name: light.spotSmoothness or light({id}).spotSmoothness
  • Type: float
  • Default Value: 1
  • Restriction: At least 0 and at most 1.
  • Example (*.deeclass)
    <float name='light.spotSmoothness'>0.2</float>

spotExponent

Set spot exponent. Shape of light fall-off from spot center to spot border. A value of 1 is linear fall-off. Values larger than 0.1 make light fall off faster near the spot center. Values smaller than 0.1 make light fall off faster near the spot border.

  • Full name: light.spotExponent or light({id}).spotExponent
  • Type: float
  • Default Value: 2
  • Restriction: At least 0
  • Example (*.deeclass)
    <float name='light.spotExponent'>1.5</float>

shape

Set shape.

  • Full name: light.shape or light({id}).shape
  • Type: string (shape format). See “Shape List Encoding” in CodecPropertyString.
  • Default Value: empty string
  • Example (*.deeclass)
    <string name='light.shape'>box:position,0,0.5,0:extends,2,1,0.5</string>

lightSkin

Set path of skin resource to use.

  • Full name: light.lightSkin or light({id}).lightSkin
  • Type: string
  • Default Value: empty string
  • Expected File Type: *.deskin
  • Example (*.deeclass)
    <string name='light.lightSkin'>spot.deskin</string>

hintMovement

Set movement hint.

  • Full name: light.hintMovement or light({id}).hintMovement
  • Type: enumeration
  • Allowed Values:

    ValueDescription
    stationaryLight remains static for the entire lifetime.
    jitteringLight remains mostly static jittering in a small area.
    dynamicLight moves around freely.
  • Default Value: stationary
  • Example (*.deeclass)
    <string name='light.hintMovement'>dynamic</string>

hintParameter

Set parameter hint.

  • Full name: light.hintParameter or light({id}).hintParameter
  • Type: enumeration
  • Allowed Values:

    ValueDescription
    initialLight parameters never change.
    activationLight parameters never change except activation.
    flickerGeometric light parameters never change but others can.
    dynamicAll light parameters can change at will any time.
  • Default Value: initial
  • Example (*.deeclass)
    <string name='light.hintParameter'>dynamic</string>

hintShadowImportance

Set hint shadow importance. Can be used by graphics module to decide which shadows can be reduced in quality or omitted if performance is low. A value of 100 indicates this shadow is important and should always be shown if possible. A value of 0 marks the shadow as unimportant which can be quickly reduced if required.

  • Full name: light.hintShadowImportance or light({id}).hintShadowImportance
  • Type: float
  • Default Value: 100
  • Restriction: At least 0 and at most 100
  • Example (*.deeclass)
    <float name='light.hintShadowImportance'>75</float>

activated

Set light active.

  • Full name: light.activated or light({id}).activated
  • Type: boolean
  • Default Value: true
  • Example (*.deeclass)
    <boolean name='light.activated'>false</boolean>

castShadows

Set light cast shadows.

  • Full name: light.castShadows or light({id}).castShadows
  • Type: boolean
  • Default Value: true
  • Example (*.deeclass)
    <boolean name='light.castShadows'>false</boolean>

position

Set position to attach resource to collider.

  • Full name: light.position or light({id}).position
  • Type: 3-component float vector
  • Default Value: (0,0,0)
  • Example (*.deeclass)
    <vector name='light.position' x='0' y='0' z='0.1'/>

orientation

Set orientation to attach resource to collider in degrees.

  • Full name: light.orientation or light({id}).orientation
  • Type: 3-component float vector
  • Default Value: (0,0,0)
  • Example (*.deeclass)
    <vector name='light.orientation' x='30' y='0' z='0'/>

bone

Set bone to attach resource to. If empty string attach to collider.

  • Full name: light.bone or light({id}).bone
  • Type: string
  • Default Value: empty string
  • Example (*.deeclass)
    <string name='light.bone'>attach</string>

trigger

Set trigger activate. If no trigger is set the state of activated property is used.

  • Full name: light.trigger or light({id}).trigger
  • Type: string
  • Default Value: state of activated
  • Example (*.deeclass)
    <string name='light.trigger'>@switchOnLight & @powerEnabled</string>

Events

This behavior provides these events:

lightActivated

Light has been activated.

lightDeactivated

Light has been deactivated.

lightParametersChanged

Light parameters have been changed.

Required Behaviors

This behavior requires no other behaviors.

Optional Behaviors

Persistency

This behavior does support element class to be persistable (setPersistable). Saves these states:

  • activated

API Documentation

ECBehaviorLight.

Since DragonScript Module Version 1.0

Use Cases

  • Add light shining from element.

Element Class Example

This example defines an element which contains a light.

class MyElement extends BehaviorElementClass
  public var ECBehaviorCollider collider
  public var ECBehaviorLight light
  func new()
    collider = ECBehaviorCollider.new(this, component)
    light = ECBehaviorLight.new(this, collider)
    light.getLight().getColor().setColor(Color.blue)
    light.getAttach().getPosition().setVector(Vector.new(0, 0, 0.3))
  end
end

Behavior Factory

Using element class supporting adding behaviors the behavior can be added like this:

<?xml version='1.0' encoding='UTF-8'?>
<elementClass name='MyClass' class='GenericBehaviorElement'>
  <behavior type='ECBehaviorCollider'/>
 
  <behavior type='ECBehaviorLight'>
    <!-- optional: set layer mask as list of bits to set. default is '0 1' which means
                   BaseGameApp.WorldLayerBit.default, BaseGameApp.WorldLayerBit.envmap -->
    <string name='layerMask'>0 1</string>
 
    <!-- optional: set shadow layer mask. default is same as 'layerMask' -->
    <string name='layerMaskShadow'>0 1</string>
 
    <!-- optional: use BaseGameApp trigger table. game can add more supported values.
                  default value is 'default' -->
    <string name='triggerTable'>default</string>
 
    <!-- optional: sync trigger with light matching identifier -->
    <string name='syncTrigger'>second</string>
 
    <!-- optional: component behaviors not casting shadows. list of behavior identifiers -->
    <list name='shadowIgnoreComponents'>
      <string>first</string>
      <string>second</string>
    </list>
 
    <!-- set element properties. omit property prefix if used inside behavior tag -->
    <color name='.color' r='0.8' g='0.6' b='0.4'/>
  </behavior>
 
  <!-- for adding multiple behaviors use unique identifiers -->
  <behavior type='ECBehaviorLight' id='second'/>
</elementClass>

Live Examples

You could leave a comment if you were logged in.
dragengine/modules/dragonscript/behavior_light.txt · Last modified: 2025/03/12 19:36 by dragonlord