Shader Code Inefficiency - Bug Reporting - WarpPortal Community Forums

Jump to content


Photo

Shader Code Inefficiency


  • Please log in to reply
No replies to this topic

#1 Cleffy

Cleffy

    Too Legit To Quit

  • Members
  • 2377 posts
  • Playing:Requiem

Posted 01 July 2014 - 08:39 AM

The pixel shader level does several unnecessary calculations which can cause performance loss.

Right now each model consists of 1 texture. This texture is in DXT5 format. It consists of the color channel, and an alpha channel. The alpha channel is actually split between transparency and gloss. The developers split the map during the pixel shader process. This means every pixel of every frame it does several additional calculations which results in an unnecessary performance impact. The basic pseudo code in the pixel shader for this step is as follows.

 

//Check if alpha is used.

//If so, alpha = whateverTexture.a * 2

//gloss = whateverTexture.a * 2 - 1

//Do specular and alpha mapping calculations.

 

As a rule of thumb, the shader code should only do calculations that are necessary at runtime. The alpha map should be separated before reaching the draw function either through code or as a separate map from the get go. For shader models before 4.0 branching should not be done at all. After 4.0 it should be done to a minimum. To put in perspective the amount of additional calculations being done, the shader code is doing a branching check, multiply, multiply, and subtraction every frame of every pixel. For a person running at HD resolution this is roughly 2 million extra calculations done every frame.


  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users