Welcome to mirror list, hosted at ThFree Co, Russian Federation.

workbench_prepass_frag.glsl « shaders « workbench « engines « draw « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c673b2484de11d69811442be9476517502d40347 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
uniform int object_id = 0;

uniform vec3 materialDiffuseColor;
uniform float materialMetallic;
uniform float materialRoughness;

uniform sampler2D image;
uniform float ImageTransparencyCutoff = 0.1;
uniform bool imageNearest;
uniform bool imagePremultiplied;

#ifdef NORMAL_VIEWPORT_PASS_ENABLED
in vec3 normal_viewport;
#endif

#ifdef V3D_SHADING_TEXTURE_COLOR
in vec2 uv_interp;
#endif
#ifdef V3D_SHADING_VERTEX_COLOR
in vec3 vertexColor;
#endif

#ifdef HAIR_SHADER
flat in float hair_rand;
#endif

#ifdef MATDATA_PASS_ENABLED
layout(location = 0) out vec4 materialData;
#endif
#ifdef OBJECT_ID_PASS_ENABLED
layout(location = 1) out uint objectId;
#endif
#ifdef NORMAL_VIEWPORT_PASS_ENABLED
layout(location = 2) out WB_Normal normalViewport;
#endif

void main()
{
#ifdef MATDATA_PASS_ENABLED
  float metallic, roughness;
  vec4 color;

#  if defined(V3D_SHADING_TEXTURE_COLOR)
  color = workbench_sample_texture(image, uv_interp, imageNearest, imagePremultiplied);
  if (color.a < ImageTransparencyCutoff) {
    discard;
  }
#  elif defined(V3D_SHADING_VERTEX_COLOR)
  color.rgb = vertexColor;
#  else
  color.rgb = materialDiffuseColor;
#  endif

#  ifdef V3D_LIGHTING_MATCAP
  /* Encode front facing in metallic channel. */
  metallic = float(gl_FrontFacing);
  roughness = 0.0;
#  else
  metallic = materialMetallic;
  roughness = materialRoughness;
#  endif

#  ifdef HAIR_SHADER
  /* Add some variation to the hairs to avoid uniform look. */
  float hair_variation = hair_rand * 0.1;
  color = clamp(color - hair_variation, 0.0, 1.0);
  metallic = clamp(materialMetallic - hair_variation, 0.0, 1.0);
  roughness = clamp(materialRoughness - hair_variation, 0.0, 1.0);
#  endif

  materialData.rgb = color.rgb;
  materialData.a = workbench_float_pair_encode(roughness, metallic);
#endif /* MATDATA_PASS_ENABLED */

#ifdef OBJECT_ID_PASS_ENABLED
  objectId = uint(object_id);
#endif

#ifdef NORMAL_VIEWPORT_PASS_ENABLED
  vec3 n = (gl_FrontFacing) ? normal_viewport : -normal_viewport;
  n = normalize(n);
  normalViewport = workbench_normal_encode(n);
#endif
}