public override void DebugRender() { if (!Enabled) { return; } Vector2 sz = Camera.main.pixelRect.size; lock (_objectsLock) { if (_currPoints == null) { return; } Vector2 v1 = Vector2.zero, v2 = Vector2.zero; for (int i = 0; i < _opticalFlow.Count; ++i) { var f = _opticalFlow [i]; v1.Set(f.v1.x * sz.x, f.v1.y * sz.y); v2.Set(f.v2.x * sz.x, f.v2.y * sz.y); GUITools.DrawCircle(v1, 3, 10, ColorCode); GUITools.DrawLine(v1, v2, ColorCode); } } }
void OnGUI() { if (GUI.Button(new Rect(50, 100, 100, 30), "Calibrate LED")) { _CalibLEDPos = true; _currPoint = 0; _calibrated = false; clrArray [0] = Color.white; clrArray [1] = Color.black; clrArray [2] = Color.black; clrArray [3] = Color.black; SetLEDs(clrArray); } if (_calibrated) { foreach (var p in LEDPos) { GUITools.DrawCircle(new Vector2(p.x * Screen.width, p.y * Screen.height), 2, 4, Color.red); } } }
protected Texture BlitImage(Texture src, int idx, Vector2 Scaler) { m_dirty = false; // Texture src = _texture.GetEyeTexture(idx); Results[idx].OriginalTexture = src; //ulong frame = CamSource.GetGrabbedBufferID ((int)Eye); //if (m_dirty) //_lastFrame = frame; int levels = _texture.GetEyeGazeLevels(); m_foveatedStreaming = (levels > 0); if (Results[idx].EyeGaze == null || Results[idx].EyeGaze.Length != levels) { Results[idx].EyeGaze = new Vector4[levels]; } for (int i = 0; i < levels; ++i) { Results[idx].EyeGaze[i] = _texture.GetEyeGaze(0, idx, i); } Vector2 frameSize = Parameters.frameSize; frameSize.x *= Scaler.x; frameSize.y *= Scaler.y; if (frameSize.x != Results[idx].CombinedTexture.width || frameSize.y != Results[idx].CombinedTexture.height) { Results[idx].CombinedTexture = new RenderTexture((int)frameSize.x, (int)frameSize.y, 16, RenderTextureFormat.Default); } Rect texRect = new Rect(0, 0, 1, 1); if (src == null) { return(null); } Results[idx].gazeSize.x = src.height; Results[idx].gazeSize.y = src.height; //Get Foveation levels if (levels > 0) { //blit scene texture Results [idx]._SceneBlitter.ProcessingMaterial.SetVector("TextureRect", new Vector4((Results[idx].gazeSize.x * levels) / (float)src.width, 0, ((float)src.width - Results[idx].gazeSize.x * levels) / (float)src.width, texRect.height)); Results[idx].SceneTexture = Results [idx]._SceneBlitter.ProcessTextureSized(src, (int)(src.width - Results[idx].gazeSize.x * levels), src.height); //CamTexture;// if (true) { RenderTexture.active = Results[idx].CombinedTexture; GL.Clear(true, true, Color.black); GL.PushMatrix(); GL.LoadPixelMatrix(0, Results[idx].CombinedTexture.width, Results[idx].CombinedTexture.height, 0); Graphics.DrawTexture(new Rect(0, 0, frameSize.x, frameSize.y), Results[idx].SceneTexture); var blitter = _GazeBlitterCircle; switch (Parameters.BlitType) { case EyegazeDataStreamer.GazeBlitType.Circular: blitter = _GazeBlitterCircle; break; case EyegazeDataStreamer.GazeBlitType.Rectangular: blitter = _GazeBlitterRect; break; } if (Results [idx].GazeTexture.Length != levels) { Results [idx].GazeTexture = new Texture[levels]; Results [idx].ProcessedGazeTexture = new Texture[levels]; } //blit all gaze levels for (int i = levels - 1; i >= 0; --i) { if (Parameters.DisabledFoveations [i]) { continue; } //blit gaze texture _GazeBlitter.ProcessingMaterial.SetVector("TextureRect", new Vector4(Results[idx].gazeSize.x * i / (float)src.width, 0, Results[idx].gazeSize.x / (float)src.width, texRect.height)); Results[idx].GazeTexture [i] = _GazeBlitter.ProcessTextureSized(src, (int)Results[idx].gazeSize.x, (int)Results[idx].gazeSize.y); //CamTexture;// var clr = ColorWheel [i % ColorWheel.Length]; blitter.ProcessingMaterial.SetFloat("DebugBlitArea", Parameters.DebugBlitArea ? 1 : 0); blitter.ProcessingMaterial.SetVector("_DebugColor", new Vector4(clr.r, clr.g, clr.b, clr.a)); blitter.ProcessingMaterial.SetVector("_Parameters", new Vector4(0.5f, 0.5f, Parameters.BlitParameter.x, Parameters.BlitParameter.y)); Results[idx].ProcessedGazeTexture[i] = blitter.ProcessTexture(Results [idx].GazeTexture [i]); Graphics.DrawTexture(new Rect(Results[idx].EyeGaze[i].x, Results[idx].EyeGaze[i].y, Results[idx].EyeGaze[i].z, Results[idx].EyeGaze[i].w), Results[idx].ProcessedGazeTexture [i]); } if (Parameters.DrawRectangle) { for (int i = 0; i < levels; ++i) { if (Parameters.DisabledFoveations [i]) { continue; } var r = new Rect(Results[idx].EyeGaze [i].x, Results[idx].EyeGaze [i].y, Results[idx].EyeGaze [i].z, Results[idx].EyeGaze [i].w); if (Parameters.BlitType == EyegazeDataStreamer.GazeBlitType.Rectangular) { GUITools.GraphicsDrawScreenRectBorder(r, 4, ColorWheel [i % ColorWheel.Length]); } else { GUITools.DrawCircle(r.center, r.height / 2, 90, ColorWheel [i % ColorWheel.Length], 3); } } } GL.PopMatrix(); RenderTexture.active = null; } else { Results[idx].CombinedTexture = Results[idx].SceneTexture as RenderTexture; } } else { Results [idx]._SceneBlitter.ProcessingMaterial.SetVector("TextureRect", new Vector4(0, 0, 1, 1)); Results[idx].SceneTexture = Results [idx]._SceneBlitter.ProcessTextureSized(src, src.width, src.height); //CamTexture;// Results[idx].CombinedTexture = Results[idx].SceneTexture as RenderTexture; } return(Results[idx].CombinedTexture); }
void BlitImage() { if (CamSource == null || !m_dirty || !DataStreamer) { return; } _blurGenerator.Size = DataStreamer.BlurSize; m_dirty = false; Texture src = CamSource.GetEyeTexture((int)Eye); OriginalTexture = src; ulong frame = CamSource.GetGrabbedBufferID((int)Eye); //if (m_dirty) { m_dirty = false; } _lastFrame = frame; int levels = CamSource.GetBaseTexture().GetEyeGazeLevels(); m_foveatedStreaming = (levels > 0); if (EyeGaze == null || EyeGaze.Length != levels) { EyeGaze = new Vector4[levels]; } for (int i = 0; i < levels; ++i) { EyeGaze[i] = CamSource.GetBaseTexture().GetEyeGaze(0, i); } if (DataStreamer.frameSize.x != _CombinedTexture.width || DataStreamer.frameSize.y != _CombinedTexture.height) { _CombinedTexture = new RenderTexture((int)DataStreamer.frameSize.x, (int)DataStreamer.frameSize.y, 16, RenderTextureFormat.Default); } ulong frame2 = CamSource.GetGrabbedBufferID((int)Eye); if (frame != frame) { Debug.LogWarning("Image frames changed!"); } Rect texRect = CamSource.GetEyeTextureCoords((int)Eye); if (src != 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) { _SrcBlitter.ProcessingMaterial.SetVector("TextureRect", new Vector4(texRect.x, texRect.y, texRect.width, texRect.height)); src = _SrcBlitter.ProcessTextureSized(src, (int)(texRect.width * src.width), (int)(texRect.height * src.height)); //CamTexture;// texRect = new Rect(0, 0, 1, 1); } /* * //blit scene texture * _SceneBlitter.ProcessingMaterial.SetVector ("TextureRect", new Vector4 (0, 0, texRect.width, ((float)src.height-256.0f)/(float)src.height)); * _RenderedTexture = _SceneBlitter.ProcessTextureSized (src,256,src.height-256);//CamTexture;// * * //blit gaze texture * _GazeBlitter.ProcessingMaterial.SetVector ("TextureRect", new Vector4 (0, ((float)src.height-256.0f)/(float)src.height, texRect.width, 256.0f/(float)src.height)); * _GazeTexture = _GazeBlitter.ProcessTextureSized (src,256,256);//CamTexture;// */ gazeSize.x = src.height; gazeSize.y = src.height; //Get Foveation levels if (levels > 0) { //blit scene texture _SceneBlitter.ProcessingMaterial.SetVector("TextureRect", new Vector4((gazeSize.x * levels) / (float)src.width, 0, ((float)src.width - gazeSize.x * levels) / (float)src.width, texRect.height)); _SceneTexture = _SceneBlitter.ProcessTextureSized(src, (int)(src.width - gazeSize.x * levels), src.height); //CamTexture;// if (true) { RenderTexture.active = _CombinedTexture; GL.Clear(true, true, Color.black); GL.PushMatrix(); GL.LoadPixelMatrix(0, _CombinedTexture.width, _CombinedTexture.height, 0); Graphics.DrawTexture(new Rect(0, 0, DataStreamer.frameSize.x, DataStreamer.frameSize.y), _SceneTexture); if (_gazeBlitMtrl == null) { _gazeBlitMtrl = new Material(_GazeBlitterCircle); _gazeBlitMtrl.hideFlags = HideFlags.DontSave; } var blitter = _GazeBlitterCircle; switch (DataStreamer.GazeBlitMethod) { case EyegazeDataStreamer.GazeBlitType.Circular: blitter = _GazeBlitterCircle; break; case EyegazeDataStreamer.GazeBlitType.Rectangular: blitter = _GazeBlitterRect; break; } _gazeBlitMtrl.shader = blitter; if (_GazeTexture.Length != levels) { _GazeTexture = new Texture[levels]; } //blit all gaze levels for (int i = levels - 1; i >= 0; --i) { if (DataStreamer.DisabledFoveations [i]) { continue; } //blit gaze texture _GazeBlitter.ProcessingMaterial.SetVector("TextureRect", new Vector4(gazeSize.x * i / (float)src.width, 0, gazeSize.x / (float)src.width, texRect.height)); _GazeTexture [i] = _GazeBlitter.ProcessTextureSized(src, (int)gazeSize.x, (int)gazeSize.y); //CamTexture;// var clr = ColorWheel [i % ColorWheel.Length]; _gazeBlitMtrl.SetFloat("DebugBlitArea", DataStreamer.DebugBlitArea ? 1 : 0); _gazeBlitMtrl.SetVector("_DebugColor", new Vector4(clr.r, clr.g, clr.b, clr.a)); _gazeBlitMtrl.SetVector("_Parameters", new Vector4(0.5f, 0.5f, DataStreamer.GazeArea.x, DataStreamer.GazeArea.y)); Graphics.DrawTexture(new Rect(EyeGaze[i].x, EyeGaze[i].y, EyeGaze[i].z, EyeGaze[i].w), _GazeTexture [i], _gazeBlitMtrl); } if (DataStreamer.DrawRectangle) { for (int i = 0; i < levels; ++i) { if (DataStreamer.DisabledFoveations [i]) { continue; } var r = new Rect(EyeGaze [i].x, EyeGaze [i].y, EyeGaze [i].z, EyeGaze [i].w); if (DataStreamer.GazeBlitMethod == EyegazeDataStreamer.GazeBlitType.Rectangular) { GUITools.GraphicsDrawScreenRectBorder(r, 4, ColorWheel [i % ColorWheel.Length]); } else { GUITools.DrawCircle(r.center, r.height / 2, 90, ColorWheel [i % ColorWheel.Length], 3); } } } GL.PopMatrix(); RenderTexture.active = null; } else { _CombinedTexture = _SceneTexture as RenderTexture; } } else { _SceneBlitter.ProcessingMaterial.SetVector("TextureRect", new Vector4(0, 0, 1, 1)); _SceneTexture = _SceneBlitter.ProcessTextureSized(src, src.width, src.height); //CamTexture;// _CombinedTexture = _SceneTexture as RenderTexture; } _Correction.ProcessingMaterial.SetVector("TextureSize", new Vector2(_CombinedTexture.width, _CombinedTexture.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 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; 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); } _CorrectedTexture = _Correction.ProcessTexture(_CombinedTexture); if (Src.Effects != null) { Texture tex = _CorrectedTexture; foreach (var e in Src.Effects) { e.ProcessTexture(tex, ref _RenderedTexture); tex = _RenderedTexture; // _GazeTexture = e.ProcessTexture (_GazeTexture); } } else { _RenderedTexture = _CorrectedTexture as RenderTexture; } Mat.mainTexture = _RenderedTexture; } }