Monday, January 30, 2017

Are Anaglyph 3D shaders used in game engines?


I have always wanted to put on the "3d glasses" and instead of watching a 3d movie, go to my pc and play a game in real 3D. Has anyone ever tried creating a Real 3D game? Are there any shaders that would allow creating Anaglyph 3D effect in real time? How do they work? (If they exist)



http://en.wikipedia.org/wiki/Anaglyph_3D



enter image description here




Answer



Your game will need to render two viewpoints, one for the left image and one for the right image. From there, a quick search revealed the following shader created by objo on Codeplex:


sampler2D input1 : register(S0); // right image input
sampler2D input2 : register(S1); // left image input

float4 main(float2 uv : TEXCOORD) : COLOR
{
float4 Color1;
Color1 = tex2D( input1 , uv.xy);


float4 Color2;
Color2 = tex2D( input2 , uv.xy);

Color1.r = Color2.r;
Color1.g = Color1.g;
Color1.b = Color1.b;
Color1.a = max(Color1.a,Color2.a);

return Color1;
}


While created for WPF applications, you might be able to use the above as-is or with a little bit of tweaking.


There have been many games from the NES on up that have rendered an anaglyphic or other method of 3d effect.


The above code is licensed under the CPOL


Link to Codeplex article: Anaglyph ShaderEffect in WPF


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...