Post Processing


You can do realtime image processing for rendered picture of 3d scene.  For post processing, program first render 3d scene to a texture, then do processing on the texture by every Post in turn. A Post is similarly to a Filter in Photoshop.

Workflow:

1. Create a new material
Click the "New" button in the Material Panel. Select a D3D Effect file from Awakening's '
effects\post' folder for the new material.

2. New a post
Click the "New" button in the Post Panel. A Select Material Dialog appears, select the material created in previous step.

3. Set Material Properties
Some effects like distort and levels needs setting textures to works well. Most effects have factors, you can define a Script Variable for the material, then do dynamic changing by scripting.

Preset Effects List:


Name
Preview Explanation
original image no post processing
auto - contrast result = (source + factor - 0.5 ) X 2

Factor:
dword factor

Usage:
local factor=toDWORD('60606060')
material.setEffectDword('dwARGB',factor)

PixelShader: No

Shader File: auto_contrast.fx

brightness/contrast
Factor:
number
brightness = [ -0.5 .. 0.5 ]
number
contrast = [ 0 .. 2 ]

Usage:
post_setBrightnessContrast( material, brightness ,contrast )

PixelShader: 1.0

Shader File: brightness_contrast.fx

blur

Factor:
number
blurfactor

Usage:
post_setBlur( material,
blurfactor )

PixelShader: No

Shader File: blur.fx

blur 2x  

Factor:
number
factor1, factor2

Usage:
post_setBlur2x( material,
factor1, factor2 )

PixelShader: 1.0

Shader File: blur_2x.fx

blur 4x

 

 

Factor:
number
factor1, factor2, factor3, factor4

Usage:

post_setBlur4x( material,
factor1, factor2, factor3, factor4 )

PixelShader: 1.0

Shader File: blur_4x.fx
( also there is blur_4x_tex.fx for blurring specific image; use material.setTexture(0, texture) to assign image )

blur 2 x 2

do 2 x 2 blurring for specific size image

Factor:
number
texture
number width
number height

Usage:
material.setTexture(0, texture)
post_setBlur2x2(material,
width, height )

PixelShader:
1.4

Shader File: blur2x2.fx  ( default for 512 x 512 size image )
( there are predefined width & height shaders: blur2x2_256.fx, blur2x2_128.fx, blur2x2_64.fx )

blur 5 x 5   do 5 x 5 blurring for specific size image

Factor:
number
texture

Usage:
material.setTexture(0, texture)

PixelShader: 2.0

Shader File: blur5x5_64.fx ~ blur5x5_1024.fx, gaussblur5x5_64.fx ~ gaussblur5x5_1024.fx

color change

result = source X factor

Factor:
dword colorfactor

Usage:
local
colorfactor=toDWORD('ff4040ff')
material.setEffectDword('dwARGB',
colorfactor)

PixelShader:
No

Shader File: color_change.fx

distort

Factor:
number
bumptexture
number bumpScale ( default is 0.1 )
 

Usage:
material.setTexture(0,
bumptexture)
material.setEffectFloat('bumpScale',0.2)

PixelShader:
No

Shader File: distort.fx

glow Factor:
number
blurfactor
number
blendfactor
number threshold= [ 0 .. 1 ]

Usage:
post_setGlow( material, blurfactor, blendfactor, threshold )

PixelShader: 1.4

Shader File: glow.fx

desaturate Factor:
number
desaturate= [ -1 .. 1 ] ( color .. gray )

Usage:
post_setDesaturate( material, desaturate )

PixelShader: 1.4

Shader File: gray.fx

invert Factor:
None

Usage:
None

PixelShader: 1.0

Shader File: invert.fx

levels

Factor:
number
r_texture
number g_texture
number b_texture

Usage:
material.setTexture(1,
r_texture)
material.setTexture(2,
g_texture)
material.setTexture(3,
b_texture)

PixelShader:
1.4

Shader File: levels.fx

gray levels

Factor:
number
texture

Usage:

material.setTexture(1,
texture)

