Shader buildings - split wall and roof tex index
Previously there was very limited texture variations as a given texture index was used for both the wall and ceiling. Now these can be specified separately, allowing for more variation in both STG defined and random buildings. Requires simgear commit 053bda26a43314a91b01b08cd4617da82f7ab807
This commit is contained in:
parent
ed375fa632
commit
87e9118965
7 changed files with 136 additions and 71 deletions
|
@ -400,7 +400,7 @@ See README.materials for details on configuring the random building parameters.
|
|||
|
||||
The referenced <filename> (in the example buildings.txt) contains lines of the form
|
||||
|
||||
X Y Z R B W D H P S O F T
|
||||
X Y Z R B W D H P S O F WT RT
|
||||
|
||||
Where:
|
||||
- X,Y,Z are the cartesian coordinates of the center of the front face. +X is East, +Y is North
|
||||
|
@ -417,7 +417,8 @@ Where:
|
|||
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)
|
||||
- T is the texture index to use (integer). Buildings with the same T value will have the same texture assigned. There are 6 small, 6 medium and 4 large textures.
|
||||
- WT is the texture index to use for walls (integer). Buildings with the same WT value will have the same wall texture assigned. There are 6 small, 6 medium and 4 large textures.
|
||||
- RT is the texture index to use for roofs (integer). Buildings with the same RT value will have the same roof texture assigned. There are 6 small, 6 medium and 4 large textures.
|
||||
|
||||
<x> <y> <z> <rot> <type>
|
||||
|
||||
|
|
|
@ -212,13 +212,17 @@
|
|||
<index>11</index>
|
||||
</attribute>
|
||||
<attribute>
|
||||
<name>rotPitchTex0x</name>
|
||||
<name>rotPitchWtex0x</name>
|
||||
<index>12</index>
|
||||
</attribute>
|
||||
<attribute>
|
||||
<name>tex0yTex1xTex1y</name>
|
||||
<name>wtex0yTex1xTex1y</name>
|
||||
<index>13</index>
|
||||
</attribute>
|
||||
<attribute>
|
||||
<name>rtex0xRtex0y</name>
|
||||
<index>14</index>
|
||||
</attribute>
|
||||
</program>
|
||||
</pass>
|
||||
</technique>
|
||||
|
@ -298,13 +302,17 @@
|
|||
<index>11</index>
|
||||
</attribute>
|
||||
<attribute>
|
||||
<name>rotPitchTex0x</name>
|
||||
<name>rotPitchWtex0x</name>
|
||||
<index>12</index>
|
||||
</attribute>
|
||||
<attribute>
|
||||
<name>tex0yTex1xTex1y</name>
|
||||
<name>wtex0yTex1xTex1y</name>
|
||||
<index>13</index>
|
||||
</attribute>
|
||||
<attribute>
|
||||
<name>rtex0xRtex0y</name>
|
||||
<index>14</index>
|
||||
</attribute>
|
||||
</program>
|
||||
<uniform>
|
||||
<name>texture</name>
|
||||
|
@ -373,13 +381,17 @@
|
|||
<index>11</index>
|
||||
</attribute>
|
||||
<attribute>
|
||||
<name>rotPitchTex0x</name>
|
||||
<name>rotPitchWtex0x</name>
|
||||
<index>12</index>
|
||||
</attribute>
|
||||
<attribute>
|
||||
<name>tex0yTex1xTex1y</name>
|
||||
<name>wtex0yTex1xTex1y</name>
|
||||
<index>13</index>
|
||||
</attribute>
|
||||
<attribute>
|
||||
<name>rtex0xRtex0y</name>
|
||||
<index>14</index>
|
||||
</attribute>
|
||||
</program>
|
||||
<uniform>
|
||||
<name>visibility</name>
|
||||
|
@ -503,12 +515,16 @@
|
|||
<index>11</index>
|
||||
</attribute>
|
||||
<attribute>
|
||||
<name>rotPitchTex0x</name>
|
||||
<name>rotPitchWtex0x</name>
|
||||
<index>12</index>
|
||||
</attribute>
|
||||
<attribute>
|
||||
<name>tex0yTex1xTex1y</name>
|
||||
<name>wtex0yTex1xTex1y</name>
|
||||
<index>13</index>
|
||||
</attribute>
|
||||
<attribute>
|
||||
<name>rtex0xRtex0y</name>
|
||||
<index>14</index>
|
||||
</attribute>
|
||||
</program>
|
||||
</pass>
|
||||
|
@ -559,12 +575,16 @@
|
|||
<index>11</index>
|
||||
</attribute>
|
||||
<attribute>
|
||||
<name>rotPitchTex0x</name>
|
||||
<name>rotPitchWtex0x</name>
|
||||
<index>12</index>
|
||||
</attribute>
|
||||
<attribute>
|
||||
<name>tex0yTex1xTex1y</name>
|
||||
<name>wtex0yTex1xTex1y</name>
|
||||
<index>13</index>
|
||||
</attribute>
|
||||
<attribute>
|
||||
<name>rtex0xRtex0y</name>
|
||||
<index>14</index>
|
||||
</attribute>
|
||||
</program>
|
||||
</pass>
|
||||
|
@ -673,13 +693,17 @@
|
|||
<index>11</index>
|
||||
</attribute>
|
||||
<attribute>
|
||||
<name>rotPitchTex0x</name>
|
||||
<name>rotPitchWtex0x</name>
|
||||
<index>12</index>
|
||||
</attribute>
|
||||
<attribute>
|
||||
<name>tex0yTex1xTex1y</name>
|
||||
<name>wtex0yTex1xTex1y</name>
|
||||
<index>13</index>
|
||||
</attribute>
|
||||
<attribute>
|
||||
<name>rtex0xRtex0y</name>
|
||||
<index>14</index>
|
||||
</attribute>
|
||||
</program>
|
||||
<!-- BEGIN fog include -->
|
||||
<!--<uniform>
|
||||
|
|
|
@ -18,8 +18,9 @@
|
|||
|
||||
attribute vec3 instancePosition; // (x,y,z)
|
||||
attribute vec3 instanceScaleRotate; // (width, depth, height)
|
||||
attribute vec3 rotPitchTex0x; // (rotation, pitch height, texture x offset)
|
||||
attribute vec3 tex0yTex1xTex1y; // (texture y offset, texture x gain, texture y gain)
|
||||
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)
|
||||
|
||||
// The constant term of the lighting equation that doesn't depend on
|
||||
// the surface normal is passed in gl_{Front,Back}Color. The alpha
|
||||
|
@ -81,17 +82,17 @@ void main()
|
|||
vec3 shadedFogColor = vec3(0.55, 0.67, 0.88);
|
||||
|
||||
// Determine the rotation for the building.
|
||||
float sr = sin(6.28 * rotPitchTex0x.x);
|
||||
float cr = cos(6.28 * rotPitchTex0x.x);
|
||||
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 (rotPitchTex0x.y * 2.0 because of the fractional z value),
|
||||
// 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 * rotPitchTex0x.y / instanceScaleRotate.z - fract(position.z);
|
||||
position.z = position.z + fract(position.z) * 2.0 * rotPitchWtex0x.y / instanceScaleRotate.z - fract(position.z);
|
||||
position = position * instanceScaleRotate.xyz;
|
||||
|
||||
// Rotation of the building and movement into position
|
||||
|
@ -100,10 +101,17 @@ void main()
|
|||
|
||||
gl_Position = gl_ModelViewProjectionMatrix * vec4(position,1.0);
|
||||
|
||||
// Texture coordinates are stored as tex0 and tex1 across two attributes.
|
||||
// tex0 contains the bottom leftmost point, and tex1 contains (w,h).
|
||||
gl_TexCoord[0].x = sign(gl_MultiTexCoord0.x) * rotPitchTex0x.z + gl_MultiTexCoord0.x * tex0yTex1xTex1y.y;
|
||||
gl_TexCoord[0].y = tex0yTex1xTex1y.x + gl_MultiTexCoord0.y * tex0yTex1xTex1y.z;
|
||||
// Texture coordinates are stored as:
|
||||
// - a separate offset for the wall (wtex0x, wtex0y), and roof (rtex0x, rtex0y)
|
||||
// - a shared gain value (tex1x, tex1y)
|
||||
//
|
||||
// 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);
|
||||
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;
|
||||
|
@ -113,7 +121,7 @@ void main()
|
|||
// 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(rotPitchTex0x.y, 0.0, 1.0) * normal + step(0.5, normal.z) * (1.0 - clamp(rotPitchTex0x.y, 0.0, 1.0)) * vec3(0,0,1);
|
||||
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)));
|
||||
|
|
|
@ -15,8 +15,9 @@
|
|||
|
||||
attribute vec3 instancePosition; // (x,y,z)
|
||||
attribute vec3 instanceScaleRotate; // (width, depth, height)
|
||||
attribute vec3 rotPitchTex0x; // (rotation, pitch height, texture x offset)
|
||||
attribute vec3 tex0yTex1xTex1y; // (texture y offset, texture x gain, texture y gain)
|
||||
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)
|
||||
|
||||
// The constant term of the lighting equation that doesn't depend on
|
||||
// the surface normal is passed in gl_{Front,Back}Color. The alpha
|
||||
|
@ -36,17 +37,17 @@ uniform int colorMode;
|
|||
void main()
|
||||
{
|
||||
// Determine the rotation for the building.
|
||||
float sr = sin(6.28 * rotPitchTex0x.x);
|
||||
float cr = cos(6.28 * rotPitchTex0x.x);
|
||||
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 (rotPitchTex0x.y * 2.0 because of the fractional z value),
|
||||
// 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 * rotPitchTex0x.y / instanceScaleRotate.z - fract(position.z);
|
||||
position.z = position.z + fract(position.z) * 2.0 * rotPitchWtex0x.y / instanceScaleRotate.z - fract(position.z);
|
||||
position = position * instanceScaleRotate.xyz;
|
||||
|
||||
// Rotation of the building and movement into position
|
||||
|
@ -55,10 +56,17 @@ void main()
|
|||
|
||||
gl_Position = gl_ModelViewProjectionMatrix * vec4(position,1.0);
|
||||
|
||||
// Texture coordinates are stored as tex0 and tex1 across two attributes.
|
||||
// tex0 contains the bottom leftmost point, and tex1 contains (w,h).
|
||||
gl_TexCoord[0].x = sign(gl_MultiTexCoord0.x) * rotPitchTex0x.z + gl_MultiTexCoord0.x * tex0yTex1xTex1y.y;
|
||||
gl_TexCoord[0].y = tex0yTex1xTex1y.x + gl_MultiTexCoord0.y * tex0yTex1xTex1y.z;
|
||||
// Texture coordinates are stored as:
|
||||
// - a separate offset for the wall (wtex0x, wtex0y), and roof (rtex0x, rtex0y)
|
||||
// - a shared gain value (tex1x, tex1y)
|
||||
//
|
||||
// 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);
|
||||
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;
|
||||
|
@ -68,7 +76,7 @@ void main()
|
|||
// 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(rotPitchTex0x.y, 0.0, 1.0) * normal + step(0.5, normal.z) * (1.0 - clamp(rotPitchTex0x.y, 0.0, 1.0)) * vec3(0,0,1);
|
||||
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)));
|
||||
|
|
|
@ -7,25 +7,26 @@
|
|||
|
||||
attribute vec3 instancePosition; // (x,y,z)
|
||||
attribute vec3 instanceScaleRotate; // (width, depth, height)
|
||||
attribute vec3 rotPitchTex0x; // (rotation, pitch height, texture x offset)
|
||||
attribute vec3 tex0yTex1xTex1y; // (texture y offset, texture x gain, texture y gain)
|
||||
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)
|
||||
|
||||
varying vec3 ecNormal;
|
||||
varying float alpha;
|
||||
|
||||
void main() {
|
||||
// Determine the rotation for the building.
|
||||
float sr = sin(6.28 * rotPitchTex0x.x);
|
||||
float cr = cos(6.28 * rotPitchTex0x.x);
|
||||
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 (rotPitchTex0x.y * 2.0 because of the fractional z value),
|
||||
// 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 * rotPitchTex0x.y / instanceScaleRotate.z - fract(position.z);
|
||||
position.z = position.z + fract(position.z) * 2.0 * rotPitchWtex0x.y / instanceScaleRotate.z - fract(position.z);
|
||||
position = position * instanceScaleRotate.xyz;
|
||||
|
||||
// Rotation of the building and movement into position
|
||||
|
@ -34,10 +35,17 @@ void main() {
|
|||
|
||||
gl_Position = gl_ModelViewProjectionMatrix * vec4(position,1.0);
|
||||
|
||||
// Texture coordinates are stored as tex0 and tex1 across two attributes.
|
||||
// tex0 contains the bottom leftmost point, and tex1 contains (w,h).
|
||||
gl_TexCoord[0].x = sign(gl_MultiTexCoord0.x) * rotPitchTex0x.z + gl_MultiTexCoord0.x * tex0yTex1xTex1y.y;
|
||||
gl_TexCoord[0].y = tex0yTex1xTex1y.x + gl_MultiTexCoord0.y * tex0yTex1xTex1y.z;
|
||||
// Texture coordinates are stored as:
|
||||
// - a separate offset for the wall (wtex0x, wtex0y), and roof (rtex0x, rtex0y)
|
||||
// - a shared gain value (tex1x, tex1y)
|
||||
//
|
||||
// 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);
|
||||
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.
|
||||
ecNormal = gl_Normal;
|
||||
|
@ -48,8 +56,8 @@ void main() {
|
|||
// 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(rotPitchTex0x.y, 0.0, 1.0) * ecNormal +
|
||||
step(0.5, ecNormal.z) * (1.0 - clamp(rotPitchTex0x.y, 0.0, 1.0)) * vec3(0,0,1);
|
||||
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)));
|
||||
|
|
|
@ -5,8 +5,9 @@
|
|||
|
||||
attribute vec3 instancePosition; // (x,y,z)
|
||||
attribute vec3 instanceScaleRotate; // (width, depth, height)
|
||||
attribute vec3 rotPitchTex0x; // (rotation, pitch height, texture x offset)
|
||||
attribute vec3 tex0yTex1xTex1y; // (texture y offset, texture x gain, texture y gain)
|
||||
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)
|
||||
|
||||
varying vec3 rawpos;
|
||||
varying vec3 VNormal;
|
||||
|
@ -54,17 +55,17 @@ void rotationMatrixH(in float sinRz, in float cosRz, out mat4 rotmat)
|
|||
void main(void)
|
||||
{
|
||||
// Determine the rotation for the building.
|
||||
float sr = sin(6.28 * rotPitchTex0x.x);
|
||||
float cr = cos(6.28 * rotPitchTex0x.x);
|
||||
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 (rotPitchTex0x.y * 2.0 because of the fractional z value),
|
||||
// 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.
|
||||
rawpos = gl_Vertex.xyz;
|
||||
rawpos.z = rawpos.z + fract(rawpos.z) * 2.0 * rotPitchTex0x.y / instanceScaleRotate.z - fract(rawpos.z);
|
||||
rawpos.z = rawpos.z + fract(rawpos.z) * 2.0 * rotPitchWtex0x.y / instanceScaleRotate.z - fract(rawpos.z);
|
||||
rawpos = rawpos * instanceScaleRotate.xyz;
|
||||
|
||||
// Rotation of the building and movement into rawpos
|
||||
|
@ -72,10 +73,17 @@ void main(void)
|
|||
rawpos = rawpos + instancePosition.xyz;
|
||||
vec4 ecPosition = gl_ModelViewMatrix * vec4(rawpos, 1.0);
|
||||
|
||||
// Texture coordinates are stored as tex0 and tex1 across two attributes.
|
||||
// tex0 contains the bottom leftmost point, and tex1 contains (w,h).
|
||||
gl_TexCoord[0].x = sign(gl_MultiTexCoord0.x) * rotPitchTex0x.z + gl_MultiTexCoord0.x * tex0yTex1xTex1y.y;
|
||||
gl_TexCoord[0].y = tex0yTex1xTex1y.x + gl_MultiTexCoord0.y * tex0yTex1xTex1y.z;
|
||||
// Texture coordinates are stored as:
|
||||
// - a separate offset for the wall (wtex0x, wtex0y), and roof (rtex0x, rtex0y)
|
||||
// - a shared gain value (tex1x, tex1y)
|
||||
//
|
||||
// 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);
|
||||
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.
|
||||
vec3 normal = gl_Normal;
|
||||
|
@ -86,8 +94,8 @@ void main(void)
|
|||
// 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(rotPitchTex0x.y, 0.0, 1.0) * normal +
|
||||
step(0.5, normal.z) * (1.0 - clamp(rotPitchTex0x.y, 0.0, 1.0)) * vec3(0,0,1);
|
||||
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)));
|
||||
|
|
|
@ -19,23 +19,24 @@ uniform int rembrandt_enabled;
|
|||
|
||||
attribute vec3 instancePosition; // (x,y,z)
|
||||
attribute vec3 instanceScaleRotate; // (width, depth, height)
|
||||
attribute vec3 rotPitchTex0x; // (rotation, pitch height, texture x offset)
|
||||
attribute vec3 tex0yTex1xTex1y; // (texture y offset, texture x gain, texture y gain)
|
||||
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)
|
||||
|
||||
void main(void)
|
||||
{
|
||||
// Determine the rotation for the building.
|
||||
float sr = sin(6.28 * rotPitchTex0x.x);
|
||||
float cr = cos(6.28 * rotPitchTex0x.x);
|
||||
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 (rotPitchTex0x.y * 2.0 because of the fractional z value),
|
||||
// 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 * rotPitchTex0x.y / instanceScaleRotate.z - fract(position.z);
|
||||
position.z = position.z + fract(position.z) * 2.0 * rotPitchWtex0x.y / instanceScaleRotate.z - fract(position.z);
|
||||
position = position * instanceScaleRotate.xyz;
|
||||
|
||||
// Rotation of the building and movement into position
|
||||
|
@ -55,7 +56,7 @@ void main(void)
|
|||
// 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(rotPitchTex0x.y, 0.0, 1.0) * normal + step(0.5, normal.z) * (1.0 - clamp(rotPitchTex0x.y, 0.0, 1.0)) * vec3(0,0,1);
|
||||
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)));
|
||||
|
@ -86,8 +87,15 @@ void main(void)
|
|||
}
|
||||
gl_ClipVertex = ecPosition;
|
||||
|
||||
// Texture coordinates are stored as tex0 and tex1 across two attributes.
|
||||
// tex0 contains the bottom leftmost point, and tex1 contains (w,h).
|
||||
gl_TexCoord[0].x = sign(gl_MultiTexCoord0.x) * rotPitchTex0x.z + gl_MultiTexCoord0.x * tex0yTex1xTex1y.y;
|
||||
gl_TexCoord[0].y = tex0yTex1xTex1y.x + gl_MultiTexCoord0.y * tex0yTex1xTex1y.z;
|
||||
// Texture coordinates are stored as:
|
||||
// - a separate offset for the wall (wtex0x, wtex0y), and roof (rtex0x, rtex0y)
|
||||
// - a shared gain value (tex1x, tex1y)
|
||||
//
|
||||
// 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);
|
||||
gl_TexCoord[0].x = tex0.x + gl_MultiTexCoord0.x * wtex0yTex1xTex1y.y;
|
||||
gl_TexCoord[0].y = tex0.y + gl_MultiTexCoord0.y * wtex0yTex1xTex1y.z;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue