-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentity.vertex
More file actions
150 lines (121 loc) · 3.28 KB
/
Copy pathentity.vertex
File metadata and controls
150 lines (121 loc) · 3.28 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// __multiversion__
// This signals the loading code to prepend either #version 100 or #version 300 es as apropriate.
// To use centroid sampling we need to have version 300 es shaders, which requires changing:
// attribute to in
// varying to out when in vertex shaders or in when in fragment shaders
// defining an out vec4 FragColor and replacing uses of gl_FragColor with FragColor
// texture2D to texture
#if __VERSION__ >= 300
#define attribute in
#define varying out
#ifdef MSAA_FRAMEBUFFER_ENABLED
#define _centroid centroid
#else
#define _centroid
#endif
_centroid out vec2 uv;
#else
varying vec2 uv;
#endif
uniform MAT4 WORLDVIEWPROJ;
uniform MAT4 WORLD;
uniform vec4 TILE_LIGHT_COLOR;
uniform vec4 OVERLAY_COLOR;
uniform vec4 CHANGE_COLOR;
uniform vec4 GLINT_COLOR;
uniform vec4 FOG_COLOR;
uniform vec2 FOG_CONTROL;
uniform float RENDER_DISTANCE;
uniform vec2 UV_ANIM;
uniform vec2 UV_OFFSET;
uniform vec2 UV_ROTATION;
uniform vec2 GLINT_UV_SCALE;
attribute mediump vec4 POSITION;
attribute vec2 TEXCOORD_0;
attribute vec4 NORMAL;
#ifdef COLOR_BASED
attribute vec4 COLOR;
#endif
varying vec4 light;
varying vec4 fogColor;
#ifdef USE_OVERLAY
varying vec4 overlayColor;
#endif
#if defined(USE_COLOR_MASK) || defined(ITEM_IN_HAND) || defined(COLOR_SECOND_TEXTURE)
varying vec4 changeColor;
#endif
#ifdef GLINT
varying vec2 layer1UV;
varying vec2 layer2UV;
varying vec4 tileLightColor;
varying vec4 glintColor;
#endif
const float AMBIENT = 0.45;
const float XFAC = -0.1;
const float ZFAC = 0.1;
float lightIntensity() {
#ifdef FANCY
vec3 N = normalize( WORLD * NORMAL ).xyz;
N.y *= TILE_LIGHT_COLOR.w; //TILE_LIGHT_COLOR.w contains the direction of the light
//take care of double sided polygons on materials without culling
#ifdef FLIP_BACKFACES
vec3 viewDir = normalize((WORLD * POSITION).xyz);
if( dot(N, viewDir) > 0.0 )
N *= -1.0;
#endif
float yLight = (1.0+N.y) * 0.5;
return yLight * (1.0-AMBIENT) + N.x*N.x * XFAC + N.z*N.z * ZFAC + AMBIENT;
#else
return 1.0;
#endif
}
#ifdef GLINT
vec2 calculateLayerUV(float offset, float rotation) {
vec2 uv = TEXCOORD_0;
uv -= 0.5;
float rsin = sin(rotation);
float rcos = cos(rotation);
uv = mat2(rcos, -rsin, rsin, rcos) * uv;
uv.x += offset;
uv += 0.5;
return uv * GLINT_UV_SCALE;
}
#endif
void main()
{
POS4 scale = POSITION;
scale.y *= 2.0;
POS4 reduce = WORLDVIEWPROJ * scale;
POS4 pos = WORLDVIEWPROJ * POSITION;
gl_Position = pos;
float L = lightIntensity();
#ifdef USE_OVERLAY
L += OVERLAY_COLOR.a * 0.35;
overlayColor = OVERLAY_COLOR;
#endif
#if defined(USE_COLOR_MASK) || defined(ITEM_IN_HAND) || defined(COLOR_SECOND_TEXTURE)
changeColor = CHANGE_COLOR;
#endif
light = vec4(vec3(L) * TILE_LIGHT_COLOR.xyz, 1.0);
#ifdef COLOR_BASED
light *= COLOR;
#endif
#ifndef NO_TEXTURE
uv = TEXCOORD_0;
#endif
#ifdef USE_UV_ANIM
uv.xy += UV_ANIM.xy;
#endif
#ifdef GLINT
glintColor = GLINT_COLOR;
layer1UV = calculateLayerUV(UV_OFFSET.x, UV_ROTATION.x);
layer2UV = calculateLayerUV(UV_OFFSET.y, UV_ROTATION.y);
tileLightColor = TILE_LIGHT_COLOR;
#endif
#ifdef ITEM_IN_HAND
gl_Position = reduce;
#endif
//fog
fogColor.rgb = FOG_COLOR.rgb;
fogColor.a = clamp(((pos.z / RENDER_DISTANCE) - FOG_CONTROL.x) / (FOG_CONTROL.y - FOG_CONTROL.x), 0.0, 1.0);
}