-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathentity.fragment
147 lines (124 loc) · 4.47 KB
/
entity.fragment
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
//for Actor ActorTint ActorMultiTexture ActorGlint Entity
//Entity.Fragment
//#define EMISSIVE
//#define EMISSIVE_ONLY
//#define CHANGE_COLOR
//#define CHANGE_COLOR_MULTI
//#define MASKED_MULTITEXTURE
//#define ALPHA_TEST
//#define COLOR_SECOND_TEXTURE
//#define GLINT
//#define TINT
//#define MULTITEXTURE
varying highp vec4 v_color0;
varying highp vec4 v_fog;
varying highp vec4 v_layerUv;
varying highp vec4 v_light;
varying highp vec2 v_texcoord0;
uniform highp vec4 UseAlphaRewrite;
uniform highp vec4 ChangeColor;
uniform highp vec4 OverlayColor;
uniform highp vec4 TintedAlphaTestEnabled;
uniform highp vec4 ColorBased;
uniform highp vec4 MatColor;
uniform highp vec4 MultiplicativeTintColor;
uniform highp vec4 TileLightColor;
uniform highp vec4 GlintColor;
uniform sampler2D s_MatTexture;
uniform sampler2D s_MatTexture1;
uniform sampler2D s_MatTexture2;
highp vec4 glintBlend(highp vec4 dest, highp vec4 source) {
// glBlendFuncSeparate(GL_SRC_COLOR, GL_ONE, GL_ONE, GL_ZERO)
return vec4(source.rgb * source.rgb, abs(source.a)) + vec4(dest.rgb, 0.0);
}
#ifdef EMISSIVE
#ifdef EMISSIVE_ONLY
#define NEEDS_DISCARD(C) (C.a < 0.00390625 || C.a > 0.9960938 )
#else
#define NEEDS_DISCARD(C) (dot (C,vec4(1.0, 1.0, 1.0, 1.0)) < 0.00390625)
#endif
#else
#if defined(CHANGE_COLOR)||defined(CHANGE_COLOR_MULTI)
#define NEEDS_DISCARD(C) (C.a < 0.5)
#else
#define NEEDS_DISCARD(C) (C.a < 0.00390625)
#endif
#endif
void main() {
highp vec4 color;
color = MatColor * texture2D(s_MatTexture, v_texcoord0);
#ifdef MASKED_MULTITEXTURE
highp vec4 markings = texture2D(s_MatTexture1, v_texcoord0);
// If markings has a non-black color and no alpha, use color; otherwise use markings
highp float maskedTexture = float(dot(markings.rgb, vec3(1.0, 1.0, 1.0)) * (1.0 - markings.a) > 0.0);
color = mix(markings, color, maskedTexture);
#endif // MASKED_MULTITEXTURE
#if defined(ALPHA_TEST) && !defined(MULTITEXTURE) && !defined(TINT)
highp vec4 color_cmp;
color_cmp.rgb = color.rgb;
color_cmp.a = mix(color.a, (color.a * OverlayColor.a), TintedAlphaTestEnabled.r);
if(NEEDS_DISCARD(color_cmp))
discard;
#endif // ALPHA_TEST
#ifdef CHANGE_COLOR_MULTI
// Texture is a mask for tinting with two colors
highp vec2 colorMask = color.rg;
// Apply the base color tint
color.rgb = colorMask.rrr * ChangeColor.rgb;
// Apply the secondary color mask and tint so long as its grayscale value is not 0
color.rgb = mix(color.rgb, colorMask.ggg * MultiplicativeTintColor.rgb, ceil(colorMask.g));
#else
#ifdef CHANGE_COLOR
color.rgb = mix(color.rgb, color.rgb * ChangeColor.rgb, color.a);
color.a *= ChangeColor.a;
#endif
#endif// CHANGE_COLOR_MULTI
#ifdef MULTITEXTURE
highp vec4 tex1 = texture2D(s_MatTexture1, v_texcoord0);
highp vec4 armor = texture2D(s_MatTexture2, v_texcoord0);
color.rgb = mix(color.rgb, tex1.rgb, tex1.a);
#ifdef COLOR_SECOND_TEXTURE
if(armor.a > 0.0) {
color.rgb =mix(armor.rgb, armor.rgb * ChangeColor.rgb, armor.a)
}
#else
color.rgb = mix(color.rgb, armor.rgb, armor.a);
#endif
#ifdef ALPHA_TEST
if(color.a < 0.5 && tex1.a < 0.00390625) {
discard;
}
#endif
#endif// MULTITEXTURE
#ifdef TINT
highp vec4 tintTex = texture2D(s_MatTexture1, v_texcoord0);
tintTex.rgb = tintTex.rgb * MultiplicativeTintColor.rgb;
#ifdef ALPHA_TEST
color.rgb = mix(color.rgb, tintTex.rgb, tintTex.a);
if(color.a + tintTex.a < 0.00390625) {
discard;
}
#endif
#endif// TINT
#ifdef ALPHA_TEST
color.a = max(UseAlphaRewrite.r, color.a);
#endif
color.rgb = color.rgb * mix(vec3(1.0, 1.0, 1.0), v_color0.rgb, ColorBased.r);
color.rgb = mix(color.rgb, OverlayColor.rgb, OverlayColor.a);
#if defined(EMISSIVE)||defined(EMISSIVE_ONLY)
//make glowy stuff
color.rgb *= mix(vec3(1.0, 1.0, 1.0), v_light.rgb, color.a);
#else
color.rgb *= v_light.rgb;
#endif
//apply fog
color.rgb = mix(color.rgb, v_fog.rgb, v_fog.a);
#ifdef GLINT
// Applies color mask to glint texture instead and blends with original color
highp vec4 layer1 = texture2D(s_MatTexture1, fract(v_layerUv.xy)).rgbr * GlintColor;
highp vec4 layer2 = texture2D(s_MatTexture1, fract(v_layerUv.zw)).rgbr * GlintColor;
highp vec4 glint = (layer1 + layer2) * TileLightColor;
color = glintBlend(color, glint);
#endif
gl_FragColor = color;
}