RXP

Enhanced Rendering (for free) and Post Processsing

Recommended Posts

Hi,

I've been experimenting a little bit with the XP11 shaders. Unlike using external tools like SweetFx or similar, which intercept the OpenGL rendering prior display and add a lot of 'plumbing' behind the scene, I've decided to just alter the stock XP11 shaders a little bit.

The neat effect is that one of the enhancements below comes for free, the other advantage is that this works on Window, Mac and Linux!

This also works in VR mode!

NB: this is a copy of my post here:
https://forums.x-plane.org/index.php?/forums/topic/149559-enhanced-rendering-for-free-and-post-processsing/&tab=comments#comment-1422161

 

All modifications are done in "XP11\Resources\shaders\tone_map.glsl"

Deeper shadows and brighter highlights:

The first item is about the tone mapping which I find a little bit too soft, especially with high contrasts (sun and shadows in the cockpit).

This one just changes the XP11 tone mapping function and has no additional pixel shader instructions than stock!

Post Processing

The second item is about post processing the pixels.

Here are 3 functions you can add to the tone_map.glsl right before the function tone_map_uncharted.

This is super easy to do and gives instant rewarding look-and-feel to the simulation.

Obviously, the next time you update XP11, these will be deleted, so make sure to make a backup of the original tone_map.glsl file if you want to restore the genuine shader, and to backup the modifications and reapply them should the tone_map.glsl file gets updated in the future!
 

How to:

Here is a simpler way to try out and experiment, plus, it could serve as the basis to extend the effects more easily.

1) open any text editor, copy the following, save into XP11\Resources\shaders\postprocess.glsl

#define POST_PROCESS_EFFECTS 1
#define POST_PROCESS_TONEMAP 1

#if POST_PROCESS_EFFECTS

vec3 PostProcessWarmth(vec3 rgb)
{
	// other: 1,35, 1.20, 1.10
	const mat3x3 warmth = mat3x3(
		vec3( 1.10,-0.10,-0.10),
		vec3(-0.10, 1.15,-0.10),
		vec3(-0.10,-0.10, 1.20));

	rgb = rgb * warmth;
	return rgb / (rgb + 2.2) * 3.0;
}

vec3 PostProcessSaturation(const vec3 rgb, float saturation)
{
	vec3 base = vec3(0.2125, 0.7154, 0.0721);
	vec3 lum  = vec3(dot(rgb, base));
	return mix(lum, rgb, saturation);
}

vec3 PostProcessVibrancy(const vec3 rgb, float vibrancy)
{
	float hi  = max(rgb.r,max(rgb.g,rgb.b));
	float lo  = min(rgb.r,min(rgb.g,rgb.b));
	float saturation = 1.0 + (vibrancy * (1.0 - (sign(vibrancy) * (hi -lo))));
	return PostProcessSaturation(rgb, saturation);
}

vec3 PostProcessTonemap(vec3 x)
{
	float A = 0.25;
	float B = 0.29;
	float C = 0.10;
	float D = 0.20;
	float E = 0.03;
	float F = 0.35;
	return ((x*(A*x+C*B)+D*E)/(x*(A*x+B)+D*F))-E/F;
}

void tone_map_uncharted(inout vec3 rgb, in float gain)
{
#if POST_PROCESS_TONEMAP
	float ExposureBias = gain;
	vec3 curr = PostProcessTonemap(ExposureBias*rgb);
	vec3 whiteScale = 1.0f/PostProcessTonemap(vec3(tonemap_gain.w));
	rgb = curr*whiteScale;
#else
	float ExposureBias = gain;
	vec3 curr = Uncharted2Tonemap(ExposureBias*rgb);
	vec3 whiteScale = 1.0f/Uncharted2Tonemap(vec3(tonemap_gain.w));
	rgb = curr*whiteScale;
#endif

	rgb = PostProcessWarmth(rgb);
	//rgb = PostProcessSaturation(rgb, 1.15);
	//rgb = PostProcessVibrancy(rgb, 1.1);
}

#endif

2) open tone_map.glsl and edit the following lines:

61: #include "postprocess.glsl"    
62: #if !POST_PROCESS_EFFECTS
82: #endif

This should ressemble this:

...
#include "postprocess.glsl"	
#if !POST_PROCESS_EFFECTS
void tone_map_uncharted(inout vec3 rgb, in float gain)
{

//			dumb clamping
//			rgb = clamp(rgb,0.0,1.0);

//			naive coolor Reinhardt - needs srgb
//			rgb = Reinhard(rgb);

//			Dawson - no srgb
//			vec3 x = max(rgb-0.004,0.0);
//			rgb = (x*(6.2*x+.5))/(x*(6.2*x+1.7)+0.06);
		
// uncharted 2
		float ExposureBias = gain;
		vec3 curr = Uncharted2Tonemap(ExposureBias*rgb);
		vec3 whiteScale = 1.0f/Uncharted2Tonemap(vec3(tonemap_gain.w));
		rgb = curr*whiteScale;
}
#endif
void tone_map_gifford(inout vec3 rgb, in float gain)
{
//	rgb = to_srgb(rgb);
	vec3 blend_rat = pow(clamp(rgb,0.0,1.0),vec3(bias));
	rgb = mix(rgb,1.0 - pow(clamp(1.0 - rgb,0.0,1.0), vec3(gain)),blend_rat);
}
...

