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 }
float R2_logDepthEncodePartial(const float z, const float depth_coefficient)
Definition: R2LogDepth.h:33
Types related to fog rendering.
vec2 uv
Object-space UV.
layout(location=0) in vec3 R2_vertex_world_position
World-space position.
Viewport types and functions.
Types relating to the view.
Types for deferred surface shading.
float positive_eye_z
Positive eye-space Z position.
float R2_fogAmountLinear(const R2_fog_t fog, const float z)
Definition: R2Fog.h:28
Interpolated vertex data that all deferred surface shaders will receive.
Logarithmic depth functions.
The type of fog parameters.
Definition: R2Fog.h:9
float depth_coefficient
The scene's logarithmic depth coefficient.
Definition: R2View.h:11
Matrices and parameters related to the view that all surface shaders will receive.
Definition: R2View.h:9