Welcome, Guest.
Username: Password: Remember me

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

BeamNG Reflective Bump Mapping Fresnel 4 months 4 weeks 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: 4 months 4 weeks ago by brother_david.
The administrator has disabled public write access.

BeamNG Reflective Bump Mapping Fresnel 4 months 4 weeks 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 4 months 3 weeks 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? 4 months 3 weeks 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: 4 months 3 weeks ago by brother_david.
The administrator has disabled public write access.

Possible to have shader use own ..._FAR_PLANE? 4 months 3 weeks ago #5

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? 4 months 3 weeks ago #6

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? 4 months 3 weeks 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? 4 months 3 weeks 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? 4 months 3 weeks 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: 4 months 3 weeks ago by brother_david.
The administrator has disabled public write access.

Possible to have shader use own ..._FAR_PLANE? 4 months 2 weeks 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.

Possible to have shader use own ..._FAR_PLANE? 2 months 3 weeks ago #11

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.

I must be stupid, i cannot get this to work. I dont know if i need to add lines to other files too? Reshade.fx for example?
The administrator has disabled public write access.

Possible to have shader use own ..._FAR_PLANE? 2 months 2 weeks ago #12

I'm not very familiar with HLSL or coding in reshade but "GetLinearDepth()" is a function that can be called by other code in the file. If you replace that with the function crosire wrote, the code that calls that function will get other data from it. So basically replace the whole function with the new function and you should not need to edit anything else.
The administrator has disabled public write access.

Possible to have shader use own ..._FAR_PLANE? 2 months 2 weeks ago #13

I think thats what ive done. I replaced the part above with his code. The original function returns ReShade::GetLinearizedDepth(coords), Crosires function returns 'depth'. Can that have something to do with it? Code later in the shader calls for the GetLinearizedDepth if i understand it right.
The administrator has disabled public write access.

Possible to have shader use own ..._FAR_PLANE? 2 months 2 weeks ago #14

It would be useful to specify what "I cannot get this to work" means. Btw. "DepthBuffer" should be "ReShade::DepthBuffer" in that code, small syntax mistake I made when I wrote it up.
Cheers, crosire =)
The administrator has disabled public write access.

Possible to have shader use own ..._FAR_PLANE? 2 months 2 weeks ago #15

Not very explainative of me but what i mean is that ive tried replacing the GetLinearized...-code with yours, which btw looks like the one in the Reshade.fxh?. Also added FAR_PLANE_2=40 as a preprocessor definition. I have tried replacing every FAR_PLANE in the rbm shader with FAR_PLANE_2. Also tried fiddeling with the Reshade.fxh.
Now ive tried replacing Depthbuffer with what you rote just now, so now the code looks like this:

float GetLinearDepth(float2 coords)
{
#if RESHADE_DEPTH_INPUT_IS_UPSIDE_DOWN
texcoord.y = 1.0 - texcoord.y;
#endif
float depth = tex2Dlod(ReShade::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;
}

Trying to find a typo in the code cause RBM wont show up in the shaders list but i get no error loading Reshade. Im guessing there is some coding error. Do i need to do something with the 'return depth;' code?

I highly appreciate all the help ive got so far, i am as you probably can see, a real newb when it comes to coding, so i understand if you get frustrated.
Last Edit: 2 months 2 weeks ago by brother_david.
The administrator has disabled public write access.

Possible to have shader use own ..._FAR_PLANE? 2 months 2 weeks ago #16

"float GetLinearDepth(float2 coords)" should be "float GetLinearDepth(float2 texcoords)". You can check errors on the log tab.
Cheers, crosire =)
The administrator has disabled public write access.

Possible to have shader use own ..._FAR_PLANE? 2 months 2 weeks ago #17

Checked errros log, it mentions texcoords as and undeclared identifier. Changed all texcoord to coords instead and it loads. Dont know if thats wrong. I do see now that the code says both texcoord and texcoord(s) so might try using texcoords everywhere instead when i get back.
Shader looks off at the moment so if changing all to texcoords doesnt change much of the look then its a dead end unfortunatly.Getting that damn fresnel look for BeamNG is hard but might have tracked down another way to do it, that uses Torque 3Ds attributes dirct on the materials instead of an overlay on the screen.
The administrator has disabled public write access.