That's all!

 

To enable post processing effect:

change the first line in postprocess.glsl to:
#define POST_PROCESS_EFFECTS 1

otherwise, change it to:
#define POST_PROCESS_EFFECTS 0

To select which effect:

un-comment only 1 of the PostProcessXXXXX line. For example, to select 'saturation' instead of 'warmth':

    //rgb = PostProcessWarmth(rgb);
    rgb = PostProcessSaturation(rgb, 1.15);
    //rgb = PostProcessVibrancy(rgb, 1.1);

To add your own post processing effect:

define a new PostProcessXXXX function, and add a line to call it below the other ones!

Please note the effects I've presented are mutually exclusive, but you can cascade effects, that is should you have a 'heat distortion' pixel shader effect, you can add it after post processing the colors like this:

rgb = PostProcessWarmth(rgb);
rgb = PostProcessHeatDistortion(rgb);

etc...

Here are some comparative pictures:

Default:

Baron_58_no_post_process.jpg

Alternate Tone Mapping + PostProcessSaturation(1.15)

Baron_58_tonemap_saturation_1_15.jpg

Alternate Tone Mapping + PostProcessWarmth (my favorite)

Baron_58_tonemap_warmth.jpg

Side by Side (default vs warmth):

Baron_58_default_vs_warmth.jpg

Inside default:

Baron_58_inside_default.jpg

Inside Warmth:

Baron_58_inside_warmth.jpg

  • Like 3
  • Upvote 3

Share this post


Link to post
Share on other sites
Help AVSIM continue to serve you!
Please donate today!

Great work Jean-Luc! I always thought that altering the default shaders could improve the (rather dull) default look of XP significantly. Unfortunately I didn't have the needed knowledge to do it myself. In the past, I just experimented a little with the sky rendering shader to improve the lighting during dusk, with some interesting results.

 

Share this post


Link to post
Share on other sites
Posted (edited)

This appears to be a good time for me to ask what to use other than Notepad because with Xplane I am always hearing about simple text file edits when all of my XP text files are massive run on sentences with little to no formatting.  I'd like to use a default Windows program if possible.

Thanks, Jean-Luc.

EDIT: found it but Id still like a usable text file reader (preferable included with Windows)

PPS: is there a dummies guide to shader code somewhere.  I spent some time with MSDN and HLSL but I simply don't know enough of the functions or the overall flow of the code to grasp it.  I have moderate C familiarity.  C++ drove me nuts.  With shader code there doesn't seem to be a 'main'.

Edited by sightseer

Share this post


Link to post
Share on other sites

notepad is standard windows program, but you can try notepad++ instead, or notepad2, or even the latest Microsoft Visual Studio Code: https://code.visualstudio.com/

Otherwise a shader course will be too long and complex as a forum topic, suffice to say there is a main (of some sort) and similar language to C, with native vec2, vec3, vec4 and mat2, mat3, mat4 types.

  • Like 2

Share this post


Link to post
Share on other sites

Interesting.  I literally haven't touched flightsim in a few weeks but I should check this out for sure so thanks!

Share this post


Link to post
Share on other sites

Tried it , getting glsl errors and so i went and updated XP11 and then i got a European Authentication message and now XP11 is showing as 11.21r2 funny.

Can you upload those two shaders files ? 

Share this post


Link to post
Share on other sites
Posted (edited)

I should have indicated this was at least for XP11.20R2 (probably for XP11.20 as well).

I doubt much has changed in the 11.21R1 shader files either.

There is really no need to upload anything: just type notepad.exe in your Windows start menu (or use any text editor on macOs, Linux) and copy/paste/save the first one as indicated. For the 2nd part, you'll have to modify the existing shader file tone_map.glsl and add 3 lines as indicated, that's all.

This is kinda experimental and anytime they change the implementation of the tone_map_uncharted() function, this will have to be 'reflected' in the postprocess.glsl copy of the function: the implementation shown above consists in 'overriding' the stock function with an alternate one, which serves to not only change the tone mapping (deeper blacks, brighter highlights), but also to be the root function for additional PostProcess functions.

Alternatively for example, should you want to keep the original tone mapping, and just want to add a little 'warmth' to the rendering, you could just modify the original function like this:

