R2 Shaders
Data Structures | Functions
R2LightPositional.h File Reference

Functions and types related to positional lighting. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  R2_light_positional_vectors_t
 Vectors used when calculating positional lighting. More...
 
struct  R2_light_positional_t
 A positional light type. More...
 

Functions

R2_light_positional_vectors_t R2_lightPositionalVectors (const R2_light_positional_t light, const vec3 p, const vec3 n)
 
float R2_lightPositionalAttenuation (const R2_light_positional_t light, const float distance)
 

Detailed Description

Functions and types related to positional lighting.

Definition in file R2LightPositional.h.

Function Documentation

§ R2_lightPositionalAttenuation()

float R2_lightPositionalAttenuation ( const R2_light_positional_t  light,
const float  distance 
)

Given a light at distance from the current point on the lit surface, calculate the amount of attenuation. The returned value is 1.0 for "no attenuation" and 0.0 for "fully attenuated".

Parameters
lightThe light
distanceThe distance from the light to the surface
Returns
An attenuation value in the range [0.0, 1.0]

Definition at line 78 of file R2LightPositional.h.

81 {
82  float linear = distance * light.inverse_range;
83  float exponential = pow (linear, light.inverse_falloff);
84  return 1.0 - clamp (exponential, 0.0, 1.0);
85 }
float inverse_falloff
The inverse falloff value (1.0 / falloff).
float inverse_range
The inverse light range (1.0 / range).

§ R2_lightPositionalVectors()

R2_light_positional_vectors_t R2_lightPositionalVectors ( const R2_light_positional_t  light,
const vec3  p,
const vec3  n 
)

Calculate the vectors required to calculate positional lighting.

Parameters
lightThe light parameters
pThe surface position (eye-space)
nThe surface normal (eye-space)
Returns
A set of lighting vectors

Definition at line 46 of file R2LightPositional.h.

50 {
51  vec3 position_diff = p - light.position;
52  vec3 observer_to_surface = normalize (p);
53  vec3 light_to_surface = normalize (position_diff);
54  vec3 surface_to_light = -light_to_surface;
55  float distance = length (position_diff);
56 
58  observer_to_surface,
59  surface_to_light,
60  light_to_surface,
61  n,
62  distance
63  );
64 }
Vectors used when calculating positional lighting.
vec3 position
The eye-space light position.