R2 Core Shaders

R2SurfaceBasicStippled.h
Go to the documentation of this file.
1 #ifndef R2_SURFACE_BASIC_STIPPLED_H
2 #define R2_SURFACE_BASIC_STIPPLED_H
3
4 /// \file R2SurfaceBasicStippled.h
5 /// \brief Basic surface implementation
6
7 #include "R2SurfaceShaderMain.h"
8 #include "R2SurfaceBasicTypes.h"
9 #include "R2Viewport.h"
10 #include "R2Stipple.h"
11
12 uniform R2_basic_surface_textures_t R2_basic_surface_textures;
13 uniform R2_basic_surface_parameters_t R2_basic_surface_parameters;
14
15 uniform R2_stipple_t R2_stipple;
16 uniform R2_viewport_t R2_viewport;
17
18 R2_surface_output_t
19 R2_deferredSurfaceMain (
20 const R2_vertex_data_t data,
21 const R2_surface_derived_t derived,
22 const R2_surface_textures_t textures,
23 const R2_view_t view,
24 const R2_surface_matrices_instance_t matrices_instance)
25 {
26 vec4 albedo_sample =
27 texture (R2_basic_surface_textures.albedo, data.uv);
28 vec4 surface =
29 mix (R2_basic_surface_parameters.albedo_color,
30 albedo_sample,
31 R2_basic_surface_parameters.albedo_mix * albedo_sample.w);
32
33 float emission_sample =
34 texture (R2_basic_surface_textures.emission, data.uv).x;
35 float emission =
36 R2_basic_surface_parameters.emission_amount * emission_sample;
37
38 vec3 specular_sample =
39 texture (R2_basic_surface_textures.specular, data.uv).xyz;
40 vec3 specular =
41 specular_sample * R2_basic_surface_parameters.specular_color;
42
43 bool discarded =
44 R2_stippleRun(R2_stipple, R2_viewport, gl_FragCoord.xy)
45 || surface.w < R2_basic_surface_parameters.alpha_discard_threshold;
46
47 return R2_surface_output_t (
48 surface.xyz,
49 emission,
50 derived.normal_bumped,
51 specular,
52 R2_basic_surface_parameters.specular_exponent,
53 discarded
54 );
55 }
56
57 #endif // R2_SURFACE_BASIC_STIPPLED_H
R2SurfaceShaderMain.h
The main function that all deferred surface shaders must implement.
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
R2Stipple.h
Stippling types and functions.
R2_basic_surface_parameters_t::specular_color
vec3 specular_color
RGB specular color.
Definition: R2SurfaceBasicTypes.h:19
R2Viewport.h
Viewport types and functions.
R2_basic_surface_textures_t::emission
sampler2D emission
R emission level texture.
Definition: R2SurfaceBasicTypes.h:35
R2_viewport_t
The type of viewports.
Definition: R2Viewport.h:9
R2_basic_surface_parameters_t
Constant surface parameters that all basic surface shaders will receive.
Definition: R2SurfaceBasicTypes.h:9
R2_basic_surface_textures_t
Input textures that all basic surface shaders will receive.
Definition: R2SurfaceBasicTypes.h:29
R2_basic_surface_parameters_t::albedo_color
vec4 albedo_color
Base RGBA albedo color.
Definition: R2SurfaceBasicTypes.h:14
R2_surface_textures_t
Textures that are required by all surfaces.
Definition: R2SurfaceTypes.h:37
R2_vertex_data_t
Interpolated vertex data that all deferred surface shaders will receive.
Definition: R2SurfaceTypes.h:11
R2_stipple_t
The type of stippling parameters.
Definition: R2Stipple.h:11
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_surface_derived_t
Derived surface data that all deferred surface shaders will receive.
Definition: R2SurfaceTypes.h:30
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
R2SurfaceBasicTypes.h
Types for basic surfaces.
R2_surface_matrices_instance_t
Matrices related to the rendered instance that all deferred surface shaders will receive.
Definition: R2SurfaceTypes.h:44
R2_basic_surface_textures_t::specular
sampler2D specular
RGB specular map texture.
Definition: R2SurfaceBasicTypes.h:33
R2_view_t
Matrices and parameters related to the view that all surface shaders will receive.
Definition: R2View.h:9
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)
Definition: R2SurfaceBasicStippled.h:19