3D anaglyph(red/cyan) shader WIP

  • 04348
  • Topic Author
More
8 years 3 months ago - 8 years 3 months ago #1 by 04348 3D anaglyph(red/cyan) shader WIP was created by 04348
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: 8 years 3 months ago by 04348.
The following user(s) said Thank You: crosire, Tycholarfero, cheapImpact, luluco250

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

  • crosire
More
8 years 3 months ago - 8 years 3 months ago #2 by crosire Replied by crosire on topic 3D anaglyph(red/cyan) shader WIP
I don't have red/cyan glasses at hand unfortunately, but judging from the debug output it looks pretty cool. Nice job!
Last edit: 8 years 3 months ago by crosire.

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

  • d-_-b
More
8 years 1 month ago #3 by d-_-b Replied by d-_-b on topic 3D anaglyph(red/cyan) shader WIP
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?

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

  • 04348
  • Topic Author
More
8 years 1 month ago - 8 years 1 month ago #4 by 04348 Replied by 04348 on topic 3D anaglyph(red/cyan) shader WIP
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 years 1 month ago by 04348.

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

  • BlueSkyKnight
More
7 years 10 months ago - 7 years 10 months ago #5 by BlueSkyKnight Replied by BlueSkyKnight on topic 3D anaglyph(red/cyan) shader WIP
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.
Last edit: 7 years 10 months ago by BlueSkyKnight.

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

  • 04348
  • Topic Author
More
7 years 10 months ago #6 by 04348 Replied by 04348 on topic 3D anaglyph(red/cyan) shader WIP
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 following user(s) said Thank You: BlueSkyKnight

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

  • BlueSkyKnight
More
7 years 10 months ago - 7 years 10 months ago #7 by BlueSkyKnight Replied by BlueSkyKnight on topic 3D anaglyph(red/cyan) shader WIP
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.
Last edit: 7 years 10 months ago by BlueSkyKnight.

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

  • BlueSkyKnight
More
7 years 10 months ago - 7 years 9 months ago #8 by BlueSkyKnight Replied by BlueSkyKnight on topic 3D anaglyph(red/cyan) shader WIP
[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.
Last edit: 7 years 9 months ago by BlueSkyKnight.

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

We use cookies
We use cookies on our website. Some of them are essential for the operation of the forum. You can decide for yourself whether you want to allow cookies or not. Please note that if you reject them, you may not be able to use all the functionalities of the site.