Welcome, Guest.
Username: Password: Remember me

TOPIC: Possible to have shader use own ..._FAR_PLANE?

BeamNG Reflective Bump Mapping Fresnel 1 month 6 days ago #1

Ive been playing with Reshade presets a while now though i barely know what im doing. Impressed by what Reshade and the community built shaders can do!
BeamNG lacks fresnel so the paint looks kind of dull. Im using RBM to try and get a fresnel look. So far its working quite well but im having a few issues.

To stop RBM from giving everything no matter depth a reflection ive set the preprocessor RESHADE_DEPTH_LINEARIZATION_FAR_PLANE=50 instead of the default 1000.
This however effects other shaders such as MXAO and DOF. Im not good at all with coding but looking at the RBM code i kind of get what some of it does. Is there a way to set the RBM depth to a fixed 50, or adjustable depth for that matter, in the code, instead of it reading RESHADE_DEPTH_LINEARIZATION_FAR_PLANE?

Also, if a vehicle has a paint color other than greyscale, the fresnel effect gets toned the opposite color, if a car is yellow then the fresnel has a blue'ish tone, if the car is red then the fresnel gets a green tone. Is there a way to bring the tone down ord esaturate it completely (other than the existing color settings which removes the effect instead)?

Theres a few other small issues but these are my main concern atm :)

My Reshade preset with fresnel:
https://beamng.com/attachments/screenshot_00097-png.393600/

Without:
https://beamng.com/attachments/screenshot_00097-png.393601/
Last Edit: 1 month 6 days ago by brother_david.
The administrator has disabled public write access.

BeamNG Reflective Bump Mapping Fresnel 1 month 6 days ago #2

Maybe a dirty fix would be to change this row:

float EyeDepth = GetLinearDepth(coords.xy)*RESHADE_DEPTH_LINEARIZATION_FAR_PLANE;

To:

float EyeDepth = GetLinearDepth(coords.xy)*(RESHADE_DEPTH_LINEARIZATION_FAR_PLANE*0.2);

What do you think?
The administrator has disabled public write access.

BeamNG Reflective Bump Mapping Fresnel 1 month 5 days ago #3

The weird coloring of the fresnel effect is gone, my fault it was there.

I tried changing theline above to acouple of different version but none seemed to make any difference. Kind of stuck on how to make RBM use a individual _FAR_PLANE instead of changing the whole Reshade one.
The administrator has disabled public write access.

Possible to have shader use own ..._FAR_PLANE? 1 month 5 days ago #4

Ive lately been trying to add a Fresnel effect in Beamng, using RBM (Reflective Bump Mapping) and have got a quite good result:



Compared to this, which uses my every shader (Depth Haze creates the blurry background, not DOF since it doesnt work) but RBM:



My problem is that every building and road in the background gets quite an obvious RBM effect unless i lower RESHADE_DEPTH_LINEARIZATION_FAR_PLANE=1000 down to say 50.
Having it at 50 lets me have a good fresnel effect (still wih flaws that ive yet to solve) on the cars paint but that also effects DOF and MXAO in a negative way. MXAO is gone and DOF is to unless i increase the amount bu then it looks off.

My question is, is there a way to make the shader have a own "..._FAR_PLANE='-value? Or multiply the _FAR_PLANE with 0.2 to get 50 as a value? In that way i can use MXAO and DOF as usual but also have the fresnel effect.

Last, i dont know my way around coding shaders but im eager to learn enough to get by.
Last Edit: 1 month 5 days ago by brother_david.
The administrator has disabled public write access.

Possible to have shader use own ..._FAR_PLANE? 1 month 5 days ago #5

  • crosire
  • crosire's Avatar
  • Online
  • Posts: 3003
  • Thank you received: 1758
Sure. Open "ReflectiveBumpMapping.fx" and search for the following code:
float GetLinearDepth(float2 coords)
{
	return ReShade::GetLinearizedDepth(coords);
}
Replace that with the following:
float GetLinearDepth(float2 coords)
{
#if RESHADE_DEPTH_INPUT_IS_UPSIDE_DOWN
	texcoord.y = 1.0 - texcoord.y;
#endif
	float depth = tex2Dlod(DepthBuffer, float4(texcoord, 0, 0)).x;

#if RESHADE_DEPTH_INPUT_IS_LOGARITHMIC
	const float C = 0.01;
	depth = (exp(depth * log(C + 1.0)) - 1.0) / C;
#endif
#if RESHADE_DEPTH_INPUT_IS_REVERSED
	depth = 1.0 - depth;
#endif
	const float N = 1.0;
	depth /= RESHADE_DEPTH_LINEARIZATION_FAR_PLANE_2 - depth * (RESHADE_DEPTH_LINEARIZATION_FAR_PLANE_2 - N);

	return depth;
}
Now it will use the value of a RESHADE_DEPTH_LINEARIZATION_FAR_PLANE_2 define instead of RESHADE_DEPTH_LINEARIZATION_FAR_PLANE.
Cheers, crosire =)
The administrator has disabled public write access.
The following user(s) said Thank You: Insomnia, AssassinsDecree, brother_david

