Permalink
Browse files

Encode sprite corner in the lightmap coords.

The texture coords are too unreliable.
  • Loading branch information...
gimhael committed Feb 21, 2016
1 parent f150b90 commit 341002a27506db6f1694e8c563806055239a0236
@@ -21985,8 +21985,7 @@ const char vertexSprite_vp[] = {
0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x66, 0x61, 0x63, 0x74, 0x6f,
0x72, 0x0a, 0x0a, 0x09, 0x63, 0x6f, 0x72, 0x6e, 0x65, 0x72, 0x20, 0x3d,
0x20, 0x73, 0x69, 0x67, 0x6e, 0x28, 0x20, 0x61, 0x74, 0x74, 0x72, 0x5f,
0x54, 0x65, 0x78, 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x2e, 0x78, 0x79,
0x20, 0x2a, 0x20, 0x32, 0x2e, 0x30, 0x20, 0x2d, 0x20, 0x31, 0x2e, 0x30,
0x54, 0x65, 0x78, 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x2e, 0x7a, 0x77,
0x20, 0x29, 0x3b, 0x0a, 0x0a, 0x09, 0x69, 0x66, 0x28, 0x20, 0x72, 0x61,
0x64, 0x69, 0x75, 0x73, 0x20, 0x3c, 0x3d, 0x20, 0x30, 0x2e, 0x30, 0x20,
0x29, 0x20, 0x7b, 0x0a, 0x09, 0x09, 0x2f, 0x2f, 0x20, 0x61, 0x75, 0x74,
@@ -22059,17 +22058,19 @@ const char vertexSprite_vp[] = {
0x6e, 0x6f, 0x72, 0x6d, 0x61, 0x6c, 0x20, 0x3d, 0x20, 0x6e, 0x6f, 0x72,
0x6d, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x28, 0x20, 0x6c, 0x65, 0x66, 0x74,
0x20, 0x29, 0x3b, 0x0a, 0x23, 0x65, 0x6e, 0x64, 0x69, 0x66, 0x0a, 0x09,
0x74, 0x65, 0x78, 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x20, 0x3d, 0x20, 0x61,
0x74, 0x74, 0x72, 0x5f, 0x54, 0x65, 0x78, 0x43, 0x6f, 0x6f, 0x72, 0x64,
0x30, 0x2e, 0x78, 0x79, 0x3b, 0x0a, 0x09, 0x6c, 0x6d, 0x43, 0x6f, 0x6f,
0x72, 0x64, 0x20, 0x20, 0x3d, 0x20, 0x61, 0x74, 0x74, 0x72, 0x5f, 0x54,
0x65, 0x78, 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x2e, 0x7a, 0x77, 0x3b,
0x0a, 0x09, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x20, 0x20, 0x20, 0x3d,
0x20, 0x61, 0x74, 0x74, 0x72, 0x5f, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x3b,
0x0a, 0x0a, 0x09, 0x75, 0x5f, 0x44, 0x65, 0x70, 0x74, 0x68, 0x53, 0x63,
0x61, 0x6c, 0x65, 0x20, 0x3d, 0x20, 0x32, 0x2e, 0x30, 0x20, 0x2a, 0x20,
0x72, 0x61, 0x64, 0x69, 0x75, 0x73, 0x3b, 0x0a, 0x7d, 0x0a, 0x23, 0x65,
0x6e, 0x64, 0x69, 0x66, 0x0a, 0x00
0x74, 0x65, 0x78, 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x20, 0x3d, 0x20, 0x30,
0x2e, 0x35, 0x20, 0x2a, 0x20, 0x63, 0x6f, 0x72, 0x6e, 0x65, 0x72, 0x20,
0x2b, 0x20, 0x30, 0x2e, 0x35, 0x3b, 0x20, 0x2f, 0x2f, 0x61, 0x74, 0x74,
0x72, 0x5f, 0x54, 0x65, 0x78, 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x2e,
0x78, 0x79, 0x3b, 0x0a, 0x09, 0x6c, 0x6d, 0x43, 0x6f, 0x6f, 0x72, 0x64,
0x20, 0x20, 0x3d, 0x20, 0x61, 0x62, 0x73, 0x28, 0x20, 0x61, 0x74, 0x74,
0x72, 0x5f, 0x54, 0x65, 0x78, 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x2e,
0x7a, 0x77, 0x20, 0x29, 0x3b, 0x0a, 0x09, 0x63, 0x6f, 0x6c, 0x6f, 0x72,
0x20, 0x20, 0x20, 0x20, 0x3d, 0x20, 0x61, 0x74, 0x74, 0x72, 0x5f, 0x43,
0x6f, 0x6c, 0x6f, 0x72, 0x3b, 0x0a, 0x0a, 0x09, 0x75, 0x5f, 0x44, 0x65,
0x70, 0x74, 0x68, 0x53, 0x63, 0x61, 0x6c, 0x65, 0x20, 0x3d, 0x20, 0x32,
0x2e, 0x30, 0x20, 0x2a, 0x20, 0x72, 0x61, 0x64, 0x69, 0x75, 0x73, 0x3b,
0x0a, 0x7d, 0x0a, 0x23, 0x65, 0x6e, 0x64, 0x69, 0x66, 0x0a, 0x00
};
const char volumetricFog_fp[] = {
0x2f, 0x2a, 0x0a, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d,
@@ -475,6 +475,39 @@ Assuming all the triangles for this shader are independent
quads, rebuild them as forward facing sprites
=====================
*/
static void ComputeCorner( int firstVertex, int numVertexes )
{
int i, j;
shaderVertex_t *v;
vec4_t tc, midtc;
for ( i = 0; i < numVertexes; i += 4 ) {
// find the midpoint
v = &tess.verts[ firstVertex + i ];
Vector4Set( midtc, 0.0f, 0.0f, 0.0f, 0.0f );
for( j = 0; j < 4; j++ ) {
halfToFloat( v[ j ].texCoords, tc );
VectorAdd( tc, midtc, midtc );
midtc[ 3 ] += tc[ 3 ];
}
midtc[ 0 ] = 0.25f * midtc[ 0 ];
midtc[ 1 ] = 0.25f * midtc[ 1 ];
for ( j = 0; j < 4; j++ ) {
halfToFloat( v[ j ].texCoords, tc );
if( tc[ 0 ] < midtc[ 0 ] ) {
tc[ 2 ] = -tc[ 2 ];
}
if( tc[ 1 ] < midtc[ 1 ] ) {
tc[ 3 ] = -tc[ 3 ];
}
floatToHalf( tc, v[ j ].texCoords );
}
}
}
static void AutospriteDeform( int firstVertex, int numVertexes, int numIndexes )
{
int i, j;
@@ -492,6 +525,8 @@ static void AutospriteDeform( int firstVertex, int numVertexes, int numIndexes )
Log::Warn("Autosprite shader %s had odd index count", tess.surfaceShader->name );
}
ComputeCorner( firstVertex, numVertexes );
for ( i = 0; i < numVertexes; i += 4 )
{
// find the midpoint
@@ -546,6 +581,8 @@ static void Autosprite2Deform( int firstVertex, int numVertexes, int numIndexes
Log::Warn("Autosprite2 shader %s had odd index count", tess.surfaceShader->name );
}
ComputeCorner( firstVertex, numVertexes );
// this is a lot of work for two triangles...
// we could precalculate a lot of it is an issue, but it would mess up
// the shader abstraction
@@ -627,7 +664,7 @@ static void Autosprite2Deform( int firstVertex, int numVertexes, int numIndexes
k = 1;
VectorSubtract( v1->xyz, mid[ k ], minor );
if ( DotProduct( cross, minor ) * ( halfToFloat( v1->texCoords[ 1 ] ) - 0.5f ) < 0.0f ) {
if ( DotProduct( cross, minor ) * ( v1->texCoords[ 3 ] < 0 ) ) {
VectorNegate( major, orientation );
} else {
VectorCopy( major, orientation );
@@ -417,7 +417,7 @@ void Tess_AddSprite( const vec3_t center, const Color::Color32Bit color, float r
vec4_t orientation;
Vector4Set( texCoord, 0.5f * (i & 2), 0.5f * ( (i + 1) & 2 ),
0.5f * (i & 2), 0.5f * ( (i + 1) & 2 ) );
(i & 2) - 1.0f, ( (i + 1) & 2 ) - 1.0f );
VectorCopy( center, tess.verts[ ndx + i ].xyz );
tess.verts[ ndx + i ].color = color;
@@ -44,7 +44,7 @@ void VertexFetch(out vec4 position,
vec3 normal = normalize( u_ViewOrigin - attr_Position ), up, left;
float s, c; // sin & cos of rotation factor
corner = sign( attr_TexCoord0.xy * 2.0 - 1.0 );
corner = sign( attr_TexCoord0.zw );
if( radius <= 0.0 ) {
// autosprite2 mode, attr_Orientation.xyz contains the up-vector
@@ -74,8 +74,8 @@ void VertexFetch(out vec4 position,
normalBasis.tangent = normalize( up );
normalBasis.binormal = normalize( left );
#endif
texCoord = attr_TexCoord0.xy;
lmCoord = attr_TexCoord0.zw;
texCoord = 0.5 * corner + 0.5; //attr_TexCoord0.xy;
lmCoord = abs( attr_TexCoord0.zw );
color = attr_Color;
u_DepthScale = 2.0 * radius;

0 comments on commit 341002a

Please sign in to comment.