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
|
- D is the building depth in meters
|
||||||
- H is the building height in meters, excluding any pitched roof
|
- H is the building height in meters, excluding any pitched roof
|
||||||
- P is the pitch height in meters. 0 for a flat 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
|
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
|
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
|
0 = parallel to the front face of the building
|
||||||
1 = orthogonal to the front face of the building
|
1 = orthogonal to the front face of the building
|
||||||
- F is the number of floors (integer)
|
- F is the number of floors (integer)
|
||||||
|
|
|
@ -223,6 +223,10 @@
|
||||||
<name>rtex0xRtex0y</name>
|
<name>rtex0xRtex0y</name>
|
||||||
<index>14</index>
|
<index>14</index>
|
||||||
</attribute>
|
</attribute>
|
||||||
|
<attribute>
|
||||||
|
<name>rooftopscale</name>
|
||||||
|
<index>15</index>
|
||||||
|
</attribute>
|
||||||
</program>
|
</program>
|
||||||
</pass>
|
</pass>
|
||||||
</technique>
|
</technique>
|
||||||
|
@ -313,6 +317,10 @@
|
||||||
<name>rtex0xRtex0y</name>
|
<name>rtex0xRtex0y</name>
|
||||||
<index>14</index>
|
<index>14</index>
|
||||||
</attribute>
|
</attribute>
|
||||||
|
<attribute>
|
||||||
|
<name>rooftopscale</name>
|
||||||
|
<index>15</index>
|
||||||
|
</attribute>
|
||||||
</program>
|
</program>
|
||||||
<uniform>
|
<uniform>
|
||||||
<name>texture</name>
|
<name>texture</name>
|
||||||
|
@ -392,6 +400,10 @@
|
||||||
<name>rtex0xRtex0y</name>
|
<name>rtex0xRtex0y</name>
|
||||||
<index>14</index>
|
<index>14</index>
|
||||||
</attribute>
|
</attribute>
|
||||||
|
<attribute>
|
||||||
|
<name>rooftopscale</name>
|
||||||
|
<index>15</index>
|
||||||
|
</attribute>
|
||||||
</program>
|
</program>
|
||||||
<uniform>
|
<uniform>
|
||||||
<name>visibility</name>
|
<name>visibility</name>
|
||||||
|
@ -525,6 +537,10 @@
|
||||||
<attribute>
|
<attribute>
|
||||||
<name>rtex0xRtex0y</name>
|
<name>rtex0xRtex0y</name>
|
||||||
<index>14</index>
|
<index>14</index>
|
||||||
|
</attribute>
|
||||||
|
<attribute>
|
||||||
|
<name>rooftopscale</name>
|
||||||
|
<index>15</index>
|
||||||
</attribute>
|
</attribute>
|
||||||
</program>
|
</program>
|
||||||
</pass>
|
</pass>
|
||||||
|
@ -585,6 +601,10 @@
|
||||||
<attribute>
|
<attribute>
|
||||||
<name>rtex0xRtex0y</name>
|
<name>rtex0xRtex0y</name>
|
||||||
<index>14</index>
|
<index>14</index>
|
||||||
|
</attribute>
|
||||||
|
<attribute>
|
||||||
|
<name>rooftopscale</name>
|
||||||
|
<index>15</index>
|
||||||
</attribute>
|
</attribute>
|
||||||
</program>
|
</program>
|
||||||
</pass>
|
</pass>
|
||||||
|
@ -703,6 +723,10 @@
|
||||||
<attribute>
|
<attribute>
|
||||||
<name>rtex0xRtex0y</name>
|
<name>rtex0xRtex0y</name>
|
||||||
<index>14</index>
|
<index>14</index>
|
||||||
|
</attribute>
|
||||||
|
<attribute>
|
||||||
|
<name>rooftopscale</name>
|
||||||
|
<index>15</index>
|
||||||
</attribute>
|
</attribute>
|
||||||
</program>
|
</program>
|
||||||
<!-- BEGIN fog include -->
|
<!-- BEGIN fog include -->
|
||||||
|
|
|
@ -21,6 +21,7 @@ attribute vec3 instanceScaleRotate; // (width, depth, height)
|
||||||
attribute vec3 rotPitchWtex0x; // (rotation, pitch height, texture x offset)
|
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 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, 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 constant term of the lighting equation that doesn't depend on
|
||||||
// the surface normal is passed in gl_{Front,Back}Color. The alpha
|
// 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 sr = sin(6.28 * rotPitchWtex0x.x);
|
||||||
float cr = cos(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;
|
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;
|
position = position * instanceScaleRotate.xyz;
|
||||||
|
|
||||||
// Rotation of the building and movement into position
|
// Rotation of the building and movement into position
|
||||||
|
@ -115,15 +118,6 @@ void main()
|
||||||
|
|
||||||
// Rotate the normal.
|
// Rotate the normal.
|
||||||
normal = gl_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.xy = vec2(dot(normal.xy, vec2(cr, sr)), dot(normal.xy, vec2(-sr, cr)));
|
||||||
normal = gl_NormalMatrix * normal;
|
normal = gl_NormalMatrix * normal;
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ void main()
|
||||||
color = clamp(color, 0.0, 1.0);
|
color = clamp(color, 0.0, 1.0);
|
||||||
texel = texture2D(texture, gl_TexCoord[0].st);
|
texel = texture2D(texture, gl_TexCoord[0].st);
|
||||||
emissive = texture2D(lightmap, gl_TexCoord[0].st);
|
emissive = texture2D(lightmap, gl_TexCoord[0].st);
|
||||||
|
|
||||||
// The lights are only switched on when the sun is below the horizon
|
// 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 = color * texel + specular + smoothstep(1.6, 1.8, sunangle) * emissive;
|
||||||
fragColor.rgb = fog_Func(fragColor.rgb, fogType);
|
fragColor.rgb = fog_Func(fragColor.rgb, fogType);
|
||||||
|
|
|
@ -17,7 +17,8 @@ attribute vec3 instancePosition; // (x,y,z)
|
||||||
attribute vec3 instanceScaleRotate; // (width, depth, height)
|
attribute vec3 instanceScaleRotate; // (width, depth, height)
|
||||||
attribute vec3 rotPitchWtex0x; // (rotation, pitch height, wall texture x offset)
|
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 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 constant term of the lighting equation that doesn't depend on
|
||||||
// the surface normal is passed in gl_{Front,Back}Color. The alpha
|
// 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 sr = sin(6.28 * rotPitchWtex0x.x);
|
||||||
float cr = cos(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;
|
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;
|
position = position * instanceScaleRotate.xyz;
|
||||||
|
|
||||||
// Rotation of the building and movement into position
|
// 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
|
// The vertex color value selects between them, with glColor.x=1 indicating walls
|
||||||
// and glColor.y=1 indicating roofs.
|
// and glColor.y=1 indicating roofs.
|
||||||
// Finally, the roof texture is on the left of the texture sheet
|
// 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),
|
float wtex0x = rotPitchWtex0x.z;
|
||||||
gl_Color.x*wtex0yTex1xTex1y.x + gl_Color.y*rtex0xRtex0y.y);
|
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].x = tex0.x + gl_MultiTexCoord0.x * wtex0yTex1xTex1y.y;
|
||||||
gl_TexCoord[0].y = tex0.y + gl_MultiTexCoord0.y * wtex0yTex1xTex1y.z;
|
gl_TexCoord[0].y = tex0.y + gl_MultiTexCoord0.y * wtex0yTex1xTex1y.z;
|
||||||
|
|
||||||
// Rotate the normal.
|
// Rotate the normal.
|
||||||
normal = gl_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.xy = vec2(dot(normal.xy, vec2(cr, sr)), dot(normal.xy, vec2(-sr, cr)));
|
||||||
normal = gl_NormalMatrix * normal;
|
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 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 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, texture y gain)
|
||||||
|
attribute vec3 rooftopscale; // (rooftop x scale, rooftop y scale)
|
||||||
|
|
||||||
varying vec3 ecNormal;
|
varying vec3 ecNormal;
|
||||||
varying float alpha;
|
varying float alpha;
|
||||||
|
@ -19,14 +20,16 @@ void main() {
|
||||||
float sr = sin(6.28 * rotPitchWtex0x.x);
|
float sr = sin(6.28 * rotPitchWtex0x.x);
|
||||||
float cr = cos(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;
|
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;
|
position = position * instanceScaleRotate.xyz;
|
||||||
|
|
||||||
// Rotation of the building and movement into position
|
// Rotation of the building and movement into position
|
||||||
|
@ -49,17 +52,6 @@ void main() {
|
||||||
|
|
||||||
// Rotate the normal.
|
// Rotate the normal.
|
||||||
ecNormal = gl_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.xy = vec2(dot(ecNormal.xy, vec2(cr, sr)), dot(ecNormal.xy, vec2(-sr, cr)));
|
||||||
ecNormal = gl_NormalMatrix * ecNormal;
|
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 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 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, texture y gain)
|
||||||
|
attribute vec3 rooftopscale; // (rooftop x scale, rooftop y scale)
|
||||||
|
|
||||||
varying vec3 rawpos;
|
varying vec3 rawpos;
|
||||||
varying vec3 VNormal;
|
varying vec3 VNormal;
|
||||||
|
@ -58,14 +59,17 @@ void main(void)
|
||||||
float sr = sin(6.28 * rotPitchWtex0x.x);
|
float sr = sin(6.28 * rotPitchWtex0x.x);
|
||||||
float cr = cos(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),
|
vec3 rawpos = gl_Vertex.xyz;
|
||||||
// so we can use this to identify them and scale up any pitched roof vertex to
|
// Adjust the very top of the roof to match the rooftop scaling. This shapes
|
||||||
// the correct pitch (rotPitchWtex0x.y * 2.0 because of the fractional z value),
|
// the rooftop - gambled, gabled etc. These vertices are identified by gl_Color.z
|
||||||
// then scale down by the building height (instanceScaleRotate.z) because
|
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.
|
// immediately afterwards we will scale UP the vertex to the correct scale.
|
||||||
rawpos = gl_Vertex.xyz;
|
rawpos.z = rawpos.z + gl_Color.z * rotPitchWtex0x.y / instanceScaleRotate.z;
|
||||||
rawpos.z = rawpos.z + fract(rawpos.z) * 2.0 * rotPitchWtex0x.y / instanceScaleRotate.z - fract(rawpos.z);
|
|
||||||
rawpos = rawpos * instanceScaleRotate.xyz;
|
rawpos = rawpos * instanceScaleRotate.xyz;
|
||||||
|
|
||||||
// Rotation of the building and movement into rawpos
|
// Rotation of the building and movement into rawpos
|
||||||
|
@ -87,16 +91,6 @@ void main(void)
|
||||||
|
|
||||||
// Rotate the normal.
|
// Rotate the normal.
|
||||||
vec3 normal = gl_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.
|
// Rotate the normal as per the building.
|
||||||
normal.xy = vec2(dot(normal.xy, vec2(cr, sr)), dot(normal.xy, vec2(-sr, cr)));
|
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 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 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, texture y gain)
|
||||||
|
attribute vec3 rooftopscale; // (rooftop x scale, rooftop y scale)
|
||||||
|
|
||||||
void main(void)
|
void main(void)
|
||||||
{
|
{
|
||||||
|
@ -29,14 +30,16 @@ void main(void)
|
||||||
float sr = sin(6.28 * rotPitchWtex0x.x);
|
float sr = sin(6.28 * rotPitchWtex0x.x);
|
||||||
float cr = cos(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;
|
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;
|
position = position * instanceScaleRotate.xyz;
|
||||||
|
|
||||||
// Rotation of the building and movement into position
|
// Rotation of the building and movement into position
|
||||||
|
@ -51,13 +54,6 @@ void main(void)
|
||||||
// Rotate the normal.
|
// Rotate the normal.
|
||||||
normal = gl_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.
|
// Rotate the normal as per the building.
|
||||||
normal.xy = vec2(dot(normal.xy, vec2(cr, sr)), dot(normal.xy, vec2(-sr, cr)));
|
normal.xy = vec2(dot(normal.xy, vec2(cr, sr)), dot(normal.xy, vec2(-sr, cr)));
|
||||||
vec3 n = normalize(normal);
|
vec3 n = normalize(normal);
|
||||||
|
|
Loading…
Add table
Reference in a new issue