Possible to have shader use own ..._FAR_PLANE? 1 month 4 days ago #6

  • Marty McFly
  • Marty McFly's Avatar
  • Offline
  • We've tried nothing and we're all out of ideas!
  • Posts: 983
  • Thank you received: 980
The far plane is the wrong value to tweak. It's used to convert raw depth buffer to linear (as in: proportional to distance to camera) one, so position calculations can be made. While changing it to a (false) value might distort the depth buffer data so it happens to create the desired result somewhat, it's still not viable to modify it.
What your changes do is merely screwing up the depth values so after a certain distance the calculated positions of objects are so off that the shader won't create any reflections anymore.
So what I've got from your text is that you want a fade out option, correct?
The administrator has disabled public write access.
The following user(s) said Thank You: brother_david

Possible to have shader use own ..._FAR_PLANE? 1 month 4 days ago #7

Thank you Crosire and thank you Marty!

Im definitely with you on that its the wrong way to do it since it alteres the funtamental value that the FAR_PLANE gives but im simply bad at this (for now).
Yes that would be what im looking for, maybe something similar to the MXAO UI MXAO_FADE_DEPTH_START and MXAO_FADE_DEPTH_END (which is really nice btw).
The administrator has disabled public write access.

Possible to have shader use own ..._FAR_PLANE? 1 month 4 days ago #8

crosire wrote:
Sure. Open "ReflectiveBumpMapping.fx" and search for the following code:
float GetLinearDepth(float2 coords)
{
	return ReShade::GetLinearizedDepth(coords);
}
Replace that with the following:
float GetLinearDepth(float2 coords)
{
#if RESHADE_DEPTH_INPUT_IS_UPSIDE_DOWN
	texcoord.y = 1.0 - texcoord.y;
#endif
	float depth = tex2Dlod(DepthBuffer, float4(texcoord, 0, 0)).x;

#if RESHADE_DEPTH_INPUT_IS_LOGARITHMIC
	const float C = 0.01;
	depth = (exp(depth * log(C + 1.0)) - 1.0) / C;
#endif
#if RESHADE_DEPTH_INPUT_IS_REVERSED
	depth = 1.0 - depth;
#endif
	const float N = 1.0;
	depth /= RESHADE_DEPTH_LINEARIZATION_FAR_PLANE_2 - depth * (RESHADE_DEPTH_LINEARIZATION_FAR_PLANE_2 - N);

	return depth;
}
Now it will use the value of a RESHADE_DEPTH_LINEARIZATION_FAR_PLANE_2 define instead of RESHADE_DEPTH_LINEARIZATION_FAR_PLANE.

Tried to replace that piece of code with the one you gave me, unfortunatly it hands me a shader compiling error. Ive added ..._FAR_PLANE_2=40 to dxgi.ini, also tried adding it to Reshade.fxh if that matters but no luck.
The administrator has disabled public write access.

Possible to have shader use own ..._FAR_PLANE? 1 month 4 days ago #9

Heres how the different combinations look for comparison, as stated by Marty, changing the _FAR_PLANE is the wrong way but ill take what i get :) Its quite obvious that alot gets messed up when i change that to 40, although my issue with RBM is toned way down.

My current preset with:

_FAR_PLANE=1000, RBM


_FAR_PLANE=1000, No RBM


_FAR_PLANE=40, RBM


_FAR_PLANE=40 No RBM
Last Edit: 1 month 4 days ago by brother_david.
The administrator has disabled public write access.

Possible to have shader use own ..._FAR_PLANE? 4 weeks 11 hours ago #10

Im very much stuck unfortunatly.
Tried to figure out how to get the code you posted Crosire, to work but no luck.
Also tried to make it the RBM settings distance adjustable but no luck with that either :pinch:
The administrator has disabled public write access.