...
void tone_map_uncharted(inout vec3 rgb, in float gain)
{

//			dumb clamping
//			rgb = clamp(rgb,0.0,1.0);

//			naive coolor Reinhardt - needs srgb
//			rgb = Reinhard(rgb);

//			Dawson - no srgb
//			vec3 x = max(rgb-0.004,0.0);
//			rgb = (x*(6.2*x+.5))/(x*(6.2*x+1.7)+0.06);
		
// uncharted 2
		float ExposureBias = gain;
		vec3 curr = Uncharted2Tonemap(ExposureBias*rgb);
		vec3 whiteScale = 1.0f/Uncharted2Tonemap(vec3(tonemap_gain.w));
		rgb = curr*whiteScale;

// warmth
	const mat3x3 warmth = mat3x3(
		vec3( 1.10,-0.10,-0.10),
		vec3(-0.10, 1.15,-0.10),
		vec3(-0.10,-0.10, 1.20));

	rgb = rgb * warmth;
	rgb = rgb / (rgb + 2.2) * 3.0;
}
...

 

Edited by RXP
clarifying it is for XP11.20r2

Share this post


Link to post
Share on other sites
Posted (edited)

@RXP

 Thanks.

Can you make a God Rays shader 😁

Edited by HumptyDumpty

Share this post


Link to post
Share on other sites
19 minutes ago, HumptyDumpty said:

Can you make a God Rays shader

You're reading my mind! I don't have much time for now for this, but it is in my list. I wanted to also find a way if I could just make some illuminated haze around city night light, as I find the night skies in urban areas lacking light pollution.

Share this post


Link to post
Share on other sites

@RXP

  I just retried the tonemap shader by adding those two lines and i get a Legacy.glsl error.

Maybe it don't work with 11.21r2 but i remember even with 11.20 it was giving this error.

 

 

Share this post


Link to post
Share on other sites
Posted (edited)

I've tested this with XP11.21r2 (macOs) but I've just compared with XP11.20r4 (win) and the shader files are the same.

It is possible this depends on your graphics settings too (hdr or not, msaa or not etc...), but it shouldn't because this is only changing the tonemap function parameters and further adjusting the RGB of the tone mapped pixel before returning to the calling function(s).

In any case, if this helps: download postprocess.glsl

Edited by RXP
download link fixed
  • Upvote 1

Share this post


Link to post
Share on other sites
1 hour ago, RXP said:

I should have indicated this was at least for XP11.20R2 (probably for XP11.20 as well).

I doubt much has changed in the 11.21R1 shader files either.

There is really no need to upload anything: just type notepad.exe in your Windows start menu (or use any text editor on macOs, Linux) and copy/paste/save the first one as indicated. For the 2nd part, you'll have to modify the existing shader file tone_map.glsl and add 3 lines as indicated, that's all.

This is kinda experimental and anytime they change the implementation of the tone_map_uncharted() function, this will have to be 'reflected' in the postprocess.glsl copy of the function: the implementation shown above consists in 'overriding' the stock function with an alternate one, which serves to not only change the tone mapping (deeper blacks, brighter highlights), but also to be the root function for additional PostProcess functions.

Alternatively for example, should you want to keep the original tone mapping, and just want to add a little 'warmth' to the rendering, you could just modify the original function like this:


...
void tone_map_uncharted(inout vec3 rgb, in float gain)
{

//			dumb clamping
//			rgb = clamp(rgb,0.0,1.0);

//			naive coolor Reinhardt - needs srgb
//			rgb = Reinhard(rgb);

//			Dawson - no srgb
//			vec3 x = max(rgb-0.004,0.0);
//			rgb = (x*(6.2*x+.5))/(x*(6.2*x+1.7)+0.06);
		
// uncharted 2
		float ExposureBias = gain;
		vec3 curr = Uncharted2Tonemap(ExposureBias*rgb);
		vec3 whiteScale = 1.0f/Uncharted2Tonemap(vec3(tonemap_gain.w));
		rgb = curr*whiteScale;

// warmth
	const mat3x3 warmth = mat3x3(
		vec3( 1.10,-0.10,-0.10),
		vec3(-0.10, 1.15,-0.10),
		vec3(-0.10,-0.10, 1.20));

	rgb = rgb * warmth;
	rgb = rgb / (rgb + 2.2) * 3.0;
}
...

 

Hi, Thanks for this, applied "warmth" and am pleased with the result, and will follow others experiences with interest! Many Thanks

Share this post


Link to post
Share on other sites
Posted (edited)

@RXP 

That file is not downloading , the file does not exists.

I have SSAO enabled in XP11. Only using FXAA 

It's an AMD GPU.

Now tried the "warmth" thing and i got a dome.glsl error and XP CTD's. So anything i put into Tonemap.glsl it crashes.

Thanks for the new link, will try it again in a while after re-adding the POSTEFFECT lines in tonemap.glsl

 

Edited by HumptyDumpty

Share this post


Link to post
Share on other sites

download link updated.

Share this post


Link to post
Share on other sites
1 minute ago, RXP said:

download link updated.

Yep thanks , downloaded the zip file. Will retry in a bit

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now