public override void OnPreRender() { BlitImage(); if (_RenderedTexture != null) { float aspect = (float)_RenderedTexture.width / (float)_RenderedTexture.height; Vector2 sfactor = CamSource.GetEyeScalingFactor((int)Eye); //sfactor.x = sfactor.x - (float)(_RenderedTexture.width)/(float)src.width; //aspect *= sfactor.x / sfactor.y; if (aspect == 0 || float.IsNaN(aspect)) { aspect = 1; } _RenderPlane.transform.localScale = new Vector3(fovScaler, fovScaler / aspect, 1); } }
public override void OnPreRender() { if (CamSource == null) { return; } _RenderedTexture = CamSource.GetEyeTexture((int)Eye); Rect texRect = CamSource.GetEyeTextureCoords((int)Eye); if (_RenderedTexture != null && Mat != null) { /* * if (_RenderedTexture != null && (_RenderedTexture as Texture2D) != null && (_RenderedTexture as Texture2D).format == TextureFormat.Alpha8) { * _RenderedTexture = _Processor.ProcessTexture (_RenderedTexture);//CamTexture;// * texRect = new Rect (0, 0, 1, 1); * }*/ if (texRect.x != 0 || texRect.y != 0 || texRect.width != 1 || texRect.height != 1) { _Blitter.ProcessingMaterial.SetVector("TextureRect", new Vector4(texRect.x, texRect.y, texRect.width, texRect.height)); _RenderedTexture = _Blitter.ProcessTexture(_RenderedTexture); //CamTexture;// texRect = new Rect(0, 0, 1, 1); } _Correction.ProcessingMaterial.SetVector("TextureSize", new Vector2(_RenderedTexture.width, _RenderedTexture.height)); //Vector4 tr=new Vector4 (texRect.x, texRect.y, texRect.width, texRect.height); //Mat.SetVector ("TextureRect",tr); // float fovScaler = 1; if (Src.Configuration != null) { if (Eye == EyeName.LeftEye) { _Correction.ProcessingMaterial.SetVector("PixelShift", Src.Configuration.CamSettings.PixelShiftLeft); } else { _Correction.ProcessingMaterial.SetVector("PixelShift", Src.Configuration.CamSettings.PixelShiftRight); } float fov = Src.Configuration.CamSettings.FoV; float focal = Src.Configuration.CamSettings.Focal; //1;//in meter float w1 = 2 * focal * Mathf.Tan(Mathf.Deg2Rad * (Camera.current.fieldOfView * 0.5f)); float w2 = 2 * (focal - Src.Configuration.CamSettings.CameraOffset) * Mathf.Tan(Mathf.Deg2Rad * fov * 0.5f); if (w1 == 0) { w1 = 1; } float ratio = w2 / w1; fovScaler = ratio; // Debug.Log("Configuration Updated"); _Correction.ProcessingMaterial.SetVector("FocalLength", Src.Configuration.CamSettings.FocalLength); _Correction.ProcessingMaterial.SetVector("LensCenter", Src.Configuration.CamSettings.LensCenter); // Vector4 WrapParams=new Vector4(Configuration.CamSettings.KPCoeff.x,Configuration.CamSettings.KPCoeff.y, // Configuration.CamSettings.KPCoeff.z,Configuration.CamSettings.KPCoeff.w); _Correction.ProcessingMaterial.SetVector("WrapParams", Src.Configuration.CamSettings.KPCoeff); } else { _Correction.ProcessingMaterial.SetVector("PixelShift", Vector2.zero); } _RenderedTexture = _Correction.ProcessTexture(_RenderedTexture); Mat.mainTexture = _RenderedTexture; Mat.SetTexture("_MainTex", _RenderedTexture); Image.texture = _RenderedTexture; float aspect = (float)_RenderedTexture.width / (float)_RenderedTexture.height; aspect *= CamSource.GetEyeScalingFactor((int)Eye).x / CamSource.GetEyeScalingFactor((int)Eye).y; if (aspect == 0 || float.IsNaN(aspect)) { aspect = 1; } // _RenderPlane.transform.localScale = new Vector3 (fovScaler, fovScaler/aspect, 1); } }
public override void OnPreRender() { if (CamSource == null) { return; } Texture src = CamSource.GetEyeTexture((int)Eye); _lastFrame = CamSource.GetGrabbedBufferID((int)Eye); if (src != null && Mat != null) { //if (offset != Vector2.zero) if (false) { Vector2 offset = Vector2.zero; if (Eye == EyeName.LeftEye) { offset = Src.Configuration.CamSettings.PixelShiftLeft; } else { offset = Src.Configuration.CamSettings.PixelShiftRight; } _Blitter.ProcessingMaterial.SetVector("PixelShift", offset); src.wrapMode = TextureWrapMode.Clamp; src = _Blitter.ProcessTexture(src); } Texture resultTex; if (Src.Effects != null && Src.Effects.Length > 0) { Texture tex = src; foreach (var e in Src.Effects) { e.ProcessTexture(tex, ref _RenderedTexture); tex = _RenderedTexture; // _GazeTexture = e.ProcessTexture (_GazeTexture); } resultTex = _RenderedTexture; } else { resultTex = src; } Mat.mainTexture = resultTex; float fov = Src.Configuration.CamSettings.FoV; float focal = Src.Configuration.CamSettings.Focal; //1;//in meter float camfov = Camera.current.fieldOfView; float w1 = 2 * focal * Mathf.Tan(Mathf.Deg2Rad * (camfov * 0.5f)); float w2 = 2 * (focal - Src.Configuration.CamSettings.CameraOffset) * Mathf.Tan(Mathf.Deg2Rad * fov * 0.5f); if (w1 == 0) { w1 = 1; } float ratio = w2 / w1; float aspect = (float)resultTex.width / (float)resultTex.height; aspect *= CamSource.GetEyeScalingFactor((int)Eye).x / CamSource.GetEyeScalingFactor((int)Eye).y; if (aspect == 0 || float.IsNaN(aspect)) { aspect = 1; } _RenderPlane.transform.localScale = new Vector3(ratio, ratio / aspect, 1); } //if (CamSource != null) // frames+=CamSource.GetGrabbedBufferID ((int)Eye)+"\t"; }