PixelShader:
1.4

Shader File: levels_gray.fx

threshold

if ( source > 0.5 ) then result = lightcolor
else result = darkcolor

Factor:
vec4 
lightcolor
vec4 darkcolor

Usage:

material.setEffectVector('vecLightColor',
lightcolor)
material.setEffectVector('vecDarkColor',darkcolor)

PixelShader: 1.4

Shader File: threshold.fx

flexible threshold   

if ( source >= threshold ) then result = lightcolor
else result = darkcolor

Factor:
vec4 
lightcolor
vec4 darkcolor
number threshold

Usage:

post_setThresholdFlexible(material,
threshold, lightcolor, darkcolor)

PixelShader:
1.4

Shader File: threshold_flexible.fx

gray threshold

1. first desaturate source color
2. if (source>0.5) then result = lightcolor
else result = darkcolor

Factor:
vec4 
lightcolor
vec4 darkcolor

Usage:

material.setEffectVector('vecLightColor',
lightcolor)
material.setEffectVector('vecDarkColor',
darkcolor)

PixelShader: 1.4

Shader File: threshold_gray.fx

flexible gray threshold  

1. first desaturate source color
2. if ( source >= threshold ) then result = lightcolor
else result = darkcolor

Factor:
vec4 
lightcolor
vec4 darkcolor
number threshold

Usage:

post_setThresholdFlexible(material,
threshold, lightcolor, darkcolor)

PixelShader:
1.4

Shader File: threshold_gray_flexible.fx

edge detect

1. first invert source color and output to a texture
2. Add the texture to original data

PixelShader: 1.0

Shader File: invert.fx, addtex0.fx

glow and brighter 1. first do auto - contrast and output to a texture
2. Add the texture to original data

PixelShader: No

Shader File: auto_contrast.fx, addtex0.fx

bright-pass filter

1. first calculate the Luminance value of source color
2. if ( Luminance >= threshold ) then result = source color
else result = darkcolor

Factor:
vec4 darkcolor
number threshold (0 ~1)

Usage:

post_setBrightPass(material,
threshold, darkcolor)

PixelShader:
1.4

Shader File: bright_pass.fx

 

present bloom result = bloom_texture X colorfactor + source

Factor:
number
bloom_texture
dword
colorfactor

Usage:
local
colorfactor=toDWORD('ffebebeb')
material.setEffectDword('dwARGB',
colorfactor)
material.setTexture(1,
bloom_texture)

PixelShader:
No

Shader File: present_bloom.fx, present_bloom2x.fx (result = 2 X bloom_texture X colorfactor + source)

mosaic Factor:
vec4 
vecMosaic (x,y: mosaic size in pixel, default is 16x16;  z,w: reserved)

Usage:

material.setEffectVector('vecMosaic',
vecMosaic)

PixelShader:
2.0

Shader File: mosaic.fx

mosaic round

Factor:
vec4 
vecMosaic (x,y: mosaic size in pixel, default is 16x16;  z,w: reserved)

Usage:

material.setEffectVector('vecMosaic',
vecMosaic)

PixelShader:
2.0

Shader File: mosaic_round.fx

expose   Adjust brightness by inputted luminance image.

1. first calculate the Luminance value of color from luminance image
2. result = source + (0.5 - Luminance) X vFactor.x

Factor:
number
lum_texture  (should be a 1x1 texture image which represent the luminance)|
vec4 
vFactor  ( only the x component is valid, default is 0.5 )

Usage:

material.setTexture(1,
lum_texture)
material.setEffectVector('vecFactor',
vFactor)

PixelShader:
1.4

Shader File: expose.fx

hdr   Map high dynamic range data to 0~1 range.

1. first calculate the Luminance value of color from luminance image
2. first do: result = source X MiddleGray / ( Luminance + 0.001);
    then, if enable tone mapping, result /= (1.0+result).

