forked from OpenRA/OpenRA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.frag
46 lines (40 loc) · 1.31 KB
/
model.frag
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
#version {VERSION}
#ifdef GL_ES
precision mediump float;
#endif
uniform sampler2D Palette, DiffuseTexture;
uniform vec2 PaletteRows;
uniform vec4 LightDirection;
uniform vec3 AmbientLight, DiffuseLight;
#if __VERSION__ == 120
varying vec4 vTexCoord;
varying vec4 vChannelMask;
varying vec4 vNormalsMask;
#else
in vec4 vTexCoord;
in vec4 vChannelMask;
in vec4 vNormalsMask;
out vec4 fragColor;
#endif
void main()
{
#if __VERSION__ == 120
vec4 x = texture2D(DiffuseTexture, vTexCoord.st);
vec4 color = texture2D(Palette, vec2(dot(x, vChannelMask), PaletteRows.x));
if (color.a < 0.01)
discard;
vec4 y = texture2D(DiffuseTexture, vTexCoord.pq);
vec4 normal = (2.0 * texture2D(Palette, vec2(dot(y, vNormalsMask), PaletteRows.y)) - 1.0);
vec3 intensity = AmbientLight + DiffuseLight * max(dot(normal, LightDirection), 0.0);
gl_FragColor = vec4(intensity * color.rgb, color.a);
#else
vec4 x = texture(DiffuseTexture, vTexCoord.st);
vec4 color = texture(Palette, vec2(dot(x, vChannelMask), PaletteRows.x));
if (color.a < 0.01)
discard;
vec4 y = texture(DiffuseTexture, vTexCoord.pq);
vec4 normal = (2.0 * texture(Palette, vec2(dot(y, vNormalsMask), PaletteRows.y)) - 1.0);
vec3 intensity = AmbientLight + DiffuseLight * max(dot(normal, LightDirection), 0.0);
fragColor = vec4(intensity * color.rgb, color.a);
#endif
}