R2 Core 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

  light | The light
  distance | The 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 }
R2_light_positional_t::inverse_falloff
float inverse_falloff
The inverse falloff value (1.0 / falloff).
Definition: R2LightPositional.h:34
R2_light_positional_t::inverse_range
float inverse_range
The inverse light range (1.0 / range).
Definition: R2LightPositional.h:32

## § 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

  light | The light parameters
  p | The surface position (eye-space)
  n | The 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
57 return R2_light_positional_vectors_t (
58 observer_to_surface,
59 surface_to_light,
60 light_to_surface,
61 n,
62 distance
63 );
64 }
R2_light_positional_vectors_t
Vectors used when calculating positional lighting.
Definition: R2LightPositional.h:9
R2_light_positional_t::position
vec3 position
The eye-space light position.
Definition: R2LightPositional.h:30