@@ -96,6 +96,30 @@ layout (std140) uniform modelData {
9696 int sMiscmapIndex;
9797};
9898
99+ in VertexOutput {
100+ #ifdef FLAG_ENV_MAP
101+ vec3 envReflect;
102+ #endif
103+ #ifdef FLAG_NORMAL_MAP
104+ mat3 tangentMatrix;
105+ #endif
106+ #ifdef FLAG_FOG
107+ float fogDist;
108+ #endif
109+ #ifdef WORKAROUND_CLIPPING_PLANES
110+ #ifdef FLAG_TRANSFORM
111+ float notVisible;
112+ #endif
113+ #endif
114+ vec4 position;
115+ vec3 normal;
116+ vec4 texCoord;
117+ #ifdef FLAG_SHADOWS
118+ vec4 shadowUV[4];
119+ vec4 shadowPos;
120+ #endif
121+ } vertIn;
122+
99123#ifdef FLAG_DIFFUSE_MAP
100124uniform sampler2DArray sBasemap;
101125#endif
@@ -107,41 +131,27 @@ uniform sampler2DArray sSpecmap;
107131#endif
108132#ifdef FLAG_ENV_MAP
109133uniform samplerCube sEnvmap;
110- in vec3 fragEnvReflect;
111134#endif
112135#ifdef FLAG_NORMAL_MAP
113136uniform sampler2DArray sNormalmap;
114- in mat3 fragTangentMatrix;
115137#endif
116138#ifdef FLAG_AMBIENT_MAP
117139uniform sampler2DArray sAmbientmap;
118140#endif
119- #ifdef FLAG_FOG
120- in float fragFogDist;
121- #endif
122141#ifdef FLAG_ANIMATED
123142uniform sampler2D sFramebuffer;
124143#endif
125- #ifdef WORKAROUND_CLIPPING_PLANES
126- #ifdef FLAG_TRANSFORM
127- in float fragNotVisible;
128- #endif
129- #endif
130144#ifdef FLAG_TEAMCOLOR
131145vec2 teamMask = vec2(0.0, 0.0);
132146#endif
133147#ifdef FLAG_MISC_MAP
134148uniform sampler2DArray sMiscmap;
135149#endif
136150#ifdef FLAG_SHADOWS
137- in vec4 fragShadowUV[4];
138- in vec4 fragShadowPos;
139151uniform sampler2DArray shadow_map;
140152#endif
141153#define SRGB_GAMMA 2.2
142- in vec4 fragPosition;
143- in vec3 fragNormal;
144- in vec4 fragTexCoord;
154+
145155out vec4 fragOut0;
146156out vec4 fragOut1;
147157out vec4 fragOut2;
@@ -161,17 +171,17 @@ void GetLightInfo(int i, out vec3 lightDir, out float attenuation)
161171 attenuation = 1.0;
162172 if (lights[i].light_type != LT_DIRECTIONAL) {
163173 // Positional light source
164- float dist = distance(lights[i].position.xyz, fragPosition .xyz);
165- lightDir = (lights[i].position.xyz - fragPosition .xyz);
174+ float dist = distance(lights[i].position.xyz, vertIn.position .xyz);
175+ lightDir = (lights[i].position.xyz - vertIn.position .xyz);
166176
167177 if (lights[i].light_type == LT_TUBE) { // Tube light
168178 float beamlength = length(lights[i].direction);
169179 vec3 beamDir = normalize(lights[i].direction);
170180 // Get nearest point on line
171- float neardist = dot(fragPosition .xyz - lights[i].position.xyz, beamDir);
181+ float neardist = dot(vertIn.position .xyz - lights[i].position.xyz, beamDir);
172182 // Move back from the endpoint of the beam along the beam by the distance we calculated
173183 vec3 nearest = lights[i].position.xyz - beamDir * abs(neardist);
174- lightDir = nearest - fragPosition .xyz;
184+ lightDir = nearest - vertIn.position .xyz;
175185 dist = length(lightDir);
176186 }
177187
@@ -181,7 +191,7 @@ void GetLightInfo(int i, out vec3 lightDir, out float attenuation)
181191}
182192vec3 CalculateLighting(vec3 normal, vec3 diffuseMaterial, vec3 specularMaterial, float gloss, float fresnel, float shadow, float aoFactor)
183193{
184- vec3 eyeDir = vec3(normalize(-fragPosition ).xyz);
194+ vec3 eyeDir = vec3(normalize(-vertIn.position ).xyz);
185195 vec3 lightAmbient = (emissionFactor + ambientFactor * ambientFactor) * aoFactor; // ambientFactor^2 due to legacy OpenGL compatibility behavior
186196 vec3 lightDiffuse = vec3(0.0, 0.0, 0.0);
187197 vec3 lightSpecular = vec3(0.0, 0.0, 0.0);
@@ -208,18 +218,18 @@ void main()
208218{
209219#ifdef WORKAROUND_CLIPPING_PLANES
210220 #ifdef FLAG_TRANSFORM
211- if(fragNotVisible >= 0.9) { discard; }
221+ if(vertIn.notVisible >= 0.9) { discard; }
212222 #endif
213223#endif
214224#ifdef FLAG_SHADOW_MAP
215225 // need depth and depth squared for variance shadow maps
216- fragOut0 = vec4(fragPosition. z, fragPosition. z * fragPosition .z * VARIANCE_SHADOW_SCALE_INV, 0.0, 1.0);
226+ fragOut0 = vec4(vertIn.position. z, vertIn.position. z * vertIn.position .z * VARIANCE_SHADOW_SCALE_INV, 0.0, 1.0);
217227 if (true) {
218228 return;
219229 }
220230#endif
221- vec3 eyeDir = vec3(normalize(-fragPosition ).xyz);
222- vec2 texCoord = fragTexCoord .xy;
231+ vec3 eyeDir = vec3(normalize(-vertIn.position ).xyz);
232+ vec2 texCoord = vertIn.texCoord .xy;
223233 vec4 baseColor = color;
224234 vec4 specColor = vec4(0.0, 0.0, 0.0, 1.0);
225235 vec4 emissiveColor = vec4(0.0, 0.0, 0.0, 1.0);
@@ -234,14 +244,14 @@ void main()
234244 // green is cavity occlusion factor which only affects diffuse and specular lighting.
235245 aoFactors = texture(sAmbientmap, vec3(texCoord, float(sAmbientmapIndex))).xy;
236246#endif
237- vec3 unitNormal = normalize(fragNormal );
247+ vec3 unitNormal = normalize(vertIn.normal );
238248 vec3 normal = unitNormal;
239249#ifdef FLAG_NORMAL_MAP
240250 // Normal map - convert from DXT5nm
241251 vec2 normalSample;
242252 normal.rg = normalSample = (texture(sNormalmap, vec3(texCoord, float(sNormalmapIndex))).ag * 2.0) - 1.0;
243253 normal.b = clamp(sqrt(1.0 - dot(normal.rg, normal.rg)), 0.0001, 1.0);
244- normal = fragTangentMatrix * normal;
254+ normal = vertIn.tangentMatrix * normal;
245255 float norm = length(normal);
246256 // prevent breaking of normal maps
247257 if (norm > 0.0)
@@ -251,7 +261,7 @@ void main()
251261#endif
252262
253263#ifdef FLAG_ANIMATED
254- vec2 distort = vec2(cos(fragPosition.x*fragPosition. w*0.005+anim_timer*20.0)*sin(fragPosition.y*fragPosition. w*0.005),sin(fragPosition.x*fragPosition. w*0.005+anim_timer*20.0)*cos(fragPosition.y*fragPosition .w*0.005))*0.03;
264+ vec2 distort = vec2(cos(vertIn.position.x*vertIn.position. w*0.005+anim_timer*20.0)*sin(vertIn.position.y*vertIn.position. w*0.005),sin(vertIn.position.x*vertIn.position. w*0.005+anim_timer*20.0)*cos(vertIn.position.y*vertIn.position .w*0.005))*0.03;
255265#endif
256266
257267#ifdef FLAG_DIFFUSE_MAP
@@ -326,7 +336,7 @@ void main()
326336 #ifdef FLAG_LIGHT
327337 float shadow = 1.0;
328338 #ifdef FLAG_SHADOWS
329- shadow = getShadowValue(shadow_map, -fragPosition. z, fragShadowPos. z, fragShadowUV , fardist, middist, neardist, veryneardist);
339+ shadow = getShadowValue(shadow_map, -vertIn.position. z, vertIn.shadowPos. z, vertIn.shadowUV , fardist, middist, neardist, veryneardist);
330340 #endif
331341 baseColor.rgb = CalculateLighting(normal, baseColor.rgb, specColor.rgb, glossData, fresnelFactor, shadow, aoFactors.x);
332342 #else
@@ -336,7 +346,7 @@ void main()
336346 #endif
337347#endif
338348#ifdef FLAG_ENV_MAP
339- vec3 envReflectNM = fragEnvReflect ;
349+ vec3 envReflectNM = vertIn.envReflect ;
340350 #ifdef FLAG_NORMAL_MAP
341351 envReflectNM += vec3(normalSample, 0.0);
342352 envReflectNM = normalize(envReflectNM);
@@ -372,8 +382,8 @@ void main()
372382 #ifdef FLAG_DIFFUSE_MAP
373383 if(blend_alpha == 1) finalFogColor *= baseColor.a;
374384 #endif
375- baseColor.rgb = mix(baseColor.rgb, finalFogColor, fragFogDist );
376- specColor.rgb *= fragFogDist ;
385+ baseColor.rgb = mix(baseColor.rgb, finalFogColor, vertIn.fogDist );
386+ specColor.rgb *= vertIn.fogDist ;
377387#endif
378388
379389#ifdef FLAG_DIFFUSE_MAP
@@ -388,21 +398,21 @@ void main()
388398 baseColor.a = baseColor.a * clamp(shinefactor * (fract(abs(texCoord.x))-anim_timer) * -10000.0,0.0,1.0);
389399 }
390400 if (effect_num == 1) {
391- float shinefactor = 1.0/(1.0 + pow(abs(fragPosition .y-anim_timer), 2.0));
401+ float shinefactor = 1.0/(1.0 + pow(abs(vertIn.position .y-anim_timer), 2.0));
392402 emissiveColor.rgb += vec3(shinefactor);
393403 #ifndef FLAG_LIGHT
394404 // ATI Wireframe fix *grumble*
395- baseColor.a = clamp((fragPosition .y-anim_timer) * 10000.0,0.0,1.0);
405+ baseColor.a = clamp((vertIn.position .y-anim_timer) * 10000.0,0.0,1.0);
396406 #endif
397407 }
398408 if (effect_num == 2) {
399409 vec2 screenPos = gl_FragCoord.xy * vec2(vpwidth,vpheight);
400410 baseColor.a = baseColor.a;
401- float cloak_interp = (sin(fragPosition.x*fragPosition. w*0.005+anim_timer*20.0)*sin(fragPosition.y*fragPosition .w*0.005)*0.5)-0.5;
411+ float cloak_interp = (sin(vertIn.position.x*vertIn.position. w*0.005+anim_timer*20.0)*sin(vertIn.position.y*vertIn.position .w*0.005)*0.5)-0.5;
402412 #ifdef FLAG_LIGHT
403413 baseColor.rgb = mix(texture(sFramebuffer, screenPos + distort*anim_timer + anim_timer*0.1*normal.xy).rgb,baseColor.rgb,clamp(cloak_interp+anim_timer*2.0,0.0,1.0));
404414 #else
405- baseColor.rgb = mix(texture(sFramebuffer, screenPos + distort*anim_timer + anim_timer*0.1*fragNormal .xy).rgb,baseColor.rgb,clamp(cloak_interp+anim_timer*2.0,0.0,1.0));
415+ baseColor.rgb = mix(texture(sFramebuffer, screenPos + distort*anim_timer + anim_timer*0.1*vertIn.normal .xy).rgb,baseColor.rgb,clamp(cloak_interp+anim_timer*2.0,0.0,1.0));
406416 #endif
407417 }
408418#endif
@@ -416,7 +426,7 @@ void main()
416426#endif
417427 fragOut0 = baseColor;
418428#ifdef FLAG_DEFERRED
419- fragOut1 = vec4(fragPosition .xyz, 1.0);
429+ fragOut1 = vec4(vertIn.position .xyz, 1.0);
420430 fragOut2 = vec4(normal, glossData);
421431 fragOut3 = vec4(specColor.rgb, fresnelFactor);
422432 fragOut4 = emissiveColor;
0 commit comments