R2 Core Shaders

R2TranslucentBasicPremultiplied.frag
Go to the documentation of this file.
1 /// \file R2TranslucentBasicPremultiplied.frag
2 /// \brief A fragment shader that provides basic textured instances with premultiplied alpha
3
4 #include "R2Fog.h"
5 #include "R2LogDepth.h"
6 #include "R2SurfaceTypes.h"
7 #include "R2View.h"
8 #include "R2Viewport.h"
9
10 in R2_vertex_data_t R2_vertex_data;
11
12 uniform sampler2D R2_texture_albedo;
13 uniform vec4 R2_color;
14 uniform float R2_fade_positive_eye_z_near;
15 uniform float R2_fade_positive_eye_z_far;
16 uniform R2_view_t R2_view;
17
18 layout(location = 0) out vec4 R2_out;
19
20 void
21 main (void)
22 {
23 // Reuse the existing fog functions to fade the surface in/out based on distance
24 R2_fog_t fog = R2_fog_t(
25 R2_fade_positive_eye_z_near,
26 R2_fade_positive_eye_z_far,
27 vec3 (1.0, 1.0, 1.0));
28
29 float opacity =
30 R2_fogAmountLinear(fog, R2_vertex_data.positive_eye_z);
31
32 vec4 texture_sample =
33 texture (R2_texture_albedo, R2_vertex_data.uv);
34 vec4 texture_mult =
35 texture_sample * R2_color;
36 vec4 surface =
37 vec4 (texture_mult.xyz * opacity, texture_mult.w * opacity);
38
39 R2_out = surface;
40
41 gl_FragDepth = R2_logDepthEncodePartial(
42 R2_vertex_data.positive_eye_z,
43 R2_view.depth_coefficient);
44 }
R2_logDepthEncodePartial
float R2_logDepthEncodePartial(const float z, const float depth_coefficient)
Definition: R2LogDepth.h:33
R2Fog.h
Types related to fog rendering.
R2_vertex_data_t::uv
vec2 uv
Object-space UV.
Definition: R2SurfaceTypes.h:19
layout
layout(location=0) in vec3 R2_vertex_world_position
World-space position.
R2Viewport.h
Viewport types and functions.
R2View.h
Types relating to the view.
R2SurfaceTypes.h
Types for deferred surface shading.
R2_vertex_data_t::positive_eye_z
float positive_eye_z
Positive eye-space Z position.
Definition: R2SurfaceTypes.h:17
R2_fogAmountLinear
float R2_fogAmountLinear(const R2_fog_t fog, const float z)
Definition: R2Fog.h:28
R2_vertex_data_t
Interpolated vertex data that all deferred surface shaders will receive.
Definition: R2SurfaceTypes.h:11
R2LogDepth.h
Logarithmic depth functions.
R2_fog_t
The type of fog parameters.
Definition: R2Fog.h:9
R2_view_t::depth_coefficient
float depth_coefficient
The scene&#39;s logarithmic depth coefficient.
Definition: R2View.h:11
R2_view_t
Matrices and parameters related to the view that all surface shaders will receive.
Definition: R2View.h:9