Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

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
in vec3 _lightDirection[MAX_LIGHT_COUNT];
smooth in float _attenuation[MAX_LIGHT_COUNT];
in vec3 _viewDirection;

#define LIGHT_DIRECTIONAL		0
#define LIGHT_OMNIDIRECTIONAL	1
#define LIGHT_SPOT				2

struct MaterialProperties {
	vec4 ambient;
	vec4 diffuse;
	vec4 specular;
	float shadowFactor;
};

uniform bool dvd_lightCastsShadows[MAX_LIGHT_COUNT];
uniform bool dvd_lightEnabled[MAX_LIGHT_COUNT];
uniform int  dvd_lightType[MAX_LIGHT_COUNT];
uniform int  dvd_lightCount;
uniform vec4 dvd_lightAmbient;

//Specular and opacity maps are available even for non-textured geometry
#if defined(USE_OPACITY_MAP)
//Opacity and specular maps
uniform sampler2D texOpacityMap;
#endif
#if defined(USE_SPECULAR_MAP)
uniform sampler2D texSpecularMap;
#endif

#include "phong_point_light.frag"
#include "phong_spot_light.frag"
#include "phong_directional_light.frag"
#include "shadowMapping.frag"

void applyLight(const in int light, 
				const in int lightType, 
				const in bool lightCastsShadows,
				const in vec2 texCoord, 
				const in vec3 normal, 
				const in vec3 viewDirection,
				inout MaterialProperties materialProp)
{

#if defined(USE_SPECULAR_MAP)
	vec4 specularValue = texture(texSpecularMap, texCoord)
#else
	vec4 specularValue = material[2];
#endif
	
	vec3 L = normalize(_lightDirection[light]);
	vec3 R = normalize(-reflect(L,normal));
	//Specular intensity based on material shininess
	float iSpecular = clamp(pow(max(dot(R, viewDirection), 0.0), material[3].x ), 0.0, 1.0);
	float NdotL = max(dot(normal, L), 0.0);

	if(lightType == LIGHT_DIRECTIONAL){
		phong_directionalLight(light, iSpecular, NdotL, specularValue, materialProp);

		if(light >= MAX_SHADOW_CASTING_LIGHTS) return;
		if(lightCastsShadows) applyShadowDirectional(NdotL, light, materialProp.shadowFactor); 

	}else if(lightType == LIGHT_OMNIDIRECTIONAL){
		phong_pointLight(light, iSpecular, NdotL, specularValue, materialProp);

		if(light >= MAX_SHADOW_CASTING_LIGHTS) return;
		if(lightCastsShadows) applyShadowPoint(light, materialProp.shadowFactor); 

    }else{//if(lightType == LIGHT_SPOT)
		phong_spotLight(light, iSpecular, NdotL, specularValue, materialProp);

		if(light >= MAX_SHADOW_CASTING_LIGHTS) return;
		if(lightCastsShadows) applyShadowSpot(light, materialProp.shadowFactor); 
	}
}

void phong_loop(in vec2 texCoord, in vec3 normal, inout MaterialProperties materialProp){
	vec3 viewDirection = normalize(_viewDirection);
	if(dvd_lightCount == 0) 
		return;
	if(dvd_lightEnabled[0]) applyLight(0, dvd_lightType[0], dvd_lightCastsShadows[0], texCoord, normal, viewDirection, materialProp);
#if MAX_LIGHT_COUNT >= 2
	if(dvd_lightCount == 1)
		return;
	if(dvd_lightEnabled[1]) applyLight(1, dvd_lightType[1], dvd_lightCastsShadows[1], texCoord, normal, viewDirection, materialProp);
#endif
#if MAX_LIGHT_COUNT >= 3
	if(dvd_lightCount == 2) 
		return;
	if(dvd_lightEnabled[2]) applyLight(2, dvd_lightType[2], dvd_lightCastsShadows[2], texCoord, normal, viewDirection, materialProp);
#endif
#if MAX_LIGHT_COUNT >= 4
	if(dvd_lightCount == 3) 
		return;
	if(dvd_lightEnabled[3]) applyLight(3, dvd_lightType[3], dvd_lightCastsShadows[3], texCoord, normal, viewDirection, materialProp);
#endif
#if MAX_LIGHT_COUNT >= 5
	if(dvd_lightCount == 4) 
		return;
	if(dvd_lightEnabled[4]) applyLight(4, dvd_lightType[4], dvd_lightCastsShadows[4], texCoord, normal, viewDirection, materialProp);
#endif
#if MAX_LIGHT_COUNT >= 6
	if(dvd_lightCount == 5) 
		return;
	if(dvd_lightEnabled[5]) applyLight(5, dvd_lightType[5], dvd_lightCastsShadows[5], texCoord, normal, viewDirection, materialProp);
#endif
#if MAX_LIGHT_COUNT >= 7
	if(dvd_lightCount == 6) 
		return;
	if(dvd_lightEnabled[6]) applyLight(6, dvd_lightType[6], dvd_lightCastsShadows[6], texCoord, normal, viewDirection, materialProp);
#endif
#if MAX_LIGHT_COUNT == 8
	if(dvd_lightCount == 7) 
		return;
	if(dvd_lightEnabled[7]) applyLight(7, dvd_lightType[7], dvd_lightCastsShadows[7], texCoord, normal, viewDirection, materialProp);
#endif
#if MAX_LIGHT_COUNT > 8
	///Apply the rest of the lights
	for(int i = 8; i =< MAX_LIGHT_COUNT; i++){
		if(dvd_lightCount == i)
			return;
		if(dvd_lightEnabled[i]) applyLight(i, dvd_lightType[i], dvd_lightCastsShadows[i], texCoord, normal, viewDirection, materialProp);
	}
#endif
}

