Rendering
This page covers general rendering concerns that are not specific to model formats.
Model Specific Rendering
More information about rendering specific model formats can be found at the following pages:
Vertex Buffers
EGxVertexBufferFormat
EGxVertexBufferFormat | Attribute Count | Size (per Vertex) | Attribute Names |
---|---|---|---|
GxVBF_P | 1 | 0x0C | position |
GxVBF_PN | 2 | 0x18 | position, normal |
GxVBF_PNC | 3 | 0x1C | position, normal, color |
GxVBF_PNT | 3 | 0x20 | position, normal, tc |
GxVBF_PNCT | 4 | 0x24 | position, normal, color, tc |
GxVBF_PNT2 | 4 | 0x28 | position, normal, tc[2] |
GxVBF_PNCT2 | 5 | 0x2C | position, normal, color, tc[2] |
GxVBF_PC | 2 | 0x10 | position, color |
GxVBF_PCT | 3 | 0x18 | position, color, tc |
GxVBF_PCT2 | 4 | 0x20 | position, color, tc[2] |
GxVBF_PT | 2 | 0x14 | position, tc |
GxVBF_PT2 | 3 | 0x1C | position, tc[2] |
GxVBF_PBNT2 | 6 | 0x30 | position, blendWeight, blendIndices, normal, tc[2] |
GxVBF_PNC2T2 | 6 | 0x30 | position, normal, color[2], tc[2] |
EGxVertexAttrib
EGxVertexAttrib | Size |
---|---|
GxVA_Position | 0x0C |
GxVA_BlendWeight | 0x04 |
GxVA_BlendIndices | 0x04 |
GxVA_Normal | 0x0C |
GxVA_Color0 | 0x04 |
GxVA_Color1 | 0x04 |
GxVA_TexCoord0 | 0x08 |
GxVA_TexCoord1 | 0x08 |
Pixel Blending
When drawing geometry (batches, meshes, etc) into a framebuffer, the interaction between the pixels of the incoming geometry and the pixels already present in the framebuffer is controlled by something called blending.
In World of Warcraft, blending states are predefined, and are referenced by the EGxBlend enum.
Note that pixel blending is separate from texture blending. Texture blending controls how multiple textures for the same geometry are blended together, prior to the geometry being drawn into the framebuffer. In other words, texture blending happens before pixel blending. It has its own section on this page.
EGxBlend
The table below is up to date with all blending modes present in the 7.1.0.22996 retail client. Not all blending modes are used, particularly in older clients.
Wrath of the Lich King and Cataclysm do not use separate alpha blending. Legion does use separate alpha blending. It's currently unknown if Mists of Pandaria or Warlords of Draenor use separate alpha blending.
GxBlend_BlendAdd was added at some point after Cataclysm.
Blend function enums are for OpenGL, but each has a Direct3D equivalent. Most pairings should be obvious, except: in Direct3D, CONSTANT_ALPHA is BLEND_FACTOR and ONE_MINUS_CONSTANT_ALPHA is INV_BLEND_FACTOR. See this gist for code that converts OpenGL constants to Direct3D (excerpt from Chrome).
Idx | EGxBlend | Blending Enabled? | Src Color | Dest Color | Src Alpha | Dest Alpha |
---|---|---|---|---|---|---|
0 | GxBlend_Opaque | No | GL_ONE | GL_ZERO | GL_ONE | GL_ZERO |
1 | GxBlend_AlphaKey | No | GL_ONE | GL_ZERO | GL_ONE | GL_ZERO |
2 | GxBlend_Alpha | Yes | GL_SRC_ALPHA | GL_ONE_MINUS_SRC_ALPHA | GL_ONE | GL_ONE_MINUS_SRC_ALPHA |
3 | GxBlend_Add | Yes | GL_SRC_ALPHA | GL_ONE | GL_ZERO | GL_ONE |
4 | GxBlend_Mod | Yes | GL_DST_COLOR | GL_ZERO | GL_DST_ALPHA | GL_ZERO |
5 | GxBlend_Mod2x | Yes | GL_DST_COLOR | GL_SRC_COLOR | GL_DST_ALPHA | GL_SRC_ALPHA |
6 | GxBlend_ModAdd | Yes | GL_DST_COLOR | GL_ONE | GL_DST_ALPHA | GL_ONE |
7 | GxBlend_InvSrcAlphaAdd | Yes | GL_ONE_MINUS_SRC_ALPHA | GL_ONE | GL_ONE_MINUS_SRC_ALPHA | GL_ONE |
8 | GxBlend_InvSrcAlphaOpaque | Yes | GL_ONE_MINUS_SRC_ALPHA | GL_ZERO | GL_ONE_MINUS_SRC_ALPHA | GL_ZERO |
9 | GxBlend_SrcAlphaOpaque | Yes | GL_SRC_ALPHA | GL_ZERO | GL_SRC_ALPHA | GL_ZERO |
10 | GxBlend_NoAlphaAdd | Yes | GL_ONE | GL_ONE | GL_ZERO | GL_ONE |
11 | GxBlend_ConstantAlpha | Yes | GL_CONSTANT_ALPHA | GL_ONE_MINUS_CONSTANT_ALPHA | GL_CONSTANT_ALPHA | GL_ONE_MINUS_CONSTANT_ALPHA |
12 | GxBlend_Screen | Yes | GL_ONE_MINUS_DST_COLOR | GL_ONE | GL_ONE | GL_ZERO |
13 | GxBlend_BlendAdd | Yes | GL_ONE | GL_ONE_MINUS_SRC_ALPHA | GL_ONE | GL_ONE_MINUS_SRC_ALPHA |
Table Credits: Deamon, for unearthing blending mode names and laying out the original table; relaxok, for checking D3D state at runtime; schlumpf, for the initial reversing work; fallenoak, for mapping Deamon's table to OpenGL enums and verifying values across several expansion clients.
Texture Blending
Texture blending controls how multiple textures are combined prior to being drawn to the framebuffer.
EGxTexBlend
Idx | EGxTexBlend | ColorOp | AlphaOp |
---|---|---|---|
0 | GxTexBlend_Opaque | GxTexOp_Mod | GxTexOp_PassThru |
1 | GxTexBlend_Mod | GxTexOp_Mod | GxTexOp_Mod |
2 | GxTexBlend_Decal | GxTexOp_Decal | GxTexOp_PassThru |
3 | GxTexBlend_Add | GxTexOp_Add | GxTexOp_Add |
4 | GxTexBlend_Mod2x | GxTexOp_Mod2x | GxTexOp_Mod2x |
5 | GxTexBlend_Fade | GxTexOp_Fade | GxTexOp_PassThru |
6 | GxTexBlend_Mod2xNA | GxTexOp_Mod2x | GxTexOp_PassThru |
7 | GxTexBlend_AddNA | GxTexOp_Add | GxTexOp_PassThru |
EGxTexOp
Idx | EGxTexOp | Op | Scale | Arg0 | Arg1 | Arg2 |
---|---|---|---|---|---|---|
0 | GxTexOp_Mod | GL_MODULATE | 1.0f | GL_PREVIOUS | GL_TEXTURE | GL_CONSTANT |
1 | GxTexOp_Mod2x | GL_MODULATE | 2.0f | GL_PREVIOUS | GL_TEXTURE | GL_CONSTANT |
2 | GxTexOp_Add | GL_ADD | 1.0f | GL_PREVIOUS | GL_TEXTURE | GL_CONSTANT |
3 | GxTexOp_PassThru | GL_REPLACE | 1.0f | GL_PREVIOUS | GL_TEXTURE | GL_CONSTANT |
4 | GxTexOp_Decal | GL_INTERPOLATE | 1.0f | GL_PREVIOUS | GL_TEXTURE | GL_TEXTURE |
5 | GxTexOp_Fade | GL_INTERPOLATE | 1.0f | GL_TEXTURE | GL_PREVIOUS | GL_TEXTURE |
ColorOp FFP State
When rendering is done using the fixed function pipeline code path, the following calls are made to set the texture blending color op:
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, op);
glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE, scale);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, arg0);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, arg1);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB, arg2);
AlphaOp FFP State
When rendering is done using the fixed function pipeline code path, the following calls are made to set the texture blending alpha op:
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, op);
glTexEnvf(GL_TEXTURE_ENV, GL_ALPHA_SCALE, scale);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, arg0);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA, arg1);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_ALPHA, arg2);
Texture Targets
EGxTexTarget
Idx | EGxTexTarget | OpenGL |
---|---|---|
0 | GxTex_2d | GL_TEXTURE_2D |
1 | GxTex_CubeMap | GL_TEXTURE_CUBE_MAP |
2 | GxTex_Rectangle | GL_TEXTURE_RECTANGLE |
3 | GxTex_NonPow2?? | GL_TEXTURE_2D |
4 | GxTex_Volume | GL_TEXTURE_3D |
5 | GxTex_Internal?? | GL_ZERO |
Screen Effects
EffectGlow
This fullscreen effect controls both the bloom-style glow effect used by the game, and player state driven blur effects like inebriation.
To apply the effect, the game creates 4 new render targets:
- RT 0: Already exists, and holds the output of rendering the given world scene
- RT 1: Created by passing RT 0 through the FFXBox4 shader (2x2 box blur)
- RT 2: Created by passing RT 1 through the FFXGauss4 shader (4-tap gaussian blur)
- RT 3: Created by passing RT 2 through the FFXGauss4 shader (second pass)
- RT 4: Created by passing RT 0 and RT 3 through the FFXGlow shader (both targets are sampled)
The blurred render targets (RT 1, RT 2, and RT 3) are sized at 1/4 of the width and 1/4 of the height of the original render target (RT 0).
FFX Shaders
The game employs shaders to create various full screen effects. These shaders are outlined below. The screen effects section on this page explains how FFX shaders are chained together to create specific effects.
FFXBox4 (7.x)
This shader implements a simple 2x2 box blur.
The client appears to precompute the texture coordinates on the CPU.
- PassBox4::box4Offs = { -1.5, -1.5, 0.5, -1.5, 0.5, 0.5, -1.5, 0.5 }
- FFX::SetupGeo_Quad::s_tex = { 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0 }
Vertex Shader
The vertex shader used for FFXBox4 is a simple full screen vertex shader, and can be found in FullScreen.bls in the appropriate vertex shader directory.
Pixel Shader
The same source render target (the output of RT 0) is bound 4 times. Each of the 4 coordinate pairs is 'slipped' such that the addition of each sampled color results in the box blur.
The coordinate pairs in in_tc0 through in_tc3 are offset as follows:
- in_tc0: reference
- in_tc1: shifted right vs in_tc0
- in_tc2: shifted up vs in_tc0
- in_tc3: shifted right and up vs in_tc0
#version 420
layout(location = 1) in vec2 in_tc0;
layout(location = 2) in vec2 in_tc1;
layout(location = 3) in vec2 in_tc2;
layout(location = 4) in vec2 in_tc3;
layout(location = 0) out vec4 out_result;
uniform sampler2D pt_texture0;
uniform sampler2D pt_texture1;
uniform sampler2D pt_texture2;
uniform sampler2D pt_texture3;
void main()
{
float blurWeight = 0.25;
vec3 color0 = texture(pt_texture0, in_tc0).rgb;
vec3 color1 = texture(pt_texture1, in_tc1).rgb;
vec3 color2 = texture(pt_texture2, in_tc2).rgb;
vec3 color3 = texture(pt_texture3, in_tc3).rgb;
vec3 finalColor = vec3(0.0);
finalColor += color0 * blurWeight;
finalColor += color1 * blurWeight;
finalColor += color2 * blurWeight;
finalColor += color3 * blurWeight;
out_result = vec4(finalColor.rgb, 1.0);
}
FFXGauss4 (7.x)
This shader implements a 4-tap gaussian blur. It's typically applied by the client in 2 passes (possibly: horizontal, then vertical).
Pixel Shader
The same source render target is bound 4 times.
#version 420
layout(location = 1) in vec2 in_tc0;
layout(location = 2) in vec2 in_tc1;
layout(location = 3) in vec2 in_tc2;
layout(location = 4) in vec2 in_tc3;
layout(location = 0) out vec4 out_result;
uniform sampler2D pt_texture0;
uniform sampler2D pt_texture1;
uniform sampler2D pt_texture2;
uniform sampler2D pt_texture3;
void main()
{
vec2 blurWeight = vec2(0.125, 0.375);
vec4 color0 = texture(pt_texture1, in_tc0);
vec4 color1 = texture(pt_texture1, in_tc1);
vec4 color2 = texture(pt_texture1, in_tc2);
vec4 color3 = texture(pt_texture1, in_tc3);
vec4 finalColor = vec4(0.0);
finalColor += color0 * blurWeight.x;
finalColor += color1 * blurWeight.y;
finalColor += color2 * blurWeight.y;
finalColor += color3 * blurWeight.x;
out_result = finalColor;
}
FFXGlow (7.x)
Vertex Shader
The vertex shader used for FFXGlow is a simple full screen vertex shader, and can be found in FullScreen.bls in the appropriate vertex shader directory.
Pixel Shader
- pc_blurAmount.z: controls how much of the final blur output (RT 3) is carried over in the final output; this is used to manage effects like blurring the screen due to inebriation
- pc_blurAmount.w: controls how much bloom-style glow is applied to the screen; this typically is sourced from the LightParams client database: LightParamsRec->m_glow
#version 420
layout(location = 1) in vec2 in_screenCoord;
layout(location = 2) in vec2 in_blurCoord;
layout(location = 0) out vec4 out_result;
layout(std140) uniform ps_cb0
{
vec4 pc_blurAmount;
};
uniform sampler2D pt_screenTex;
uniform sampler2D pt_blurTex;
void main()
{
float blurFactor = pc_blurAmount.z;
float glowFactor = pc_blurAmount.w;
vec4 screenColor = texture(pt_screenTex, in_screenCoord);
vec3 blurColor = texture(pt_blurTex, in_blurCoord).rgb;
// Mix screen and blur color (to handle effects like inebriation)
vec4 finalColor = vec4(mix(screenColor.rgb, blurColor, vec3(blurFactor)), 0.0);
// Calculate the glow color
vec3 glowColor = (blurColor * blurColor) * glowFactor;
// Add the glow color
finalColor.rgb += glowColor;
out_result = vec4(finalColor.rgb, screenColor.a);
}
FFXGlow Shaders (3.x)
TODO
Fog
ViewSettings::s_fogInfo
There are 4 types of fog defined in ViewSettings::s_fogInfo
- 0: Unk (maybe: exterior above water fog)
- 1: Unk (maybe: interior above water fog)
- 2: Exterior underwater fog
- 3: Interior underwater fog
Liquid
Liquid::s_waterDetail
Liquid rendering quality. From http://wow.gamepedia.com/Console_variables#Graphics:
- 0: Old water
- 1: Screen space reflection
- 2: Dynamic reflection