Shader buildings multiple roof types
Shader buildings now support different roof types - flat - gabled - hipped - pyramidal Primarily for osm2city use.
This commit is contained in:
parent
ce80930dc9
commit
564e7b31fd
8 changed files with 85 additions and 87 deletions
|
@ -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)
|
||||
|
|
|
@ -223,6 +223,10 @@
|
|||
<name>rtex0xRtex0y</name>
|
||||
<index>14</index>
|
||||
</attribute>
|
||||
<attribute>
|
||||
<name>rooftopscale</name>
|
||||
<index>15</index>
|
||||
</attribute>
|
||||
</program>
|
||||
</pass>
|
||||
</technique>
|
||||
|
@ -313,6 +317,10 @@
|
|||
<name>rtex0xRtex0y</name>
|
||||
<index>14</index>
|
||||
</attribute>
|
||||
<attribute>
|
||||
<name>rooftopscale</name>
|
||||
<index>15</index>
|
||||
</attribute>
|
||||
</program>
|
||||
<uniform>
|
||||
<name>texture</name>
|
||||
|
@ -392,6 +400,10 @@
|
|||
<name>rtex0xRtex0y</name>
|
||||
<index>14</index>
|
||||
</attribute>
|
||||
<attribute>
|
||||
<name>rooftopscale</name>
|
||||
<index>15</index>
|
||||
</attribute>
|
||||
</program>
|
||||
<uniform>
|
||||
<name>visibility</name>
|
||||
|
@ -525,6 +537,10 @@
|
|||
<attribute>
|
||||
<name>rtex0xRtex0y</name>
|
||||
<index>14</index>
|
||||
</attribute>
|
||||
<attribute>
|
||||
<name>rooftopscale</name>
|
||||
<index>15</index>
|
||||
</attribute>
|
||||
</program>
|
||||
</pass>
|
||||
|
@ -585,6 +601,10 @@
|
|||
<attribute>
|
||||
<name>rtex0xRtex0y</name>
|
||||
<index>14</index>
|
||||
</attribute>
|
||||
<attribute>
|
||||
<name>rooftopscale</name>
|
||||
<index>15</index>
|
||||
</attribute>
|
||||
</program>
|
||||
</pass>
|
||||
|
@ -703,6 +723,10 @@
|
|||
<attribute>
|
||||
<name>rtex0xRtex0y</name>
|
||||
<index>14</index>
|
||||
</attribute>
|
||||
<attribute>
|
||||
<name>rooftopscale</name>
|
||||
<index>15</index>
|
||||
</attribute>
|
||||
</program>
|
||||
<!-- BEGIN fog include -->
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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)));
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue