Welcome, Guest.
Username: Password: Remember me

TOPIC: Light Shafts + Tone Mapping?

Light Shafts + Tone Mapping? 1 year 1 month ago #1

  • Quentin-Tarantino
  • Quentin-Tarantino's Avatar
  • Offline
  • If there is no struggle, there is no progress.
  • Posts: 351
  • Thank you received: 218
The administrator has disabled public write access.

Light Shafts + Tone Mapping? 1 year 1 month ago #2

light shafts == god rays
The administrator has disabled public write access.

Light Shafts + Tone Mapping? 1 year 1 month ago #3

  • Quentin-Tarantino
  • Quentin-Tarantino's Avatar
  • Offline
  • If there is no struggle, there is no progress.
  • Posts: 351
  • Thank you received: 218
I know but looking more like the ones in the link?
The administrator has disabled public write access.

Light Shafts + Tone Mapping? 1 year 1 month ago #4

I sure hope so. I don't think godrays is quite the same as that.
I'm always learning.
The administrator has disabled public write access.

Light Shafts + Tone Mapping? 1 year 1 month ago #5

  • 04348
  • 04348's Avatar
  • Offline
  • Posts: 13
  • Thank you received: 11
I've managed to get something, but there's some issues with the distance and ReShade can't easily detect the sun/light position, specifically when it's out of the screen.


float4 PS_mdGRMask(float4 vpos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target
{
	float4 color = tex2D(RFX_backbufferColor, texcoord);
	float depth = tex2D(RFX_depthColor,texcoord).r;
	if (depth == 1 && (color.r+color.g+color.b)/3 > GR_Bright) return color;
	return float4(0,0,0,0);
}

float4 PS_mdGRBlur(float4 vpos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target
{
	float4 color = tex2D(RFX_backbufferColor, texcoord);
	float4 mask = tex2D(SamplerMask, texcoord);
	float4 output = float4(0,0,0,0);
	float  count = 0;
	float2 lightXY = float2(0.5,0.0);
	float angle = 0;
	float2 vect;
	for (int c=0;c<=GR_Size;c+=GR_Skip) {
		if (texcoord.x >= 0.5) angle = atan( abs(texcoord.y - lightXY.y)/abs(texcoord.x - lightXY.x)  ); //droite
		else angle = PI-atan( abs(texcoord.y - lightXY.y) / abs(texcoord.x - lightXY.x) ); // gauche
		vect = float2( -c*cos(angle)*PIXSIZE.x, -c*sin(angle)*PIXSIZE.y);
		count ++;// 1-tex2D(RFX_depthTexColor, texcoord.xy + vect.xy).r;
		output += tex2D(SamplerMask, texcoord.xy + vect.xy );//*(1-tex2D(RFX_depthTexColor, texcoord.xy + vect.xy).r);	
	}
	return color + (output/count)*GR_Alpha;
}

technique Custom_Tech <bool enabled = RFX_Start_Enabled; int toggle = Custom_ToggleKey; >
{
	pass mdGRMask
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = PS_mdGRMask;
		RenderTarget = texMask;
	}
	pass mdGRBlur
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = PS_mdGRBlur;
	}
}

Util.h :
#define RENDERMODE RGBA8
#define PIXSIZE  	float2(BUFFER_RCP_WIDTH, BUFFER_RCP_HEIGHT)
//textures

texture   texMask 	{ Width = BUFFER_WIDTH/2; Height = BUFFER_HEIGHT/2; MipLevels = 8; Format = RENDERMODE;};
texture   texGR 	{ Width = BUFFER_WIDTH/4; Height = BUFFER_HEIGHT/4; MipLevels = 8; Format = RENDERMODE;};


sampler2D SamplerMask
{
	Texture = texMask;
	MinFilter = LINEAR;
	MagFilter = LINEAR;
	MipFilter = LINEAR;
	AddressU = Clamp;
	AddressV = Clamp;
};

sampler2D SamplerGR
{
	Texture = texGR;
	MinFilter = LINEAR;
	MagFilter = LINEAR;
	MipFilter = LINEAR;
	AddressU = Clamp;
	AddressV = Clamp;
};
int br(float4 color) {
	return (color.r+color.b+color.g)/3;
}

void PS_Init(float4 vpos : SV_Position, float2 texcoord : TEXCOORD, out float4 hdrT : SV_Target0) 
{
	hdrT = tex2D(RFX_originalColor, texcoord.xy);
}

technique Init_Tech  < enabled = true; >
{
	pass Init_Mask
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = PS_Init;
		RenderTarget = texMask;
	}

}
Last Edit: 1 year 1 month ago by 04348.
The administrator has disabled public write access.

Light Shafts + Tone Mapping? 1 year 1 month ago #6

  • Marty McFly
  • Marty McFly's Avatar
  • Offline
  • We've tried nothing and we're all out of ideas!
  • Posts: 609
  • Thank you received: 716
Anything that is outside the screen is totally nonexistant for ReShade.
The administrator has disabled public write access.

Light Shafts + Tone Mapping? 1 year 1 month ago #7

  • matsilagi
  • matsilagi's Avatar
  • Offline
  • Posts: 199
  • Thank you received: 54
It didn't work for me, its missing GR_Bright and GR_Skip.
Loves to test stuff for no reason.
The administrator has disabled public write access.

Light Shafts + Tone Mapping? 1 year 1 month ago #8

those are macros

#define GR_Bright 0.8 //[0,1] brightpass
#define GR_Size 8 // step count for blur
#define GR_Skip 1 // skipping step counts in blur
#define GR_Alpha 1 //blending weight

also there is still room for optimization in the code.
no need to atan first and sincos later, vectors will work.
The administrator has disabled public write access.

Light Shafts + Tone Mapping? 1 year 1 month ago #9

  • 04348
  • 04348's Avatar
  • Offline
  • Posts: 13
  • Thank you received: 11
Yes, it was more a proof of concept to see limitations involved by ReShade than a usable shader ^^
For optimisation, vector are far better than trigonometry but i didn't see a single fps drop between use of atan and only vertical ray without atan or vector so I didn't change it to vector :p
Last Edit: 1 year 1 month ago by 04348.
The administrator has disabled public write access.
The following user(s) said Thank You: kingeric1992

Light Shafts + Tone Mapping? 1 year 1 month ago #10

  • matsilagi
  • matsilagi's Avatar
  • Offline
  • Posts: 199
  • Thank you received: 54
@04348:Do you have any sort of contact method? (Email, Steam)?
I usually have shaders i like to see ported and it would be cool to have another person to help me with them.
Also, thanks for the shader, it worked fine after kingeric posted the macros.
Loves to test stuff for no reason.
The administrator has disabled public write access.

Light Shafts + Tone Mapping? 1 year 1 month ago #11

  • 04348
  • 04348's Avatar
  • Offline
  • Posts: 13
  • Thank you received: 11
My Steam is 04348, I can try to help you but I have to warn you, I'm not very familiar with shader programming :p
The administrator has disabled public write access.

Light Shafts + Tone Mapping? 1 year 1 month ago #12

  • matsilagi
  • matsilagi's Avatar
  • Offline
  • Posts: 199
  • Thank you received: 54
Added, thanks a lot.
Lemme know when you get online.
Incase i added the wrong profile, just search for me, it isn't hard (Matsilagi2 is the id, Matsilagi is the steam name)
Loves to test stuff for no reason.
Last Edit: 1 year 1 month ago by matsilagi.
The administrator has disabled public write access.