scg3  0.6
scg::Light Class Reference

A light to be applied to all nodes of its sub-tree (composite node). More...

#include "Light.h"

Inheritance diagram for scg::Light:
[legend]
Collaboration diagram for scg::Light:
[legend]

Public Member Functions

 Light ()
 
virtual ~Light ()
 
LightsetPosition (const glm::vec4 &position)
 
LightsetAmbient (const glm::vec4 &color)
 
LightsetDiffuse (const glm::vec4 &color)
 
LightsetSpecular (const glm::vec4 &color)
 
LightsetDiffuseAndSpecular (const glm::vec4 &color)
 
LightsetSpot (const glm::vec3 &direction, float cutoffDeg, float exponent)
 
void setModelTransform (const glm::mat4 modelTransform)
 
void init ()
 
virtual void accept (Traverser *traverser)
 
virtual void acceptPost (Traverser *traverser)
 
virtual void render (RenderState *renderState)
 
virtual void renderPost (RenderState *renderState)
 
- Public Member Functions inherited from scg::Composite
 Composite ()
 
virtual ~Composite ()=0
 
virtual void destroy ()
 
CompositeaddChild (NodeSP child)
 
CompositeremoveChild (Node *node, bool &result)
 
CompositeremoveChild (Node *node)
 
virtual void traverse (Traverser *traverser)
 
- Public Member Functions inherited from scg::Node
 Node ()
 
virtual ~Node ()=0
 
virtual void clear ()
 
int getNCores () const
 
const std::string & getMetaInfo (const std::string &key) const
 
void setMetaInfo (const std::string &key, const std::string &value)
 
bool isVisible () const
 
void setVisible (bool isVisible=true)
 

Static Public Member Functions

static LightSP create ()
 

Static Public Attributes

static const size_t FLOAT_SIZE = 4
 
static const size_t VEC4_SIZE = 16
 
static const size_t POSITION_OFFSET = 0
 
static const size_t AMBIENT_OFFSET = 16
 
static const size_t DIFFUSE_OFFSET = 32
 
static const size_t SPECULAR_OFFSET = 48
 
static const size_t HALF_VECTOR_OFFSET = 64
 
static const size_t SPOT_DIRECTION_OFFSET = 80
 
static const size_t SPOT_COS_CUTOFF_OFFSET = 96
 
static const size_t SPOT_EXPONENT_OFFSET = 100
 
static const size_t BUFFER_SIZE = 112
 

Protected Attributes

GLuint ubo_
 
glm::vec4 position_
 
glm::vec4 ambient_
 
glm::vec4 diffuse_
 
glm::vec4 specular_
 
glm::vec4 spotDirection_
 
float spotCosCutoff_
 
float spotExponent_
 
glm::mat4 modelTransform_
 
- Protected Attributes inherited from scg::Composite
NodeSP leftChild_
 
- Protected Attributes inherited from scg::Node
NodeSP rightSibling_
 
Compositeparent_
 
std::vector< CoreSPcores_
 
bool isVisible_
 
std::unordered_map< std::string, std::string > metaInfo_
 

Additional Inherited Members

- Protected Member Functions inherited from scg::Node
void addSibling_ (NodeSP sibling)
 
void removeSibling_ (Node *node, bool &result)
 
void processCores_ (RenderState *renderState)
 
void postProcessCores_ (RenderState *renderState)
 

Detailed Description

A light to be applied to all nodes of its sub-tree (composite node).

The light is applied to all nodes of its sub-tree, its location within the scene graph is thus logical, not physical. The light position is given by the member variable position_, which is multiplied by the current view transformation (but not by the model transformation). A light position according to a location within the scene graph can be defined by means of a LightPosition node.

Default parameters:
position_ = (0,0,0,1) (point light)
ambient_ = (0,0,0,1)
diffuse_ = (0,0,0,1)
specular = (0,0,0,1)
spotCosCutoff = 0 (no spotlight)
spotExponent = 0

Examples
scg3_minimal_example.cpp.

Definition at line 54 of file Light.h.

Constructor & Destructor Documentation

◆ Light()

scg::Light::Light ( )

Constructor.

◆ ~Light()

virtual scg::Light::~Light ( )
virtual

Destructor.

Member Function Documentation

◆ accept()

virtual void scg::Light::accept ( Traverser traverser)
virtual

Accept traverser.

Reimplemented from scg::Node.

◆ acceptPost()

virtual void scg::Light::acceptPost ( Traverser traverser)
virtual

Accept traverser after traversing sub-tree.

Reimplemented from scg::Composite.

◆ create()

static LightSP scg::Light::create ( )
static

Create shared pointer.

Examples
scg3_table_scene_example.cpp.

◆ init()

void scg::Light::init ( )

