Welcome, Guest.
Username: Password: Remember me

TOPIC: 3D anaglyph(red/cyan) shader WIP

3D anaglyph(red/cyan) shader WIP 11 months 3 hours ago #1

  • 04348
  • 04348's Avatar
  • Offline
  • Posts: 13
  • Thank you received: 11
Hi !

I've tried this morning to mimic a 3D image using one picture + zBuffer instead of the classic way, compute one picture for each eye.

It was it was obviously more complicated than what I expected, but I got something which is nearly functional :) It use 4 pass, two θ(1) and two θ(divergence) so it's pretty fast and this can certainly be improved, cuz I'm not very familiar with shader programming :P



There's still some artifact, especially to fill the "empty" areas for each eye.
It work with red/cyan glasses, I've no 3D TV but I think it could work using frame sequential 3D or side-by-side (but will reduce resolution).
#define pix  	float2(BUFFER_RCP_WIDTH, BUFFER_RCP_HEIGHT)

uniform float frames < source = "framecount"; >;

texture2D texR 	{ Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; Format = RGBA8;};
texture2D texL 	{ Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; Format = RGBA8;}; 
texture2D texC 	{ Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; Format = RGBA32F;}; //needed to recover accurate coordinates

sampler2D SamplerR
{
	Texture = texR;
	MinFilter = LINEAR;
	MagFilter = LINEAR;
	MipFilter = LINEAR;
	AddressU = Clamp;
	AddressV = Clamp;
};

sampler2D SamplerL
{
	Texture = texL;
	MinFilter = LINEAR;
	MagFilter = LINEAR;
	MipFilter = LINEAR;
	AddressU = Clamp;
	AddressV = Clamp;
};

sampler2D SamplerC
{
	Texture = texC;
	MinFilter = LINEAR;
	MagFilter = LINEAR;
	MipFilter = LINEAR;
	AddressU = Clamp;
	AddressV = Clamp;
};

#define divergence 30
#define RENDER 1 // 1:Anaglyph 2:Frame-by-Frame
#define USE_DUBOIS_CORRECTION 1
#define ANAGLYPHE_DEBUG 0 // 0:None 1:Only Left 2:Only Right

float geth (float2 tex) {
	return (pow(abs(1-tex2D(RFX_depthTexColor, tex).r),10));
	//return (-1+(pow(abs(1-tex2D(RFX_depthTexColor, tex).r),10))*2); //For depth
}

void PS_calcRL(in float4 position : SV_Position, in float2 tex : TEXCOORD0, out float3 color : SV_Target)
{
	color.rgb = float3(0,0,tex.x-divergence*pix.x*geth(tex));
	color.r = tex.x+divergence*pix.x*geth(tex);

}


void PS_renderL(in float4 position : SV_Position, in float2 tex : TEXCOORD0, out float3 color : SV_Target)
{
	color.rgb = tex2D(RFX_backbufferColor, float2(tex.x-divergence*pix.x*geth(tex), tex.y)).rgb;//tex2D(RFX_backbufferColor, tex).rgb;
	for (int i = 0; i <= divergence+1; i++) {
		if (tex2D(SamplerC, float2(tex.x-i*pix.x,tex.y)).r >= tex.x-pix.x/2 && tex2D(SamplerC, float2(tex.x-i*pix.x,tex.y)).r <= tex.x+pix.x/2) {
			color.rgb = tex2D(RFX_backbufferColor, float2(tex.x-i*pix.x, tex.y)).rgb;
		}
	}
}

void PS_renderR(in float4 position : SV_Position, in float2 tex : TEXCOORD0, out float3 color : SV_Target)
{
	color.rgb = tex2D(RFX_backbufferColor, float2(tex.x+divergence*pix.x*geth(tex), tex.y)).rgb;
	float2 col = float2 (0,0);
	for (int j = 0; j <= divergence+1; j++) {
		if (tex2D(SamplerC, float2(tex.x+j*pix.x,tex.y)).b >= tex.x-pix.x/2 && tex2D(SamplerC, float2(tex.x+j*pix.x,tex.y)).b <= tex.x+pix.x/2) {
			color.rgb = tex2D(RFX_backbufferColor, float2(tex.x+j*pix.x, tex.y)).rgb;
		}
	}
}

