@@ -3264,10 +3264,11 @@ static void R_LoadFogs( lump_t *l, lump_t *brushesLump, lump_t *sidesLump )
32643264
32653265 struct FogVert
32663266 {
3267- float position[ 3 ] ;
3267+ vec3_t position;
32683268 vec4_t surface;
3269+ vec4_t planes[ 5 ]; // faces other than the current triangle's
32693270 };
3270- std::vector<FogVert> fogVerts (8 * count);
3271+ std::vector<FogVert> fogVerts (24 * count);
32713272 std::vector<glIndex_t> fogIndexes (36 * count);
32723273
32733274 for ( i = 0 ; i < count; i++, fogs++ )
@@ -3349,22 +3350,50 @@ static void R_LoadFogs( lump_t *l, lump_t *brushesLump, lump_t *sidesLump )
33493350 out->surface [ 3 ] = -s_worldData.planes [ planeNum ].dist ;
33503351 }
33513352
3352- // add faces of fog brush for drawing fog from inside
3353- for ( int p = 0 ; p < 8 ; p++ )
3353+ // add faces of fog brush with information about the other planes
3354+ // TODO: allow non-axis-aligned boxes. The GLSL can draw any brush with up to 6 faces.
3355+ constexpr int faces[ 6 ][ 4 ]
33543356 {
3355- fogVerts[ i * 8 + p ].position [ 0 ] = out->bounds [ p & 1 ][ 0 ];
3356- fogVerts[ i * 8 + p ].position [ 1 ] = out->bounds [ ( p >> 1 ) & 1 ][ 1 ];
3357- fogVerts[ i * 8 + p ].position [ 2 ] = out->bounds [ p >> 2 ][ 2 ];
3357+ { 2 , 0 , 6 , 4 },
3358+ { 1 , 3 , 5 , 7 },
3359+ { 0 , 1 , 4 , 5 },
3360+ { 3 , 2 , 7 , 6 },
3361+ { 2 , 3 , 0 , 1 },
3362+ { 7 , 6 , 5 , 4 }
3363+ };
3364+
3365+ for ( int face = 0 ; face < 6 ; face++ )
3366+ {
3367+ for ( int v = 0 ; v < 4 ; v++ )
3368+ {
3369+ FogVert &vert = fogVerts[ i * 24 + face * 4 + v ];
3370+ int p = faces[ face ][ v ];
3371+ vert.position [ 0 ] = out->bounds [ p & 1 ][ 0 ];
3372+ vert.position [ 1 ] = out->bounds [ ( p >> 1 ) & 1 ][ 1 ];
3373+ vert.position [ 2 ] = out->bounds [ p >> 2 ][ 2 ];
33583374
3359- VectorCopy ( out->surface , fogVerts[ i * 8 + p ].surface );
3360- fogVerts[ i * 8 + p ].surface [ 3 ] = -out->surface [ 3 ];
3361- }
3375+ VectorCopy ( out->surface , vert.surface );
3376+ vert.surface [ 3 ] = -out->surface [ 3 ];
33623377
3363- constexpr int box[ 36 ] = { 2 , 3 , 0 , 0 , 3 , 1 , 0 , 1 , 4 , 4 , 1 , 5 , 2 , 0 , 6 , 6 , 0 , 4 ,
3364- 1 , 3 , 5 , 5 , 3 , 7 , 3 , 2 , 7 , 7 , 2 , 6 , 7 , 6 , 5 , 5 , 6 , 4 };
3365- for ( int p = 0 ; p < 36 ; p++ )
3366- {
3367- fogIndexes[ 36 * i + p ] = 8 * i + box[ p ];
3378+ vec4_t *plane = vert.planes ;
3379+ for ( int otherFace = 0 ; otherFace < 6 ; otherFace++ )
3380+ {
3381+ if ( face != otherFace )
3382+ {
3383+ planeNum = LittleLong ( sides[ firstSide + otherFace ].planeNum );
3384+ VectorCopy ( s_worldData.planes [ planeNum ].normal , *plane );
3385+ ( *plane )[ 3 ] = s_worldData.planes [ planeNum ].dist ;
3386+ ++plane;
3387+ }
3388+ }
3389+ }
3390+
3391+ fogIndexes[ 36 * i + 6 * face + 0 ] = i * 24 + face * 4 + 0 ;
3392+ fogIndexes[ 36 * i + 6 * face + 1 ] = i * 24 + face * 4 + 1 ;
3393+ fogIndexes[ 36 * i + 6 * face + 2 ] = i * 24 + face * 4 + 2 ;
3394+ fogIndexes[ 36 * i + 6 * face + 3 ] = i * 24 + face * 4 + 2 ;
3395+ fogIndexes[ 36 * i + 6 * face + 4 ] = i * 24 + face * 4 + 1 ;
3396+ fogIndexes[ 36 * i + 6 * face + 5 ] = i * 24 + face * 4 + 3 ;
33683397 }
33693398
33703399 // add draw surf for fog brush faces
@@ -3378,11 +3407,16 @@ static void R_LoadFogs( lump_t *l, lump_t *brushesLump, lump_t *sidesLump )
33783407 vertexAttributeSpec_t attributes[] {
33793408 { ATTR_INDEX_POSITION, GL_FLOAT, GL_FLOAT, &fogVerts[ 0 ].position , 3 , sizeof ( fogVerts[ 0 ] ), 0 },
33803409 { ATTR_INDEX_FOG_SURFACE, GL_FLOAT, GL_FLOAT, &fogVerts[ 0 ].surface , 4 , sizeof ( fogVerts[ 0 ] ), 0 },
3410+ { ATTR_INDEX_FOG_PLANES_0 + 0 , GL_FLOAT, GL_FLOAT, &fogVerts[ 0 ].planes [ 0 ], 4 , sizeof ( FogVert ), 0 },
3411+ { ATTR_INDEX_FOG_PLANES_0 + 1 , GL_FLOAT, GL_FLOAT, &fogVerts[ 0 ].planes [ 1 ], 4 , sizeof ( FogVert ), 0 },
3412+ { ATTR_INDEX_FOG_PLANES_0 + 2 , GL_FLOAT, GL_FLOAT, &fogVerts[ 0 ].planes [ 2 ], 4 , sizeof ( FogVert ), 0 },
3413+ { ATTR_INDEX_FOG_PLANES_0 + 3 , GL_FLOAT, GL_FLOAT, &fogVerts[ 0 ].planes [ 3 ], 4 , sizeof ( FogVert ), 0 },
3414+ { ATTR_INDEX_FOG_PLANES_0 + 4 , GL_FLOAT, GL_FLOAT, &fogVerts[ 0 ].planes [ 4 ], 4 , sizeof ( FogVert ), 0 },
33813415 };
33823416 VBO_t *fogVBO = R_CreateStaticVBO (
33833417 " fogs VBO" , std::begin ( attributes ), std::end ( attributes ), fogVerts.size () );
33843418 IBO_t *fogIBO = R_CreateStaticIBO ( " fogs IBO" , &fogIndexes[ 0 ], fogIndexes.size () );
3385- SetupVAOBuffers ( fogVBO, fogIBO, ATTR_POSITION | ATTR_FOG_SURFACE, &fogVBO->VAO );
3419+ SetupVAOBuffers ( fogVBO, fogIBO, ATTR_POSITION | ATTR_FOG_SURFACE | ATTR_FOG_PLANES , &fogVBO->VAO );
33863420
33873421 for ( int j = 1 ; j < s_worldData.numFogs ; j++ )
33883422 {
0 commit comments