Post-processing-effectors (PPE)

From Mod Wiki

Jump to: navigation, search
Custom PPE for sepia vision
Custom PPE for sepia vision

Post-process effectors (.ppe) in STALKER are used to create visual effects like radiation-exposure, drunkenness, psy-effects, night-vision and other. They are binary files that have a certain internal structure. Once you understand the structure and manage to keep the overview in the file, you can edit them or even create new effectors. Note that PPEs always affect the whole screen, so it is not possible to limit the effects to certain areas. A necessary tool to edit PPEs is a decent hex editor like HxD. Also, sometimes you would want to calculate Hex values to decimal values and reverse. Some websites offer this possibility (e.g. easycalculation.com).

This article is based on the Russian version by Green Hawk (see interwiki link). Many thanks to him for doing the research and sharing with the community!

Contents

Analysis

It may help you to understand the structure of PPEs if you look into \gamedata\script\postprocess.script and into some ltx like \gamedata\config\scripts\proba.ltx. It seems like postprocess.script was used to create PPEs - or at least read PPE configurations from .ltx'.

Every PPE file contains multiple sets of rules. The structure of these rule-sets can be guessed by looking at the files above. But to make things easier, here is an overview over the structure. If you open a PPE in HxD to compare the structure with this explanation, it can be useful to change the number of bytes per row to something like eight. It may help you to gain a better overview of the file segments.

File header

Every file starts with 01 00 00 00. This is most likely a signature to identify the file content. Note: The camera animation files .anm share the same structure and have the signature 00 11 00 00. They are located within the same folder as the PPEs. After the signature, four bytes with unknown meaning follow. Usually they are 7C 00 00 00, but there are variations. So our file until here looks like 01 00 00 00 7C 00 00 00. Now the rule-sets follow.

Rule-sets introduction

Every set begins with 01 01 XX 00 where XX is the number of rules that the set contains. For example 01 01 00 00 means that no rule follows, so the set is not active at all. Many mistakes happen if the number given at the start of the set does not fit the number of rules. Make sure to check it, every time you change something. Rules always consist of 23 bytes! If a rule-set started with 01 01 04 00 then there will be 04 x 23 bytes of rules following.

Tips on keeping the overview

The 23 byte rule size makes keeping the overview more complicated because there are even headers and odd content. So the lines will break pretty fast. Also there can be bigger rules-sets like sets of 14 rules (0E in hex)! If you are about to loose the overview in a file, reduce the number of hex values per line to eight and write down the offset value of important points in the file - for example the starting positions of rule-sets. The offset of positions within a line, is written on the status bar in the lower left corner of HxD. When using eight byte lines in HxD, you can use the fact that three lines are equal to 24 bytes, so you can go down three lines and go back one byte, to get from the start of a rule to its end. If you hold SHIFT while doing that, you will highlight the rule, which helps you not to slip into a wrong line or to loose your position. While counting rules of 23 bytes, keep in mind that the rule-set header (4 bytes) is not part of the rules and must be excluded of the counting.

Now it might be good to look at an example file with comments, before we look at the explanation of the segments.

Example file with comments

The following example shows the structure of a PPE with comments. It is taken from the Russian article.

01 00 00 00 		;signature
 
; crank the colors up to the max
 
7C 00 00 00 		;unknown1
01 01 02 00 		;color_add_red
00 00 80 3F 00 00 00 00 00 00 80 00 80 00 80 00 80 00 80 00 80 00 80 
00 00 80 3F 00 00 00 41 00 00 80 00 80 00 80 00 80 00 80 00 80 00 80 
01 01 02 00 		;color_add_green
00 00 80 3F 00 00 00 00 00 00 80 00 80 00 80 00 80 00 80 00 80 00 80 
00 00 80 3F 00 00 00 41 00 00 80 00 80 00 80 00 80 00 80 00 80 00 80 
01 01 02 00 		;color_add_blue
00 00 80 3F 00 00 00 00 00 00 80 00 80 00 80 00 80 00 80 00 80 00 80 
00 00 80 3F 00 00 00 41 00 00 80 00 80 00 80 00 80 00 80 00 80 00 80 
 
