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
|
[require]
GLSL >= 1.10
[vertex shader]
#version 120
#extension GL_ARB_texture_rectangle : enable
#define flat
#define texture2DRectOffset(sampler, coords, offset) texture2DRect(sampler, coords + vec2(offset))
#define shadow2DRectOffset(sampler, coords, offset) shadow2DRect(sampler, coords + vec2(offset))
attribute vec4 vvertex, vtangent;
attribute vec3 vnormal;
attribute vec2 vtexcoord0;
uniform mat4 camprojmatrix;
uniform vec2 texgenscroll;
varying vec2 texcoord0;
varying mat3 world;
uniform vec3 camera;
varying vec3 camvec;
uniform vec4 blendmapparams;
varying vec2 texcoord1;
uniform vec4 glowcolor;
uniform vec4 specscale;
uniform vec4 envscale;
void main(void)
{
gl_Position = camprojmatrix * vvertex;
texcoord0 = vtexcoord0 + texgenscroll;
vec3 bitangent = cross(vnormal, vtangent.xyz) * vtangent.w;
world = mat3(vtangent.xyz, bitangent, vnormal);
camvec = camera - vvertex.xyz;
texcoord1 = (vvertex.xy - blendmapparams.xy)*blendmapparams.zw;
}
[fragment shader]
#version 120
#extension GL_ARB_texture_rectangle : enable
#define flat
#define texture2DRectOffset(sampler, coords, offset) texture2DRect(sampler, coords + vec2(offset))
#define shadow2DRectOffset(sampler, coords, offset) shadow2DRect(sampler, coords + vec2(offset))
#define fragdata(loc, name, type)
#define gcolor gl_FragData[0]
#define gnormal gl_FragData[1]
#define gglow gl_FragData[2]
uniform vec4 colorparams;
uniform sampler2D diffusemap, normalmap;
varying mat3 world;
fragdata(0, gcolor, vec4)
fragdata(1, gnormal, vec4)
fragdata(2, gglow, vec4)
varying vec2 texcoord0;
varying vec3 camvec;
uniform sampler2D glowmap;
uniform samplerCube envmap;
uniform float blendlayer;
uniform sampler2D blendmap;
varying vec2 texcoord1;
uniform vec4 glowcolor;
uniform vec4 specscale;
uniform vec4 envscale;
void main(void)
{
vec3 camvecn = normalize(camvec);
#define dtc texcoord0
vec4 diffuse = texture2D(diffusemap, dtc);
vec3 bump = texture2D(normalmap, dtc).rgb*2.0 - 1.0;
vec3 bumpw = normalize(world * bump);
gcolor.rgb = diffuse.rgb*colorparams.rgb;
gcolor.a = diffuse.a*specscale.x * 0.5;
float invfresnel = dot(camvecn, bumpw);
vec3 rvec = 2.0*bumpw*invfresnel - camvecn;
vec3 reflect = textureCube(envmap, rvec).rgb;
vec3 rmod = envscale.xyz*diffuse.a;
gcolor.rgb = mix(gcolor.rgb, reflect, rmod*clamp(1.0 - invfresnel, 0.0, 1.0));
vec3 glow = texture2D(glowmap, dtc).rgb;
glow *= glowcolor.xyz;
float colork = max(gcolor.r, max(gcolor.g, gcolor.b)), glowk = max(glow.r, max(glow.g, glow.b));
glowk /= glowk + colork + 1.0e-3;
gcolor.rgb = mix(gcolor.rgb, glow, glowk) * (1.0 - 2.0*glowk*(glowk - 1.0));
#define packnorm 1.0-glowk
gnormal.rgb = bumpw*0.5 + 0.5;
#ifdef packnorm
gnormal.a = (packnorm);
#else
gnormal.a = 1.0;
#endif
float blend = abs(texture2D(blendmap, texcoord1).r - blendlayer);
gcolor *= blend;
gnormal.rgb *= blend;
gnormal.a *= blendlayer;
}
|