This file is indexed.

/usr/share/oolite/Shaders/oolite-default-planet.fragment is in oolite-data 1.77.1-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/*
	oolite-default-planet.fragment
	Default fragment shader for Oolite NEW_PLANETS.
	
	
	© 2009–2013 Jens Ayton
	
	Permission is hereby granted, free of charge, to any person obtaining a copy
	of this software and associated documentation files (the "Software"), to deal
	in the Software without restriction, including without limitation the rights
	to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
	copies of the Software, and to permit persons to whom the Software is
	furnished to do so, subject to the following conditions:
	
	The above copyright notice and this permission notice shall be included in all
	copies or substantial portions of the Software.
	
	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
	SOFTWARE.
*/

#ifndef IS_OOLITE
#define IS_OOLITE 0
#endif

#if IS_OOLITE
#define SPECULAR_LIGHT		(gl_LightSource[1].specular.rgb)
#define DIFFUSE_LIGHT		(gl_LightSource[1].diffuse.rgb)
#define AMBIENT_LIGHT		(gl_LightModel.ambient.rgb)
#else
#define OO_REDUCED_COMPLEXITY				0
#define SPECULAR_LIGHT 						vec3(0.8)
#define DIFFUSE_LIGHT 						vec3(0.8)
#define AMBIENT_LIGHT						vec3(0.2)
#define OOSTD_ILLUMINATION_MAP				1
#define OOSTD_NORMAL_MAP					1
#define OOSTD_SPECULAR_MAP					1
#endif


#ifndef OO_REDUCED_COMPLEXITY
#define OO_REDUCED_COMPLEXITY 0
#endif
#ifndef OOSTD_ILLUMINATION_MAP
#define OOSTD_ILLUMINATION_MAP 0
#endif
#ifndef OOSTD_DIFFUSE_AND_ILLUMINATION_MAP
#define OOSTD_DIFFUSE_AND_ILLUMINATION_MAP 0
#endif
#ifndef OOSTD_NORMAL_MAP
#define OOSTD_NORMAL_MAP 0
#endif
#ifndef OOSTD_SPECULAR_MAP
#define OOSTD_SPECULAR_MAP 0
#endif
#ifndef OOSTD_NORMAL_AND_SPECULAR_MAP
#define OOSTD_NORMAL_AND_SPECULAR_MAP 0
#endif
#ifndef OOSTD_HARSH_MISTRESS
#define OOSTD_HARSH_MISTRESS 0
#endif


// Illumination map parameters.
#define USE_ILLUMINATION OOSTD_ILLUMINATION_MAP || OOSTD_DIFFUSE_AND_ILLUMINATION_MAP
#if OOSTD_ILLUMINATION_MAP
uniform sampler2D		uIlluminationMap;
#define ILLUMINATION_COLOR texture2D(uIlluminationMap, texCoords).rgb
#elif OOSTD_DIFFUSE_AND_ILLUMINATION_MAP
#define ILLUMINATION_COLOR (diffuseMapSample.a * vec3(0.8, 0.8, 0.4))
#endif


// Specular map parameters.
// Separate OOSTD_SPECULAR_MAP is for testing in OpenGL Shader Builder, which doesn’t deal with alpha channels sensibly.
#define USE_SPECULAR OOSTD_SPECULAR_MAP || OOSTD_NORMAL_AND_SPECULAR_MAP
#if (OOSTD_SPECULAR_MAP)
uniform sampler2D		uSpecularMap;
#define SPECULAR_FACTOR (texture2D(uSpecularMap, texCoords).r)
#elif OOSTD_NORMAL_AND_SPECULAR_MAP
#define SPECULAR_FACTOR (normalMapSample.a)
#endif


// Normal map parameters.
#define USE_NORMAL_MAP OOSTD_NORMAL_MAP || OOSTD_NORMAL_AND_SPECULAR_MAP
#if USE_NORMAL_MAP
uniform sampler2D		uNormalMap;
#endif

/*	"Harsh shadow factor": degree to which normal map affects global diffuse light
	with terminator and full shadow, as opposed to "local light" which is a normal
	Lambertian light.
	
	Terminator threshold: defines the width and colour of the terminator. The
	numbers are cosines of the angle where it transitions to full light.
	
	Both of these factors are ignored in simple shader mode.
*/
#if OOSTD_HARSH_MISTRESS
const float 			kHarshShadowFactor	= 0.3;
const vec3				kTerminatorThreshold = vec3(0.08);
#else
const float 			kHarshShadowFactor	= 0.05;
const vec3				kTerminatorThreshold = vec3(0.1, 0.105, 0.12);
#endif


// Texture coordinate calcuation.
#if OO_REDUCED_COMPLEXITY
#define TEXTURE_COORDS vTexCoords
#else
#define TEXTURE_COORDS vec2(TexLongitude(coords.x, coords.z), vTexCoords.t)
#endif



uniform sampler2D		uDiffuseMap;

// No vNormal, because normal is always 0,0,1 in tangent space.
varying vec3			vEyeVector;
varying vec2			vTexCoords;
varying vec3			vLight1Vector;
varying vec3			vCoords;