; I do not understand how, but this triad is tinting already discolored 
; image, so now we're adding a bit of blue tone to result and  - at
; the same time - we slightly reduce red and green. -- Green Hawk
 
6C 10 00 00  		;unknown2
01 01 02 00 		;color_base_red
CD CC CC 3D 00 00 00 00 00 00 80 00 80 00 80 00 80 00 80 00 80 00 80 
CD CC CC 3D 00 00 00 41 00 00 80 00 80 00 80 00 80 00 80 00 80 00 80 
01 01 02 00 		;color_base_green
CD CC CC 3D 00 00 00 00 00 00 80 00 80 00 80 00 80 00 80 00 80 00 80 
CD CC CC 3D 00 00 00 41 00 00 80 00 80 00 80 00 80 00 80 00 80 00 80 
01 01 02 00 		;color_base_blue
CD CC 4C 3E 00 00 00 00 00 00 80 00 80 00 80 00 80 00 80 00 80 00 80 
CD CC 4C 3E 00 00 00 41 00 00 80 00 80 00 80 00 80 00 80 00 80 00 80 
 
;In the gray mode all red objects are white; all blue and green objects are black
 
7C 00 00 00  		;unknown3
01 01 02 00 		;color_gray_red
00 00 80 3F 00 00 00 00 00 00 80 00 80 00 80 00 80 00 80 00 80 00 80 
00 00 80 3F 00 00 00 41 00 00 80 00 80 00 80 00 80 00 80 00 80 00 80 
01 01 02 00 		;color_gray_green
00 00 80 BF 00 00 00 00 00 00 80 00 80 00 80 00 80 00 80 00 80 00 80 
00 00 80 BF 00 00 00 41 00 00 80 00 80 00 80 00 80 00 80 00 80 00 80 
01 01 02 00 		;color_gray_blue
00 00 80 BF 00 00 00 00 00 00 80 00 80 00 80 00 80 00 80 00 80 00 80 
00 00 80 BF 00 00 00 41 00 00 80 00 80 00 80 00 80 00 80 00 80 00 80 
 
;Fully black-and-white image, subject to the rules color_gray_*
 
01 01 02 00 		;gray
00 00 80 3F 00 00 00 00 00 00 80 00 80 00 80 00 80 00 80 00 80 00 80 
00 00 80 3F 00 00 00 41 00 00 80 00 80 00 80 00 80 00 80 00 80 00 80 
 
;No blur
 
01 01 00 00 		;blur
 
;No image doubling 
 
01 01 00 00 		;duality_h
01 01 00 00 		;duality_v
 
;Noise is also turned off
 
01 01 00 00 		;noise_intensivity
01 01 00 00 		;noise_granularity
01 01 00 00		;noise_fps

Rule-sets explanation

Chosen color component is multiplied by the factor, if parameter is equal to 1, pure white color will remain white and pure black - black, but all the other colors will be toned by colors of the component.

  • unknown1
  • color_add_red
  • color_add_green
  • color_add_blue

This value was adopted as a base for the colour, that is, if the value of the pixel color below the specified, it was adopted as specified and, if more, it remains the same. It should be noted that this is the only set of variables, raising which values above 0.5 is meaningless. 0.5 is added automatically by the game engine.

  • unknown2
  • color_base_red
  • color_base_green
  • color_base_blue

This triad affect the color intensity in gray/bright presentation. In normal colour mode the result is not visible. But with increased gray effect intensity, it is clear that with color_gray_red = -1 pure red components will become black, 0 = will remain unchanged, 1 - will became pure white:

  • unknown2
  • color_gray_red
  • color_gray_green
  • color_gray_blue

