• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1
2[VS]
3#include ":defaultVS"
4#include ":fogVS"
5
6[FS]
7#include ":defaultFS"
8
9[lights]
10// Declare all lighting uniforms
11#include ":ambient"
12#include ":pointLights"
13#include ":dirLights"
14
15[default]
16// Declare methods for the default lighting algorithm
17#include "common.glsl:separateAmbientFlag"
18#include ":ambient"
19
20	varying vec3 v_lightAmbient;
21	varying vec3 v_lightDiffuse;
22	varying vec3 v_lightSpecular;
23
24 	vec3 g_lightAmbient = vec3(0.0);
25	vec3 g_lightDiffuse = vec3(0.0);
26	vec3 g_lightSpecular = vec3(0.0);
27
28[defaultVS]
29#include ":default"
30
31#ifdef lightingFlag
32	#define passLightAmbient()	(v_lightAmbient = g_lightAmbient)
33	#define passLightDiffuse()	(v_lightDiffuse = g_lightDiffuse)
34	#define passLightSpecular()	(v_lightSpecular = g_lightSpecular)
35#else
36	#define passLightAmbient() nop()
37	#define passLightDiffuse() nop()
38	#define passLightSpecular()	nop()
39#endif
40	#define passLights() { passLightAmbient(); passLightDiffuse(); passLightSpecular(); }
41
42[defaultFS]
43#include ":default"
44
45#ifdef lightingFlag
46	#define pullLightAmbient()	(g_lightAmbient = v_lightAmbient)
47	#define pullLightDiffuse()	(g_lightDiffuse = v_lightDiffuse)
48	#define pullLightSpecular()	(g_lightSpecular = v_lightSpecular)
49#else
50	#define pullLightAmbient() nop()
51	#define pullLightDiffuse() nop()
52	#define pullLightSpecular()	nop()
53#endif
54	#define pullLights() { pullLightAmbient(); pullLightDiffuse(); pullLightSpecular(); }
55
56[fogVS]
57#include "common.glsl:nop"
58 	varying float v_fog;
59#ifdef fogFlag
60	float calculateFog(const in float distanceSq, const in float camW)	{
61		return min(distanceSq * camW, 1.0);
62	}
63	float calculateFog(const in vec3 distance, const in float camW) {
64		return calculateFog(dot(distance, distance), camW)
65	}
66	float calculateFog(const in vec4 position, const in vec4 camPos) {
67		return calculateFog(camPos.xyz - position.xyz, camPos.w)
68	}
69	#define passFog(val) (v_fog = val)
70#else
71	#define calculateFog(distanceSq, camW) (1.0)
72	#define passFog(val) nop()
73#endif
74	#define pushFog(val) (v_fog = val)
75
76[ambient]
77#include ":ambientLight"
78#include ":ambientCubemap"
79
80#if defined(ambientLightFlag) && defined(ambientCubemapFlag)
81	#define getAmbient(normal) (getAmbientLight() + getAmbientCubeLight(normal))
82#elif defined(ambientLightFlag)
83	#define getAmbient(normal) getAmbientLight()
84#elif defined(ambientCubemapFlag)
85	#define getAmbient(normal) getAmbientCubeLight(normal)
86#else
87	#define getAmbient(normal) (vec3(0.0))
88#endif
89
90[ambientLight]
91 //////////////////////////////////////////////////////
92 ////// AMBIENT LIGHT
93 //////////////////////////////////////////////////////
94#ifdef ambientLightFlag
95	#ifndef ambientFlag
96		#define ambientFlag
97	#endif
98 	uniform vec3 u_ambientLight;
99	#define getAmbientLight() (u_ambientLight)
100#else
101	#define getAmbientLight() (vec3(0.0))
102#endif
103
104
105[ambientCubemap]
106//////////////////////////////////////////////////////
107////// AMBIENT CUBEMAP
108//////////////////////////////////////////////////////
109#ifdef ambientCubemapFlag
110	#ifndef ambientFlag
111		#define ambientFlag
112	#endif
113 	uniform vec3 u_ambientCubemap[6];
114	vec3 getAmbientCubeLight(const in vec3 normal) {
115		vec3 squaredNormal = normal * normal;
116		vec3 isPositive  = step(0.0, normal);
117		return squaredNormal.x * mix(u_ambientCubemap[0], u_ambientCubemap[1], isPositive.x) +
118				squaredNormal.y * mix(u_ambientCubemap[2], u_ambientCubemap[3], isPositive.y) +
119				squaredNormal.z * mix(u_ambientCubemap[4], u_ambientCubemap[5], isPositive.z);
120	}
121#else
122	#define getAmbientCubeLight(normal) (vec3(0.0))
123#endif
124
125
126[dirLights]
127//////////////////////////////////////////////////////
128////// DIRECTIONAL LIGHTS
129//////////////////////////////////////////////////////
130#ifdef lightingFlag
131	#if defined(numDirectionalLights) && (numDirectionalLights > 0)
132		#define directionalLightsFlag
133	#endif // numDirectionalLights
134#endif //lightingFlag
135
136#ifdef directionalLightsFlag
137	struct DirectionalLight
138	{
139		vec3 color;
140		vec3 direction;
141	};
142	uniform DirectionalLight u_dirLights[numDirectionalLights];
143#endif
144
145[pointLights]
146//////////////////////////////////////////////////////
147////// POINTS LIGHTS
148//////////////////////////////////////////////////////
149#ifdef lightingFlag
150	#if defined(numPointLights) && (numPointLights > 0)
151		#define pointLightsFlag
152	#endif // numPointLights
153#endif //lightingFlag
154
155#ifdef pointLightsFlag
156	struct PointLight
157	{
158		vec3 color;
159		vec3 position;
160		float intensity;
161	};
162	uniform PointLight u_pointLights[numPointLights];
163#endif
164
165