R2 Shaders
Functions
R2SurfaceShaderMain.h File Reference

The main function that all deferred surface shaders must implement. More...

#include "R2SurfaceTypes.h"
#include "R2View.h"
Include dependency graph for R2SurfaceShaderMain.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

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)
 

Detailed Description

The main function that all deferred surface shaders must implement.

Definition in file R2SurfaceShaderMain.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
dataSurface data (typically coming from a vertex)
derivedSurface data calculated from the original vertex
texturesTextures that are required by all surfaces
viewMatrices and parameters related to the current view
matrices_instanceMatrices related to the instance to which this surface belongs
Returns
Calculated surface values

Definition at line 14 of file R2SurfaceBasic.h.

20 {
21  vec4 albedo_sample =
22  texture (R2_basic_surface_textures.albedo, data.uv);
23  vec4 surface =
24  mix (R2_basic_surface_parameters.albedo_color,
25  albedo_sample,
26  R2_basic_surface_parameters.albedo_mix * albedo_sample.w);
27 
28  float emission_sample =
29  texture (R2_basic_surface_textures.emission, data.uv).x;
30  float emission =
31  R2_basic_surface_parameters.emission_amount * emission_sample;
32 
33  vec3 specular_sample =
34  texture (R2_basic_surface_textures.specular, data.uv).xyz;
35  vec3 specular =
36  specular_sample * R2_basic_surface_parameters.specular_color;
37 
38  bool discarded =
39  surface.w < R2_basic_surface_parameters.alpha_discard_threshold;
40 
41  return R2_surface_output_t (
42  surface.xyz,
43  emission,
44  derived.normal_bumped,
45  specular,
46  R2_basic_surface_parameters.specular_exponent,
47  discarded
48  );
49 }
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.
vec4 albedo_color
Base RGBA albedo color.
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.
float albedo_mix
Albedo color/texture mix.
float alpha_discard_threshold
Alpha discard threshold in the range [0, 1].
sampler2D specular
RGB specular map texture.