diff --git a/Docs/README.scenery b/Docs/README.scenery
index 4920648d3..77802cf1a 100644
--- a/Docs/README.scenery
+++ b/Docs/README.scenery
@@ -410,10 +410,10 @@ Where:
- D is the building depth in meters
- H is the building height in meters, excluding any pitched roof
- P is the pitch height in meters. 0 for a flat roof
-- S is the roof shape (currently unused - all roofs are flat or gabled depending on pitch height) :
+- S is the roof shape (only 0, 2, 4, 6 are implemented, others are approximated to those) :
0=flat 1=skillion 2=gabled 3=half-hipped 4=hipped 5=pyramidal 6=gambled
7=mansard 8=dome 9=onion 10=round 11=saltbox
-- O is the roof ridge orientation (currently unused, all roofs are assumed orthogonal) :
+- O is the roof ridge orientation :
0 = parallel to the front face of the building
1 = orthogonal to the front face of the building
- F is the number of floors (integer)
diff --git a/Effects/building.eff b/Effects/building.eff
index 849799be2..8b64001e3 100644
--- a/Effects/building.eff
+++ b/Effects/building.eff
@@ -223,6 +223,10 @@
rtex0xRtex0y
14
+
+ rooftopscale
+ 15
+
@@ -313,6 +317,10 @@
rtex0xRtex0y
14
+
+ rooftopscale
+ 15
+
texture
@@ -392,6 +400,10 @@
rtex0xRtex0y
14
+
+ rooftopscale
+ 15
+
visibility
@@ -525,6 +537,10 @@
rtex0xRtex0y
14
+
+
+ rooftopscale
+ 15
@@ -585,6 +601,10 @@
rtex0xRtex0y
14
+
+
+ rooftopscale
+ 15
@@ -703,6 +723,10 @@
rtex0xRtex0y
14
+
+
+ rooftopscale
+ 15
diff --git a/Shaders/building-ALS.vert b/Shaders/building-ALS.vert
index dc149c470..cd55ba1e9 100644
--- a/Shaders/building-ALS.vert
+++ b/Shaders/building-ALS.vert
@@ -21,6 +21,7 @@ attribute vec3 instanceScaleRotate; // (width, depth, height)
attribute vec3 rotPitchWtex0x; // (rotation, pitch height, texture x offset)
attribute vec3 wtex0yTex1xTex1y; // (wall texture y offset, wall/roof texture x gain, wall/roof texture y gain)
attribute vec3 rtex0xRtex0y; // (roof texture y offset, roof texture x gain, texture y gain)
+attribute vec3 rooftopscale; // (rooftop x scale, rooftop y scale)
// The constant term of the lighting equation that doesn't depend on
// the surface normal is passed in gl_{Front,Back}Color. The alpha
@@ -85,14 +86,16 @@ void main()
float sr = sin(6.28 * rotPitchWtex0x.x);
float cr = cos(6.28 * rotPitchWtex0x.x);
- // Adjust pitch of roof to the correct height.
- // The top roof vertices are the only ones that have fractional z values (1.5),
- // so we can use this to identify them and scale up any pitched roof vertex to
- // the correct pitch (rotPitchWtex0x.y * 2.0 because of the fractional z value),
- // then scale down by the building height (instanceScaleRotate.z) because
- // immediately afterwards we will scale UP the vertex to the correct scale.
vec3 position = gl_Vertex.xyz;
- position.z = position.z + fract(position.z) * 2.0 * rotPitchWtex0x.y / instanceScaleRotate.z - fract(position.z);
+ // Adjust the very top of the roof to match the rooftop scaling. This shapes
+ // the rooftop - gambled, gabled etc. These vertices are identified by gl_Color.z
+ position.x = (1.0 - gl_Color.z) * position.x + gl_Color.z * ((position.x + 0.5) * rooftopscale.x - 0.5);
+ position.y = (1.0 - gl_Color.z) * position.y + gl_Color.z * (position.y * rooftopscale.y);
+
+ // Adjust pitch of roof to the correct height. These vertices are identified by gl_Color.z
+ // Scale down by the building height (instanceScaleRotate.z) because
+ // immediately afterwards we will scale UP the vertex to the correct scale.
+ position.z = position.z + gl_Color.z * rotPitchWtex0x.y / instanceScaleRotate.z;
position = position * instanceScaleRotate.xyz;
// Rotation of the building and movement into position
@@ -115,15 +118,6 @@ void main()
// Rotate the normal.
normal = gl_Normal;
-
- // The roof pieces have a normal of (+/-0.7, 0.0, 0.7)
- // If the roof is flat, then we need to change it to (0,0,1).
- // First term evaluates for normals without a +z component (all except roof)
- // Second term evaluates for roof normals with a pitch
- // Third term evaluates for flat roofs
- normal = step(0.5, 1.0 - normal.z) * normal + step(0.5, normal.z) * clamp(rotPitchWtex0x.y, 0.0, 1.0) * normal + step(0.5, normal.z) * (1.0 - clamp(rotPitchWtex0x.y, 0.0, 1.0)) * vec3(0,0,1);
-
- // Rotate the normal as per the building.
normal.xy = vec2(dot(normal.xy, vec2(cr, sr)), dot(normal.xy, vec2(-sr, cr)));
normal = gl_NormalMatrix * normal;
diff --git a/Shaders/building-default.frag b/Shaders/building-default.frag
index 2e9c15345..c2306eed5 100644
--- a/Shaders/building-default.frag
+++ b/Shaders/building-default.frag
@@ -54,7 +54,7 @@ void main()
color = clamp(color, 0.0, 1.0);
texel = texture2D(texture, gl_TexCoord[0].st);
emissive = texture2D(lightmap, gl_TexCoord[0].st);
-
+
// The lights are only switched on when the sun is below the horizon
fragColor = color * texel + specular + smoothstep(1.6, 1.8, sunangle) * emissive;
fragColor.rgb = fog_Func(fragColor.rgb, fogType);
diff --git a/Shaders/building-default.vert b/Shaders/building-default.vert
index f67ca28f4..2cc44cb34 100644
--- a/Shaders/building-default.vert
+++ b/Shaders/building-default.vert
@@ -17,7 +17,8 @@ attribute vec3 instancePosition; // (x,y,z)
attribute vec3 instanceScaleRotate; // (width, depth, height)
attribute vec3 rotPitchWtex0x; // (rotation, pitch height, wall texture x offset)
attribute vec3 wtex0yTex1xTex1y; // (wall texture y offset, wall/roof texture x gain, wall/roof texture y gain)
-attribute vec3 rtex0xRtex0y; // (roof texture y offset, roof texture x gain, texture y gain)
+attribute vec3 rtex0xRtex0y; // (roof texture y offset, roof texture x gain, unused)
+attribute vec3 rooftopscale; // (rooftop x scale, rooftop y scale)
// The constant term of the lighting equation that doesn't depend on
// the surface normal is passed in gl_{Front,Back}Color. The alpha
@@ -40,14 +41,16 @@ void main()
float sr = sin(6.28 * rotPitchWtex0x.x);
float cr = cos(6.28 * rotPitchWtex0x.x);
- // Adjust pitch of roof to the correct height.
- // The top roof vertices are the only ones that have fractional z values (1.5),
- // so we can use this to identify them and scale up any pitched roof vertex to
- // the correct pitch (rotPitchWtex0x.y * 2.0 because of the fractional z value),
- // then scale down by the building height (instanceScaleRotate.z) because
- // immediately afterwards we will scale UP the vertex to the correct scale.
vec3 position = gl_Vertex.xyz;
- position.z = position.z + fract(position.z) * 2.0 * rotPitchWtex0x.y / instanceScaleRotate.z - fract(position.z);
+ // Adjust the very top of the roof to match the rooftop scaling. This shapes
+ // the rooftop - gambled, gabled etc. These vertices are identified by gl_Color.z
+ position.x = (1.0 - gl_Color.z) * position.x + gl_Color.z * ((position.x + 0.5) * rooftopscale.x - 0.5);
+ position.y = (1.0 - gl_Color.z) * position.y + gl_Color.z * (position.y * rooftopscale.y);
+
+ // Adjust pitch of roof to the correct height. These vertices are identified by gl_Color.z
+ // Scale down by the building height (instanceScaleRotate.z) because
+ // immediately afterwards we will scale UP the vertex to the correct scale.
+ position.z = position.z + gl_Color.z * rotPitchWtex0x.y / instanceScaleRotate.z;
position = position * instanceScaleRotate.xyz;
// Rotation of the building and movement into position
@@ -63,22 +66,17 @@ void main()
// The vertex color value selects between them, with glColor.x=1 indicating walls
// and glColor.y=1 indicating roofs.
// Finally, the roof texture is on the left of the texture sheet
- vec2 tex0 = vec2(sign(gl_MultiTexCoord0.x) * (gl_Color.x*rotPitchWtex0x.z + gl_Color.y*rtex0xRtex0y.x),
- gl_Color.x*wtex0yTex1xTex1y.x + gl_Color.y*rtex0xRtex0y.y);
+ float wtex0x = rotPitchWtex0x.z;
+ float wtex0y = wtex0yTex1xTex1y.x;
+ float rtex0x = rtex0xRtex0y.x;
+ float rtex0y = rtex0xRtex0y.y;
+ vec2 tex0 = vec2(sign(gl_MultiTexCoord0.x) * (gl_Color.x*wtex0x + gl_Color.y*rtex0x),
+ gl_Color.x*wtex0y + gl_Color.y*rtex0y);
gl_TexCoord[0].x = tex0.x + gl_MultiTexCoord0.x * wtex0yTex1xTex1y.y;
gl_TexCoord[0].y = tex0.y + gl_MultiTexCoord0.y * wtex0yTex1xTex1y.z;
// Rotate the normal.
normal = gl_Normal;
-
- // The roof pieces have a normal of (+/-0.7, 0.0, 0.7)
- // If the roof is flat, then we need to change it to (0,0,1).
- // First term evaluates for normals without a +z component (all except roof)
- // Second term evaluates for roof normals with a pitch
- // Third term evaluates for flat roofs
- normal = step(0.5, 1.0 - normal.z) * normal + step(0.5, normal.z) * clamp(rotPitchWtex0x.y, 0.0, 1.0) * normal + step(0.5, normal.z) * (1.0 - clamp(rotPitchWtex0x.y, 0.0, 1.0)) * vec3(0,0,1);
-
- // Rotate the normal as per the building.
normal.xy = vec2(dot(normal.xy, vec2(cr, sr)), dot(normal.xy, vec2(-sr, cr)));
normal = gl_NormalMatrix * normal;
diff --git a/Shaders/building-deferred-gbuffer.vert b/Shaders/building-deferred-gbuffer.vert
index 2ed8fb656..df6830f15 100644
--- a/Shaders/building-deferred-gbuffer.vert
+++ b/Shaders/building-deferred-gbuffer.vert
@@ -10,6 +10,7 @@ attribute vec3 instanceScaleRotate; // (width, depth, height)
attribute vec3 rotPitchWtex0x; // (rotation, pitch height, texture x offset)
attribute vec3 wtex0yTex1xTex1y; // (wall texture y offset, wall/roof texture x gain, wall/roof texture y gain)
attribute vec3 rtex0xRtex0y; // (roof texture y offset, roof texture x gain, texture y gain)
+attribute vec3 rooftopscale; // (rooftop x scale, rooftop y scale)
varying vec3 ecNormal;
varying float alpha;
@@ -19,14 +20,16 @@ void main() {
float sr = sin(6.28 * rotPitchWtex0x.x);
float cr = cos(6.28 * rotPitchWtex0x.x);
- // Adjust pitch of roof to the correct height.
- // The top roof vertices are the only ones that have fractional z values (1.5),
- // so we can use this to identify them and scale up any pitched roof vertex to
- // the correct pitch (rotPitchWtex0x.y * 2.0 because of the fractional z value),
- // then scale down by the building height (instanceScaleRotate.z) because
- // immediately afterwards we will scale UP the vertex to the correct scale.
vec3 position = gl_Vertex.xyz;
- position.z = position.z + fract(position.z) * 2.0 * rotPitchWtex0x.y / instanceScaleRotate.z - fract(position.z);
+ // Adjust the very top of the roof to match the rooftop scaling. This shapes
+ // the rooftop - gambled, gabled etc. These vertices are identified by gl_Color.z
+ position.x = (1.0 - gl_Color.z) * position.x + gl_Color.z * ((position.x + 0.5) * rooftopscale.x - 0.5);
+ position.y = (1.0 - gl_Color.z) * position.y + gl_Color.z * (position.y * rooftopscale.y);
+
+ // Adjust pitch of roof to the correct height. These vertices are identified by gl_Color.z
+ // Scale down by the building height (instanceScaleRotate.z) because
+ // immediately afterwards we will scale UP the vertex to the correct scale.
+ position.z = position.z + gl_Color.z * rotPitchWtex0x.y / instanceScaleRotate.z;
position = position * instanceScaleRotate.xyz;
// Rotation of the building and movement into position
@@ -49,17 +52,6 @@ void main() {
// Rotate the normal.
ecNormal = gl_Normal;
-
- // The roof pieces have a normal of (+/-0.7, 0.0, 0.7)
- // If the roof is flat, then we need to change it to (0,0,1).
- // First term evaluates for normals without a +z component (all except roof)
- // Second term evaluates for roof normals with a pitch
- // Third term evaluates for flat roofs
- ecNormal = step(0.5, 1.0 - ecNormal.z) * ecNormal +
- step(0.5, ecNormal.z) * clamp(rotPitchWtex0x.y, 0.0, 1.0) * ecNormal +
- step(0.5, ecNormal.z) * (1.0 - clamp(rotPitchWtex0x.y, 0.0, 1.0)) * vec3(0,0,1);
-
- // Rotate the normal as per the building.
ecNormal.xy = vec2(dot(ecNormal.xy, vec2(cr, sr)), dot(ecNormal.xy, vec2(-sr, cr)));
ecNormal = gl_NormalMatrix * ecNormal;
diff --git a/Shaders/building-model-ALS-ultra.vert b/Shaders/building-model-ALS-ultra.vert
index 43723a227..9e8f91e32 100644
--- a/Shaders/building-model-ALS-ultra.vert
+++ b/Shaders/building-model-ALS-ultra.vert
@@ -8,6 +8,7 @@ attribute vec3 instanceScaleRotate; // (width, depth, height)
attribute vec3 rotPitchWtex0x; // (rotation, pitch height, texture x offset)
attribute vec3 wtex0yTex1xTex1y; // (wall texture y offset, wall/roof texture x gain, wall/roof texture y gain)
attribute vec3 rtex0xRtex0y; // (roof texture y offset, roof texture x gain, texture y gain)
+attribute vec3 rooftopscale; // (rooftop x scale, rooftop y scale)
varying vec3 rawpos;
varying vec3 VNormal;
@@ -58,14 +59,17 @@ void main(void)
float sr = sin(6.28 * rotPitchWtex0x.x);
float cr = cos(6.28 * rotPitchWtex0x.x);
- // Adjust pitch of roof to the correct height.
- // The top roof vertices are the only ones that have fractional z values (1.5),
- // so we can use this to identify them and scale up any pitched roof vertex to
- // the correct pitch (rotPitchWtex0x.y * 2.0 because of the fractional z value),
- // then scale down by the building height (instanceScaleRotate.z) because
+
+ vec3 rawpos = gl_Vertex.xyz;
+ // Adjust the very top of the roof to match the rooftop scaling. This shapes
+ // the rooftop - gambled, gabled etc. These vertices are identified by gl_Color.z
+ rawpos.x = (1.0 - gl_Color.z) * rawpos.x + gl_Color.z * ((rawpos.x + 0.5) * rooftopscale.x - 0.5);
+ rawpos.y = (1.0 - gl_Color.z) * rawpos.y + gl_Color.z * (rawpos.y * rooftopscale.y);
+
+ // Adjust pitch of roof to the correct height. These vertices are identified by gl_Color.z
+ // Scale down by the building height (instanceScaleRotate.z) because
// immediately afterwards we will scale UP the vertex to the correct scale.
- rawpos = gl_Vertex.xyz;
- rawpos.z = rawpos.z + fract(rawpos.z) * 2.0 * rotPitchWtex0x.y / instanceScaleRotate.z - fract(rawpos.z);
+ rawpos.z = rawpos.z + gl_Color.z * rotPitchWtex0x.y / instanceScaleRotate.z;
rawpos = rawpos * instanceScaleRotate.xyz;
// Rotation of the building and movement into rawpos
@@ -87,16 +91,6 @@ void main(void)
// Rotate the normal.
vec3 normal = gl_Normal;
-
- // The roof pieces have a normal of (+/-0.7, 0.0, 0.7)
- // If the roof is flat, then we need to change it to (0,0,1).
- // First term evaluates for normals without a +z component (all except roof)
- // Second term evaluates for roof normals with a pitch
- // Third term evaluates for flat roofs
- normal = step(0.5, 1.0 - normal.z) * normal +
- step(0.5, normal.z) * clamp(rotPitchWtex0x.y, 0.0, 1.0) * normal +
- step(0.5, normal.z) * (1.0 - clamp(rotPitchWtex0x.y, 0.0, 1.0)) * vec3(0,0,1);
-
// Rotate the normal as per the building.
normal.xy = vec2(dot(normal.xy, vec2(cr, sr)), dot(normal.xy, vec2(-sr, cr)));
diff --git a/Shaders/building-ubershader.vert b/Shaders/building-ubershader.vert
index cf0a89229..33b712665 100644
--- a/Shaders/building-ubershader.vert
+++ b/Shaders/building-ubershader.vert
@@ -22,6 +22,7 @@ attribute vec3 instanceScaleRotate; // (width, depth, height)
attribute vec3 rotPitchWtex0x; // (rotation, pitch height, texture x offset)
attribute vec3 wtex0yTex1xTex1y; // (wall texture y offset, wall/roof texture x gain, wall/roof texture y gain)
attribute vec3 rtex0xRtex0y; // (roof texture y offset, roof texture x gain, texture y gain)
+attribute vec3 rooftopscale; // (rooftop x scale, rooftop y scale)
void main(void)
{
@@ -29,14 +30,16 @@ void main(void)
float sr = sin(6.28 * rotPitchWtex0x.x);
float cr = cos(6.28 * rotPitchWtex0x.x);
- // Adjust pitch of roof to the correct height.
- // The top roof vertices are the only ones that have fractional z values (1.5),
- // so we can use this to identify them and scale up any pitched roof vertex to
- // the correct pitch (rotPitchWtex0x.y * 2.0 because of the fractional z value),
- // then scale down by the building height (instanceScaleRotate.z) because
- // immediately afterwards we will scale UP the vertex to the correct scale.
vec3 position = gl_Vertex.xyz;
- position.z = position.z + fract(position.z) * 2.0 * rotPitchWtex0x.y / instanceScaleRotate.z - fract(position.z);
+ // Adjust the very top of the roof to match the rooftop scaling. This shapes
+ // the rooftop - gambled, gabled etc. These vertices are identified by gl_Color.z
+ position.x = (1.0 - gl_Color.z) * position.x + gl_Color.z * ((position.x + 0.5) * rooftopscale.x - 0.5);
+ position.y = (1.0 - gl_Color.z) * position.y + gl_Color.z * (position.y * rooftopscale.y);
+
+ // Adjust pitch of roof to the correct height. These vertices are identified by gl_Color.z
+ // Scale down by the building height (instanceScaleRotate.z) because
+ // immediately afterwards we will scale UP the vertex to the correct scale.
+ position.z = position.z + gl_Color.z * rotPitchWtex0x.y / instanceScaleRotate.z;
position = position * instanceScaleRotate.xyz;
// Rotation of the building and movement into position
@@ -51,13 +54,6 @@ void main(void)
// Rotate the normal.
normal = gl_Normal;
- // The roof pieces have a normal of (+/-0.7, 0.0, 0.7)
- // If the roof is flat, then we need to change it to (0,0,1).
- // First term evaluates for normals without a +z component (all except roof)
- // Second term evaluates for roof normals with a pitch
- // Third term evaluates for flat roofs
- normal = step(0.5, 1.0 - normal.z) * normal + step(0.5, normal.z) * clamp(rotPitchWtex0x.y, 0.0, 1.0) * normal + step(0.5, normal.z) * (1.0 - clamp(rotPitchWtex0x.y, 0.0, 1.0)) * vec3(0,0,1);
-
// Rotate the normal as per the building.
normal.xy = vec2(dot(normal.xy, vec2(cr, sr)), dot(normal.xy, vec2(-sr, cr)));
vec3 n = normalize(normal);