Game Development Community

Anaglyph Shader

by Matt Vitelli · in Torque Game Engine Advanced · 05/28/2007 (12:06 pm) · 2 replies

Redirected from here.

This is a simple fullscreen shader that can be used to put your game in basic anaglyph 3D. Eventually it would be great to have this be done based on depth, kind of like Depth of Field. If anyone is interested in expanding on this please contact me. This can be used with the fullscreen shader resource found here.

AnaglyphP.hlsl
//Matt Vitelli 2007
//Basic Anaglyph Rendering
//Based off blur example code from ATI

sampler RT: register(s0);

float4 main(float2 texCoord: TEXCOORD0) : COLOR {

float sampleDist0 = 0.02;

float2 samples[1] = {
   0.3, 0.3,
};
float2 samples2[1] = {
   -0.3, -0.3,
};

float4 sum = tex2D(RT, texCoord);
   for (int i = 0; i < 1; i++){
      float4 col1 = tex2D(RT, texCoord + sampleDist0 * samples[i]);
      float4 col2 = tex2D(RT, texCoord + sampleDist0 * samples2[i]);
      float4 red = {1,0,0,1};
      float4 blue = {0,1,1,1};
      sum += col1 * red;
      sum += col2 * blue;
      }
      
      return sum / 2;


}

AnaglyphV.hlsl
//-----------------------------------------------------------------------------
// Structures                                                                  
//-----------------------------------------------------------------------------
struct VS_OUTPUT
{
   float4 Pos             : POSITION;
   float2 texCoord        : TEXCOORD0;
};

//-----------------------------------------------------------------------------
// Main                                                                        
//-----------------------------------------------------------------------------
VS_OUTPUT main( VS_OUTPUT IN,
                  uniform float4x4 modelview       : register(C0)

)
{
   VS_OUTPUT OUT;

   OUT.Pos = mul(modelview, IN.Pos);
   OUT.texCoord = IN.texCoord;
   return OUT;
}

#1
06/12/2007 (1:26 pm)
So this just makes it where it will render for the red and gree 3D glasses yes?

Isn't there already a fullscreen depth of field shader?
#2
06/14/2007 (8:41 pm)
Red and Cyan, yes. Also, I haven't seen any depth of field shaders floating around. The standard approach is to use multiple render targets, though in theory you could render a depth map through a shader and use that for blurring. It's another thing on my to-do list.