| View previous topic :: View next topic |
Juan
Joined: 21 May 2009 Posts: 59
|
Posted: Fri Jul 10, 2009 12:12 pm Post subject: |
|
|
|
can someone post a demo of this?
This is really interesting.
Cheers.
|
|
| Back to top |
|
|
DerWoDaSo

Joined: 25 May 2009 Posts: 74
|
Posted: Tue Jul 21, 2009 12:51 am Post subject: |
|
|
|
With the new nVidia beta divers you can create anaglyph renderings in almost any 3D application... but didn't check if it works with unity.
But my eyes start to hurt anyway after a few minutes because of the retinal rivalry... did some tests with anaglyph rendering in XNA last year.
|
|
| Back to top |
|
|
monark
Joined: 02 May 2008 Posts: 712 Location: London
|
Posted: Thu Oct 01, 2009 5:02 pm Post subject: |
|
|
|
I've been playing around with this a bit today here are some screen grabs, using red/green rather than red/cyan. It works even better when it's moving around and on windows where the gamma makes the red stronger. Might depend on your glasses too I suppose.
|
|
| Back to top |
|
|
monark
Joined: 02 May 2008 Posts: 712 Location: London
|
Posted: Sat Oct 10, 2009 1:48 pm Post subject: |
|
|
|
| Jonathan Czeck wrote: | The method in this thread actually is the incorrect way to do stereo and results in "vertical parallax distortions" in the rendered image. Check out chapter 14 in this free book if anyone is interested in doing it the accurate way:
http://www.pangeasoft.net/book/buy.html
Cheers,
-Jon |
Thanks for this link!
I've implemented the skewed projection matrix method and it does seem easier on the eyes.
It's quite simple to do if anyone else wants to try the code for skewing the matrix is in the Unity help, the code below can just be bolted into the original script.
| Code: |
function PerspectiveOffCenter(
left : float, right : float,
bottom : float, top : float,
near : float, far : float ) : Matrix4x4
{
var x = (2.0 * near) / (right - left);
var y = (2.0 * near) / (top - bottom);
var a = (right + left) / (right - left);
var b = (top + bottom) / (top - bottom);
var c = -(far + near) / (far - near);
var d = -(2.0 * far * near) / (far - near);
var e = -1.0;
var m : Matrix4x4;
m[0,0] = x; m[0,1] = 0; m[0,2] = a; m[0,3] = 0;
m[1,0] = 0; m[1,1] = y; m[1,2] = b; m[1,3] = 0;
m[2,0] = 0; m[2,1] = 0; m[2,2] = c; m[2,3] = d;
m[3,0] = 0; m[3,1] = 0; m[3,2] = e; m[3,3] = 0;
return m;
}
function projectionMatrix(isLeftEye : boolean) : Matrix4x4 {
var left : float;
var right : float;
var a : float;
var b : float;
var fov : float;
fov = camera.fieldOfView / 180.0 * Mathf.PI; // convert FOV to radians
var aspect : float = camera.aspect;
a = camera.nearClipPlane * Mathf.Tan(fov * 0.5);
b = camera.nearClipPlane / S3DV.focalDistance;
if (isLeftEye) // left camera
{
left = - aspect * a + (S3DV.eyeDistance) * b;
right = aspect * a + (S3DV.eyeDistance) * b;
}
else // right camera
{
left = - aspect * a - (S3DV.eyeDistance) * b;
right = aspect * a - (S3DV.eyeDistance) * b;
}
return PerspectiveOffCenter(left, right, -a, a, camera.nearClipPlane, camera.farClipPlane);
}
|
Then just modify the part of the original script that rotates the left and right eye cameras so instead of doing that they just copy the rotation from the original camera and then get their projection matrices modified thus
| Code: |
if (useOffsetMatrix) {
leftEye.transform.rotation = transform.rotation;
rightEye.transform.rotation = transform.rotation;
leftEye.camera.projectionMatrix = projectionMatrix(true);
rightEye.camera.projectionMatrix = projectionMatrix(false);
}
|
|
|
| Back to top |
|
|
monark
Joined: 02 May 2008 Posts: 712 Location: London
|
Posted: Sat Oct 10, 2009 1:51 pm Post subject: |
|
|
|
I've also been playing with the colour balancing method also found in the link posted above.
So instead of just using the anaglyph shader embedded in the script use this one instead
| Code: |
Shader "Hidden/Colour Balance Anaglyph" {
Properties {
_LeftTex ("Left (RGB)", RECT) = "white" {}
_RightTex ("Right (RGB)", RECT) = "white" {}
}
SubShader {
Pass {
ZTest Always Cull Off ZWrite Off
Fog { Mode off }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
#define RED_RATIO_ADJ .6f
#define GREEN_RATIO_ADJ .4f
#define BLUE_RATIO_ADJ .8f
uniform samplerRECT _LeftTex;
uniform samplerRECT _RightTex;
struct v2f {
float4 pos : POSITION;
float2 uv : TEXCOORD0;
};
v2f vert( appdata_img v )
{
v2f o;
o.pos = mul (glstate.matrix.mvp, v.vertex);
float2 uv = MultiplyUV( glstate.matrix.texture[0], v.texcoord );
o.uv = uv;
return o;
}
half4 frag (v2f i) : COLOR
{
float r, g, b;
float4 texR = texRECT(_LeftTex, i.uv);
float4 texGB = texRECT(_RightTex, i.uv);
float4 texRGB;
r=texR.r;
g=texGB.g;
b=texGB.b;
float lumR = texR.r * 0.299f;
float lumGB = texR.g * 0.587f + texR.b * 0.114f;
// Balance red
float ratio = lumGB / lumR;
float d = texR.r * ratio * RED_RATIO_ADJ;
if (d > texR.r) {
r = d;
if (r > 0xff) r = 0xff;
}
lumR = texGB.r * 0.299f;
lumGB = texGB.g * 0.587f + texGB.b * 0.114f;
//Balance green
ratio = lumR / lumGB;
d = texGB.g * ratio * GREEN_RATIO_ADJ;
if (d > texGB.g) {
g = d;
if (g > 0xff) g = 0xff;
}
//Balance blue
d = texGB.b * ratio * BLUE_RATIO_ADJ;
if (d > texGB.b) {
b = d;
if (b > 0xff) b = 0xff;
}
texRGB = float4(r,g,b,1);
return texRGB;
}
ENDCG
}
}
Fallback off
}
|
However I'm ussure as to whether this is supported on all hardware, can anyone who knows shaderLab better confirm if this would work always?
Last edited by monark on Thu Oct 15, 2009 2:05 pm; edited 1 time in total |
|
| Back to top |
|
|
rahuxx
Joined: 08 May 2009 Posts: 21
|
Posted: Thu Oct 15, 2009 1:54 pm Post subject: Help for Passive and active stereoscopy |
|
|
|
hi there,
first of all great software and nice work.
More i got the idea how anaglyph works in unity, but i am quiet confused on how passive stereoscopy and active stereoscopy works.
if some one can provide a tutorial or script on which i can try and work to improve my knowledge will be great help for me.
Thanks for all
hope for the comming days
rahuxx
|
|
| Back to top |
|
|
wimwouters
Joined: 07 Jan 2009 Posts: 10
|
Posted: Sun Oct 25, 2009 6:05 pm Post subject: |
|
|
|
We're also using Anaglyph rendering... but using a much more "low-tech" way to do it...
We just put a plane in front of each camera (red/cyaan) then combined the 2 camera views...
DEMO: (we should avoid red stoplights...)
http://www.underdog.be/games/cruiserVR/
Press G for anaglyph
|
|
| Back to top |
|
|
rahuxx
Joined: 08 May 2009 Posts: 21
|
Posted: Thu Nov 05, 2009 8:43 am Post subject: Nice game, i played online earlier |
|
|
|
Nice work.
But if you can provide some short of tutorial on it will help me more.
Thanks in advance
|
|
| Back to top |
|
|
rahuxx
Joined: 08 May 2009 Posts: 21
|
Posted: Sat Nov 07, 2009 12:25 pm Post subject: Not able to use rollover script on objects with anaglyph scr |
|
|
|
Hi there
Thanks for the script.
I loved to work on unity using this new script, but struck to this silly problem that when i am using rollover script on object and use this script, generated exe has no rollover effect on objects.
Please some one help me on it, its hardly needed.
thanks
rahu
|
|
| Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|