void PS_DisplayDepth(in float4 position : SV_Position, in float2 tex : TEXCOORD0, out float3 color : SV_Target)
{
	float4 l = tex2D(SamplerR, tex);
	float4 r = tex2D(SamplerL, tex);
	#if RENDER == 1
		#if USE_DUBOIS_CORRECTION == 1

			float red = 0.456100 * l.r + 0.500484 * l.g + 0.176381 * l.b
					- 0.0434706 * r.r - 0.0879388 * r.g - 0.00155529 * r.b;
			if (red > 1) { red = 1; }   if (red < 0) { red = 0; }

			float green = -0.0400822 * l.r - 0.0378246 * l.g
						 -0.0157589 * l.b + 0.378476 * r.r
						 +0.73364 * r.g - 0.0184503 * r.b;
			if (green > 1) { green = 1; }   if (green < 0) { green = 0; }

			float blue = -0.0152161 * l.r - 0.0205971 * l.g
						-0.00546856 * l.b - 0.0721527 * r.r
						-0.112961 * r.g + 1.2264 * r.b;
			if (blue > 1) { blue = 1; }   if (blue < 0) { blue = 0; }

		   color.rgb = float3(red, green, blue);
	   #endif
	   #if USE_DUBOIS_CORRECTION == 0
		   color.rgb = l.rgb;
		   color.r = r.r;
	   #endif
   #endif
   
   #if RENDER == 2
		if ((frames%2) == 0) {
			color.rgb = l.rgb;
		} else {
			color.rgb = r.rgb;
		}
   #endif
   #if ANAGLYPHE_DEBUG == 1
	color.rgb = l.rgb;
   #endif
   #if ANAGLYPHE_DEBUG == 2
	color.rgb = r.rgb;
   #endif
	
}

technique Depth_Tech < enabled = true; toggle = Depth_ToggleKey;>
{
	pass
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = PS_calcRL;
		RenderTarget = texC;
	}
	pass
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = PS_renderR;
		RenderTarget = texR;
	}
	pass
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = PS_renderL;
		RenderTarget = texL;
	}
	pass
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = PS_DisplayDepth;
	}
}

If you have some idea to improve this, I take :lol:
Last Edit: 10 months 4 weeks ago by 04348.
The administrator has disabled public write access.
The following user(s) said Thank You: crosire, Tycholarfero, cheapImpact, luluco250

3D anaglyph(red/cyan) shader WIP 11 months 2 hours ago #2

  • crosire
  • crosire's Avatar
  • Offline
  • Posts: 2451
  • Thank you received: 1391
I don't have red/cyan glasses at hand unfortunately, but judging from the debug output it looks pretty cool. Nice job!
Cheers, crosire =)
Last Edit: 11 months 1 hour ago by crosire.
The administrator has disabled public write access.

3D anaglyph(red/cyan) shader WIP 8 months 3 weeks ago #3

Hey, for one, this is great, i've been looking for an anaglyph 3d shader for a while, considering in theory it's not hard to do cheap 3d with depth information.

Do you have any plan to update this for reshade 2.0? I have many missing identifiers/defines and i don't know the reshade framework enough to fix it all...
Either that or does it depend on something else enabled to define things?
The administrator has disabled public write access.

3D anaglyph(red/cyan) shader WIP 8 months 2 weeks ago #4

  • 04348
  • 04348's Avatar
  • Offline
  • Posts: 13
  • Thank you received: 11
Yeah I can, it's certainly only some variable renaming :)

Edit : Done ! www.mediafire.com/download/f6h36rc8r131dld/anaglyph.zip
Extract this in your ReShade folder (and replace the pipeline.cfg) and it should work :)
Last Edit: 8 months 2 weeks ago by 04348.
The administrator has disabled public write access.

3D anaglyph(red/cyan) shader WIP 5 months 3 weeks ago #5

Your file seems to be missing the Shaders_by_Grenbur.cfg

Here is my Take on your script For Side By Side 3D.
www.mediafire.com/download/2rhfku1m1zlg0...r_Reshade_2.0.3f1.7z

For OGL games like Amnesia Set DFix to 2

Should work with OGL games aswell

