1
0
Fork 0

Random Buildings - improved texture mapping

Previously the front and side faces of random/OSM buildings
had identical texture coordinates.  This resulted in the sides
of buildings texture mapping being squeezed or stretched.

This change generates a separate texture mapping for the sides
of the buildings.
This commit is contained in:
Stuart Buchanan 2019-11-23 17:08:04 +00:00
parent e7ee72a6e4
commit 119fb5efe2
7 changed files with 188 additions and 118 deletions

View file

@ -411,7 +411,7 @@ Where:
- 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 (only 0, 2, 4, 6 are implemented, others are approximated to those) : - 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=gambrel
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 : - O is the roof ridge orientation :
0 = parallel to the front face of the building 0 = parallel to the front face of the building

View file

@ -208,19 +208,19 @@
<index>10</index> <index>10</index>
</attribute> </attribute>
<attribute> <attribute>
<name>instanceScaleRotate</name> <name>instanceScale</name>
<index>11</index> <index>11</index>
</attribute> </attribute>
<attribute> <attribute>
<name>rotPitchWtex0x</name> <name>rotPitchWtexX0</name>
<index>12</index> <index>12</index>
</attribute> </attribute>
<attribute> <attribute>
<name>wtex0yTex1xTex1y</name> <name>wtexY0FRtexx1FSRtexY1</name>
<index>13</index> <index>13</index>
</attribute> </attribute>
<attribute> <attribute>
<name>rtex0xRtex0y</name> <name>rtexX0RtexY0StexX1</name>
<index>14</index> <index>14</index>
</attribute> </attribute>
<attribute> <attribute>
@ -302,19 +302,19 @@
<index>10</index> <index>10</index>
</attribute> </attribute>
<attribute> <attribute>
<name>instanceScaleRotate</name> <name>instanceScale</name>
<index>11</index> <index>11</index>
</attribute> </attribute>
<attribute> <attribute>
<name>rotPitchWtex0x</name> <name>rotPitchWtexX0</name>
<index>12</index> <index>12</index>
</attribute> </attribute>
<attribute> <attribute>
<name>wtex0yTex1xTex1y</name> <name>wtexY0FRtexx1FSRtexY1</name>
<index>13</index> <index>13</index>
</attribute> </attribute>
<attribute> <attribute>
<name>rtex0xRtex0y</name> <name>rtexX0RtexY0StexX1</name>
<index>14</index> <index>14</index>
</attribute> </attribute>
<attribute> <attribute>
@ -385,19 +385,19 @@
<index>10</index> <index>10</index>
</attribute> </attribute>
<attribute> <attribute>
<name>instanceScaleRotate</name> <name>instanceScale</name>
<index>11</index> <index>11</index>
</attribute> </attribute>
<attribute> <attribute>
<name>rotPitchWtex0x</name> <name>rotPitchWtexX0</name>
<index>12</index> <index>12</index>
</attribute> </attribute>
<attribute> <attribute>
<name>wtex0yTex1xTex1y</name> <name>wtexY0FRtexx1FSRtexY1</name>
<index>13</index> <index>13</index>
</attribute> </attribute>
<attribute> <attribute>
<name>rtex0xRtex0y</name> <name>rtexX0RtexY0StexX1</name>
<index>14</index> <index>14</index>
</attribute> </attribute>
<attribute> <attribute>
@ -523,19 +523,19 @@
<index>10</index> <index>10</index>
</attribute> </attribute>
<attribute> <attribute>
<name>instanceScaleRotate</name> <name>instanceScale</name>
<index>11</index> <index>11</index>
</attribute> </attribute>
<attribute> <attribute>
<name>rotPitchWtex0x</name> <name>rotPitchWtexX0</name>
<index>12</index> <index>12</index>
</attribute> </attribute>
<attribute> <attribute>
<name>wtex0yTex1xTex1y</name> <name>wtexY0FRtexx1FSRtexY1</name>
<index>13</index> <index>13</index>
</attribute> </attribute>
<attribute> <attribute>
<name>rtex0xRtex0y</name> <name>rtexX0RtexY0StexX1</name>
<index>14</index> <index>14</index>
</attribute> </attribute>
<attribute> <attribute>
@ -587,19 +587,19 @@
<index>10</index> <index>10</index>
</attribute> </attribute>
<attribute> <attribute>
<name>instanceScaleRotate</name> <name>instanceScale</name>
<index>11</index> <index>11</index>
</attribute> </attribute>
<attribute> <attribute>
<name>rotPitchWtex0x</name> <name>rotPitchWtexX0</name>
<index>12</index> <index>12</index>
</attribute> </attribute>
<attribute> <attribute>
<name>wtex0yTex1xTex1y</name> <name>wtexY0FRtexx1FSRtexY1</name>
<index>13</index> <index>13</index>
</attribute> </attribute>
<attribute> <attribute>
<name>rtex0xRtex0y</name> <name>rtexX0RtexY0StexX1</name>
<index>14</index> <index>14</index>
</attribute> </attribute>
<attribute> <attribute>
@ -709,19 +709,19 @@
<index>10</index> <index>10</index>
</attribute> </attribute>
<attribute> <attribute>
<name>instanceScaleRotate</name> <name>instanceScale</name>
<index>11</index> <index>11</index>
</attribute> </attribute>
<attribute> <attribute>
<name>rotPitchWtex0x</name> <name>rotPitchWtexX0</name>
<index>12</index> <index>12</index>
</attribute> </attribute>
<attribute> <attribute>
<name>wtex0yTex1xTex1y</name> <name>wtexY0FRtexx1FSRtexY1</name>
<index>13</index> <index>13</index>
</attribute> </attribute>
<attribute> <attribute>
<name>rtex0xRtex0y</name> <name>rtexX0RtexY0StexX1</name>
<index>14</index> <index>14</index>
</attribute> </attribute>
<attribute> <attribute>

View file

@ -17,10 +17,10 @@
#define MODE_AMBIENT_AND_DIFFUSE 2 #define MODE_AMBIENT_AND_DIFFUSE 2
attribute vec3 instancePosition; // (x,y,z) attribute vec3 instancePosition; // (x,y,z)
attribute vec3 instanceScaleRotate; // (width, depth, height) attribute vec3 instanceScale; // (width, depth, height)
attribute vec3 rotPitchWtex0x; // (rotation, pitch height, texture x offset) attribute vec3 rotPitchWtexX0; // (rotation, pitch height, wall texture x0)
attribute vec3 wtex0yTex1xTex1y; // (wall texture y offset, wall/roof texture x gain, wall/roof texture y gain) attribute vec3 wtexY0FRtexx1FSRtexY1; // (wall texture y0, front/roof texture x1, front/side/roof texture y1)
attribute vec3 rtex0xRtex0y; // (roof texture y offset, roof texture x gain, texture y gain) attribute vec3 rtexX0RtexY0StexX1; // (roof texture x0, roof texture y0, side texture x1)
attribute vec3 rooftopscale; // (rooftop x scale, rooftop y scale) 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
@ -83,8 +83,8 @@ void main()
vec3 shadedFogColor = vec3(0.55, 0.67, 0.88); vec3 shadedFogColor = vec3(0.55, 0.67, 0.88);
// Determine the rotation for the building. // Determine the rotation for the building.
float sr = sin(6.28 * rotPitchWtex0x.x); float sr = sin(6.28 * rotPitchWtexX0.x);
float cr = cos(6.28 * rotPitchWtex0x.x); float cr = cos(6.28 * rotPitchWtexX0.x);
vec3 position = gl_Vertex.xyz; vec3 position = gl_Vertex.xyz;
// Adjust the very top of the roof to match the rooftop scaling. This shapes // Adjust the very top of the roof to match the rooftop scaling. This shapes
@ -93,10 +93,10 @@ void main()
position.y = (1.0 - gl_Color.z) * position.y + gl_Color.z * (position.y * rooftopscale.y); 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 // 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 // Scale down by the building height (instanceScale.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.
position.z = position.z + gl_Color.z * rotPitchWtex0x.y / instanceScaleRotate.z; position.z = position.z + gl_Color.z * rotPitchWtexX0.y / instanceScale.z;
position = position * instanceScaleRotate.xyz; position = position * instanceScale.xyz;
// Rotation of the building and movement into position // Rotation of the building and movement into position
position.xy = vec2(dot(position.xy, vec2(cr, sr)), dot(position.xy, vec2(-sr, cr))); position.xy = vec2(dot(position.xy, vec2(cr, sr)), dot(position.xy, vec2(-sr, cr)));
@ -105,16 +105,31 @@ void main()
gl_Position = gl_ModelViewProjectionMatrix * vec4(position,1.0); gl_Position = gl_ModelViewProjectionMatrix * vec4(position,1.0);
// Texture coordinates are stored as: // Texture coordinates are stored as:
// - a separate offset for the wall (wtex0x, wtex0y), and roof (rtex0x, rtex0y) // - a separate offset (x0, y0) for the wall (wtex0x, wtex0y), and roof (rtex0x, rtex0y)
// - a shared gain value (tex1x, tex1y) // - a semi-shared (x1, y1) so that the front and side of the building can have
// different texture mappings
// //
// The vertex color value selects between them, with glColor.x=1 indicating walls // The vertex color value selects between them:
// and glColor.y=1 indicating roofs. // gl_Color.x=1 indicates front/back walls
// Finally, the roof texture is on the left of the texture sheet // gl_Color.y=1 indicates roof
vec2 tex0 = vec2(sign(gl_MultiTexCoord0.x) * (gl_Color.x*rotPitchWtex0x.z + gl_Color.y*rtex0xRtex0y.x), // gl_Color.z=1 indicates top roof vertexs (used above)
gl_Color.x*wtex0yTex1xTex1y.x + gl_Color.y*rtex0xRtex0y.y); // gl_Color.a=1 indicates sides
gl_TexCoord[0].x = tex0.x + gl_MultiTexCoord0.x * wtex0yTex1xTex1y.y; // Finally, the roof texture is on the right of the texture sheet
gl_TexCoord[0].y = tex0.y + gl_MultiTexCoord0.y * wtex0yTex1xTex1y.z; float wtex0x = rotPitchWtexX0.z; // Front/Side texture X0
float wtex0y = wtexY0FRtexx1FSRtexY1.x; // Front/Side texture Y0
float rtex0x = rtexX0RtexY0StexX1.x; // Roof texture X0
float rtex0y = rtexX0RtexY0StexX1.y; // Roof texture Y0
float wtex1x = wtexY0FRtexx1FSRtexY1.y; // Front/Roof texture X1
float stex1x = rtexX0RtexY0StexX1.z; // Side texture X1
float wtex1y = wtexY0FRtexx1FSRtexY1.z; // Front/Roof/Side texture Y1
vec2 tex0 = vec2(sign(gl_MultiTexCoord0.x) * (gl_Color.x*wtex0x + gl_Color.y*rtex0x + gl_Color.a*wtex0x),
gl_Color.x*wtex0y + gl_Color.y*rtex0y + gl_Color.a*wtex0y);
vec2 tex1 = vec2(gl_Color.x*wtex1x + gl_Color.y*wtex1x + gl_Color.a*stex1x,
wtex1y);
gl_TexCoord[0].x = tex0.x + gl_MultiTexCoord0.x * tex1.x;
gl_TexCoord[0].y = tex0.y + gl_MultiTexCoord0.y * tex1.y;
// Rotate the normal. // Rotate the normal.
normal = gl_Normal; normal = gl_Normal;

View file

@ -14,10 +14,10 @@
#define MODE_AMBIENT_AND_DIFFUSE 2 #define MODE_AMBIENT_AND_DIFFUSE 2
attribute vec3 instancePosition; // (x,y,z) attribute vec3 instancePosition; // (x,y,z)
attribute vec3 instanceScaleRotate; // (width, depth, height) attribute vec3 instanceScale ; // (width, depth, height)
attribute vec3 rotPitchWtex0x; // (rotation, pitch height, wall texture x offset) attribute vec3 rotPitchWtexX0; // (rotation, pitch height, wall texture x0)
attribute vec3 wtex0yTex1xTex1y; // (wall texture y offset, wall/roof texture x gain, wall/roof texture y gain) attribute vec3 wtexY0FRtexx1FSRtexY1; // (wall texture y0, front/roof texture x1, front/side/roof texture y1)
attribute vec3 rtex0xRtex0y; // (roof texture y offset, roof texture x gain, unused) attribute vec3 rtexX0RtexY0StexX1; // (roof texture x0, roof texture y0, side texture x1)
attribute vec3 rooftopscale; // (rooftop x scale, rooftop y scale) 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
@ -38,8 +38,8 @@ uniform int colorMode;
void main() void main()
{ {
// Determine the rotation for the building. // Determine the rotation for the building.
float sr = sin(6.28 * rotPitchWtex0x.x); float sr = sin(6.28 * rotPitchWtexX0.x);
float cr = cos(6.28 * rotPitchWtex0x.x); float cr = cos(6.28 * rotPitchWtexX0.x);
vec3 position = gl_Vertex.xyz; vec3 position = gl_Vertex.xyz;
// Adjust the very top of the roof to match the rooftop scaling. This shapes // Adjust the very top of the roof to match the rooftop scaling. This shapes
@ -48,10 +48,10 @@ void main()
position.y = (1.0 - gl_Color.z) * position.y + gl_Color.z * (position.y * rooftopscale.y); 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 // 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 // Scale down by the building height (instanceScale.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.
position.z = position.z + gl_Color.z * rotPitchWtex0x.y / instanceScaleRotate.z; position.z = position.z + gl_Color.z * rotPitchWtexX0.y / instanceScale.z;
position = position * instanceScaleRotate.xyz; position = position * instanceScale.xyz;
// Rotation of the building and movement into position // Rotation of the building and movement into position
position.xy = vec2(dot(position.xy, vec2(cr, sr)), dot(position.xy, vec2(-sr, cr))); position.xy = vec2(dot(position.xy, vec2(cr, sr)), dot(position.xy, vec2(-sr, cr)));
@ -60,20 +60,31 @@ void main()
gl_Position = gl_ModelViewProjectionMatrix * vec4(position,1.0); gl_Position = gl_ModelViewProjectionMatrix * vec4(position,1.0);
// Texture coordinates are stored as: // Texture coordinates are stored as:
// - a separate offset for the wall (wtex0x, wtex0y), and roof (rtex0x, rtex0y) // - a separate offset (x0, y0) for the wall (wtex0x, wtex0y), and roof (rtex0x, rtex0y)
// - a shared gain value (tex1x, tex1y) // - a semi-shared (x1, y1) so that the front and side of the building can have
// different texture mappings
// //
// The vertex color value selects between them, with glColor.x=1 indicating walls // The vertex color value selects between them:
// and glColor.y=1 indicating roofs. // gl_Color.x=1 indicates front/back walls
// Finally, the roof texture is on the left of the texture sheet // gl_Color.y=1 indicates roof
float wtex0x = rotPitchWtex0x.z; // gl_Color.z=1 indicates top roof vertexs (used above)
float wtex0y = wtex0yTex1xTex1y.x; // gl_Color.a=1 indicates sides
float rtex0x = rtex0xRtex0y.x; // Finally, the roof texture is on the right of the texture sheet
float rtex0y = rtex0xRtex0y.y; float wtex0x = rotPitchWtexX0.z; // Front/Side texture X0
vec2 tex0 = vec2(sign(gl_MultiTexCoord0.x) * (gl_Color.x*wtex0x + gl_Color.y*rtex0x), float wtex0y = wtexY0FRtexx1FSRtexY1.x; // Front/Side texture Y0
gl_Color.x*wtex0y + gl_Color.y*rtex0y); float rtex0x = rtexX0RtexY0StexX1.x; // Roof texture X0
gl_TexCoord[0].x = tex0.x + gl_MultiTexCoord0.x * wtex0yTex1xTex1y.y; float rtex0y = rtexX0RtexY0StexX1.y; // Roof texture Y0
gl_TexCoord[0].y = tex0.y + gl_MultiTexCoord0.y * wtex0yTex1xTex1y.z; float wtex1x = wtexY0FRtexx1FSRtexY1.y; // Front/Roof texture X1
float stex1x = rtexX0RtexY0StexX1.z; // Side texture X1
float wtex1y = wtexY0FRtexx1FSRtexY1.z; // Front/Roof/Side texture Y1
vec2 tex0 = vec2(sign(gl_MultiTexCoord0.x) * (gl_Color.x*wtex0x + gl_Color.y*rtex0x + gl_Color.a*wtex0x),
gl_Color.x*wtex0y + gl_Color.y*rtex0y + gl_Color.a*wtex0y);
vec2 tex1 = vec2(gl_Color.x*wtex1x + gl_Color.y*wtex1x + gl_Color.a*stex1x,
wtex1y);
gl_TexCoord[0].x = tex0.x + gl_MultiTexCoord0.x * tex1.x;
gl_TexCoord[0].y = tex0.y + gl_MultiTexCoord0.y * tex1.y;
// Rotate the normal. // Rotate the normal.
normal = gl_Normal; normal = gl_Normal;

View file

@ -7,9 +7,9 @@
attribute vec3 instancePosition; // (x,y,z) attribute vec3 instancePosition; // (x,y,z)
attribute vec3 instanceScaleRotate; // (width, depth, height) attribute vec3 instanceScaleRotate; // (width, depth, height)
attribute vec3 rotPitchWtex0x; // (rotation, pitch height, texture x offset) attribute vec3 rotPitchWtexX0; // (rotation, pitch height, wall texture x0)
attribute vec3 wtex0yTex1xTex1y; // (wall texture y offset, wall/roof texture x gain, wall/roof texture y gain) attribute vec3 wtexY0FRtexx1FSRtexY1; // (wall texture y0, front/roof texture x1, front/side/roof texture y1)
attribute vec3 rtex0xRtex0y; // (roof texture y offset, roof texture x gain, texture y gain) attribute vec3 rtexX0RtexY0StexX1; // (roof texture x0, roof texture y0, side texture x1)
attribute vec3 rooftopscale; // (rooftop x scale, rooftop y scale) attribute vec3 rooftopscale; // (rooftop x scale, rooftop y scale)
varying vec3 ecNormal; varying vec3 ecNormal;
@ -17,8 +17,8 @@ varying float alpha;
void main() { void main() {
// Determine the rotation for the building. // Determine the rotation for the building.
float sr = sin(6.28 * rotPitchWtex0x.x); float sr = sin(6.28 * rotPitchWtexX0.x);
float cr = cos(6.28 * rotPitchWtex0x.x); float cr = cos(6.28 * rotPitchWtexX0.x);
vec3 position = gl_Vertex.xyz; vec3 position = gl_Vertex.xyz;
// Adjust the very top of the roof to match the rooftop scaling. This shapes // Adjust the very top of the roof to match the rooftop scaling. This shapes
@ -29,7 +29,7 @@ void main() {
// Adjust pitch of roof to the correct height. These vertices are identified by gl_Color.z // 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 // 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.
position.z = position.z + gl_Color.z * rotPitchWtex0x.y / instanceScaleRotate.z; position.z = position.z + gl_Color.z * rotPitchWtexX0.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
@ -39,16 +39,31 @@ void main() {
gl_Position = gl_ModelViewProjectionMatrix * vec4(position,1.0); gl_Position = gl_ModelViewProjectionMatrix * vec4(position,1.0);
// Texture coordinates are stored as: // Texture coordinates are stored as:
// - a separate offset for the wall (wtex0x, wtex0y), and roof (rtex0x, rtex0y) // - a separate offset (x0, y0) for the wall (wtex0x, wtex0y), and roof (rtex0x, rtex0y)
// - a shared gain value (tex1x, tex1y) // - a semi-shared (x1, y1) so that the front and side of the building can have
// different texture mappings
// //
// The vertex color value selects between them, with glColor.x=1 indicating walls // The vertex color value selects between them:
// and glColor.y=1 indicating roofs. // gl_Color.x=1 indicates front/back walls
// Finally, the roof texture is on the left of the texture sheet // gl_Color.y=1 indicates roof
vec2 tex0 = vec2(sign(gl_MultiTexCoord0.x) * (gl_Color.x*rotPitchWtex0x.z + gl_Color.y*rtex0xRtex0y.x), // gl_Color.z=1 indicates top roof vertexs (used above)
gl_Color.x*wtex0yTex1xTex1y.x + gl_Color.y*rtex0xRtex0y.y); // gl_Color.a=1 indicates sides
gl_TexCoord[0].x = tex0.x + gl_MultiTexCoord0.x * wtex0yTex1xTex1y.y; // Finally, the roof texture is on the right of the texture sheet
gl_TexCoord[0].y = tex0.y + gl_MultiTexCoord0.y * wtex0yTex1xTex1y.z; float wtex0x = rotPitchWtexX0.z; // Front/Side texture X0
float wtex0y = wtexY0FRtexx1FSRtexY1.x; // Front/Side texture Y0
float rtex0x = rtexX0RtexY0StexX1.x; // Roof texture X0
float rtex0y = rtexX0RtexY0StexX1.y; // Roof texture Y0
float wtex1x = wtexY0FRtexx1FSRtexY1.y; // Front/Roof texture X1
float stex1x = rtexX0RtexY0StexX1.z; // Side texture X1
float wtex1y = wtexY0FRtexx1FSRtexY1.z; // Front/Roof/Side texture Y1
vec2 tex0 = vec2(sign(gl_MultiTexCoord0.x) * (gl_Color.x*wtex0x + gl_Color.y*rtex0x + gl_Color.a*wtex0x),
gl_Color.x*wtex0y + gl_Color.y*rtex0y + gl_Color.a*wtex0y);
vec2 tex1 = vec2(gl_Color.x*wtex1x + gl_Color.y*wtex1x + gl_Color.a*stex1x,
wtex1y);
gl_TexCoord[0].x = tex0.x + gl_MultiTexCoord0.x * tex1.x;
gl_TexCoord[0].y = tex0.y + gl_MultiTexCoord0.y * tex1.y;
// Rotate the normal. // Rotate the normal.
ecNormal = gl_Normal; ecNormal = gl_Normal;

View file

@ -4,10 +4,10 @@
#version 120 #version 120
attribute vec3 instancePosition; // (x,y,z) attribute vec3 instancePosition; // (x,y,z)
attribute vec3 instanceScaleRotate; // (width, depth, height) attribute vec3 instanceScale ; // (width, depth, height)
attribute vec3 rotPitchWtex0x; // (rotation, pitch height, texture x offset) attribute vec3 rotPitchWtexX0; // (rotation, pitch height, wall texture x0)
attribute vec3 wtex0yTex1xTex1y; // (wall texture y offset, wall/roof texture x gain, wall/roof texture y gain) attribute vec3 wtexY0FRtexx1FSRtexY1; // (wall texture y0, front/roof texture x1, front/side/roof texture y1)
attribute vec3 rtex0xRtex0y; // (roof texture y offset, roof texture x gain, texture y gain) attribute vec3 rtexX0RtexY0StexX1; // (roof texture x0, roof texture y0, side texture x1)
attribute vec3 rooftopscale; // (rooftop x scale, rooftop y scale) attribute vec3 rooftopscale; // (rooftop x scale, rooftop y scale)
varying vec3 rawpos; varying vec3 rawpos;
@ -56,8 +56,8 @@ void rotationMatrixH(in float sinRz, in float cosRz, out mat4 rotmat)
void main(void) void main(void)
{ {
// Determine the rotation for the building. // Determine the rotation for the building.
float sr = sin(6.28 * rotPitchWtex0x.x); float sr = sin(6.28 * rotPitchWtexX0.x);
float cr = cos(6.28 * rotPitchWtex0x.x); float cr = cos(6.28 * rotPitchWtexX0.x);
vec3 rawpos = gl_Vertex.xyz; vec3 rawpos = gl_Vertex.xyz;
@ -67,10 +67,10 @@ void main(void)
rawpos.y = (1.0 - gl_Color.z) * rawpos.y + gl_Color.z * (rawpos.y * rooftopscale.y); 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 // 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 // Scale down by the building height (instanceScale.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.z = rawpos.z + gl_Color.z * rotPitchWtex0x.y / instanceScaleRotate.z; rawpos.z = rawpos.z + gl_Color.z * rotPitchWtexX0.y / instanceScale.z;
rawpos = rawpos * instanceScaleRotate.xyz; rawpos = rawpos * instanceScale.xyz;
// Rotation of the building and movement into rawpos // Rotation of the building and movement into rawpos
rawpos.xy = vec2(dot(rawpos.xy, vec2(cr, sr)), dot(rawpos.xy, vec2(-sr, cr))); rawpos.xy = vec2(dot(rawpos.xy, vec2(cr, sr)), dot(rawpos.xy, vec2(-sr, cr)));
@ -78,16 +78,31 @@ void main(void)
vec4 ecPosition = gl_ModelViewMatrix * vec4(rawpos, 1.0); vec4 ecPosition = gl_ModelViewMatrix * vec4(rawpos, 1.0);
// Texture coordinates are stored as: // Texture coordinates are stored as:
// - a separate offset for the wall (wtex0x, wtex0y), and roof (rtex0x, rtex0y) // - a separate offset (x0, y0) for the wall (wtex0x, wtex0y), and roof (rtex0x, rtex0y)
// - a shared gain value (tex1x, tex1y) // - a semi-shared (x1, y1) so that the front and side of the building can have
// // different texture mappings
// The vertex color value selects between them, with glColor.x=1 indicating walls //
// and glColor.y=1 indicating roofs. // The vertex color value selects between them:
// Finally, the roof texture is on the left of the texture sheet // gl_Color.x=1 indicates front/back walls
vec2 tex0 = vec2(sign(gl_MultiTexCoord0.x) * (gl_Color.x*rotPitchWtex0x.z + gl_Color.y*rtex0xRtex0y.x), // gl_Color.y=1 indicates roof
gl_Color.x*wtex0yTex1xTex1y.x + gl_Color.y*rtex0xRtex0y.y); // gl_Color.z=1 indicates top roof vertexs (used above)
gl_TexCoord[0].x = tex0.x + gl_MultiTexCoord0.x * wtex0yTex1xTex1y.y; // gl_Color.a=1 indicates sides
gl_TexCoord[0].y = tex0.y + gl_MultiTexCoord0.y * wtex0yTex1xTex1y.z; // Finally, the roof texture is on the right of the texture sheet
float wtex0x = rotPitchWtexX0.z; // Front/Side texture X0
float wtex0y = wtexY0FRtexx1FSRtexY1.x; // Front/Side texture Y0
float rtex0x = rtexX0RtexY0StexX1.x; // Roof texture X0
float rtex0y = rtexX0RtexY0StexX1.y; // Roof texture Y0
float wtex1x = wtexY0FRtexx1FSRtexY1.y; // Front/Roof texture X1
float stex1x = rtexX0RtexY0StexX1.z; // Side texture X1
float wtex1y = wtexY0FRtexx1FSRtexY1.z; // Front/Roof/Side texture Y1
vec2 tex0 = vec2(sign(gl_MultiTexCoord0.x) * (gl_Color.x*wtex0x + gl_Color.y*rtex0x + gl_Color.a*wtex0x),
gl_Color.x*wtex0y + gl_Color.y*rtex0y + gl_Color.a*wtex0y);
vec2 tex1 = vec2(gl_Color.x*wtex1x + gl_Color.y*wtex1x + gl_Color.a*stex1x,
wtex1y);
gl_TexCoord[0].x = tex0.x + gl_MultiTexCoord0.x * tex1.x;
gl_TexCoord[0].y = tex0.y + gl_MultiTexCoord0.y * tex1.y;
// Rotate the normal. // Rotate the normal.
vec3 normal = gl_Normal; vec3 normal = gl_Normal;

View file

@ -18,17 +18,17 @@ uniform int shader_qual;
uniform int rembrandt_enabled; uniform int rembrandt_enabled;
attribute vec3 instancePosition; // (x,y,z) attribute vec3 instancePosition; // (x,y,z)
attribute vec3 instanceScaleRotate; // (width, depth, height) attribute vec3 instanceScale; // (width, depth, height)
attribute vec3 rotPitchWtex0x; // (rotation, pitch height, texture x offset) attribute vec3 rotPitchWtexX0; // (rotation, pitch height, wall texture x0)
attribute vec3 wtex0yTex1xTex1y; // (wall texture y offset, wall/roof texture x gain, wall/roof texture y gain) attribute vec3 wtexY0FRtexx1FSRtexY1; // (wall texture y0, front/roof texture x1, front/side/roof texture y1)
attribute vec3 rtex0xRtex0y; // (roof texture y offset, roof texture x gain, texture y gain) attribute vec3 rtexX0RtexY0StexX1; // (roof texture x0, roof texture y0, side texture x1)
attribute vec3 rooftopscale; // (rooftop x scale, rooftop y scale) attribute vec3 rooftopscale; // (rooftop x scale, rooftop y scale)
void main(void) void main(void)
{ {
// Determine the rotation for the building. // Determine the rotation for the building.
float sr = sin(6.28 * rotPitchWtex0x.x); float sr = sin(6.28 * rotPitchWtexX0.x);
float cr = cos(6.28 * rotPitchWtex0x.x); float cr = cos(6.28 * rotPitchWtexX0.x);
vec3 position = gl_Vertex.xyz; vec3 position = gl_Vertex.xyz;
// Adjust the very top of the roof to match the rooftop scaling. This shapes // Adjust the very top of the roof to match the rooftop scaling. This shapes
@ -37,10 +37,10 @@ void main(void)
position.y = (1.0 - gl_Color.z) * position.y + gl_Color.z * (position.y * rooftopscale.y); 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 // 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 // Scale down by the building height (instanceScale.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.
position.z = position.z + gl_Color.z * rotPitchWtex0x.y / instanceScaleRotate.z; position.z = position.z + gl_Color.z * rotPitchWtexX0.y / instanceScale.z;
position = position * instanceScaleRotate.xyz; position = position * instanceScale.xyz;
// Rotation of the building and movement into position // Rotation of the building and movement into position
position.xy = vec2(dot(position.xy, vec2(cr, sr)), dot(position.xy, vec2(-sr, cr))); position.xy = vec2(dot(position.xy, vec2(cr, sr)), dot(position.xy, vec2(-sr, cr)));
@ -84,14 +84,28 @@ void main(void)
gl_ClipVertex = ecPosition; gl_ClipVertex = ecPosition;
// Texture coordinates are stored as: // Texture coordinates are stored as:
// - a separate offset for the wall (wtex0x, wtex0y), and roof (rtex0x, rtex0y) // - a separate offset (x0, y0) for the wall (wtex0x, wtex0y), and roof (rtex0x, rtex0y)
// - a shared gain value (tex1x, tex1y) // - a semi-shared (x1, y1) so that the front and side of the building can have
// different texture mappings
// //
// The vertex color value selects between them, with glColor.x=1 indicating walls // The vertex color value selects between them:
// and glColor.y=1 indicating roofs. // gl_Color.x=1 indicates front/back walls
// Finally, the roof texture is on the left of the texture sheet // gl_Color.y=1 indicates roof
vec2 tex0 = vec2(sign(gl_MultiTexCoord0.x) * (gl_Color.x*rotPitchWtex0x.z + gl_Color.y*rtex0xRtex0y.x), // gl_Color.z=1 indicates top roof vertexs (used above)
gl_Color.x*wtex0yTex1xTex1y.x + gl_Color.y*rtex0xRtex0y.y); // gl_Color.a=1 indicates sides
gl_TexCoord[0].x = tex0.x + gl_MultiTexCoord0.x * wtex0yTex1xTex1y.y; // Finally, the roof texture is on the right of the texture sheet
gl_TexCoord[0].y = tex0.y + gl_MultiTexCoord0.y * wtex0yTex1xTex1y.z; float wtex0x = rotPitchWtexX0.z; // Front/Side texture X0
} float wtex0y = wtexY0FRtexx1FSRtexY1.x; // Front/Side texture Y0
float rtex0x = rtexX0RtexY0StexX1.x; // Roof texture X0
float rtex0y = rtexX0RtexY0StexX1.y; // Roof texture Y0
float wtex1x = wtexY0FRtexx1FSRtexY1.y; // Front/Roof texture X1
float stex1x = rtexX0RtexY0StexX1.z; // Side texture X1
float wtex1y = wtexY0FRtexx1FSRtexY1.z; // Front/Roof/Side texture Y1
vec2 tex0 = vec2(sign(gl_MultiTexCoord0.x) * (gl_Color.x*wtex0x + gl_Color.y*rtex0x + gl_Color.a*wtex0x),
gl_Color.x*wtex0y + gl_Color.y*rtex0y + gl_Color.a*wtex0y);
vec2 tex1 = vec2(gl_Color.x*wtex1x + gl_Color.y*wtex1x + gl_Color.a*stex1x,
wtex1y);
gl_TexCoord[0].x = tex0.x + gl_MultiTexCoord0.x * tex1.x;
gl_TexCoord[0].y = tex0.y + gl_MultiTexCoord0.y * tex1.y;}