Factor:
number
lum_texture  (should be a 1x1 texture image which represent the luminance)|
bool
g_bEnableBlueShift ( whether enable Blue Shift, default is false )
bool g_bEnableToneMap ( whether enable Tone Mapping, default is false )
number g_fMiddleGray ( the middle gray key value for Tone Mapping, default is 0.5 )


Usage:

material.setTexture(1,
lum_texture)
material.setEffectBool('g_bEnableToneMap',
true )
material.setEffectFloat('g_fMiddleGray',
0.8 )


PixelShader: 2
.0

Shader File: hdr.fx

calculate adapted luminance   Calculate adapted luminance by inputted luminance image

result = (lum_texture_src - lum_texture) X 0.02 X 30 X ElapsedTime + lum_texture

Factor:
number
lum_texture ( adapted luminance image for expose, the result should also output to this image )
number lum_texture_src   ( source instantaneous luminance image )

Usage:
material.setTexture(0,
lum_texture)
material.setTexture(1,
lum_texture_src)

PixelShader:
1.4

Shader File: calc_adapted_lum.fx

stretch copy  
result = input_texture

You can use this shader to copy & scale image.

Factor:
number
input_texture
Usage:


material.setTexture(0,
input_texture)

PixelShader:
No

Shader File: stretch_copy.fx

down sample 4x4  
You can use this shader to scale the source texture down to 1/16 scale.

Factor:
number
input_texture
Usage:


material.setTexture(0,
input_texture)

PixelShader:
2.0

Shader File: down_sample_4x4_4.fx ~ down_sample_4x4_512.fx

depth of field
Combine the original scene image and blurred image by the depth texture.

Factor:
number
blurred_texture
number
depth_texture

number
fFocusDepth ( 0~1, default is 0.4 )
number
fAperture ( default is 1.5 )

Usage:

material.setTexture(1,
blurred_texture)
material.setTexture(2,
depth_texture)
material.setEffectFloat('fFocusDepth',
0.8 )
material.setEffectFloat('fAperture',
0.8 )

PixelShader: 2
.0

Shader File: depth_of_field.fx

combine
Combine original texture and input texture by a factor.

result = original_texture + (input_texture - original_texture) X blur

Factor:
number
input_texture
number
blur ( default is 0.7 )

Usage:

material.setTexture(1,
input_texture)
material.setEffectFloat('blur',
0.8 )

PixelShader:
1.4

Shader File: combine.fx

sun shafts mask generation
Generate sun shafts mask pattern by original texture and depth image.

Factor:
number
depth_texture

Usage:

material.setTexture(1,
depth_texture)

PixelShader:
2.0

Shader File: sun_shafts_mask_gen.fx

sun shafts generation
Generate sun shafts by the mask pattern.

Factor:
number
mask_texture
vec4 
SunShafts_SunPos  ( the sun position, in world space )


Usage:

material.setTexture(0,
mask_texture)
material.setEffectVector('SunShafts_SunPos',vec4.new(sunpos.x,sunpos.y,sunpos.z,1))

PixelShader:
2.0

Shader File: sun_shafts_gen.fx

sun shafts display


Combine the original scene image and shafts image.

Factor:
number
shafts_texture
number
SunShafts_Intensity (0~1, default is 0.6)
vec4 
SunShafts_SunColor (default is 1,1,1,1)

Usage:

material.setTexture(1,
shafts_texture)
material.setEffectFloat('SunShafts_Intensity',0.9)
material.setEffectVector( 'SunShafts_SunColor', vec4.new(1, .8, .5, 1) )

PixelShader:
2.0

Shader File: sun_shafts_disp.fx

Remark: you can set texture parameters in the 'texture' rollout of material panel; instead of scripting.

Output to Texture:
You can assign a render target to a post, so output the post result to texture, not to screen any more. Then you can reuse the texture in succeeding posts. For example, you can first use a post to output whole image to a small texture, then enlarge the small texture to full screen in succeeding post, to create a consuming blurring effect.

Custom You Own Post

Bloom Effect

Auto-sensing Brightness

Depth Of Field

Motion Blur

Sun Shafts