Welcome, Guest.
Username: Password: Remember me

TOPIC: Grey gamma

Grey gamma 1 week 1 day ago #1

A simple one this time, just the gamma version of my grey S-curves:

Regular gamma:


Grey gamma:

Saturation is retained in the colours.
#include "ReShadeUI.fxh"

uniform int Gamma_type < __UNIFORM_COMBO_INT1
    ui_items = "Grey gamma\0Regular Gamma\0";
> = 0;

uniform float Gamma < __UNIFORM_DRAG_FLOAT1
	ui_min = -1.0; ui_max = 10.0;
> = 1.0;

uniform bool Split <> = false;

uniform bool Flip_split <> = false;

uniform float Split_position < __UNIFORM_SLIDER_FLOAT1
	ui_min = 0; ui_max =1;
	ui_tooltip = "0 is on the far left, 1 on the far right.";
> = 0.5;

#include "ReShade.fxh"


float4 GammaPass(float4 position : SV_Position, float2 texcoord : TEXCOORD0) : SV_Target
{

float4 colorOrig = tex2D(ReShade::BackBuffer, texcoord);
float4 color=colorOrig;

float4 c1=color;
float colMax=max(color.r,max(color.g,color.b));
c1.rgb=(Gamma_type==0)?saturate(pow(abs(colMax),Gamma)*(color.rgb/colMax)):pow(abs(color.rgb),Gamma);
color=(Gamma!=1)?c1:color;

float4 c2=(texcoord.x>=Split_position*Split)?color:colorOrig;
float4 c3=(texcoord.x<=Split_position*Split)?color:colorOrig;

float4 c4=(Flip_split*Split==1)?c3:c2;

float divLine = abs(texcoord.x - Split_position) < BUFFER_RCP_WIDTH;
c4 =(Split==0)?c4: c4*(1.0 - divLine); //invert divline

return c4;

}

technique Grey_Gamma
{
	pass
	{
		VertexShader = PostProcessVS;
		PixelShader = GammaPass;
	}
}

N.B. When I optimise my shaders as Marty McFly suggested in the Line Thinning thread, I'll probably re-upload all my shaders at once, optimised.

EDIT: I could put this function into another shader, but personally I like it being standalone in order to be more stackable,

The .hlsl version is here.
Last Edit: 2 days 15 hours ago by crabshank.
The administrator has disabled public write access.
The following user(s) said Thank You: Wicked Sick, jas01

Grey gamma 6 days 10 hours ago #2

Rewrote the file to show some optimizations you can do:

pastebin.com/CkT2Rkz7

Basically first of all, ditch as many branches as you can. Using if/else to just assign one variable or early return is super slow, shaders don't have an early return, there are no jump operations, so it'll all end up being assigned to one register that's returned at the end. Ternary operator (the ? : operator of C languages) is much better suited for that as it doesn't branch, just a conditional assign.
Computing the max of all channels into a separate variable makes sure to compiler doesn't calculate it two times- it probably won't but making sure is better.

The splitscreen is a huge abomination with many branches and conditions which can be easily simplified using a bit of math. I made it so the width is always 2 pixels. Important to know that booleans don't exist in shaders, we only have integers and floats, and quite often, integers are also emulated, so keep all math in float as long as possible. I put a lot of comments in there to show you what I did, might want to do a revision and also consider that for your other shaders. Thing is, you might consider ditching the split altogether, because we already have a splitscreen shader iirc, and doing the calculation in every shader is straining performance.

Happy programming!
The administrator has disabled public write access.
The following user(s) said Thank You: Wicked Sick, crabshank

Grey gamma 6 days 10 hours ago #3

Thanks a lot for the tips, I'll re-write my code as soon as I can.

EDIT: TBH, I didn't even know that the x=y>z construction was even a thing.
Last Edit: 6 days 10 hours ago by crabshank.
The administrator has disabled public write access.

Grey gamma 5 days 23 hours ago #4

Marty McFly wrote:
Thing is, you might consider ditching the split altogether, because we already have a splitscreen shader iirc, and doing the calculation in every shader is straining performance.

Perhaps it's better for crabshank to release it as a separate thing? Being honest I prefer his version of this shader. Mixing them into one splitscreen could work as well (adding dynamic slider from his work to what we already have - if I'm right there is no such thing in it right now).
Last Edit: 5 days 23 hours ago by jas01. Reason: .
The administrator has disabled public write access.
The following user(s) said Thank You: crabshank

Grey gamma 3 days 6 hours ago #5

Optimised ^
The administrator has disabled public write access.