Rendering: Difference between revisions

From wowdev
Jump to navigation Jump to search
Line 31: Line 31:
This shader implements a simple 2x2 [https://en.wikipedia.org/wiki/Box_blur box blur].
This shader implements a simple 2x2 [https://en.wikipedia.org/wiki/Box_blur box blur].


The client appears to precompute the texture coordinates on the CPU. Each of the 4 coordinate pairs is 'slipped' such that the addition of each sampled color results in the blur.
The client appears to precompute the texture coordinates on the CPU. Each of the 4 coordinate pairs is 'slipped' such that the addition of each sampled color results in the blur (see below).


'''Vertex Shader'''
'''Vertex Shader'''
Line 39: Line 39:
'''Pixel Shader'''
'''Pixel Shader'''


The same source render target is bound 4 times.
The same source render target (the output of <tt>RT 0</tt>) is bound 4 times.
 
The coordinate pairs in <tt>in_tc0</tt> through <tt>in_tc3</tt> are offset as follows:
 
* <tt>in_tc0</tt>: reference
* <tt>in_tc1</tt>: shifted right vs <tt>in_tc0</tt>
* <tt>in_tc2</tt>: shifted up vs <tt>in_tc0</tt>
* <tt>in_tc3</tt>: shifted right and up vs <tt>in_tc0</tt>


<syntaxhighlight lang="glsl">
<syntaxhighlight lang="glsl">

Revision as of 20:27, 1 December 2016

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:

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).

FFXBox4 Shaders (7.x)

This shader implements a simple 2x2 box blur.

The client appears to precompute the texture coordinates on the CPU. Each of the 4 coordinate pairs is 'slipped' such that the addition of each sampled color results in the blur (see below).

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.

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 Shaders (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 Shaders (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)