/// <summary> /// The recursive print function /// </summary> /// <param name="cur">current node we are printing</param> /// <param name="level">how far in we are (ie. how many dashes to print before)</param> private void PrintTree(ImageFilter cur, int level = 1) { foreach (ImageFilter j in cur.Parents) { if (j.NeedRender) { return; } } string s = ""; //add a psace per level - 1 for (int i = 0; i < level - 1; i++) { s += " "; } //add one of these per line s += "|___"; System.Diagnostics.Debug.WriteLine(s + cur.ToString()); cur.NeedRender = false; //recurse foreach (ImageFilter i in cur.Children) { PrintTree(i, level + 1); } }
/// <summary> /// Add all the hlsl files here /// </summary> public void AddEffects() { Renderer = new GPUImageGame(this.Dispatcher); FirstFilter = new InitialFilter(@"HLSL\RenderToScreen.fxo"); FirstFilter.AddInput("cat.dds"); temp = new InitialFilter(@"HLSL\FirstFilter.fxo"); second = new ImageFilter(@"HLSL\SpotLight.fxo", new Parameter("ImageSize", new Vector2(1, 1)), new Parameter("LightPos", new Vector2(400, 400))); second.AddInput(FirstFilter); Renderer.TerminalFilter = second; Renderer.Run(DisplayGrid); Task t = Task.Factory.StartNew(new Action(() => { Vector2 pos = new Vector2(0, 0); int add = 1; while (true) { pos.X = (pos.X + 1 * add); if (pos.X == 800 || pos.X == 0) { pos.Y = (pos.Y + 40) % 1200; add *= -1; } second.UpdateParameter("LightPos", pos); Thread.Sleep(1); } })); }
/// <summary> /// recursively update non-root filters /// </summary> /// <param name="cur"></param> private void UpdateRec(ImageFilter cur) { foreach (ImageFilter i in cur.Children) { i.SendParametersToGPU(); } }
/// <summary> /// set the current filter and each child recursively to need render = true (ie. NEEDS to be rendered) /// </summary> /// <param name="cur"></param> private void ChangeNeedsRender(ImageFilter cur) { // cur.NeedRender = true; foreach (ImageFilter i in cur.Children) { ChangeNeedsRender(i); } }
/// <summary> /// Specifies that you would like the input of the filter to be another filter /// </summary> /// <param name="imfil">The filter to use as input</param> /// <param name="num">If there is one input to the fitler, leave blank and name the input "InputTexture" in the HLSL. If there is multiple inputs, name them "InputTexture[0-9]*", and put that number here</param> public void AddInput(ImageFilter imfil, int num = -1) { //make sure the parent/child relation holds if (!Parents.Contains(imfil)) { Parents.Add(imfil); } if (!imfil.Children.Contains(this)) { imfil.Children.Add(this); } RemoveInput(num); Inputs.Add(imfil, num); }
/// <summary> /// recursively draw all non-initial nodes (ie. the ones with other filters as input) /// </summary> /// <param name="cur">The filter we are currently trying to render</param> private void DrawRec(ImageFilter cur) { //first check to make sure that all the parent filters have been drawn foreach (ImageFilter j in cur.Parents) { //if needRender is true. we need to render the parents if (j.NeedRender) { return; } } //render current filter GraphicsDevice.SetRenderTargets(cur.RenderTarget); GraphicsDevice.DrawQuad(cur.RenderEffect); cur.NeedRender = false; foreach (ImageFilter i in cur.Children) { i.SendParametersToGPU(); DrawRec(i); } }
/// <summary> /// Recursively add all the remaining children filters /// </summary> /// <param name="cur"></param> private void LoadContentRec(ImageFilter cur, bool isInitial = false) { //first load the effect if (!isInitial) { cur.RenderEffect = ToDisposeContent(Content.Load <Effect>(cur.Path)); cur.RenderTarget = CreateRenderTarget2D(); } //add the parameters foreach (Parameter p in cur.Parameters) { if (p.Name == "ImageSize") { p.Value = new Vector2(GraphicsDevice.BackBuffer.Width, GraphicsDevice.BackBuffer.Height); } } //recurse foreach (ImageFilter i in cur.Children) { LoadContentRec(i); } }