Initialize light, i.e., create UBO.

◆ render()

virtual void scg::Light::render ( RenderState renderState)
virtual

Render light, i.e., add light to render state and bind UBO.

Reimplemented from scg::Node.

◆ renderPost()

virtual void scg::Light::renderPost ( RenderState renderState)
virtual

Render light after traversing sub-tree, i.e., remove light from render state.

Reimplemented from scg::Composite.

◆ setAmbient()

Light* scg::Light::setAmbient ( const glm::vec4 &  color)

Set ambient RGBA color.

Returns
this pointer for method chaining

◆ setDiffuse()

Light* scg::Light::setDiffuse ( const glm::vec4 &  color)

Set diffuse RGBA color.

Returns
this pointer for method chaining

◆ setDiffuseAndSpecular()

Light* scg::Light::setDiffuseAndSpecular ( const glm::vec4 &  color)

Set diffuse and specular RGBA colors.

Returns
this pointer for method chaining

◆ setModelTransform()

void scg::Light::setModelTransform ( const glm::mat4  modelTransform)

Set model transformation from scene graph location, to be called by PreTraverser.

◆ setPosition()

Light* scg::Light::setPosition ( const glm::vec4 &  position)

Set light position.

Parameters
positionlight position, with w = 0 for directional light and w = 1 for point light
Returns
this pointer for method chaining

◆ setSpecular()

Light* scg::Light::setSpecular ( const glm::vec4 &  color)

Set specular RGBA color.

Returns
this pointer for method chaining

◆ setSpot()

Light* scg::Light::setSpot ( const glm::vec3 &  direction,
float  cutoffDeg,
float  exponent 
)

Set spot parameters. Note: For the spot to be enabled the light has to be a point light (position_.w = 1.0).

Parameters
directionspot direction vector (need not be normalized)
cutoffDegcutoff angle, half cone opening angle (0 to 90 degrees)
exponentattenuation exponent
Returns
this pointer for method chaining

Member Data Documentation

◆ ambient_

glm::vec4 scg::Light::ambient_
protected

Definition at line 168 of file Light.h.

◆ AMBIENT_OFFSET

const size_t scg::Light::AMBIENT_OFFSET = 16
static

Definition at line 155 of file Light.h.

◆ BUFFER_SIZE

const size_t scg::Light::BUFFER_SIZE = 112
static

Definition at line 162 of file Light.h.

◆ diffuse_

glm::vec4 scg::Light::diffuse_
protected

Definition at line 169 of file Light.h.

◆ DIFFUSE_OFFSET

const size_t scg::Light::DIFFUSE_OFFSET = 32
static

Definition at line 156 of file Light.h.

◆ FLOAT_SIZE

const size_t scg::Light::FLOAT_SIZE = 4
static

Definition at line 152 of file Light.h.

◆ HALF_VECTOR_OFFSET

const size_t scg::Light::HALF_VECTOR_OFFSET = 64
static

Definition at line 158 of file Light.h.

◆ modelTransform_

glm::mat4 scg::Light::modelTransform_
protected

Definition at line 174 of file Light.h.

◆ position_

glm::vec4 scg::Light::position_
protected

Definition at line 167 of file Light.h.

◆ POSITION_OFFSET

const size_t scg::Light::POSITION_OFFSET = 0
static

Definition at line 154 of file Light.h.

◆ specular_

glm::vec4 scg::Light::specular_
protected

Definition at line 170 of file Light.h.

◆ SPECULAR_OFFSET

const size_t scg::Light::SPECULAR_OFFSET = 48
static

Definition at line 157 of file Light.h.

◆ SPOT_COS_CUTOFF_OFFSET

const size_t scg::Light::SPOT_COS_CUTOFF_OFFSET = 96
static

Definition at line 160 of file Light.h.

◆ SPOT_DIRECTION_OFFSET

const size_t scg::Light::SPOT_DIRECTION_OFFSET = 80
static

Definition at line 159 of file Light.h.

◆ SPOT_EXPONENT_OFFSET

const size_t scg::Light::SPOT_EXPONENT_OFFSET = 100
static

Definition at line 161 of file Light.h.

◆ spotCosCutoff_

float scg::Light::spotCosCutoff_
protected

Definition at line 172 of file Light.h.

◆ spotDirection_

glm::vec4 scg::Light::spotDirection_
protected

Definition at line 171 of file Light.h.

◆ spotExponent_

float scg::Light::spotExponent_
protected

Definition at line 173 of file Light.h.

◆ ubo_

GLuint scg::Light::ubo_
protected

Definition at line 166 of file Light.h.

◆ VEC4_SIZE

const size_t scg::Light::VEC4_SIZE = 16
static

Definition at line 153 of file Light.h.


The documentation for this class was generated from the following file: