File: SMFVertProg.glsl

package info (click to toggle)
spring 88.0%2Bdfsg1-1.1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 41,524 kB
  • sloc: cpp: 343,114; ansic: 38,414; python: 12,257; java: 12,203; awk: 5,748; sh: 1,204; xml: 997; perl: 405; objc: 192; makefile: 181; php: 134; sed: 2
file content (57 lines) | stat: -rwxr-xr-x 1,988 bytes parent folder | download
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
#define SMF_TEXSQR_SIZE 1024.0
#define SMF_DETAILTEX_RES 0.02

// uniform vec2 mapSizePO2;   // pwr2map{x,z} * SQUARE_SIZE (TODO programmatically #define this)
// uniform vec2 mapSize;      //     map{x,z} * SQUARE_SIZE (TODO programmatically #define this)
// uniform vec2 mapHeights;   // readmap->curr{Min, Max}Height

uniform vec2 normalTexGen;   // either 1.0/mapSize (when NPOT are supported) or 1.0/mapSizePO2
uniform vec2 specularTexGen; // 1.0/mapSize
uniform ivec2 texSquare;

uniform vec4 splatTexScales; // defaults to SMF_DETAILTEX_RES per channel
uniform vec3 cameraPos;
uniform vec4 lightDir;       // mapInfo->light.sunDir


varying vec3 halfDir;
varying float fogFactor;
varying vec4 vertexWorldPos;
varying vec2 diffuseTexCoords;
varying vec2 specularTexCoords;
varying vec2 normalTexCoords;



void main() {
	// calc some lighting variables
	vec3 viewDir = vec3(gl_ModelViewMatrixInverse * vec4(0.0, 0.0, 0.0, 1.0));
	viewDir = normalize(viewDir - gl_Vertex.xyz);
	halfDir = normalize(lightDir.xyz + viewDir);
	vertexWorldPos = gl_Vertex;

	// calc texcoords
	diffuseTexCoords = (floor(gl_Vertex.xz) / SMF_TEXSQR_SIZE) - vec2(texSquare);
	specularTexCoords = gl_Vertex.xz * specularTexGen;
	normalTexCoords   = gl_Vertex.xz * normalTexGen;

	// detail-tex coords
	#if (SMF_DETAIL_TEXTURE_SPLATTING == 0)
		gl_TexCoord[0].st  = gl_Vertex.xz * vec2(SMF_DETAILTEX_RES);
	#else
		gl_TexCoord[0].st  = gl_Vertex.xz * vec2(splatTexScales.r);
		gl_TexCoord[0].pq  = gl_Vertex.xz * vec2(splatTexScales.g);
		gl_TexCoord[1].st  = gl_Vertex.xz * vec2(splatTexScales.b);
		gl_TexCoord[1].pq  = gl_Vertex.xz * vec2(splatTexScales.a);
	#endif

	// transform vertex pos
	gl_Position = gl_ModelViewMatrix * gl_Vertex;
	float fogCoord = length(gl_Position.xyz);
	gl_Position = gl_ProjectionMatrix * gl_Position;

	// emulate linear fog
	fogFactor = (gl_Fog.end - fogCoord) * gl_Fog.scale; // gl_Fog.scale == 1.0 / (gl_Fog.end - gl_Fog.start)
	fogFactor = clamp(fogFactor, 0.0, 1.0);
}