This member has provided no bio about themself...

RSS My Blogs

Shaders in Xray - Gamma correction

MSwartz Blog 1 comment

Stalker games do not have gamma correct images.

To correct this, there are just a few steps.

In common_functions.h or common.h depending on the game and the renderer, you will see this line:

rgb = rgb*scale;

You want to replace that line with this:

rgb = rgb * (rgb * (rgb * 0.305306011 + 0.682171111) + 0.012522878)*scale;

Why not rgb = pow(rgb,2.2f)? Because it's wrong.

Now there are two more things you need to do: you need to make changes in combine_1.ps and hmodel.h.

In combine_1.ps, add this:

  float3 S1 = sqrt(D.rgb);
  float3 S2 = sqrt(S1);
  float3 S3 = sqrt(S2);
  D.rgb = 0.662002687 * S1 + 0.684122060 * S2 - 0.323583601 * S3 - 0.0225411470 * D.rgb;

In hmodel.h, do the exact same thing (replacing D.rgb with hscale instead).

Now, if you're working with Call of Pripyat, you'll also need to do that last bit of code to "res" in accum_volumetric_sun.ps as well.

And that's it. You now have proper gamma correction in Xray. This should work in all three games, but note the only released mod that you can currently do this for based on CoP is Call of Chernobyl.

Source: Chilliant.blogspot.com

Shaders in Xray 1.6 - Common mistakes

MSwartz Blog 2 comments

So with Radium in the works, and the next version of Call of Chernobyl adding support for 3rd party shader authoring, I thought I'd give a little insight on how shader authoring in Xray 1.6 works. This will be a multi-part series.

Note that it is already possible to author shaders for DirectX 9 in Xray 1.6. To do this, you need to delete your "shaders_cache" folder, which is present in your appdata folder, before you will be able to load any new shaders. You can not currently add new shaders for DX10-11, though you will be able to when Radium is out, and even sooner when Call of Chernobyl 1.4 is out.

This blog series is going to assume you have thoroughly read Crash Course in HLSL before attempting anything. It's really the least you should know. This blog post is more about things that are specific to Xray 1.6.

Common mistakes

When people have messed around with shaders in the previous games, some mistakes seem to be common.

1) Do not remove white space from your shaders. All it does is make your shader impossible for others to read. People do this thinking it is a way of "optimizing" shaders. It is not, at run-time when the shader is compiled, it does not read the white space.

2) Modifications of the wrong functions. This obviously comes from lack of knowledge, but I'll give you an example of one I came across. Someone was modifying the water shader for a different stalker game, and claimed they were improving the wave effect of the water. The value they were modifying was "Fc". Let me show you that part of the shader:

 // water fog
 half  fog_exp_intens = -4.0h;
 float fog = 1-exp(fog_exp_intens*waterDepth);
 half3 Fc   = half3( 0.1h, 0.1h, 0.1h) * water_intensity.r;
 final   = lerp (Fc, final*I.c0*2, alpha);

 alpha   = min(alpha, saturate(waterDepth));
 alpha   = max (fog, alpha);
Notice something? Take a look at the comment that was left (// is a comment): this area is used to calculate 
the fog in the water. Fc is a half3 value, meaning, it is a half-precision function that contains three floating
point values.
Another clue, is the next line, where you see that linear interpolation is done between Fc, final, I.c0 
(the input Color), and the alpha value.

Final is defined earlier as:

    half3 final=lerp(c_reflection,base.rgb,base.a);
   final *= I.c0*2;

So what is Fc? It's the fog color. It has nothing to do with water distortion.

3) Naming shaders you create something very unique or new, when it either already has a name, or it is not what you're claiming it is. Don't do it. It does not make you sound intelligent, it makes you look like a moron when someone reads your shader after your claims and then realizes you were full of shit.

Examples: slightly modifying lighting effects by multiplying a single value and calling it a new type of lighting, or changes the number of samples that the parallax mapping function draws from and giving it a new fancy name.


This has been shorter than anticipated, but stay tuned soon for part 2: Creating a new Pixel shader effect without having to modify the engine code.


Level
Avatar
Avatar
Last Online
Country
United States United States
Gender
Male
Friends
Become friends
Member watch
Follow
Blog Statistics
Articles
2
Views
65
Views Today
1
Feed
RSS