Weird problem with fog image effect
Hi guys,
I have a strange issue regarding Oculus DK2 and a full-screen post image effect.
This is how it looks on a PC with the Debug Mode enabled (no device attached but OVR is running in debug mode) on and htiting play into the editor. It plays ok:
And this is what happens in another PC with the device (wrong!):
Note that the image effect runs fine on Windows and Mac. It just get distorted when Virtual Reality checkbox is enabled and during playmode.
This is the vertex shader:
_ClipToWorld is set from the C# script as:
Note the line above:
farPlaneClip *= float4(1,-1,1,1);
I had to introduce this to make the fog effect work on my PC with the debug mode on. But it still doesn't work on the PC with Oculus DK2.
So, right now I'm a little lost since it works then I enable Debug but it doesn't otherwise on the other PC?
Anyone has faced a similar problem with Oculus / Virtual Reality enabled? Is this a bug?
Also I'd love to read some details about how does Virtual Reality check affect projections in Unity since at this moment I'm rather lost.
thank you very much in advance!
I have a strange issue regarding Oculus DK2 and a full-screen post image effect.
This is how it looks on a PC with the Debug Mode enabled (no device attached but OVR is running in debug mode) on and htiting play into the editor. It plays ok:
And this is what happens in another PC with the device (wrong!):
Note that the image effect runs fine on Windows and Mac. It just get distorted when Virtual Reality checkbox is enabled and during playmode.
This is the vertex shader:
float4x4 _ClipToWorld;
struct appdata {
float4 vertex : POSITION;
half2 texcoord : TEXCOORD0;
};
struct v2f {
float4 pos : POSITION;
float2 uv: TEXCOORD0;
float2 depthUV : TEXCOORD1;
float3 cameraToFarPlane : TEXCOORD2;
};
v2f vert(appdata v) {
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.depthUV = MultiplyUV(UNITY_MATRIX_TEXTURE0, v.texcoord);
o.uv = o.depthUV;
#if UNITY_UV_STARTS_AT_TOP
if (_MainTex_TexelSize.y < 0) {
// Depth texture is inverted WRT the main texture
o.depthUV.y = 1 - o.depthUV.y;
}
#endif
// Clip space X and Y coords
float2 clipXY = o.pos.xy / o.pos.w;
// Position of the far plane in clip space
float4 farPlaneClip = float4(clipXY, 1, 1);
// Homogeneous world position on the far plane
[B] farPlaneClip *= float4(1,-1,1,1);[/B]
float4 farPlaneWorld4 = mul(_ClipToWorld , farPlaneClip);
// World position on the far plane
float3 farPlaneWorld = farPlaneWorld4.xyz / farPlaneWorld4.w;
// Vector from the camera to the far plane
o.cameraToFarPlane = farPlaneWorld - _WorldSpaceCameraPos;
return o;
}
_ClipToWorld is set from the C# script as:
material.SetMatrix ("_ClipToWorld", Camera.main.cameraToWorldMatrix * Camera.main.projectionMatrix.inverse);Note the line above:
farPlaneClip *= float4(1,-1,1,1);
I had to introduce this to make the fog effect work on my PC with the debug mode on. But it still doesn't work on the PC with Oculus DK2.
So, right now I'm a little lost since it works then I enable Debug but it doesn't otherwise on the other PC?
Anyone has faced a similar problem with Oculus / Virtual Reality enabled? Is this a bug?
Also I'd love to read some details about how does Virtual Reality check affect projections in Unity since at this moment I'm rather lost.
thank you very much in advance!