I would love for some one that's better at this then I to help make this better.
My PayPal Me Link If you like to donate paypal.me/BlueSkyDefender

Also my steam page steamcommunity.com/id/BlueSkyDefender
Last Edit: 5 months 3 weeks ago by BlueSkyKnight.
The administrator has disabled public write access.

3D anaglyph(red/cyan) shader WIP 5 months 3 weeks ago #6

  • 04348
  • 04348's Avatar
  • Offline
  • Posts: 13
  • Thank you received: 11
I forgot to include the config file :side:
Here is the complete zip : www.mediafire.com/download/y11e8eq0xkavz..._Anaglyph_shader.zip (well, i hope it is ^^ )

I havn't a 3D screen to test your modification, but it seems to work well :)

I'm currently in traineeship, working with an ingeneer in 3D visualisation, maybe I can learn some tips to improve the shader :p
The administrator has disabled public write access.
The following user(s) said Thank You: BlueSkyKnight

3D anaglyph(red/cyan) shader WIP 5 months 3 weeks ago #7

This is my new prototype. This one allows you to change the depth map settings and view it in real time to adjust the depth map to your liking.

I have a problem with image halos but the depth you get in 3D is better now.

Anyway you can help me with removing the halos? * Fixed

Never mind I got it working........... Here it is www.mediafire.com/download/xlcmjky6haho4...r_Reshade_2.0.3f1.7z

Here my New rewrite www.mediafire.com/download/byic9m7x32dny...k_2.0.3f1_Depth3D.7z And repacked with Reshade

Also here is the reshade.me/compatibility ReShade Compatibility List too see if your game is supported. Some games on here do work even if it says it dose not work like Among the Sleep does work. So take this list with a grain of salt.
My PayPal Me Link If you like to donate paypal.me/BlueSkyDefender

Also my steam page steamcommunity.com/id/BlueSkyDefender
Last Edit: 5 months 3 weeks ago by BlueSkyKnight.
The administrator has disabled public write access.

3D anaglyph(red/cyan) shader WIP 5 months 2 weeks ago #8

[Compatibility](reshade.me/compatibility) will depend on Depth Access.

Version 1.4 Is out now Fixes and Features
*L/R and R/L swaping is now supported
*Uses a liner depth map now
*Fixed Double Image in right eye
*Cleaned a lot of my left over trash in the script.
*Added image warping to both eyes. Note you may want to turn this off in open world games like DarkSouls 3 so you can raise the Separation. It's Called **Pop**
*4 Alternate DepthMap options adjust Near Far Cam Automatically.
*Fallout 4 Compatablity with AltDepthMap 4


Super DepthMap 3D v1.4
www.mediafire.com/download/wv0t209f0841r..._DepthMap_3D_v1.4.7z

ReShade Repack Super DepthMap 3D v1.4
www.mediafire.com/download/xqjp8gnjjzq3q...ap_3D_v1.4_Repack.7z

Super DepthMap v1.5.3
They are the Basic Depth maps you can use for your games listed and not listed. Look at this link for other game Compatablity.

[Compatibility](reshade.me/compatibility)
At this link look for Depth Map compatablity.

* Among The Sleep :: AltDepthMap = 0 -DepthFix = 1
* Naruto Shippuden UNS3 Full Blurst :: AltDepthMap = 1
* Quake 4 :: AltDepthMap = 2
* Amnesia Games :: AltDepthMap = 3
* Fallout 4 :: AltDepthMap = 4
* Souls Games & The Evil With In :: AltDepthMap = 5
* Sleeping Dogs: DE :: AltDepthMap = 6
* Assassin Creed Unity :: AltDepthMap = 7

Super DepthMap 3D v1.5.3
www.mediafire.com/download/2cb1d9k3d2t7n...pthMap_3D_v1.5.3.zip

Super DepthMap 3D v1.5.3 Repack
www.mediafire.com/download/9vay77lzlrvj4...3D_v1.5.3_Repack.zip

I will no longer be posting updates here. As this forum pertains to 3D anaglyph shader.
My PayPal Me Link If you like to donate paypal.me/BlueSkyDefender

Also my steam page steamcommunity.com/id/BlueSkyDefender
Last Edit: 5 months 1 week ago by BlueSkyKnight.
The administrator has disabled public write access.