2014-11-20 10:52:14 +00:00
|
|
|
|
|
|
|
// Base light calculations
|
|
|
|
|
2014-12-03 15:47:33 +00:00
|
|
|
#ifdef HAVE_LIGHT
|
2014-11-20 10:52:14 +00:00
|
|
|
uniform sampler2D lightTex;
|
2014-12-03 15:47:33 +00:00
|
|
|
#endif
|
2015-07-21 02:11:19 +00:00
|
|
|
uniform float cullMode; // 0 if backface culling is enabled, 1 if it is disabled
|
2014-11-20 10:52:14 +00:00
|
|
|
|
|
|
|
// uncomment the following lines for debugging light directions:
|
|
|
|
// yellow: light up, blue: light down, turqoise: light right, pink: light left
|
|
|
|
// brightness: light strength
|
2015-01-01 20:40:02 +00:00
|
|
|
//#define LIGHT_DEBUG
|
2014-11-20 10:52:14 +00:00
|
|
|
|
Colored lights
The color of object lights can now be changed. This includes the following changes:
- added light test scenario, based on DarkCastle, with some lights,
- new functions SetLightColor() and GetLightColor() with C4Script documentation,
- third drawing pass for rendering the light color, the drawing passes are now referenced by enum,
- the blending of light from multiple colored light sources works correctly with alpha blending,
- light color value affects the intensity of the light,
- alpha blending of the light depends on color value and lightness. This means that brighter (= more value) and lighter (= more whiteish) light will be preferred in blending over other lights,
- the object light color is rendered to the lower half of the fow light texture now,
- the shader accesses the brightness/direction information and color information correctly,
The patch was created from the following commits:
dab898a SetLightColor()
f57286e Color texture experiment
d0702f5 Dynamic color
fa14cdf Light test scenario
f99203d Alternate lights
474bade Bugfixes
3113698 Brightness handled better
516fb21 GetLightColor
1d91ec9 Improvements
3cfbf6c Documentation
95ec185 Improvements: Light Shader
a63bffc Scope of alpha
20c7ca0 Improvement: C4FoWLight
17d9123 Undo code style
d79411b Cleaner code
(cherry picked from commit 36dec610e36860b88417e91ce727250673bc2ec2)
Conflicts:
src/landscape/fow/C4FoWRegion.cpp, merged
2015-06-28 18:58:53 +00:00
|
|
|
// uncomment the following lines for debugging light color:
|
|
|
|
// the light will always come from the front and have a uniform brightness.
|
|
|
|
//#define LIGHT_DEBUG_COLOR
|
|
|
|
|
|
|
|
// uncomment the following lines to set the light color to pink for all lights for debugging:
|
|
|
|
//#define LIGHT_DEBUG_PINK
|
|
|
|
|
2014-11-23 19:01:21 +00:00
|
|
|
// At what point of light intensity we set the "darkness" point. This
|
2015-06-10 19:21:33 +00:00
|
|
|
// is to compensate for the fact that the engine "smoothes" the light
|
2014-11-23 19:01:21 +00:00
|
|
|
// and therefore will often never arrive at 0 light intensity.
|
|
|
|
const float lightDarknessLevel = 8.0 / 256.0;
|
|
|
|
|
2014-12-05 01:43:07 +00:00
|
|
|
slice(texture+5)
|
2014-11-20 10:52:14 +00:00
|
|
|
{
|
2014-12-03 15:47:33 +00:00
|
|
|
#ifdef HAVE_LIGHT
|
Colored lights
The color of object lights can now be changed. This includes the following changes:
- added light test scenario, based on DarkCastle, with some lights,
- new functions SetLightColor() and GetLightColor() with C4Script documentation,
- third drawing pass for rendering the light color, the drawing passes are now referenced by enum,
- the blending of light from multiple colored light sources works correctly with alpha blending,
- light color value affects the intensity of the light,
- alpha blending of the light depends on color value and lightness. This means that brighter (= more value) and lighter (= more whiteish) light will be preferred in blending over other lights,
- the object light color is rendered to the lower half of the fow light texture now,
- the shader accesses the brightness/direction information and color information correctly,
The patch was created from the following commits:
dab898a SetLightColor()
f57286e Color texture experiment
d0702f5 Dynamic color
fa14cdf Light test scenario
f99203d Alternate lights
474bade Bugfixes
3113698 Brightness handled better
516fb21 GetLightColor
1d91ec9 Improvements
3cfbf6c Documentation
95ec185 Improvements: Light Shader
a63bffc Scope of alpha
20c7ca0 Improvement: C4FoWLight
17d9123 Undo code style
d79411b Cleaner code
(cherry picked from commit 36dec610e36860b88417e91ce727250673bc2ec2)
Conflicts:
src/landscape/fow/C4FoWRegion.cpp, merged
2015-06-28 18:58:53 +00:00
|
|
|
|
2014-11-20 10:52:14 +00:00
|
|
|
// Query light texture
|
Colored lights
The color of object lights can now be changed. This includes the following changes:
- added light test scenario, based on DarkCastle, with some lights,
- new functions SetLightColor() and GetLightColor() with C4Script documentation,
- third drawing pass for rendering the light color, the drawing passes are now referenced by enum,
- the blending of light from multiple colored light sources works correctly with alpha blending,
- light color value affects the intensity of the light,
- alpha blending of the light depends on color value and lightness. This means that brighter (= more value) and lighter (= more whiteish) light will be preferred in blending over other lights,
- the object light color is rendered to the lower half of the fow light texture now,
- the shader accesses the brightness/direction information and color information correctly,
The patch was created from the following commits:
dab898a SetLightColor()
f57286e Color texture experiment
d0702f5 Dynamic color
fa14cdf Light test scenario
f99203d Alternate lights
474bade Bugfixes
3113698 Brightness handled better
516fb21 GetLightColor
1d91ec9 Improvements
3cfbf6c Documentation
95ec185 Improvements: Light Shader
a63bffc Scope of alpha
20c7ca0 Improvement: C4FoWLight
17d9123 Undo code style
d79411b Cleaner code
(cherry picked from commit 36dec610e36860b88417e91ce727250673bc2ec2)
Conflicts:
src/landscape/fow/C4FoWRegion.cpp, merged
2015-06-28 18:58:53 +00:00
|
|
|
vec2 lightDirCoord = lightCoord.st;
|
|
|
|
|
|
|
|
vec4 lightPx = texture2D(lightTex, lightDirCoord);
|
2015-06-10 19:21:33 +00:00
|
|
|
float lightBright = max(0.0, lightPx.a-lightDarknessLevel);
|
Colored lights
The color of object lights can now be changed. This includes the following changes:
- added light test scenario, based on DarkCastle, with some lights,
- new functions SetLightColor() and GetLightColor() with C4Script documentation,
- third drawing pass for rendering the light color, the drawing passes are now referenced by enum,
- the blending of light from multiple colored light sources works correctly with alpha blending,
- light color value affects the intensity of the light,
- alpha blending of the light depends on color value and lightness. This means that brighter (= more value) and lighter (= more whiteish) light will be preferred in blending over other lights,
- the object light color is rendered to the lower half of the fow light texture now,
- the shader accesses the brightness/direction information and color information correctly,
The patch was created from the following commits:
dab898a SetLightColor()
f57286e Color texture experiment
d0702f5 Dynamic color
fa14cdf Light test scenario
f99203d Alternate lights
474bade Bugfixes
3113698 Brightness handled better
516fb21 GetLightColor
1d91ec9 Improvements
3cfbf6c Documentation
95ec185 Improvements: Light Shader
a63bffc Scope of alpha
20c7ca0 Improvement: C4FoWLight
17d9123 Undo code style
d79411b Cleaner code
(cherry picked from commit 36dec610e36860b88417e91ce727250673bc2ec2)
Conflicts:
src/landscape/fow/C4FoWRegion.cpp, merged
2015-06-28 18:58:53 +00:00
|
|
|
vec3 lightDir = extend_normal(vec2(1.0, 1.0) - lightPx.yz * 3.0);
|
2015-06-10 19:21:33 +00:00
|
|
|
|
Colored lights
The color of object lights can now be changed. This includes the following changes:
- added light test scenario, based on DarkCastle, with some lights,
- new functions SetLightColor() and GetLightColor() with C4Script documentation,
- third drawing pass for rendering the light color, the drawing passes are now referenced by enum,
- the blending of light from multiple colored light sources works correctly with alpha blending,
- light color value affects the intensity of the light,
- alpha blending of the light depends on color value and lightness. This means that brighter (= more value) and lighter (= more whiteish) light will be preferred in blending over other lights,
- the object light color is rendered to the lower half of the fow light texture now,
- the shader accesses the brightness/direction information and color information correctly,
The patch was created from the following commits:
dab898a SetLightColor()
f57286e Color texture experiment
d0702f5 Dynamic color
fa14cdf Light test scenario
f99203d Alternate lights
474bade Bugfixes
3113698 Brightness handled better
516fb21 GetLightColor
1d91ec9 Improvements
3cfbf6c Documentation
95ec185 Improvements: Light Shader
a63bffc Scope of alpha
20c7ca0 Improvement: C4FoWLight
17d9123 Undo code style
d79411b Cleaner code
(cherry picked from commit 36dec610e36860b88417e91ce727250673bc2ec2)
Conflicts:
src/landscape/fow/C4FoWRegion.cpp, merged
2015-06-28 18:58:53 +00:00
|
|
|
// Query light color texture (part of the light texture)
|
|
|
|
vec2 lightColorCoord = lightCoord.st - vec2(0.0, 0.5); // subtract offset for the color texture
|
2015-06-10 19:21:33 +00:00
|
|
|
|
Colored lights
The color of object lights can now be changed. This includes the following changes:
- added light test scenario, based on DarkCastle, with some lights,
- new functions SetLightColor() and GetLightColor() with C4Script documentation,
- third drawing pass for rendering the light color, the drawing passes are now referenced by enum,
- the blending of light from multiple colored light sources works correctly with alpha blending,
- light color value affects the intensity of the light,
- alpha blending of the light depends on color value and lightness. This means that brighter (= more value) and lighter (= more whiteish) light will be preferred in blending over other lights,
- the object light color is rendered to the lower half of the fow light texture now,
- the shader accesses the brightness/direction information and color information correctly,
The patch was created from the following commits:
dab898a SetLightColor()
f57286e Color texture experiment
d0702f5 Dynamic color
fa14cdf Light test scenario
f99203d Alternate lights
474bade Bugfixes
3113698 Brightness handled better
516fb21 GetLightColor
1d91ec9 Improvements
3cfbf6c Documentation
95ec185 Improvements: Light Shader
a63bffc Scope of alpha
20c7ca0 Improvement: C4FoWLight
17d9123 Undo code style
d79411b Cleaner code
(cherry picked from commit 36dec610e36860b88417e91ce727250673bc2ec2)
Conflicts:
src/landscape/fow/C4FoWRegion.cpp, merged
2015-06-28 18:58:53 +00:00
|
|
|
vec4 lightColor = texture2D(lightTex, lightColorCoord.st);
|
2015-06-10 19:21:33 +00:00
|
|
|
|
Colored lights
The color of object lights can now be changed. This includes the following changes:
- added light test scenario, based on DarkCastle, with some lights,
- new functions SetLightColor() and GetLightColor() with C4Script documentation,
- third drawing pass for rendering the light color, the drawing passes are now referenced by enum,
- the blending of light from multiple colored light sources works correctly with alpha blending,
- light color value affects the intensity of the light,
- alpha blending of the light depends on color value and lightness. This means that brighter (= more value) and lighter (= more whiteish) light will be preferred in blending over other lights,
- the object light color is rendered to the lower half of the fow light texture now,
- the shader accesses the brightness/direction information and color information correctly,
The patch was created from the following commits:
dab898a SetLightColor()
f57286e Color texture experiment
d0702f5 Dynamic color
fa14cdf Light test scenario
f99203d Alternate lights
474bade Bugfixes
3113698 Brightness handled better
516fb21 GetLightColor
1d91ec9 Improvements
3cfbf6c Documentation
95ec185 Improvements: Light Shader
a63bffc Scope of alpha
20c7ca0 Improvement: C4FoWLight
17d9123 Undo code style
d79411b Cleaner code
(cherry picked from commit 36dec610e36860b88417e91ce727250673bc2ec2)
Conflicts:
src/landscape/fow/C4FoWRegion.cpp, merged
2015-06-28 18:58:53 +00:00
|
|
|
#ifdef LIGHT_DEBUG_COLOR
|
|
|
|
lightBright = 0.5;
|
|
|
|
lightDir = vec3(0.0, 0.0, 1.0);
|
|
|
|
#endif
|
2014-12-03 15:47:33 +00:00
|
|
|
#else
|
2014-12-28 14:07:42 +00:00
|
|
|
// When lighting is disabled, put a light source coming from the camera.
|
|
|
|
// Note that in most cases this does not actually matter, since in the
|
|
|
|
// case with lighting disabled, ambient lighting takes fully over.
|
2014-12-03 15:47:33 +00:00
|
|
|
float lightBright = 0.5;
|
Colored lights
The color of object lights can now be changed. This includes the following changes:
- added light test scenario, based on DarkCastle, with some lights,
- new functions SetLightColor() and GetLightColor() with C4Script documentation,
- third drawing pass for rendering the light color, the drawing passes are now referenced by enum,
- the blending of light from multiple colored light sources works correctly with alpha blending,
- light color value affects the intensity of the light,
- alpha blending of the light depends on color value and lightness. This means that brighter (= more value) and lighter (= more whiteish) light will be preferred in blending over other lights,
- the object light color is rendered to the lower half of the fow light texture now,
- the shader accesses the brightness/direction information and color information correctly,
The patch was created from the following commits:
dab898a SetLightColor()
f57286e Color texture experiment
d0702f5 Dynamic color
fa14cdf Light test scenario
f99203d Alternate lights
474bade Bugfixes
3113698 Brightness handled better
516fb21 GetLightColor
1d91ec9 Improvements
3cfbf6c Documentation
95ec185 Improvements: Light Shader
a63bffc Scope of alpha
20c7ca0 Improvement: C4FoWLight
17d9123 Undo code style
d79411b Cleaner code
(cherry picked from commit 36dec610e36860b88417e91ce727250673bc2ec2)
Conflicts:
src/landscape/fow/C4FoWRegion.cpp, merged
2015-06-28 18:58:53 +00:00
|
|
|
vec3 lightDir = vec3(0.0, 0.0, 1.0);
|
|
|
|
|
|
|
|
vec4 lightColor = vec4(1.0, 1.0, 1.0, 1.0);
|
2014-12-03 15:47:33 +00:00
|
|
|
#endif
|
2014-11-20 10:52:14 +00:00
|
|
|
}
|
|
|
|
|
2014-12-05 01:43:07 +00:00
|
|
|
slice(light)
|
2014-11-20 10:52:14 +00:00
|
|
|
{
|
2015-08-04 02:43:07 +00:00
|
|
|
float light = 2.0 * lightBright * max(max(dot(normal, lightDir), 0.0), cullMode * max(dot(-normal, lightDir), 0.0));
|
2014-11-20 10:52:14 +00:00
|
|
|
#ifdef HAVE_2PX
|
2015-08-04 02:43:07 +00:00
|
|
|
float light2 = 2.0 * lightBright * max(max(dot(normal2, lightDir), 0.0), cullMode * max(dot(-normal2, lightDir), 0.0));
|
2014-11-20 10:52:14 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-12-05 01:43:07 +00:00
|
|
|
slice(color+5)
|
2014-11-20 10:52:14 +00:00
|
|
|
{
|
Colored lights
The color of object lights can now be changed. This includes the following changes:
- added light test scenario, based on DarkCastle, with some lights,
- new functions SetLightColor() and GetLightColor() with C4Script documentation,
- third drawing pass for rendering the light color, the drawing passes are now referenced by enum,
- the blending of light from multiple colored light sources works correctly with alpha blending,
- light color value affects the intensity of the light,
- alpha blending of the light depends on color value and lightness. This means that brighter (= more value) and lighter (= more whiteish) light will be preferred in blending over other lights,
- the object light color is rendered to the lower half of the fow light texture now,
- the shader accesses the brightness/direction information and color information correctly,
The patch was created from the following commits:
dab898a SetLightColor()
f57286e Color texture experiment
d0702f5 Dynamic color
fa14cdf Light test scenario
f99203d Alternate lights
474bade Bugfixes
3113698 Brightness handled better
516fb21 GetLightColor
1d91ec9 Improvements
3cfbf6c Documentation
95ec185 Improvements: Light Shader
a63bffc Scope of alpha
20c7ca0 Improvement: C4FoWLight
17d9123 Undo code style
d79411b Cleaner code
(cherry picked from commit 36dec610e36860b88417e91ce727250673bc2ec2)
Conflicts:
src/landscape/fow/C4FoWRegion.cpp, merged
2015-06-28 18:58:53 +00:00
|
|
|
// pink shade for debugging!
|
|
|
|
#ifdef LIGHT_DEBUG_PINK
|
|
|
|
lightColor = vec4(1.0, 0.0, 1.0, 1.0);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
lightColor.rgb = sqrt(3.0) * normalize(lightColor.rgb);
|
|
|
|
|
2014-11-20 10:52:14 +00:00
|
|
|
// Add light
|
2015-07-02 18:59:20 +00:00
|
|
|
color.rgb = light * color.rgb * lightColor.rgb;
|
2014-11-20 10:52:14 +00:00
|
|
|
#ifdef HAVE_2PX
|
2015-07-02 18:59:20 +00:00
|
|
|
color2.rgb = light2 * color2.rgb * lightColor.rgb;
|
2014-11-20 10:52:14 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-12-05 01:43:07 +00:00
|
|
|
slice(finish+5)
|
2014-11-20 10:52:14 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
#ifdef LIGHT_DEBUG
|
2015-01-01 20:01:30 +00:00
|
|
|
#ifdef HAVE_LIGHT
|
2014-11-20 10:52:14 +00:00
|
|
|
float lightYDir = lightPx.b - 1.0/3.0;
|
|
|
|
float lightXDir = lightPx.g - 1.0/3.0;
|
2015-06-10 19:21:33 +00:00
|
|
|
float lightStrength = lightPx.a;
|
2015-01-01 20:01:30 +00:00
|
|
|
color =
|
2014-11-20 10:52:14 +00:00
|
|
|
vec4(lightStrength * vec3(1.0-1.5*(max(0.0, lightYDir) + max(0.0,lightXDir)),
|
|
|
|
1.0-1.5*(max(0.0, lightYDir) + max(0.0,-lightXDir)),
|
|
|
|
1.0-1.5*max(0.0, -lightYDir)),
|
|
|
|
1.0);
|
2015-01-15 11:30:29 +00:00
|
|
|
#else
|
|
|
|
color = vec4(0.0, 0.0, 0.0, 0.0); // invisible
|
2014-11-20 10:52:14 +00:00
|
|
|
#endif
|
2015-01-01 20:01:30 +00:00
|
|
|
#endif
|
2014-11-20 10:52:14 +00:00
|
|
|
|
|
|
|
}
|