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: 94e41b4bcd4fb74dece3c0e2ce4b5b532845fa58 (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
85
86
87
88
89
90
91
92

uniform vec4 materialColorAndMetal;
uniform float materialRoughness;

#ifdef TEXTURE_IMAGE_ARRAY
uniform sampler2DArray image_tile_array;
uniform sampler1DArray image_tile_data;
#else
uniform sampler2D image;
#endif
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)
#    ifdef TEXTURE_IMAGE_ARRAY
  color = workbench_sample_texture_array(
      image_tile_array, image_tile_data, uv_interp, imageNearest, imagePremultiplied);
#    else
  color = workbench_sample_texture(image, uv_interp, imageNearest, imagePremultiplied);
#    endif
  if (color.a < ImageTransparencyCutoff) {
    discard;
  }
#  elif defined(V3D_SHADING_VERTEX_COLOR)
  color.rgb = vertexColor;
#  else
  color.rgb = materialColorAndMetal.rgb;
#  endif

#  ifdef V3D_LIGHTING_MATCAP
  /* Encode front facing in metallic channel. */
  metallic = float(gl_FrontFacing);
  roughness = 0.0;
#  else
  metallic = materialColorAndMetal.a;
  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(materialColorAndMetal.a - 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(resource_id + 1) & 0xFFu;
#endif

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