@@ -1002,53 +1002,31 @@ void R_UploadImage( const byte **dataArray, int numLayers, int numMips,
10021002 }
10031003 else
10041004 {
1005- int samples;
1006-
10071005 // scan the texture for each channel's max values
10081006 // and verify if the alpha channel is being used or not
1007+
10091008 c = image->width * image->height ;
10101009 scan = dataArray[0 ];
10111010
1012- samples = 3 ;
1011+ // lightmap does not have alpha channel
10131012
1014- // Tr3B: normalmaps have the displacement maps in the alpha channel
1015- // samples 3 would cause an opaque alpha channel and odd displacements!
1016- if ( image->bits & IF_NORMALMAP )
1017- {
1018- if ( image->bits & ( IF_DISPLACEMAP | IF_ALPHATEST ) )
1019- {
1020- samples = 4 ;
1021- }
1022- else
1023- {
1024- samples = 3 ;
1025- }
1026- }
1027- else if ( image->bits & IF_LIGHTMAP )
1028- {
1029- samples = 3 ;
1030- }
1031- else
1013+ // normalmap may have the displacement maps in the alpha channel
1014+ // opaque alpha channel means no displacement, so we can enable
1015+ // alpha channel everytime it is used, even for normalmap
1016+
1017+ internalFormat = GL_RGB8;
1018+
1019+ if ( !( image->bits & IF_LIGHTMAP ) )
10321020 {
10331021 for ( i = 0 ; i < c; i++ )
10341022 {
10351023 if ( scan[ i * 4 + 3 ] != 255 )
10361024 {
1037- samples = 4 ;
1025+ internalFormat = GL_RGBA8 ;
10381026 break ;
10391027 }
10401028 }
10411029 }
1042-
1043- // select proper internal format
1044- if ( samples == 3 )
1045- {
1046- internalFormat = GL_RGB8;
1047- }
1048- else if ( samples == 4 )
1049- {
1050- internalFormat = GL_RGBA8;
1051- }
10521030 }
10531031
10541032 // 3D textures are uploaded in slices via glTexSubImage3D,
@@ -2837,7 +2815,7 @@ void R_CreateBuiltinImages()
28372815 tr.blueImage = R_CreateImage ( " _blue" , ( const byte ** ) &dataPtr,
28382816 8 , 8 , 1 , IF_NOPICMIP, filterType_t::FT_LINEAR, wrapTypeEnum_t::WT_REPEAT );
28392817
2840- // generate a default normalmap with a zero heightmap
2818+ // generate a default normalmap with a fully opaque heightmap (no displacement)
28412819 for ( x = DEFAULT_SIZE * DEFAULT_SIZE, out = &data[0 ][0 ][0 ]; x; --x, out += 4 )
28422820 {
28432821 out[ 0 ] = out[ 1 ] = 128 ;
0 commit comments