-
Notifications
You must be signed in to change notification settings - Fork 11
/
cel-shader-base.gdshader
185 lines (158 loc) · 3.86 KB
/
cel-shader-base.gdshader
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
shader_type spatial;
#define USE_ALPHA 0
#define USE_ALPHA_CUTOFF 0
#define USE_EMISSION 0
#define USE_REFLECTIONS 0
#define USE_NORMAL_MAP 0
#define USE_OCCLUSION 0
#define USE_ANISOTROPY 0
#define USE_BACKLIGHT 0
#define USE_REFRACTION 0
#if USE_ALPHA
render_mode depth_draw_always;
#endif
#include "includes/base-cel-shader.gdshaderinc"
#if USE_EMISSION
#include "includes/emission.gdshaderinc"
#endif
#if USE_REFLECTIONS
#include "includes/reflections.gdshaderinc"
#endif
#if USE_NORMAL_MAP
#include "includes/normal-map.gdshaderinc"
#endif
#if USE_OCCLUSION
#include "includes/occlusion.gdshaderinc"
#endif
#if USE_ANISOTROPY
#include "includes/anisotropy.gdshaderinc"
#endif
#if USE_BACKLIGHT
#include "includes/backlight.gdshaderinc"
#endif
#if USE_REFRACTION
#include "includes/refraction.gdshaderinc"
#elif !USE_REFRACTION && USE_ALPHA
#include "includes/transparency.gdshaderinc"
#endif
group_uniforms BaseProperties;
#if USE_ALPHA_CUTOFF
uniform float alpha_cutoff: hint_range(0.0, 1.0) = 0.5;
#endif
uniform vec4 color: source_color = vec4(0.7, 0.12, 0.86, 1.0);
uniform sampler2D base_texture: source_color;
uniform vec4 specular: source_color = vec4(0.3, 0.3, 0.3, 0.5);
uniform sampler2D specular_texture: hint_default_white;
uniform vec4 fresnel: source_color = vec4(0.2, 0.2, 0.2, 0.3);
uniform sampler2D fresnel_texture: hint_default_white;
group_uniforms;
varying vec3 SPECULAR_COLOR;
varying float SPECULAR_STRENGTH;
varying vec3 FRESNEL_COLOR;
varying float FRESNEL_STRENGTH;
group_uniforms Tiling;
uniform vec2 uv_scale = vec2(1,1);
uniform vec2 uv_offset = vec2(0,0);
group_uniforms;
void vertex() {
UV = UV * uv_scale.xy + uv_offset.xy;
}
void fragment() {
ALBEDO = color.rgb * texture(base_texture, UV).rgb;
#if USE_ALPHA
float alpha = color.a * texture(base_texture, UV).a;
ALBEDO *= alpha;
#elif USE_ALPHA_CUTOFF
ALPHA = color.a * texture(base_texture, UV).a;
ALPHA_SCISSOR_THRESHOLD = color.a * texture(base_texture, UV).a;
#endif
#if USE_REFRACTION && USE_ALPHA
EMISSION += refraction_fragment(alpha, NORMAL, SCREEN_UV, FRAGCOORD.z);
#elif !USE_REFRACTION && USE_ALPHA
EMISSION += transparency_fragment(alpha, SCREEN_UV);
#endif
SPECULAR_COLOR = specular.rgb * texture(specular_texture, UV).rgb;
SPECULAR_STRENGTH = specular.a * texture(specular_texture, UV).a;
FRESNEL_COLOR = fresnel.rgb * texture(fresnel_texture, UV).rgb;
FRESNEL_STRENGTH = fresnel.a * texture(fresnel_texture, UV).a;
#if USE_EMISSION
EMISSION += emission_fragment(UV);
#endif
#if USE_REFLECTIONS
Surface surf = reflections_fragment(UV);
METALLIC = surf.metallic;
ROUGHNESS = surf.roughness;
#endif
#if USE_NORMAL_MAP
NormalData normal = normal_map_fragment(UV, NORMAL, TANGENT, BINORMAL);
NORMAL = normal.vector;
NORMAL_MAP = normal.map;
NORMAL_MAP_DEPTH = normal.depth;
#endif
#if USE_OCCLUSION
OcclusionData occlusion = occlusion_fragment(UV);
AO = occlusion.ao;
AO_LIGHT_AFFECT = occlusion.ao_light_affect;
#endif
#if USE_ANISOTROPY
AnisotropyData aniso = anisotropy_fragment(UV);
ANISOTROPY_DIR = aniso.direction;
ANISOTROPY_RATIO = aniso.ratio;
#endif
#if USE_BACKLIGHT
BACKLIGHT = backlight_fragment(UV);
#endif
}
void light() {
#if USE_BACKLIGHT
DIFFUSE_LIGHT += backlight_diffuse(
ALBEDO,
LIGHT_COLOR,
LIGHT,
NORMAL,
ATTENUATION,
BACKLIGHT
);
#else
DIFFUSE_LIGHT += diffuse_light(
ALBEDO,
LIGHT_COLOR,
LIGHT,
NORMAL,
ATTENUATION
);
#endif
#if USE_ANISOTROPY
SPECULAR_LIGHT += anisotropy_specular(
LIGHT_COLOR,
SPECULAR_COLOR,
SPECULAR_STRENGTH,
NORMAL,
VIEW,
LIGHT,
ATTENUATION,
UV,
ANISOTROPY_DIR,
ANISOTROPY_RATIO
);
#else
SPECULAR_LIGHT += specular_light(
LIGHT_COLOR,
SPECULAR_COLOR,
SPECULAR_STRENGTH,
NORMAL,
VIEW,
LIGHT,
ATTENUATION
);
#endif
SPECULAR_LIGHT += fresnel_light(
LIGHT_COLOR,
FRESNEL_COLOR,
FRESNEL_STRENGTH,
NORMAL,
VIEW,
LIGHT,
ATTENUATION
);
}