Variable manages the saturation value of the inverse, that is, the more gray (maximum 1) the lower the saturation of images:

  • gray

Blur effect, at large (higher than 25) factor some graphic artifacts appear on the the lower part of the screen:

  • blur

Image split effect, separately set for horizontal and vertical movement. Factor is set relatively to a screen so, with 1 copy of object, originally located in the center, others will be exactly at the edges:

  • duality_h
  • duality_v
  • noise_intensity
  • noise_granularity (the size of noise grain)
  • noise_fps (how many times per second should noise be calculated)

Rule explanation

Every rule (23 bytes) consists of different fields. Example rule with field labels:

value time function k1 k2 k3 unused (?)
9A 99 99 3E 00 00 A0 40 00 00 80 00 80 00 80 00 80 00 80 00 80 00 80
The exact structure of values in single rules is not yet clear to me. More information would be appreciated! Atrocious
  • value is what you usually want to change. It should be a 4 Byte float variable.
  • time
  • function is 00 in all PPEs, but it can be changed to 03 sinus, 01/05 cosine, 02 linear, 04 CTD.
  • k1, k2, k3 are probably ratios affected by function, but their usage is yet unresolved.
  • unused doesn't seem to be used, thus the name.

Using new effector files

  • A simple way to try new effector files is, to call them nightvision_bad.ppe or nightvision_good.ppe and put them into the gamedata\anims folder. Then you can use the effectors in game with suits that have either good night-vision or bad night-vision.
  • A little more complex (but necessary if you don't want to overwrite the existing night-visions) is the following: Call the new effector file like you want e.g. my_super_effector.ppe and make a new section for it in gamedata\config\misc\postprocess.ltx. You could also replace the link to another .ppe in an existing section. Then you can tie the new section to another suit, for example.
  • In scripts you can use the following codes
to add an effector to the vision:
level.add_pp_effector("my_super_effector.ppe", 2008, true)
to remove the effector again:
level.remove_pp_effector(2008)
Note that 2008 in this case is the unique identifier for the effector. You could use a different number as well.

Source codes

You can copy the following source codes and use them as templates for experiments. Simply make a new file with HxD, then copy the hex codes from this page into HxD (ignore the warning) and save the file. If you want to compare both source files, to see what I have changed to make the gray vision, you can copy them into a text file, save as text document and compare them with WinMerge or Compare It!.

If you did something wrong, X-ray will crash to desktop and bug-trap will report: Description  : noise.grain cant be zero! see postprocess.

Please add more source codes, if you achieve interesting effects.

Example file without comments

This is the example file Green Hawk posted on the Russian article. It's some kind of good night-vision.

Purple NV good (at day)
Purple NV good (at day)
01 00 00 00 7C 00 00 00 01 01 02 00 00 00 80 3F 
00 00 00 00 00 00 80 00 80 00 80 00 80 00 80 00 
80 00 80 00 00 80 3F 00 00 00 41 00 00 80 00 80 
00 80 00 80 00 80 00 80 00 80 01 01 02 00 00 00 
80 3F 00 00 00 00 00 00 80 00 80 00 80 00 80 00 
80 00 80 00 80 00 00 80 3F 00 00 00 41 00 00 80 
00 80 00 80 00 80 00 80 00 80 00 80 01 01 02 00 
00 00 80 3F 00 00 00 00 00 00 80 00 80 00 80 00 
80 00 80 00 80 00 80 00 00 80 3F 00 00 00 41 00 
00 80 00 80 00 80 00 80 00 80 00 80 00 80 6C 10 
00 00 01 01 02 00 CD CC CC 3D 00 00 00 00 00 00 
80 00 80 00 80 00 80 00 80 00 80 00 80 CD CC CC 
3D 00 00 00 41 00 00 80 00 80 00 80 00 80 00 80 
00 80 00 80 01 01 02 00 CD CC CC 3D 00 00 00 00 
00 00 80 00 80 00 80 00 80 00 80 00 80 00 80 CD 
CC CC 3D 00 00 00 41 00 00 80 00 80 00 80 00 80 
00 80 00 80 00 80 01 01 02 00 CD CC 4C 3E 00 00 
00 00 00 00 80 00 80 00 80 00 80 00 80 00 80 00 
80 CD CC 4C 3E 00 00 00 41 00 00 80 00 80 00 80 
00 80 00 80 00 80 00 80 7C 00 00 00 01 01 02 00 
00 00 80 3F 00 00 00 00 00 00 80 00 80 00 80 00 
80 00 80 00 80 00 80 00 00 80 3F 00 00 00 41 00 
00 80 00 80 00 80 00 80 00 80 00 80 00 80 01 01 
02 00 00 00 80 BF 00 00 00 00 00 00 80 00 80 00 
80 00 80 00 80 00 80 00 80 00 00 80 BF 00 00 00 
41 00 00 80 00 80 00 80 00 80 00 80 00 80 00 80 
01 01 02 00 00 00 80 BF 00 00 00 00 00 00 80 00 
80 00 80 00 80 00 80 00 80 00 80 00 00 80 BF 00 
00 00 41 00 00 80 00 80 00 80 00 80 00 80 00 80 
00 80 01 01 02 00 00 00 80 3F 00 00 00 00 00 00 
80 00 80 00 80 00 80 00 80 00 80 00 80 00 00 80 
3F 00 00 00 41 00 00 80 00 80 00 80 00 80 00 80 
00 80 00 80 01 01 00 00 01 01 00 00 01 01 00 00 
01 01 00 00 01 01 00 00 01 01 00 00

Sepia vision effector

Coincidental I made a grey filter that has something of another color in it. A bit like sepia filter. Atrocious

Sepia vision effector
Sepia vision effector
01 00 00 00 7C 00 00 00 01 01 02 00 00 00 80 3F 
00 00 00 00 00 00 80 00 80 00 80 00 80 00 80 00 
80 00 80 00 00 80 3F 00 00 00 41 00 00 80 00 80 
00 80 00 80 00 80 00 80 00 80 01 01 02 00 00 00 
80 3F 00 00 00 00 00 00 80 00 80 00 80 00 80 00 
80 00 80 00 80 00 00 80 3F 00 00 00 41 00 00 80 
00 80 00 80 00 80 00 80 00 80 00 80 01 01 02 00 
00 00 80 3F 00 00 00 00 00 00 80 00 80 00 80 00 
80 00 80 00 80 00 80 00 00 80 3F 00 00 00 41 00 
00 80 00 80 00 80 00 80 00 80 00 80 00 80 6C 10 
00 00 01 01 02 00 CD CC CC 3D 00 00 00 00 00 00 
80 00 80 00 80 00 80 00 80 00 80 00 80 CD CC CC 
3D 00 00 00 41 00 00 80 00 80 00 80 00 80 00 80 
00 80 00 80 01 01 02 00 CD CC CC 3D 00 00 00 00 
00 00 80 00 80 00 80 00 80 00 80 00 80 00 80 CD 
CC CC 3D 00 00 00 41 00 00 80 00 80 00 80 00 80 
00 80 00 80 00 80 01 01 02 00 CD CC CC 3D 00 00 
00 00 00 00 80 00 80 00 80 00 80 00 80 00 80 00 
80 CD CC CC 3D 00 00 00 41 00 00 80 00 80 00 80 
00 80 00 80 00 80 00 80 7C 00 00 00 01 01 02 00 
00 00 00 01 00 00 00 00 00 00 80 00 80 00 80 00 
80 00 80 00 80 00 80 00 00 00 01 00 00 00 41 00 
00 80 00 80 00 80 00 80 00 80 00 80 00 80 01 01 
02 00 00 00 00 01 00 00 00 00 00 00 80 00 80 00 
80 00 80 00 80 00 80 00 80 00 00 00 01 00 00 00 
41 00 00 80 00 80 00 80 00 80 00 80 00 80 00 80 
01 01 02 00 00 00 00 01 00 00 00 00 00 00 80 00 
80 00 80 00 80 00 80 00 80 00 80 00 00 00 01 00 
00 00 41 00 00 80 00 80 00 80 00 80 00 80 00 80 
00 80 01 01 02 00 00 00 DD DD 00 00 00 00 00 00 
80 00 80 00 80 00 80 00 80 00 80 00 80 00 00 DD 
DD 00 00 00 41 00 00 80 00 80 00 80 00 80 00 80 
00 80 00 80 01 01 00 00 01 01 00 00 01 01 00 00 
01 01 00 00 01 01 00 00 01 01 00 00

Black and White vision effector

Again some effect happened, as I tried working with sinus. Atrocious

Black and White vision effector
Black and White vision effector
01 00 00 00 7C 00 00 00 01 01 02 00 00 00 80 3F 
00 00 00 00 00 00 80 00 80 00 80 00 80 00 80 00 
80 00 80 00 00 80 3F 00 00 00 41 00 00 80 00 80 
00 80 00 80 00 80 00 80 00 80 01 01 02 00 00 00 
80 3F 00 00 00 00 00 00 80 00 80 00 80 00 80 00 
80 00 80 00 80 00 00 80 3F 00 00 00 41 00 00 80 
00 80 00 80 00 80 00 80 00 80 00 80 01 01 02 00 
00 00 80 3F 00 00 00 00 00 00 80 00 80 00 80 00 
80 00 80 00 80 00 80 00 00 80 3F 00 00 00 41 00 
00 80 00 80 00 80 00 80 00 80 00 80 00 80 6C 10 
00 00 01 01 02 00 40 A0 00 00 00 00 00 00 03 00 
80 00 80 00 80 00 80 00 80 00 80 00 80 40 20 00 
00 00 00 00 41 03 00 80 00 80 00 80 00 80 00 80 
00 80 00 80 01 01 02 00 00 00 00 00 00 00 00 00 
00 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00 
00 00 00 00 00 00 41 00 00 80 00 80 00 80 00 80 
00 80 00 80 00 80 01 01 02 00 00 00 00 00 00 00 
00 00 00 00 80 00 80 00 80 00 80 00 80 00 80 00 
80 00 00 00 00 00 00 00 41 00 00 80 00 80 00 80 
00 80 00 80 00 80 00 80 7C 00 00 00 01 01 02 00 
00 00 80 3F 00 00 00 00 00 00 80 00 80 00 80 00 
80 00 80 00 80 00 80 00 00 80 3F 00 00 00 41 00 
00 80 00 80 00 80 00 80 00 80 00 80 00 80 01 01 
02 00 00 00 80 BF 00 00 00 00 00 00 80 00 80 00 
80 00 80 00 80 00 80 00 80 00 00 80 BF 00 00 00 
41 00 00 80 00 80 00 80 00 80 00 80 00 80 00 80 
01 01 02 00 00 00 80 BF 00 00 00 00 00 00 80 00 
80 00 80 00 80 00 80 00 80 00 80 00 00 80 BF 00 
00 00 41 00 00 80 00 80 00 80 00 80 00 80 00 80 
00 80 01 01 02 00 00 00 80 3F 00 00 00 00 00 00 
80 00 80 00 80 00 80 00 80 00 80 00 80 00 00 80 
3F 00 00 00 41 00 00 80 00 80 00 80 00 80 00 80 
00 80 00 80 01 01 00 00 01 01 00 00 01 01 00 00 
01 01 00 00 01 01 00 00 01 01 00 00

Questions

As you can see, there are still open questions:

  • What are the byte blocks that are labled unknownX?
  • How do k1, k2, k3 work?
  • Is there a meaning for the unused part of each rule?

Feel free to contribute, if you find out anything about it.

Personal tools
In other languages