summaryrefslogtreecommitdiff
path: root/graphics/asymptote/webgl/vertex.glsl
blob: 250c0b7b4ac62134f17151a1f867e689fb0c5bf0 (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
attribute vec3 position;
#ifdef WIDTH
attribute float width;
#endif
#ifdef NORMAL
attribute vec3 normal;
#endif
attribute float materialIndex;
#ifdef COLOR
attribute vec4 color;
#endif

uniform mat3 normMat;
uniform mat4 viewMat;
uniform mat4 projViewMat;

#ifdef NORMAL
#ifndef ORTHOGRAPHIC
varying vec3 ViewPosition;
#endif
varying vec3 Normal;
#endif
varying vec4 diffuse;
varying vec3 specular;
varying float roughness,metallic,fresnel0;
varying vec4 emissive;

struct Material {
  vec4 diffuse,emissive,specular;
  vec4 parameters;
};

uniform Material Materials[Nmaterials];

void main(void)
{
  vec4 v=vec4(position,1.0);
  gl_Position=projViewMat*v;
#ifdef NORMAL
#ifndef ORTHOGRAPHIC
  ViewPosition=(viewMat*v).xyz;
#endif      
  Normal=normal*normMat;
        
  Material m;
#ifdef TRANSPARENT
  m=Materials[int(abs(materialIndex))-1];
  if(materialIndex >= 0.0) {
    diffuse=m.diffuse;
    emissive=m.emissive;
  } else {
    diffuse=color;
#if nlights > 0
    emissive=vec4(0.0);
#else
    emissive=color;
#endif
  }
#else
  m=Materials[int(materialIndex)];
#ifdef COLOR
  diffuse=color;
#if nlights > 0
  emissive=vec4(0.0);
#else
  emissive=color;
#endif
#else
  diffuse=m.diffuse;
  emissive=m.emissive;
#endif
#endif
  specular=m.specular.rgb;
  vec4 parameters=m.parameters;
  roughness=1.0-parameters[0];
  metallic=parameters[1];
  fresnel0=parameters[2];
#else
  emissive=Materials[int(materialIndex)].emissive;
#endif
#ifdef WIDTH
  gl_PointSize=width;
#endif
}