LightSource

Attributes

LightSource(win[, pos, diffuseColor, ...])

Class for representing a light source in a scene.

Details

class psychopy.visual.LightSource(win, pos=(0.0, 0.0, 0.0), diffuseColor=(1.0, 1.0, 1.0), specularColor=(1.0, 1.0, 1.0), ambientColor=(0.0, 0.0, 0.0), colorSpace='rgb', contrast=1.0, lightType='point', attenuation=(1, 0, 0))[source]

Class for representing a light source in a scene. This is a lazy-imported class, therefore import using full path from psychopy.visual.stim3d import LightSource when inheriting from it.

Only point and directional lighting is supported by this object for now. The ambient color of the light source contributes to the scene ambient color defined by ambientLight.

Warning

This class is experimental and may result in undefined behavior.

Parameters:
  • win (~psychopy.visual.Window) – Window associated with this light source.

  • pos (array_like) – Position of the light source (x, y, z, w). If w=1.0 the light will be a point source and x, y, and z is the position in the scene. If w=0.0, the light source will be directional and x, y, and z will define the vector pointing to the direction the light source is coming from. For instance, a vector of (0, 1, 0, 0) will indicate that a light source is coming from above.

  • diffuseColor (array_like) – Diffuse light color.

  • specularColor (array_like) – Specular light color.

  • ambientColor (array_like) – Ambient light color.

  • colorSpace (str or None) – Colorspace for diffuse, specular, and ambient color components.

  • contrast (float) – Contrast of the lighting color components. This acts as a ‘gain’ factor which scales color values. Must be between 0.0 and 1.0.

  • attenuation (array_like) – Values for the constant, linear, and quadratic terms of the lighting attenuation formula. Default is (1, 0, 0) which results in no attenuation.

property ambientColor

Ambient color of the light source (psychopy.color.Color, ArrayLike or None).

The ambient color component is used to simulate indirect lighting caused by the light source. For instance, light bouncing off adjacent surfaces or atmospheric scattering if the light source is a sun. This is independent of the global ambient color.

property ambientRGB

Ambient RGB1 color of the material. This value is passed to OpenGL.

property attenuation

Values for the constant, linear, and quadratic terms of the lighting attenuation formula.

property colorSpace

The name of the color space currently being used (str or None).

For strings and hex values this is not needed. If None the default colorSpace for the stimulus is used (defined during initialisation).

Please note that changing colorSpace does not change stimulus parameters. Thus, you usually want to specify colorSpace before setting the color.

property contrast

A value that is simply multiplied by the color (float).

This may be used to adjust the gain of the light source. This is applied to all lighting color components.

Examples

Basic usage:

stim.contrast =  1.0  # unchanged contrast
stim.contrast =  0.5  # decrease contrast
stim.contrast =  0.0  # uniform, no contrast
stim.contrast = -0.5  # slightly inverted
stim.contrast = -1.0  # totally inverted

Setting contrast outside range -1 to 1 is permitted, but may produce strange results if color values exceeds the monitor limits.:

stim.contrast =  1.2  # increases contrast
stim.contrast = -1.2  # inverts with increased contrast
property diffuseColor

Diffuse color for the light source (psychopy.color.Color, ArrayLike or None).

property diffuseRGB

Diffuse RGB1 color of the material. This value is passed to OpenGL.

property lightType

Type of light source, can be ‘point’ or ‘directional’.

property pos

Position of the light source in the scene in scene units.

setAmbientColor(color, colorSpace=None, operation='', log=None)[source]

Set the ambient color for the light source.

Use this function if you wish to supress logging or apply operations on the color component.

Parameters:
  • color (ArrayLike or ~psychopy.colors.Color) – Color to set as the ambient component of the light source.

  • colorSpace (str or None) – Colorspace to use. This is only used to set the color, the value of ambientColor after setting uses the color space of the object.

  • operation (str) – Operation string.

  • log (bool or None) – Enable logging.

setDiffuseColor(color, colorSpace=None, operation='', log=None)[source]

Set the diffuse color for the light source. Use this function if you wish to supress logging or apply operations on the color component.

Parameters:
  • color (ArrayLike or ~psychopy.colors.Color) – Color to set as the diffuse component of the light source.

  • colorSpace (str or None) – Colorspace to use. This is only used to set the color, the value of diffuseColor after setting uses the color space of the object.

  • operation (str) – Operation string.

  • log (bool or None) – Enable logging.

setSpecularColor(color, colorSpace=None, operation='', log=None)[source]

Set the diffuse color for the light source. Use this function if you wish to supress logging or apply operations on the color component.

Parameters:
  • color (ArrayLike or ~psychopy.colors.Color) – Color to set as the specular component of the light source.

  • colorSpace (str or None) – Colorspace to use. This is only used to set the color, the value of diffuseColor after setting uses the color space of the object.

  • operation (str) – Operation string.

  • log (bool or None) – Enable logging.

property specularColor

Specular color of the light source (psychopy.color.Color, ArrayLike or None).

property specularRGB

Specular RGB1 color of the material. This value is passed to OpenGL.


Back to top