R2 Core Shaders

Data Structures | Functions | Variables
R2SurfaceBasicReflective.h File Reference

Basic pseudo-reflective (environment mapped) deferred surface implementation. More...

`#include "R2SurfaceShaderMain.h"`
`#include "R2EnvironmentReflection.h"`
`#include "R2SurfaceBasicTypes.h"`
Include dependency graph for R2SurfaceBasicReflective.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Data Structures
struct | R2_surface_reflective_textures_t
| Textures for reflections. More...
struct | R2_surface_reflective_parameters_t
| Parameters for reflections. More...

## Functions
R2_surface_output_t | R2_deferredSurfaceMain (const R2_vertex_data_t data, const R2_surface_derived_t derived, const R2_surface_textures_t textures, const R2_view_t view, const R2_surface_matrices_instance_t matrices_instance)

## Variables
uniform R2_basic_surface_textures_t | R2_basic_surface_textures
uniform R2_basic_surface_parameters_t | R2_basic_surface_parameters
uniform R2_surface_reflective_textures_t | R2_surface_reflective_textures
uniform R2_surface_reflective_parameters_t | R2_surface_reflective_parameters

## Detailed Description

Basic pseudo-reflective (environment mapped) deferred surface implementation.

Definition in file R2SurfaceBasicReflective.h.

## Function Documentation

## § R2_deferredSurfaceMain()

R2_surface_output_t R2_deferredSurfaceMain | ( | const R2_vertex_data_t | data,
|  | const R2_surface_derived_t | derived,
|  | const R2_surface_textures_t | textures,
|  | const R2_view_t | view,
|  | const R2_surface_matrices_instance_t | matrices_instance
| ) |  |

Calculate surface values for the current surface. Implementations of this function are expected to calculate a description of the current surface. The description is encoded into the G-buffer by the caller.

Parameters

  data | Surface data (typically coming from a vertex)
  derived | Surface data calculated from the original vertex
  textures | Textures that are required by all surfaces
  view | Matrices and parameters related to the current view
  matrices_instance | Matrices related to the instance to which this surface belongs

Returns
  Calculated surface values

Definition at line 34 of file R2SurfaceBasicReflective.h.

40 {
41 vec4 albedo_sample =
42 texture (R2_basic_surface_textures.albedo, data.uv);
43 vec4 albedo =
44 mix (R2_basic_surface_parameters.albedo_color,
45 albedo_sample,
46 R2_basic_surface_parameters.albedo_mix * albedo_sample.w);
47
48 vec4 environment_sample =
49 R2_environmentReflection (
50 R2_surface_reflective_textures.environment,
51 data.position_eye.xyz,
52 derived.normal_bumped,
53 R2_surface_reflective_parameters.transform_view_inverse
54 );
55
56 vec4 surface =
57 mix (albedo, environment_sample, R2_surface_reflective_parameters.environment_mix);
58
59 float emission_sample =
60 texture (R2_basic_surface_textures.emission, data.uv).x;
61 float emission =
62 R2_basic_surface_parameters.emission_amount * emission_sample;
63
64 vec3 specular_sample =
65 texture (R2_basic_surface_textures.specular, data.uv).xyz;
66 vec3 specular =
67 specular_sample * R2_basic_surface_parameters.specular_color;
68
69 bool discarded =
70 surface.w < R2_basic_surface_parameters.alpha_discard_threshold;
71
72 return R2_surface_output_t (
73 surface.xyz,
74 emission,
75 derived.normal_bumped,
76 specular,
77 R2_basic_surface_parameters.specular_exponent,
78 discarded
79 );
80 }
R2_basic_surface_parameters_t::emission_amount
float emission_amount
Emission level in the range [0, 1]
Definition: R2SurfaceBasicTypes.h:11
R2_vertex_data_t::uv
vec2 uv
Object-space UV.
Definition: R2SurfaceTypes.h:19
R2_surface_derived_t::normal_bumped
vec3 normal_bumped
Final uncompressed eye-space normal produced by bump/normal mapping.
Definition: R2SurfaceTypes.h:32
R2_basic_surface_parameters_t::specular_color
vec3 specular_color
RGB specular color.
Definition: R2SurfaceBasicTypes.h:19
R2_basic_surface_textures_t::emission
sampler2D emission
R emission level texture.
Definition: R2SurfaceBasicTypes.h:35
R2_surface_reflective_parameters_t::transform_view_inverse
mat4x4 transform_view_inverse
Eye-to-world matrix for transforming reflection vectors.
Definition: R2SurfaceBasicReflective.h:22
R2_surface_reflective_parameters_t::environment_mix
float environment_mix
Mix factor in the range [0, 1], where 1 indicates a fully reflective surface.
Definition: R2SurfaceBasicReflective.h:24
R2_vertex_data_t::position_eye
vec4 position_eye
Eye-space surface position.
Definition: R2SurfaceTypes.h:13
R2_basic_surface_parameters_t::albedo_color
vec4 albedo_color
Base RGBA albedo color.
Definition: R2SurfaceBasicTypes.h:14
R2_basic_surface_textures_t::albedo
sampler2D albedo
RGBA albedo texture.
Definition: R2SurfaceBasicTypes.h:31
R2_basic_surface_parameters_t::specular_exponent
float specular_exponent
Specular exponent in the range [0, 256]
Definition: R2SurfaceBasicTypes.h:21
R2_surface_output_t
The type of surface details that all deferred surface shaders are required to calculate.
Definition: R2SurfaceOutput.h:9
R2_environmentReflection
vec4 R2_environmentReflection(const samplerCube t, const vec3 v_eye, const vec3 n_eye, const mat4x4 view_inv)
Definition: R2EnvironmentReflection.h:24
R2_basic_surface_parameters_t::albedo_mix
float albedo_mix
Albedo color/texture mix.
Definition: R2SurfaceBasicTypes.h:16
R2_basic_surface_parameters_t::alpha_discard_threshold
float alpha_discard_threshold
Alpha discard threshold in the range [0, 1].
Definition: R2SurfaceBasicTypes.h:24
R2_surface_reflective_textures_t::environment
samplerCube environment
A right-handed cube map representing the reflected environment.
Definition: R2SurfaceBasicReflective.h:15
R2_basic_surface_textures_t::specular
sampler2D specular
RGB specular map texture.
Definition: R2SurfaceBasicTypes.h:33