Skip to content

Commit cf657f4

Browse files
committed
Compute size_factor only once
1 parent bd8e4e9 commit cf657f4

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

ogre_media/materials/glsl150/box.geom

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,10 @@ const vec4 axes[3] = vec4[] (
3939
const float lightness[6] = float[] (
4040
0.9, 0.5, 0.6, 0.6, 1.0, 0.4 );
4141

42-
43-
void emitVertex( int side, vec4 x, vec4 y, vec4 z, vec3 tex )
42+
void emitVertex( int side, vec4 x, vec4 y, vec4 z, vec3 tex, vec4 size_factor )
4443
{
45-
// if auto_size == 1, then size_factor == size*gl_Vertex.z
46-
// if auto_size == 0, then size_factor == size
47-
vec4 size_factor = (1-auto_size.x+(auto_size.x*gl_in[0].gl_Position.z))*size;
48-
4944
vec4 pos_rel = tex.x*x + tex.y*y + tex.z*z;
50-
vec4 pos = gl_in[0].gl_Position + vec4( pos_rel * size_factor * 0.5 );
45+
vec4 pos = gl_in[0].gl_Position + vec4( pos_rel * size_factor );
5146
gl_Position = worldviewproj_matrix * pos;
5247
gl_TexCoord[0] = vec4( tex.x*0.5+0.5, tex.y*0.5+0.5, 0.0, 0.0 );
5348

@@ -67,24 +62,28 @@ void emitVertex( int side, vec4 x, vec4 y, vec4 z, vec3 tex )
6762

6863
void main()
6964
{
65+
// if auto_size == 1, then size_factor == size*gl_Vertex.z
66+
// if auto_size == 0, then size_factor == size
67+
vec4 size_factor = (0.5*(1-auto_size.x+(auto_size.x*gl_in[0].gl_Position.z)))*size;
68+
7069
for( int side=0; side<3; side++ )
7170
{
7271
vec4 x=axes[ side ];
7372
vec4 y=axes[ (side+1)%3 ];
7473
vec4 z=axes[ (side+2)%3 ];
7574

7675
// face for +z
77-
emitVertex( side, x, y, z, vec3(-1, -1, +1) );
78-
emitVertex( side, x, y, z, vec3(+1, -1, +1) );
79-
emitVertex( side, x, y, z, vec3(-1, +1, +1) );
80-
emitVertex( side, x, y, z, vec3(+1, +1, +1) );
76+
emitVertex( side, x, y, z, vec3(-1, -1, +1), size_factor );
77+
emitVertex( side, x, y, z, vec3(+1, -1, +1), size_factor );
78+
emitVertex( side, x, y, z, vec3(-1, +1, +1), size_factor );
79+
emitVertex( side, x, y, z, vec3(+1, +1, +1), size_factor );
8180
EndPrimitive();
8281

8382
// face for -z
84-
emitVertex( side+3, x, y, z, vec3(-1, -1, -1) );
85-
emitVertex( side+3, x, y, z, vec3(-1, +1, -1) );
86-
emitVertex( side+3, x, y, z, vec3(+1, -1, -1) );
87-
emitVertex( side+3, x, y, z, vec3(+1, +1, -1) );
83+
emitVertex( side+3, x, y, z, vec3(-1, -1, -1), size_factor );
84+
emitVertex( side+3, x, y, z, vec3(-1, +1, -1), size_factor );
85+
emitVertex( side+3, x, y, z, vec3(+1, -1, -1), size_factor );
86+
emitVertex( side+3, x, y, z, vec3(+1, +1, -1), size_factor );
8887
EndPrimitive();
8988
}
9089
}

0 commit comments

Comments
 (0)