Welcome, Guest.
Username: Password: Remember me

TOPIC: sRGB to Linear RGB (approximation)

sRGB to Linear RGB (approximation) 2 months 1 week ago #1

A very simple shader that removes the inherent gamma correction in sRGB and approximates the linear RGB (where gamma=1) that a camera captures:
#include "ReShadeUI.fxh"

#include "ReShade.fxh"

float4 LinearisePass(float4 vpos : SV_Position, float2 texcoord : TexCoord) : SV_Target
{

float4 c0=tex2D(ReShade::BackBuffer, texcoord);

c0.rgb=(c0.rgb > 0.0404482362771082)?pow(abs((c0.rgb+0.055)/1.055),2.4):c0.rgb/12.92;
	
return c0;
}

float4 sRGBPass(float4 vpos : SV_Position, float2 texcoord : TexCoord) : SV_Target
{

float4 c0=tex2D(ReShade::BackBuffer, texcoord);

c0.rgb=( c0.rgb > 0.00313066844250063 )?1.055 * pow(abs(c0.rgb),1/2.4) - 0.055:12.92 *c0.rgb;

return c0;
}

technique sRGB_to_Linear
{
	pass
	{
		VertexShader = PostProcessVS;
		PixelShader = LinearisePass;
	}
}

technique Linear_to_sRGB
{
	pass
	{
		VertexShader = PostProcessVS;
		PixelShader = sRGBPass;
	}
}





Then re-grade as you see fit, I suggest applying gamma (choosing your own value or algorithm could lead to better results) first.

The image above uses the inverse setting.

Video shader here

I also have a version that uses an implicit method, but the gamma function is less accurate (straight gamma of 2.2) here
Last Edit: 36 minutes ago by crabshank. Reason: Separated transforms into separate techniques
The administrator has disabled public write access.
The following user(s) said Thank You: Wicked Sick, sajittarius, jas01, Deathmedic

sRGB to Linear RGB (approximation) 3 days 5 hours ago #2

UPDATE: Included both transforms (to Linear and inverse).
The administrator has disabled public write access.

sRGB to Linear RGB (approximation) 1 hour 11 minutes ago #3

Would it be possible to make a version of this with an adjustable gamma slider? I tried it in Star Wars Jedi: Fallen Order with HDR on and its amazing but could use a tiny tweak to the gamma values.

This shader works in HDR, whilst many other gamma ones (LevelsPlus, Tonemap, etc) do not, so i could see it helping in a lot of games where the HDR seems washed out.
The administrator has disabled public write access.
The following user(s) said Thank You: crabshank

sRGB to Linear RGB (approximation) 34 minutes ago #4

UPDATE: Separated transforms into separate techniques.

@sajittarius using my grey gamma shader after this should help.
The administrator has disabled public write access.