R2 Shaders
R2SurfaceBasicReflective.h
Go to the documentation of this file.
1 #ifndef R2_SURFACE_BASIC_REFLECTIVE_H
2 #define R2_SURFACE_BASIC_REFLECTIVE_H
3 
4 /// \file R2SurfaceBasicReflective.h
5 /// \brief Basic pseudo-reflective (environment mapped) deferred surface implementation
6 
7 #include "R2SurfaceShaderMain.h"
9 #include "R2SurfaceBasicTypes.h"
10 
11 /// Textures for reflections
12 
14  /// A right-handed cube map representing the reflected environment
15  samplerCube environment;
16 };
17 
18 /// Parameters for reflections
19 
21  /// Eye-to-world matrix for transforming reflection vectors.
23  /// Mix factor in the range `[0, 1]`, where 1 indicates a fully reflective surface
25 };
26 
27 uniform R2_basic_surface_textures_t R2_basic_surface_textures;
28 uniform R2_basic_surface_parameters_t R2_basic_surface_parameters;
29 
30 uniform R2_surface_reflective_textures_t R2_surface_reflective_textures;
31 uniform R2_surface_reflective_parameters_t R2_surface_reflective_parameters;
32 
35  const R2_vertex_data_t data,
36  const R2_surface_derived_t derived,
37  const R2_surface_textures_t textures,
38  const R2_view_t view,
39  const R2_surface_matrices_instance_t matrices_instance)
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 =
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 }
81 
82 #endif // R2_SURFACE_BASIC_REFLECTIVE_H
The main function that all deferred surface shaders must implement.
float emission_amount
Emission level in the range [0, 1]
vec2 uv
Object-space UV.
vec3 normal_bumped
Final uncompressed eye-space normal produced by bump/normal mapping.
vec3 specular_color
RGB specular color.
sampler2D emission
R emission level texture.
mat4x4 transform_view_inverse
Eye-to-world matrix for transforming reflection vectors.
float environment_mix
Mix factor in the range [0, 1], where 1 indicates a fully reflective surface.
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)
Constant surface parameters that all basic surface shaders will receive.
vec4 position_eye
Eye-space surface position.
Functions for environment-mapped reflections.
Input textures that all basic surface shaders will receive.
vec4 albedo_color
Base RGBA albedo color.
Textures that are required by all surfaces.
Interpolated vertex data that all deferred surface shaders will receive.
sampler2D albedo
RGBA albedo texture.
float specular_exponent
Specular exponent in the range [0, 256]
The type of surface details that all deferred surface shaders are required to calculate.
Derived surface data that all deferred surface shaders will receive.
vec4 R2_environmentReflection(const samplerCube t, const vec3 v_eye, const vec3 n_eye, const mat4x4 view_inv)
float albedo_mix
Albedo color/texture mix.
float alpha_discard_threshold
Alpha discard threshold in the range [0, 1].
Types for basic surfaces.
Matrices related to the rendered instance that all deferred surface shaders will receive.
samplerCube environment
A right-handed cube map representing the reflected environment.
sampler2D specular
RGB specular map texture.
Matrices and parameters related to the view that all surface shaders will receive.
Definition: R2View.h:9