vec3 CalcDiffuseIntensity(in vec3 lightVector, in vec3 normal)
{
	float LdotN = lightVector.z;
	
#if USE_NORMAL_MAP
	float globalTerm = dot(normalize(mix(vec3(0.0, 0.0, 1.0), normal, kHarshShadowFactor)), lightVector);
#else
	float globalTerm = LdotN;
#endif
	
#if OO_REDUCED_COMPLEXITY
	// Hardish terminator.
	float rev = min(1.0 - globalTerm, 1.0);
	rev *= rev;
	vec3 baseLight = vec3(1.0 - (rev * rev));
#else
	// Hard terminator with slight redish-orange tinge. Note: threshold values are cosines.
	vec3 baseLight = smoothstep(vec3(0.0), kTerminatorThreshold, vec3(globalTerm));
#endif
	
#if USE_NORMAL_MAP
	// Modulate with normal-mapped "local" illumination.
	float local = dot(lightVector, normal);
	local -= LdotN;
	
	baseLight *= local + 1.0;
#endif
	
	return baseLight;
}


vec3 CalcSpecularLight(in vec3 lightVector, in vec3 eyeVector, in float exponent, in vec3 normal, in vec3 lightColor)
{
#if USE_NORMAL_MAP
	vec3 reflection = -reflect(lightVector, normal);
	float NdotE = dot(normal, eyeVector);
#else
	/*	reflect(I, N) is defined as I - 2 * dot(N, I) * N
		If N is (0,0,1), this becomes (I.x,I.y,-I.z).
		Note that we want it negated as per above.
	*/
	vec3 reflection = vec3(-lightVector.x, -lightVector.y, lightVector.z);
	float NdotE = eyeVector.z;
#endif
	
	float RdotE = max(dot(reflection, eyeVector), 0.0);
	float intensity = pow(max(RdotE, 0.0), exponent);
	
	// Approximate Fresnel term.
	float kRefract = 1.0/1.33;	// Index of refraction of water.
	float F0 = ((kRefract - 1.0) * (kRefract - 1.0)) / ((kRefract + 1.0) * (kRefract + 1.0));
	float Fa = F0 + pow((1.0 - NdotE), 4.0) * (1.0 - F0);
	intensity *= 0.4 + Fa;
	
	return lightColor * intensity;
}


#if !OO_REDUCED_COMPLEXITY
/*	Approximation of atan(y/z) with quadrant rectification, scaled to -0.5..0.5 instead of -pi..pi.
	It is assumed that the values are in range. You are not expected to understand this.
*/
float TexLongitude(float z, float y)
{
	const float	k2Pi = 6.283185307179586;
	const float	kMagic = 0.2732395447351;	// (4 - pi) / pi
	
	float ratio = z / y;
	
	float r1 = 1.0 / ((ratio + kMagic / ratio) * k2Pi);	// Result when abs(z) >= abs(x).
	float r2 = 0.25 * sign(ratio) - ratio / ((1.0 + kMagic * ratio * ratio) * k2Pi);  // Result when abs(z) <= abs(x).
	
	float result = (abs(ratio) > 1.0) ? r1 : r2;
	
	// Adjust for sector.
	// Equivalent to (z < 0.0) ? ((y > 0.0) ? 0.75 : -0.25) : 0.25.
	// Well, technically not equivalent for z < 0, y = 0, but you'll very rarely see that exact case.
	return result + step(z, 0.0) * sign(y) * 0.5 + 0.25;
}
#endif


void main()
{
	vec3 totalColor = vec3(0);
	vec3 coords = normalize(vCoords);
	vec2 texCoords = TEXTURE_COORDS;
	
	/*	Fun sphere facts: the normalized coordinates of a point on a sphere at the origin
		is equal to the object-space normal of the surface at that point.
		Furthermore, we can construct the binormal (a vector pointing westward along the
		surface) as the cross product of the normal with the Y axis. (This produces
		singularities at the pole, but there have to be singularities according to the
		Hairy Ball Theorem.) The tangent (a vector north along the surface) is then the
		inverse of the cross product of the normal and binormal.
	*/
#if USE_NORMAL_MAP
	vec4 normalMapSample = texture2D(uNormalMap, texCoords);
	vec3 normal = normalize(normalMapSample.xyz - vec3(0.5));
#else
	vec3 normal = vec3(0, 0, 1);
#endif
	
	// Diffuse light
	vec3 light1Vector = normalize(vLight1Vector);
	vec3 diffuseIntensity = CalcDiffuseIntensity(light1Vector, normal);
	vec3 diffuseLight = diffuseIntensity * DIFFUSE_LIGHT;
	vec4 diffuseMapSample = texture2D(uDiffuseMap, texCoords);
	vec3 diffuseColor = diffuseMapSample.rgb;
	totalColor += diffuseColor * diffuseLight;
	
	// Ambient light, biased towards blue.
	vec3 ambientColor = diffuseColor;
#if !OO_REDUCED_COMPLEXITY && !OOSTD_HARSH_MISTRESS
	ambientColor *= vec3(0.8, 0.8, 1.0);
#endif
	totalColor += AMBIENT_LIGHT * ambientColor;
	
	// Specular light.
#if USE_SPECULAR
	float specularFactor = SPECULAR_FACTOR;
	vec3 specularLight = CalcSpecularLight(light1Vector, normalize(vEyeVector), 30.0 * specularFactor, normal, SPECULAR_LIGHT);
	totalColor += specularLight * 0.6 * specularFactor;
#endif
	
#if USE_ILLUMINATION
	vec3 illuminationColor = ILLUMINATION_COLOR;
	totalColor += (1.0 - diffuseIntensity.r) * illuminationColor;
#endif
	
	gl_FragColor = vec4(totalColor, 1.0);
}