Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/engine/renderer/glsl_source/reliefMapping_fp.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@ vec3 NormalInTangentSpace(vec2 texNormal)
#if defined(r_NormalScale)
normal.z *= r_NormalScale;
#endif

#else // !r_normalMapping
normal = vec3(0.0, 0.0, 1.0);
#endif // r_normalMapping

return normal;
Expand Down
44 changes: 11 additions & 33 deletions src/engine/renderer/tr_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1002,53 +1002,31 @@ void R_UploadImage( const byte **dataArray, int numLayers, int numMips,
}
else
{
int samples;

// scan the texture for each channel's max values
// and verify if the alpha channel is being used or not

c = image->width * image->height;
scan = dataArray[0];

samples = 3;
// lightmap does not have alpha channel

// Tr3B: normalmaps have the displacement maps in the alpha channel
// samples 3 would cause an opaque alpha channel and odd displacements!
if ( image->bits & IF_NORMALMAP )
{
if ( image->bits & ( IF_DISPLACEMAP | IF_ALPHATEST ) )
{
samples = 4;
}
else
{
samples = 3;
}
}
else if ( image->bits & IF_LIGHTMAP )
{
samples = 3;
}
else
// normalmap may have the displacement maps in the alpha channel
// opaque alpha channel means no displacement, so we can enable
// alpha channel everytime it is used, even for normalmap

internalFormat = GL_RGB8;

if ( !( image->bits & IF_LIGHTMAP ) )
{
for ( i = 0; i < c; i++ )
{
if ( scan[ i * 4 + 3 ] != 255 )
{
samples = 4;
internalFormat = GL_RGBA8;
break;
}
}
}

// select proper internal format
if ( samples == 3 )
{
internalFormat = GL_RGB8;
}
else if ( samples == 4 )
{
internalFormat = GL_RGBA8;
}
}

// 3D textures are uploaded in slices via glTexSubImage3D,
Expand Down Expand Up @@ -2837,7 +2815,7 @@ void R_CreateBuiltinImages()
tr.blueImage = R_CreateImage( "_blue", ( const byte ** ) &dataPtr,
8, 8, 1, IF_NOPICMIP, filterType_t::FT_LINEAR, wrapTypeEnum_t::WT_REPEAT );

// generate a default normalmap with a zero heightmap
// generate a default normalmap with a fully opaque heightmap (no displacement)
for ( x = DEFAULT_SIZE * DEFAULT_SIZE, out = &data[0][0][0]; x; --x, out += 4 )
{
out[ 0 ] = out[ 1 ] = 128;
Expand Down