Commits for Divide-Framework/trunk/assets/shaders/GLSL/fragmentAtoms/phong_light_loop.frag

Diff revisions: vs.
Revision Author Commited Message
168 Diff Diff k1ngp1n picture k1ngp1n Sat 26 Oct, 2013 19:03:21 +0000

- Reworked the Camera class[[BR]]
— Now fully quaternion based [[BR]]
— Basic camera types added but not used yet (third person, first person, orbit) [[BR]]
- Cleaned up Material and Texture handling [[BR]]
- Added clipping plane support [[BR]]
— Similar to OpenGL fixed-function clip planes but fully shader driven [[BR]]
— Added a new class, “Plane”, that helps define clip planes [[BR]]
- Optimized the Singleton class to allow faster “getInstance” calls without performance penalties [[BR]]
-- “createInstance” must be called for each singleton class before usage. Or “gerOrCreateInstance” can be used, which is basically the former “getInstance” implementation [[BR]]
- Improved console logging by changing some heap allocations to stack and removing dependencies on the std::string class [[BR]]
- Added a lot of performance optimizations related to coding standards and redundant calculations [[BR]]
— e.g. Frustum AABB check didn’t need to recompute the AABB points as they were calculated already [[BR]]
— e.g. A vector did not need to be set to 0 on initialization as that is already it’s default state on creation [[BR]]
— e.g. Faster Framerate and Timing calculations by using less member variables that are not needed outsied of calling functions [[BR]]
- The SceneState now contains the SceneRenderState and is passed on to the SceneGraph’s update calls [[BR]]
- Better material export/import to/from XML format [[BR]]
- More bug fixes and cleanups [[BR]]

154 Diff Diff k1ngp1n picture k1ngp1n Sun 23 Jun, 2013 23:39:07 +0000

[Ionut] [[BR]]
- Changed math computation for: Matrix multiplication, Normal and Tangent calculation, Quaternion to Matrix conversion and more [[BR]]
- Removed useless UBO classes and extended the functionality of the base UBO class [[BR]]
- Changed lighting shaders to be more streamlined [[BR]]
- Added full shader based fog [[BR]]
— Added per-scene optional fog settings [[BR]]
- Re-enabled sorting by shader program for Mesh Delegate Bin (was set to Front to Back for debugging purposes and forgotten there) [[BR]]

152 Diff Diff k1ngp1n picture k1ngp1n Thu 20 Jun, 2013 14:23:31 +0000

[Ionut] [[BR]]
- New rendering pipeline (experimental and unstable): [[BR]]
— OpenGL 3.x clean context (glLight commands are still used for now, but UBO support is there, but not used yet) [[BR]]
— Custom matrix stacks and UBO based shader data (UBOs cause some link errors on some nVidia cards)[[BR]]
— Multi-threaded texture loading and shader compilation (mt shader compilation disabled for now. needs more tests) [[BR]]
— VAO rendering is self contained (no more enable/disable calls before a draw request) [[BR]]
— Render instance class used for rendering information [[BR]]
[[BR]]
- New unique ID generation base class: GUIDWrapper. Each class that derives from this, gets an application wide unique id on construction [[BR]]
- Added base code for an in-game editor using CEGUI [[BR]]
- Replaced some mutex locks with lockless data structures or atomic data [[BR]]
- CEGUI 0.8.2, FTGL-GL3 and GLIM 0.4 modified to support GLEW_MX if defined [[BR]]
- Dropped VS2008 support [[BR]]
- Networking library, server framework and ReCast files are now projects inside the Divide Framework solution [[BR]]
- New console command “setFov” that modifies the horizontal FoV value in realtime [[BR]]
- New console command “recompileShader” that reparses shader files, recompiles shaders and relinks shader programs who’s names match or contain the argument string [[BR]]
- New debug utility: axis angle drawn in corner of the screen if needed [[BR]]
- More ‘const’-s pasted around the code, more loop performance tweaks (allocations before a loop, tighter loops, etc), more utility member functions added to various classes [[BR]]

146 k1ngp1n picture k1ngp1n Wed 10 Apr, 2013 13:20:15 +0000

[Ionut] [[BR]]
*Final LightBranch updates 2/3 : Main trunk merge and build test (VC90, VC100, gDebugger) [[BR]]
-Merged light branch with trunk [[BR]]
-Deleted light branch [[BR]]