Reduce shader attribute usage by packing floats
Previously we required 6 shader attributes to pass in all the required information for the building shader. By using packing techniques this has been reduced to 4. This should improve support for integrated graphics cards.
This commit is contained in:
parent
7b16a0cda4
commit
fc27175690
6 changed files with 175 additions and 162 deletions
|
@ -170,21 +170,13 @@
|
||||||
<index>11</index>
|
<index>11</index>
|
||||||
</attribute>
|
</attribute>
|
||||||
<attribute>
|
<attribute>
|
||||||
<name>rotPitchWtexX0</name>
|
<name>attrib1</name>
|
||||||
<index>12</index>
|
<index>12</index>
|
||||||
</attribute>
|
</attribute>
|
||||||
<attribute>
|
<attribute>
|
||||||
<name>wtexY0FRtexx1FSRtexY1</name>
|
<name>attrib2</name>
|
||||||
<index>13</index>
|
<index>13</index>
|
||||||
</attribute>
|
</attribute>
|
||||||
<attribute>
|
|
||||||
<name>rtexX0RtexY0StexX1</name>
|
|
||||||
<index>14</index>
|
|
||||||
</attribute>
|
|
||||||
<attribute>
|
|
||||||
<name>rooftopscale</name>
|
|
||||||
<index>15</index>
|
|
||||||
</attribute>
|
|
||||||
</program>
|
</program>
|
||||||
</pass>
|
</pass>
|
||||||
</technique>
|
</technique>
|
||||||
|
@ -224,21 +216,13 @@
|
||||||
<index>11</index>
|
<index>11</index>
|
||||||
</attribute>
|
</attribute>
|
||||||
<attribute>
|
<attribute>
|
||||||
<name>rotPitchWtexX0</name>
|
<name>attrib1</name>
|
||||||
<index>12</index>
|
<index>12</index>
|
||||||
</attribute>
|
</attribute>
|
||||||
<attribute>
|
<attribute>
|
||||||
<name>wtexY0FRtexx1FSRtexY1</name>
|
<name>attrib2</name>
|
||||||
<index>13</index>
|
<index>13</index>
|
||||||
</attribute>
|
</attribute>
|
||||||
<attribute>
|
|
||||||
<name>rtexX0RtexY0StexX1</name>
|
|
||||||
<index>14</index>
|
|
||||||
</attribute>
|
|
||||||
<attribute>
|
|
||||||
<name>rooftopscale</name>
|
|
||||||
<index>15</index>
|
|
||||||
</attribute>
|
|
||||||
</program>
|
</program>
|
||||||
</pass>
|
</pass>
|
||||||
</technique>
|
</technique>
|
||||||
|
@ -289,20 +273,12 @@
|
||||||
<index>11</index>
|
<index>11</index>
|
||||||
</attribute>
|
</attribute>
|
||||||
<attribute>
|
<attribute>
|
||||||
<name>rotPitchWtexX0</name>
|
<name>attrib1</name>
|
||||||
<index>12</index>
|
<index>12</index>
|
||||||
</attribute>
|
</attribute>
|
||||||
<attribute>
|
<attribute>
|
||||||
<name>wtexY0FRtexx1FSRtexY1</name>
|
<name>attrib2</name>
|
||||||
<index>13</index>
|
<index>13</index>
|
||||||
</attribute>
|
|
||||||
<attribute>
|
|
||||||
<name>rtexX0RtexY0StexX1</name>
|
|
||||||
<index>14</index>
|
|
||||||
</attribute>
|
|
||||||
<attribute>
|
|
||||||
<name>rooftopscale</name>
|
|
||||||
<index>15</index>
|
|
||||||
</attribute>
|
</attribute>
|
||||||
</program>
|
</program>
|
||||||
</pass>
|
</pass>
|
||||||
|
@ -354,20 +330,12 @@
|
||||||
<index>11</index>
|
<index>11</index>
|
||||||
</attribute>
|
</attribute>
|
||||||
<attribute>
|
<attribute>
|
||||||
<name>rotPitchWtexX0</name>
|
<name>attrib1</name>
|
||||||
<index>12</index>
|
<index>12</index>
|
||||||
</attribute>
|
</attribute>
|
||||||
<attribute>
|
<attribute>
|
||||||
<name>wtexY0FRtexx1FSRtexY1</name>
|
<name>attrib2</name>
|
||||||
<index>13</index>
|
<index>13</index>
|
||||||
</attribute>
|
|
||||||
<attribute>
|
|
||||||
<name>rtexX0RtexY0StexX1</name>
|
|
||||||
<index>14</index>
|
|
||||||
</attribute>
|
|
||||||
<attribute>
|
|
||||||
<name>rooftopscale</name>
|
|
||||||
<index>15</index>
|
|
||||||
</attribute>
|
</attribute>
|
||||||
</program>
|
</program>
|
||||||
</pass>
|
</pass>
|
||||||
|
@ -419,20 +387,12 @@
|
||||||
<index>11</index>
|
<index>11</index>
|
||||||
</attribute>
|
</attribute>
|
||||||
<attribute>
|
<attribute>
|
||||||
<name>rotPitchWtexX0</name>
|
<name>attrib1</name>
|
||||||
<index>12</index>
|
<index>12</index>
|
||||||
</attribute>
|
</attribute>
|
||||||
<attribute>
|
<attribute>
|
||||||
<name>wtexY0FRtexx1FSRtexY1</name>
|
<name>attrib2</name>
|
||||||
<index>13</index>
|
<index>13</index>
|
||||||
</attribute>
|
|
||||||
<attribute>
|
|
||||||
<name>rtexX0RtexY0StexX1</name>
|
|
||||||
<index>14</index>
|
|
||||||
</attribute>
|
|
||||||
<attribute>
|
|
||||||
<name>rooftopscale</name>
|
|
||||||
<index>15</index>
|
|
||||||
</attribute>
|
</attribute>
|
||||||
</program>
|
</program>
|
||||||
</pass>
|
</pass>
|
||||||
|
@ -457,20 +417,12 @@
|
||||||
<index>11</index>
|
<index>11</index>
|
||||||
</attribute>
|
</attribute>
|
||||||
<attribute>
|
<attribute>
|
||||||
<name>rotPitchWtexX0</name>
|
<name>attrib1</name>
|
||||||
<index>12</index>
|
<index>12</index>
|
||||||
</attribute>
|
</attribute>
|
||||||
<attribute>
|
<attribute>
|
||||||
<name>wtexY0FRtexx1FSRtexY1</name>
|
<name>attrib2</name>
|
||||||
<index>13</index>
|
<index>13</index>
|
||||||
</attribute>
|
|
||||||
<attribute>
|
|
||||||
<name>rtexX0RtexY0StexX1</name>
|
|
||||||
<index>14</index>
|
|
||||||
</attribute>
|
|
||||||
<attribute>
|
|
||||||
<name>rooftopscale</name>
|
|
||||||
<index>15</index>
|
|
||||||
</attribute>
|
</attribute>
|
||||||
</program>
|
</program>
|
||||||
</pass>
|
</pass>
|
||||||
|
@ -568,21 +520,13 @@
|
||||||
<index>11</index>
|
<index>11</index>
|
||||||
</attribute>
|
</attribute>
|
||||||
<attribute>
|
<attribute>
|
||||||
<name>rotPitchWtexX0</name>
|
<name>attrib1</name>
|
||||||
<index>12</index>
|
<index>12</index>
|
||||||
</attribute>
|
</attribute>
|
||||||
<attribute>
|
<attribute>
|
||||||
<name>wtexY0FRtexx1FSRtexY1</name>
|
<name>attrib2</name>
|
||||||
<index>13</index>
|
<index>13</index>
|
||||||
</attribute>
|
</attribute>
|
||||||
<attribute>
|
|
||||||
<name>rtexX0RtexY0StexX1</name>
|
|
||||||
<index>14</index>
|
|
||||||
</attribute>
|
|
||||||
<attribute>
|
|
||||||
<name>rooftopscale</name>
|
|
||||||
<index>15</index>
|
|
||||||
</attribute>
|
|
||||||
</program>
|
</program>
|
||||||
<uniform>
|
<uniform>
|
||||||
<name>fogType</name>
|
<name>fogType</name>
|
||||||
|
|
|
@ -18,10 +18,8 @@
|
||||||
|
|
||||||
attribute vec3 instancePosition; // (x,y,z)
|
attribute vec3 instancePosition; // (x,y,z)
|
||||||
attribute vec3 instanceScale; // (width, depth, height)
|
attribute vec3 instanceScale; // (width, depth, height)
|
||||||
attribute vec3 rotPitchWtexX0; // (rotation, pitch height, wall texture x0)
|
attribute vec3 attrib1; // Generic packed attributes
|
||||||
attribute vec3 wtexY0FRtexx1FSRtexY1; // (wall texture y0, front/roof texture x1, front/side/roof texture y1)
|
attribute vec3 attrib2;
|
||||||
attribute vec3 rtexX0RtexY0StexX1; // (roof texture x0, roof texture y0, side texture x1)
|
|
||||||
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
|
||||||
|
@ -68,6 +66,16 @@ if (x < -15.0) {return 0.0;}
|
||||||
return e / pow((1.0 + a * exp(-b * (x-c)) ),(1.0/d));
|
return e / pow((1.0 + a * exp(-b * (x-c)) ),(1.0/d));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const float c_precision = 128.0;
|
||||||
|
const float c_precisionp1 = c_precision + 1.0;
|
||||||
|
|
||||||
|
vec3 float2vec(float value) {
|
||||||
|
vec3 val;
|
||||||
|
val.x = mod(value, c_precisionp1) / c_precision;
|
||||||
|
val.y = mod(floor(value / c_precisionp1), c_precisionp1) / c_precision;
|
||||||
|
val.z = floor(value / (c_precisionp1 * c_precisionp1)) / c_precision;
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
|
@ -82,20 +90,25 @@ void main()
|
||||||
float scattering;
|
float scattering;
|
||||||
vec3 shadedFogColor = vec3(0.55, 0.67, 0.88);
|
vec3 shadedFogColor = vec3(0.55, 0.67, 0.88);
|
||||||
|
|
||||||
|
// Unpack generic attributes
|
||||||
|
vec3 attr1 = float2vec(attrib1.x);
|
||||||
|
vec3 attr2 = float2vec(attrib1.z);
|
||||||
|
vec3 attr3 = float2vec(attrib2.x);
|
||||||
|
|
||||||
// Determine the rotation for the building.
|
// Determine the rotation for the building.
|
||||||
float sr = sin(6.28 * rotPitchWtexX0.x);
|
float sr = sin(6.28 * attr1.x);
|
||||||
float cr = cos(6.28 * rotPitchWtexX0.x);
|
float cr = cos(6.28 * attr1.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
|
||||||
// the rooftop - gambled, gabled etc. These vertices are identified by gl_Color.z
|
// 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.x = (1.0 - gl_Color.z) * position.x + gl_Color.z * ((position.x + 0.5) * attr3.z - 0.5);
|
||||||
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 * attrib2.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 (instanceScale.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 * rotPitchWtexX0.y / instanceScale.z;
|
position.z = position.z + gl_Color.z * attrib1.y / instanceScale.z;
|
||||||
position = position * instanceScale.xyz;
|
position = position * instanceScale.xyz;
|
||||||
|
|
||||||
// Rotation of the building and movement into position
|
// Rotation of the building and movement into position
|
||||||
|
@ -115,13 +128,13 @@ void main()
|
||||||
// gl_Color.z=1 indicates top roof vertexs (used above)
|
// gl_Color.z=1 indicates top roof vertexs (used above)
|
||||||
// gl_Color.a=1 indicates sides
|
// gl_Color.a=1 indicates sides
|
||||||
// Finally, the roof texture is on the right of the texture sheet
|
// Finally, the roof texture is on the right of the texture sheet
|
||||||
float wtex0x = rotPitchWtexX0.z; // Front/Side texture X0
|
float wtex0x = attr1.y; // Front/Side texture X0
|
||||||
float wtex0y = wtexY0FRtexx1FSRtexY1.x; // Front/Side texture Y0
|
float wtex0y = attr1.z; // Front/Side texture Y0
|
||||||
float rtex0x = rtexX0RtexY0StexX1.x; // Roof texture X0
|
float rtex0x = attr2.z; // Roof texture X0
|
||||||
float rtex0y = rtexX0RtexY0StexX1.y; // Roof texture Y0
|
float rtex0y = attr3.x; // Roof texture Y0
|
||||||
float wtex1x = wtexY0FRtexx1FSRtexY1.y; // Front/Roof texture X1
|
float wtex1x = attr2.x; // Front/Roof texture X1
|
||||||
float stex1x = rtexX0RtexY0StexX1.z; // Side texture X1
|
float stex1x = attr3.y; // Side texture X1
|
||||||
float wtex1y = wtexY0FRtexx1FSRtexY1.z; // Front/Roof/Side texture Y1
|
float wtex1y = attr2.y; // Front/Roof/Side texture Y1
|
||||||
vec2 tex0 = vec2(sign(gl_MultiTexCoord0.x) * (gl_Color.x*wtex0x + gl_Color.y*rtex0x + gl_Color.a*wtex0x),
|
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);
|
gl_Color.x*wtex0y + gl_Color.y*rtex0y + gl_Color.a*wtex0y);
|
||||||
|
|
||||||
|
|
|
@ -14,11 +14,9 @@
|
||||||
#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 instanceScale ; // (width, depth, height)
|
attribute vec3 instanceScale ; // (width, depth, height)
|
||||||
attribute vec3 rotPitchWtexX0; // (rotation, pitch height, wall texture x0)
|
attribute vec3 attrib1; // Generic packed attributes
|
||||||
attribute vec3 wtexY0FRtexx1FSRtexY1; // (wall texture y0, front/roof texture x1, front/side/roof texture y1)
|
attribute vec3 attrib2;
|
||||||
attribute vec3 rtexX0RtexY0StexX1; // (roof texture x0, roof texture y0, side texture x1)
|
|
||||||
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
|
||||||
|
@ -35,22 +33,38 @@ uniform int colorMode;
|
||||||
//void fog_Func(int type);
|
//void fog_Func(int type);
|
||||||
/////////////////////////
|
/////////////////////////
|
||||||
|
|
||||||
|
const float c_precision = 128.0;
|
||||||
|
const float c_precisionp1 = c_precision + 1.0;
|
||||||
|
|
||||||
|
vec3 float2vec(float value) {
|
||||||
|
vec3 val;
|
||||||
|
val.x = mod(value, c_precisionp1) / c_precision;
|
||||||
|
val.y = mod(floor(value / c_precisionp1), c_precisionp1) / c_precision;
|
||||||
|
val.z = floor(value / (c_precisionp1 * c_precisionp1)) / c_precision;
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
// Determine the rotation for the building.
|
// Unpack generic attributes
|
||||||
float sr = sin(6.28 * rotPitchWtexX0.x);
|
vec3 attr1 = float2vec(attrib1.x);
|
||||||
float cr = cos(6.28 * rotPitchWtexX0.x);
|
vec3 attr2 = float2vec(attrib1.z);
|
||||||
|
vec3 attr3 = float2vec(attrib2.x);
|
||||||
|
|
||||||
|
// Determine the rotation for the building.
|
||||||
|
float sr = sin(6.28 * attr1.x);
|
||||||
|
float cr = cos(6.28 * attr1.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
|
||||||
// the rooftop - gambled, gabled etc. These vertices are identified by gl_Color.z
|
// 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.x = (1.0 - gl_Color.z) * position.x + gl_Color.z * ((position.x + 0.5) * attr3.z - 0.5);
|
||||||
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 * attrib2.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 (instanceScale.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 * rotPitchWtexX0.y / instanceScale.z;
|
position.z = position.z + gl_Color.z * attrib1.y / instanceScale.z;
|
||||||
position = position * instanceScale.xyz;
|
position = position * instanceScale.xyz;
|
||||||
|
|
||||||
// Rotation of the building and movement into position
|
// Rotation of the building and movement into position
|
||||||
|
@ -70,13 +84,13 @@ void main()
|
||||||
// gl_Color.z=1 indicates top roof vertexs (used above)
|
// gl_Color.z=1 indicates top roof vertexs (used above)
|
||||||
// gl_Color.a=1 indicates sides
|
// gl_Color.a=1 indicates sides
|
||||||
// Finally, the roof texture is on the right of the texture sheet
|
// Finally, the roof texture is on the right of the texture sheet
|
||||||
float wtex0x = rotPitchWtexX0.z; // Front/Side texture X0
|
float wtex0x = attr1.y; // Front/Side texture X0
|
||||||
float wtex0y = wtexY0FRtexx1FSRtexY1.x; // Front/Side texture Y0
|
float wtex0y = attr1.z; // Front/Side texture Y0
|
||||||
float rtex0x = rtexX0RtexY0StexX1.x; // Roof texture X0
|
float rtex0x = attr2.z; // Roof texture X0
|
||||||
float rtex0y = rtexX0RtexY0StexX1.y; // Roof texture Y0
|
float rtex0y = attr3.x; // Roof texture Y0
|
||||||
float wtex1x = wtexY0FRtexx1FSRtexY1.y; // Front/Roof texture X1
|
float wtex1x = attr2.x; // Front/Roof texture X1
|
||||||
float stex1x = rtexX0RtexY0StexX1.z; // Side texture X1
|
float stex1x = attr3.y; // Side texture X1
|
||||||
float wtex1y = wtexY0FRtexx1FSRtexY1.z; // Front/Roof/Side texture Y1
|
float wtex1y = attr2.y; // Front/Roof/Side texture Y1
|
||||||
vec2 tex0 = vec2(sign(gl_MultiTexCoord0.x) * (gl_Color.x*wtex0x + gl_Color.y*rtex0x + gl_Color.a*wtex0x),
|
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);
|
gl_Color.x*wtex0y + gl_Color.y*rtex0y + gl_Color.a*wtex0y);
|
||||||
|
|
||||||
|
|
|
@ -7,29 +7,43 @@
|
||||||
|
|
||||||
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 rotPitchWtexX0; // (rotation, pitch height, wall texture x0)
|
attribute vec3 attrib1; // Generic packed attributes
|
||||||
attribute vec3 wtexY0FRtexx1FSRtexY1; // (wall texture y0, front/roof texture x1, front/side/roof texture y1)
|
attribute vec3 attrib2;
|
||||||
attribute vec3 rtexX0RtexY0StexX1; // (roof texture x0, roof texture y0, side texture x1)
|
|
||||||
attribute vec3 rooftopscale; // (rooftop x scale, rooftop y scale)
|
|
||||||
|
|
||||||
varying vec3 ecNormal;
|
varying vec3 ecNormal;
|
||||||
varying float alpha;
|
varying float alpha;
|
||||||
|
|
||||||
|
const float c_precision = 128.0;
|
||||||
|
const float c_precisionp1 = c_precision + 1.0;
|
||||||
|
|
||||||
|
vec3 float2vec(float value) {
|
||||||
|
vec3 val;
|
||||||
|
val.x = mod(value, c_precisionp1) / c_precision;
|
||||||
|
val.y = mod(floor(value / c_precisionp1), c_precisionp1) / c_precision;
|
||||||
|
val.z = floor(value / (c_precisionp1 * c_precisionp1)) / c_precision;
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
// Unpack generic attributes
|
||||||
|
vec3 attr1 = float2vec(attrib1.x);
|
||||||
|
vec3 attr2 = float2vec(attrib1.z);
|
||||||
|
vec3 attr3 = float2vec(attrib2.x);
|
||||||
|
|
||||||
// Determine the rotation for the building.
|
// Determine the rotation for the building.
|
||||||
float sr = sin(6.28 * rotPitchWtexX0.x);
|
float sr = sin(6.28 * attr1.x);
|
||||||
float cr = cos(6.28 * rotPitchWtexX0.x);
|
float cr = cos(6.28 * attr1.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
|
||||||
// the rooftop - gambled, gabled etc. These vertices are identified by gl_Color.z
|
// 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.x = (1.0 - gl_Color.z) * position.x + gl_Color.z * ((position.x + 0.5) * attr3.z - 0.5);
|
||||||
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 * attrib2.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 (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 * rotPitchWtexX0.y / instanceScaleRotate.z;
|
position.z = position.z + gl_Color.z * attrib1.y / instanceScale.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,22 +63,22 @@ void main() {
|
||||||
// gl_Color.z=1 indicates top roof vertexs (used above)
|
// gl_Color.z=1 indicates top roof vertexs (used above)
|
||||||
// gl_Color.a=1 indicates sides
|
// gl_Color.a=1 indicates sides
|
||||||
// Finally, the roof texture is on the right of the texture sheet
|
// Finally, the roof texture is on the right of the texture sheet
|
||||||
float wtex0x = rotPitchWtexX0.z; // Front/Side texture X0
|
float wtex0x = attr1.y; // Front/Side texture X0
|
||||||
float wtex0y = wtexY0FRtexx1FSRtexY1.x; // Front/Side texture Y0
|
float wtex0y = attr1.z; // Front/Side texture Y0
|
||||||
float rtex0x = rtexX0RtexY0StexX1.x; // Roof texture X0
|
float rtex0x = attr2.z; // Roof texture X0
|
||||||
float rtex0y = rtexX0RtexY0StexX1.y; // Roof texture Y0
|
float rtex0y = attr3.x; // Roof texture Y0
|
||||||
float wtex1x = wtexY0FRtexx1FSRtexY1.y; // Front/Roof texture X1
|
float wtex1x = attr2.x; // Front/Roof texture X1
|
||||||
float stex1x = rtexX0RtexY0StexX1.z; // Side texture X1
|
float stex1x = attr3.y; // Side texture X1
|
||||||
float wtex1y = wtexY0FRtexx1FSRtexY1.z; // Front/Roof/Side texture Y1
|
float wtex1y = attr2.y; // Front/Roof/Side texture Y1
|
||||||
vec2 tex0 = vec2(sign(gl_MultiTexCoord0.x) * (gl_Color.x*wtex0x + gl_Color.y*rtex0x + gl_Color.a*wtex0x),
|
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);
|
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,
|
vec2 tex1 = vec2(gl_Color.x*wtex1x + gl_Color.y*wtex1x + gl_Color.a*stex1x,
|
||||||
wtex1y);
|
wtex1y);
|
||||||
|
|
||||||
|
gl_TexCoord[0].x = tex0.x + gl_MultiTexCoord0.x * tex1.x;
|
||||||
|
gl_TexCoord[0].y = tex0.y + gl_MultiTexCoord0.y * tex1.y;
|
||||||
|
|
||||||
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;
|
||||||
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)));
|
||||||
|
|
|
@ -5,10 +5,8 @@
|
||||||
|
|
||||||
attribute vec3 instancePosition; // (x,y,z)
|
attribute vec3 instancePosition; // (x,y,z)
|
||||||
attribute vec3 instanceScale ; // (width, depth, height)
|
attribute vec3 instanceScale ; // (width, depth, height)
|
||||||
attribute vec3 rotPitchWtexX0; // (rotation, pitch height, wall texture x0)
|
attribute vec3 attrib1; // Generic packed attributes
|
||||||
attribute vec3 wtexY0FRtexx1FSRtexY1; // (wall texture y0, front/roof texture x1, front/side/roof texture y1)
|
attribute vec3 attrib2;
|
||||||
attribute vec3 rtexX0RtexY0StexX1; // (roof texture x0, roof texture y0, side texture x1)
|
|
||||||
attribute vec3 rooftopscale; // (rooftop x scale, rooftop y scale)
|
|
||||||
|
|
||||||
varying vec3 rawpos;
|
varying vec3 rawpos;
|
||||||
varying vec3 VNormal;
|
varying vec3 VNormal;
|
||||||
|
@ -53,23 +51,38 @@ void rotationMatrixH(in float sinRz, in float cosRz, out mat4 rotmat)
|
||||||
0.0 , 0.0 , 0.0, 1.0 );
|
0.0 , 0.0 , 0.0, 1.0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const float c_precision = 128.0;
|
||||||
|
const float c_precisionp1 = c_precision + 1.0;
|
||||||
|
|
||||||
|
vec3 float2vec(float value) {
|
||||||
|
vec3 val;
|
||||||
|
val.x = mod(value, c_precisionp1) / c_precision;
|
||||||
|
val.y = mod(floor(value / c_precisionp1), c_precisionp1) / c_precision;
|
||||||
|
val.z = floor(value / (c_precisionp1 * c_precisionp1)) / c_precision;
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
void main(void)
|
void main(void)
|
||||||
{
|
{
|
||||||
// Determine the rotation for the building.
|
// Unpack generic attributes
|
||||||
float sr = sin(6.28 * rotPitchWtexX0.x);
|
vec3 attr1 = float2vec(attrib1.x);
|
||||||
float cr = cos(6.28 * rotPitchWtexX0.x);
|
vec3 attr2 = float2vec(attrib1.z);
|
||||||
|
vec3 attr3 = float2vec(attrib2.x);
|
||||||
|
|
||||||
|
// Determine the rotation for the building.
|
||||||
|
float sr = sin(6.28 * attr1.x);
|
||||||
|
float cr = cos(6.28 * attr1.x);
|
||||||
|
|
||||||
vec3 rawpos = gl_Vertex.xyz;
|
vec3 rawpos = 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
|
||||||
// the rooftop - gambled, gabled etc. These vertices are identified by gl_Color.z
|
// 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.x = (1.0 - gl_Color.z) * rawpos.x + gl_Color.z * ((rawpos.x + 0.5) * attr3.z - 0.5);
|
||||||
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 * attrib2.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 (instanceScale.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 * rotPitchWtexX0.y / instanceScale.z;
|
rawpos.z = rawpos.z + gl_Color.z * attrib1.y / instanceScale.z;
|
||||||
rawpos = rawpos * instanceScale.xyz;
|
rawpos = rawpos * instanceScale.xyz;
|
||||||
|
|
||||||
// Rotation of the building and movement into rawpos
|
// Rotation of the building and movement into rawpos
|
||||||
|
@ -88,13 +101,13 @@ void main(void)
|
||||||
// gl_Color.z=1 indicates top roof vertexs (used above)
|
// gl_Color.z=1 indicates top roof vertexs (used above)
|
||||||
// gl_Color.a=1 indicates sides
|
// gl_Color.a=1 indicates sides
|
||||||
// Finally, the roof texture is on the right of the texture sheet
|
// Finally, the roof texture is on the right of the texture sheet
|
||||||
float wtex0x = rotPitchWtexX0.z; // Front/Side texture X0
|
float wtex0x = attr1.y; // Front/Side texture X0
|
||||||
float wtex0y = wtexY0FRtexx1FSRtexY1.x; // Front/Side texture Y0
|
float wtex0y = attr1.z; // Front/Side texture Y0
|
||||||
float rtex0x = rtexX0RtexY0StexX1.x; // Roof texture X0
|
float rtex0x = attr2.z; // Roof texture X0
|
||||||
float rtex0y = rtexX0RtexY0StexX1.y; // Roof texture Y0
|
float rtex0y = attr3.x; // Roof texture Y0
|
||||||
float wtex1x = wtexY0FRtexx1FSRtexY1.y; // Front/Roof texture X1
|
float wtex1x = attr2.x; // Front/Roof texture X1
|
||||||
float stex1x = rtexX0RtexY0StexX1.z; // Side texture X1
|
float stex1x = attr3.y; // Side texture X1
|
||||||
float wtex1y = wtexY0FRtexx1FSRtexY1.z; // Front/Roof/Side texture Y1
|
float wtex1y = attr2.y; // Front/Roof/Side texture Y1
|
||||||
vec2 tex0 = vec2(sign(gl_MultiTexCoord0.x) * (gl_Color.x*wtex0x + gl_Color.y*rtex0x + gl_Color.a*wtex0x),
|
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);
|
gl_Color.x*wtex0y + gl_Color.y*rtex0y + gl_Color.a*wtex0y);
|
||||||
|
|
||||||
|
|
|
@ -19,27 +19,41 @@ uniform int rembrandt_enabled;
|
||||||
|
|
||||||
attribute vec3 instancePosition; // (x,y,z)
|
attribute vec3 instancePosition; // (x,y,z)
|
||||||
attribute vec3 instanceScale; // (width, depth, height)
|
attribute vec3 instanceScale; // (width, depth, height)
|
||||||
attribute vec3 rotPitchWtexX0; // (rotation, pitch height, wall texture x0)
|
attribute vec3 attrib1; // Generic packed attributes
|
||||||
attribute vec3 wtexY0FRtexx1FSRtexY1; // (wall texture y0, front/roof texture x1, front/side/roof texture y1)
|
attribute vec3 attrib2;
|
||||||
attribute vec3 rtexX0RtexY0StexX1; // (roof texture x0, roof texture y0, side texture x1)
|
|
||||||
attribute vec3 rooftopscale; // (rooftop x scale, rooftop y scale)
|
const float c_precision = 128.0;
|
||||||
|
const float c_precisionp1 = c_precision + 1.0;
|
||||||
|
|
||||||
|
vec3 float2vec(float value) {
|
||||||
|
vec3 val;
|
||||||
|
val.x = mod(value, c_precisionp1) / c_precision;
|
||||||
|
val.y = mod(floor(value / c_precisionp1), c_precisionp1) / c_precision;
|
||||||
|
val.z = floor(value / (c_precisionp1 * c_precisionp1)) / c_precision;
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
void main(void)
|
void main(void)
|
||||||
{
|
{
|
||||||
|
// Unpack generic attributes
|
||||||
|
vec3 attr1 = float2vec(attrib1.x);
|
||||||
|
vec3 attr2 = float2vec(attrib1.z);
|
||||||
|
vec3 attr3 = float2vec(attrib2.x);
|
||||||
|
|
||||||
// Determine the rotation for the building.
|
// Determine the rotation for the building.
|
||||||
float sr = sin(6.28 * rotPitchWtexX0.x);
|
float sr = sin(6.28 * attr1.x);
|
||||||
float cr = cos(6.28 * rotPitchWtexX0.x);
|
float cr = cos(6.28 * attr1.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
|
||||||
// the rooftop - gambled, gabled etc. These vertices are identified by gl_Color.z
|
// 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.x = (1.0 - gl_Color.z) * position.x + gl_Color.z * ((position.x + 0.5) * attr3.z - 0.5);
|
||||||
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 * attrib2.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 (instanceScale.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 * rotPitchWtexX0.y / instanceScale.z;
|
position.z = position.z + gl_Color.z * attrib1.y / instanceScale.z;
|
||||||
position = position * instanceScale.xyz;
|
position = position * instanceScale.xyz;
|
||||||
|
|
||||||
// Rotation of the building and movement into position
|
// Rotation of the building and movement into position
|
||||||
|
@ -94,18 +108,19 @@ void main(void)
|
||||||
// gl_Color.z=1 indicates top roof vertexs (used above)
|
// gl_Color.z=1 indicates top roof vertexs (used above)
|
||||||
// gl_Color.a=1 indicates sides
|
// gl_Color.a=1 indicates sides
|
||||||
// Finally, the roof texture is on the right of the texture sheet
|
// Finally, the roof texture is on the right of the texture sheet
|
||||||
float wtex0x = rotPitchWtexX0.z; // Front/Side texture X0
|
float wtex0x = attr1.y; // Front/Side texture X0
|
||||||
float wtex0y = wtexY0FRtexx1FSRtexY1.x; // Front/Side texture Y0
|
float wtex0y = attr1.z; // Front/Side texture Y0
|
||||||
float rtex0x = rtexX0RtexY0StexX1.x; // Roof texture X0
|
float rtex0x = attr2.z; // Roof texture X0
|
||||||
float rtex0y = rtexX0RtexY0StexX1.y; // Roof texture Y0
|
float rtex0y = attr3.x; // Roof texture Y0
|
||||||
float wtex1x = wtexY0FRtexx1FSRtexY1.y; // Front/Roof texture X1
|
float wtex1x = attr2.x; // Front/Roof texture X1
|
||||||
float stex1x = rtexX0RtexY0StexX1.z; // Side texture X1
|
float stex1x = attr3.y; // Side texture X1
|
||||||
float wtex1y = wtexY0FRtexx1FSRtexY1.z; // Front/Roof/Side texture Y1
|
float wtex1y = attr2.y; // Front/Roof/Side texture Y1
|
||||||
vec2 tex0 = vec2(sign(gl_MultiTexCoord0.x) * (gl_Color.x*wtex0x + gl_Color.y*rtex0x + gl_Color.a*wtex0x),
|
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);
|
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,
|
vec2 tex1 = vec2(gl_Color.x*wtex1x + gl_Color.y*wtex1x + gl_Color.a*stex1x,
|
||||||
wtex1y);
|
wtex1y);
|
||||||
|
|
||||||
gl_TexCoord[0].x = tex0.x + gl_MultiTexCoord0.x * tex1.x;
|
gl_TexCoord[0].x = tex0.x + gl_MultiTexCoord0.x * tex1.x;
|
||||||
gl_TexCoord[0].y = tex0.y + gl_MultiTexCoord0.y * tex1.y;}
|
gl_TexCoord[0].y = tex0.y + gl_MultiTexCoord0.y * tex1.y;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue