R2 Core Shaders

R2LightProjectiveLambertBlinnPhongShadowVariance.h
Go to the documentation of this file.
1 #ifndef R2_LIGHT_PROJECTIVE_LAMBERT_BLINN_PHONG_SHADOW_VARIANCE_H
2 #define R2_LIGHT_PROJECTIVE_LAMBERT_BLINN_PHONG_SHADOW_VARIANCE_H
3
4 /// \file R2LightProjectiveLambertBlinnPhongShadowVariance.h
5 /// \brief A projective light with Blinn-Phong specular highlights and a variance shadow
6
7 #include "R2LightShaderMain.h"
8 #include "R2LightPositional.h"
9 #include "R2LightProjective.h"
10 #include "R2LightSpherical.h"
11 #include "R2ShadowVariance.h"
12
13 uniform R2_light_positional_t R2_light_projective;
14 uniform R2_shadow_variance_t R2_shadow_variance;
15 uniform sampler2D R2_light_projective_image;
16 uniform mat4x4 R2_transform_eye_to_light_eye;
17 uniform mat4x4 R2_transform_light_projection;
18
19 R2_light_output_t
20 R2_deferredLightMain(
21 const R2_reconstructed_surface_t surface)
22 {
23 R2_light_projective_vectors_t vectors = R2_lightProjectiveVectors(
24 R2_light_projective,
25 surface.position.xyz,
26 surface.normal,
27 R2_transform_eye_to_light_eye,
28 R2_transform_light_projection);
29
30 float shadow =
31 R2_varianceShadowFactor (R2_shadow_variance, vectors);
32
33 float attenuation =
34 R2_lightPositionalAttenuation(
35 R2_light_projective,
36 vectors.positional.distance) * vectors.back_projected * shadow;
37
38 vec3 image_sample =
39 texture (R2_light_projective_image, vectors.surface_light_uv).rgb;
40
41 vec3 diffuse =
42 R2_lightSphericalDiffuseLambertTerm (R2_light_projective, vectors.positional);
43 vec3 specular =
44 R2_lightSphericalSpecularBlinnPhongTerm(
45 R2_light_projective,
46 vectors.positional,
47 surface.specular,
48 surface.specular_exponent);
49
50 return R2_light_output_t(
51 diffuse * image_sample * attenuation,
52 specular * image_sample * attenuation);
53 }
54
55 #endif // R2_LIGHT_PROJECTIVE_LAMBERT_BLINN_PHONG_SHADOW_VARIANCE_H
R2_light_projective_vectors_t
Vectors used when calculating projective lighting.
Definition: R2LightProjective.h:11
R2_lightPositionalAttenuation
float R2_lightPositionalAttenuation(const R2_light_positional_t light, const float distance)
Definition: R2LightPositional.h:78
R2_lightSphericalSpecularBlinnPhongTerm
vec3 R2_lightSphericalSpecularBlinnPhongTerm(const R2_light_positional_t light, const R2_light_positional_vectors_t v, const vec3 specular_color, const float specular_exponent)
Definition: R2LightSpherical.h:62
R2_reconstructed_surface_t::position
vec4 position
The eye-space position of the surface.
Definition: R2ReconstructedSurface.h:30
R2_lightProjectiveVectors
R2_light_projective_vectors_t R2_lightProjectiveVectors(const R2_light_positional_t light, const vec3 p, const vec3 n, const mat4x4 m_eye_to_light_eye, const mat4x4 m_light_projection)
Definition: R2LightProjective.h:42
R2_reconstructed_surface_t::specular_exponent
float specular_exponent
The sampled surface specular exponent in the range [0, 256]
Definition: R2ReconstructedSurface.h:25
R2_lightSphericalDiffuseLambertTerm
vec3 R2_lightSphericalDiffuseLambertTerm(const R2_light_positional_t light, const R2_light_positional_vectors_t v)
Definition: R2LightSpherical.h:17
R2_reconstructed_surface_t
Reconstructed surface data, taken from the G-Buffer.
Definition: R2ReconstructedSurface.h:16
R2_light_projective_vectors_t::surface_light_uv
vec2 surface_light_uv
The surface position as UV coordinates from the perspective of the light.
Definition: R2LightProjective.h:25
R2_light_positional_vectors_t::distance
float distance
The distance between the surface and light source.
Definition: R2LightPositional.h:19
R2_light_positional_t
A positional light type.
Definition: R2LightPositional.h:24
R2_reconstructed_surface_t::normal
vec3 normal
The eye-space normal vector of the surface.
Definition: R2ReconstructedSurface.h:28
R2_varianceShadowFactor
float R2_varianceShadowFactor(const R2_shadow_variance_t s, const R2_light_projective_vectors_t v)
Definition: R2ShadowVariance.h:95
R2LightShaderMain.h
The main function that all deferred light shaders must implement.
R2ShadowVariance.h
Functions for variance shadows.
R2_reconstructed_surface_t::specular
vec3 specular
The sampled surface specular color.
Definition: R2ReconstructedSurface.h:23
R2LightSpherical.h
Functions and types related to spherical lighting.
R2LightPositional.h
Functions and types related to positional lighting.
R2_light_output_t
The type of light values that all deferred light shaders calculate.
Definition: R2LightOutput.h:9
R2_deferredLightMain
R2_light_output_t R2_deferredLightMain(const R2_reconstructed_surface_t surface)
Definition: R2LightProjectiveLambertBlinnPhongShadowVariance.h:20
R2LightProjective.h
Functions and types related to projective lighting.
R2_light_projective_vectors_t::positional
R2_light_positional_vectors_t positional
The vectors for positional lighting.
Definition: R2LightProjective.h:13
R2_shadow_variance_t
A variance shadow.
Definition: R2ShadowVariance.h:10
R2_light_projective_vectors_t::back_projected
float back_projected
A value that indicates whether or not the light fragment is back projected (0.0 means back projected...
Definition: R2LightProjective.h:28