Light Shafts + Tone Mapping?

  • Quentin-Tarantino
  • Quentin-Tarantino's Avatar Topic Author
  • Offline
  • Posts: 351
4 years 9 months ago #1 by Quentin-Tarantino

Please Log in or Create an account to join the conversation.

  • Posts: 177
4 years 9 months ago #2 by kingeric1992
light shafts == god rays

Please Log in or Create an account to join the conversation.

  • Quentin-Tarantino
  • Quentin-Tarantino's Avatar Topic Author
  • Offline
  • Posts: 351
4 years 9 months ago #3 by Quentin-Tarantino
I know but looking more like the ones in the link?

Please Log in or Create an account to join the conversation.

  • Posts: 249
4 years 9 months ago #4 by Constantine PC
I sure hope so. I don't think godrays is quite the same as that.

Please Log in or Create an account to join the conversation.

  • Posts: 13
4 years 9 months ago - 4 years 9 months ago #5 by 04348
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;
	}

}

Please Log in or Create an account to join the conversation.

  • Posts: 1221
4 years 9 months ago #6 by Marty McFly
Anything that is outside the screen is totally nonexistant for ReShade.

Please Log in or Create an account to join the conversation.

  • Posts: 292
4 years 9 months ago #7 by matsilagi
It didn't work for me, its missing GR_Bright and GR_Skip.

Please Log in or Create an account to join the conversation.

  • Posts: 177
4 years 9 months ago #8 by kingeric1992
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.

Please Log in or Create an account to join the conversation.

  • Posts: 13
4 years 9 months ago - 4 years 9 months ago #9 by 04348
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
The following user(s) said Thank You: kingeric1992

Please Log in or Create an account to join the conversation.

  • Posts: 292
4 years 9 months ago #10 by matsilagi
@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.

Please Log in or Create an account to join the conversation.

  • Posts: 13
4 years 9 months ago #11 by 04348
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

Please Log in or Create an account to join the conversation.

  • Posts: 292
4 years 9 months ago - 4 years 9 months ago #12 by matsilagi
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)

Please Log in or Create an account to join the conversation.