public TextNode(int w, int h, GraphPixelType p = GraphPixelType.RGBA) { Name = "Text"; Id = Guid.NewGuid().ToString(); tileX = tileY = 1; width = w; height = h; fontSize = 32; fontFamily = "Arial"; text = ""; fonts = FontManager.GetAvailableFonts(); position = new MVector(); rotation = 0; scale = new MVector(1, 1); style = FontStyle.Regular; alignment = TextAlignment.Center; spacing = 1; processor = new TextProcessor(); //establish character holder texture character = new GLTextuer2D(GLInterfaces.PixelInternalFormat.Rgba); character.Bind(); character.Linear(); character.ClampToEdge(); GLTextuer2D.Unbind(); internalPixelType = p; previewProcessor = new BasicImageRenderer(); Output = new NodeOutput(NodeType.Gray, this); Inputs = new List <NodeInput>(); Outputs = new List <NodeOutput>(); Outputs.Add(Output); }
protected void ApplyTransformNoAuto(GLTextuer2D inc, GLTextuer2D o, int owidth, int oheight, MVector translation, MVector scale, float angle, MVector pivot) { Matrix4 proj = Matrix4.CreateOrthographic(owidth, oheight, 0.03f, 1000f); Matrix4 pTrans = Matrix4.CreateTranslation(-pivot.X, -pivot.Y, 0); Matrix4 iPTrans = Matrix4.CreateTranslation(pivot.X, pivot.Y, 0); Matrix4 trans = Matrix4.CreateTranslation(translation.X, translation.Y, 0); Matrix4 sm = Matrix4.CreateScale(scale.X, scale.Y, 1); Matrix4 rot = Matrix4.CreateRotationZ(angle); Matrix4 model = pTrans * sm * rot * iPTrans * trans; Matrix4 view = Matrix4.LookAt(new Vector3(0, 0, 1), Vector3.Zero, Vector3.UnitY); IGL.Primary.Viewport(0, 0, owidth, oheight); resizeProcessor.Model = model; resizeProcessor.View = view; resizeProcessor.Projection = proj; resizeProcessor.Luminosity = Luminosity; resizeProcessor.Bind(inc); inc.ClampToEdge(); if (renderQuad != null) { renderQuad.Draw(); } inc.Repeat(); resizeProcessor.Unbind(); o.Bind(); o.Repeat(); GLTextuer2D.Unbind(); Blit(o, owidth, oheight); /*o.Bind(); * o.Repeat(); * o.CopyFromFrameBuffer(owidth, oheight); * GLTextuer2D.Unbind();*/ }
public void Process(int width, int height, GLTextuer2D tex, GLTextuer2D warp, GLTextuer2D output) { base.Process(width, height, tex, output); if (shader != null) { ResizeViewTo(tex, output, tex.Width, tex.Height, width, height); tex = output; IGL.Primary.Clear((int)(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit)); Vector2 tiling = new Vector2(TileX, TileY); shader.Use(); shader.SetUniform2("tiling", ref tiling); shader.SetUniform("MainTex", 0); shader.SetUniform("intensity", Intensity); IGL.Primary.ActiveTexture((int)TextureUnit.Texture0); tex.Bind(); tex.ClampToEdge(); shader.SetUniform("Warp", 1); IGL.Primary.ActiveTexture((int)TextureUnit.Texture1); warp.Bind(); if (renderQuad != null) { renderQuad.Draw(); } tex.Bind(); tex.Repeat(); GLTextuer2D.Unbind(); //output.Bind(); //output.CopyFromFrameBuffer(width, height); //GLTextuer2D.Unbind(); Blit(output, width, height); } }
public void Process(int width, int height, GLTextuer2D tex, GLTextuer2D source, GLTextuer2D output) { base.Process(width, height, tex, output); if (Shader != null && PreShader != null) { GLTextuer2D temp = new GLTextuer2D(output.InternalFormat); temp.Bind(); temp.SetData(IntPtr.Zero, PixelFormat.Rgba, width, height); temp.Linear(); temp.Repeat(); GLTextuer2D.Unbind(); GLTextuer2D temp2 = new GLTextuer2D(output.InternalFormat); temp2.Bind(); temp2.SetData(IntPtr.Zero, PixelFormat.Rgba, width, height); temp2.Linear(); temp2.Repeat(); GLTextuer2D.Unbind(); GLTextuer2D temp3 = new GLTextuer2D(PixelInternalFormat.Rgba32f); temp3.Bind(); temp3.SetData(IntPtr.Zero, PixelFormat.Rgba, width + 1, height + 1); temp3.Nearest(); temp3.ClampToEdge(); GLTextuer2D.Unbind(); ResizeViewTo(tex, temp, tex.Width, tex.Height, width, height); IGL.Primary.Clear((int)(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit)); if (source != null) { ResizeViewTo(source, temp2, source.Width, source.Height, width, height); } IGL.Primary.Clear((int)(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit)); tex = temp; PreShader.Use(); output.Bind(); output.BindAsImage(0, true, true); tex.Bind(); tex.BindAsImage(1, true, true); temp2.Bind(); temp2.BindAsImage(2, true, true); temp3.Bind(); temp3.BindAsImage(3, true, true); PreShader.SetUniform("width", (float)width); PreShader.SetUniform("height", (float)height); PreShader.SetUniform("sourceOnly", SourceOnly); PreShader.SetUniform("maxDistance", Distance); //stage 1 convert temp input range //into proper format //for dt PreShader.SetUniform("stage", (int)0); IGL.Primary.DispatchCompute(width / 8, height / 8, 1); Shader.Use(); output.Bind(); output.BindAsImage(0, true, true); tex.Bind(); tex.BindAsImage(1, true, true); temp2.Bind(); temp2.BindAsImage(2, true, true); temp3.Bind(); temp3.BindAsImage(3, true, true); Shader.SetUniform("width", (float)width); Shader.SetUniform("height", (float)height); Shader.SetUniform("sourceOnly", SourceOnly); Shader.SetUniform("maxDistance", Distance); //stage 2 run column transform Shader.SetUniform("stage", (int)0); IGL.Primary.DispatchCompute(width / 8, 1, 1); //stage 3 run row transform Shader.SetUniform("stage", (int)1); IGL.Primary.DispatchCompute(height / 8, 1, 1); PreShader.Use(); output.Bind(); output.BindAsImage(0, true, true); tex.Bind(); tex.BindAsImage(1, true, true); temp2.Bind(); temp2.BindAsImage(2, true, true); temp3.Bind(); temp3.BindAsImage(3, true, true); PreShader.SetUniform("width", (float)width); PreShader.SetUniform("height", (float)height); PreShader.SetUniform("sourceOnly", SourceOnly); PreShader.SetUniform("maxDistance", Distance); //stage 4 finalize with sqrt() etc PreShader.SetUniform("stage", (int)1); IGL.Primary.DispatchCompute(width / 8, height / 8, 1); GLTextuer2D.UnbindAsImage(0); GLTextuer2D.UnbindAsImage(1); GLTextuer2D.UnbindAsImage(2); GLTextuer2D.UnbindAsImage(3); GLTextuer2D.Unbind(); temp.Release(); temp2.Release(); temp3.Release(); } }
/// <summary> /// This would be too slow for real time performance at 60fps /// but since we are not doing 60fps it is fine /// it is a fast box gaussian blur /// produces results better than adobes gaussian blur /// and faster than theirs! /// can easily blur 4kx4k textures in low ms on a 1080 gtx gpu with 64+ intensity /// </summary> /// <param name="width"></param> /// <param name="height"></param> /// <param name="tex"></param> /// <param name="output"></param> public override void Process(int width, int height, GLTextuer2D tex, GLTextuer2D output) { base.Process(width, height, tex, output); colorBuff.Bind(); colorBuff.ClampToEdge(); GLTextuer2D.Unbind(); if (shader != null) { ResizeViewTo(tex, output, tex.Width, tex.Height, width, height); tex = output; IGL.Primary.Clear((int)(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit)); Vector2 tiling = new Vector2(TileX, TileY); float[] boxes = Materia.Nodes.Helpers.Blur.BoxesForGaussian(Intensity, 3); shader.Use(); shader.SetUniform2("tiling", ref tiling); shader.SetUniform("MainTex", 0); shader.SetUniform("horizontal", true); shader.SetUniform("intensity", (boxes[0] - 1.0f) / 2.0f); IGL.Primary.ActiveTexture((int)TextureUnit.Texture0); tex.Bind(); //clamp to prevent blur wrap tex.ClampToEdge(); if (renderQuad != null) { renderQuad.Draw(); } GLTextuer2D.Unbind(); /*output.Bind(); * output.CopyFromFrameBuffer(width, height); * GLTextuer2D.Unbind();*/ Blit(output, width, height); tex.Bind(); tex.Repeat(); GLTextuer2D.Unbind(); shader.SetUniform("horizontal", false); IGL.Primary.ActiveTexture((int)TextureUnit.Texture0); output.Bind(); //clamp to prevent blur wrap output.ClampToEdge(); IGL.Primary.Clear((int)ClearBufferMask.ColorBufferBit); IGL.Primary.Clear((int)ClearBufferMask.DepthBufferBit); if (renderQuad != null) { renderQuad.Draw(); } GLTextuer2D.Unbind(); /*output.Bind(); * output.CopyFromFrameBuffer(width, height); * GLTextuer2D.Unbind();*/ Blit(output, width, height); //begin second box shader.SetUniform("horizontal", true); shader.SetUniform("intensity", (boxes[1] - 1.0f) / 2.0f); IGL.Primary.ActiveTexture((int)TextureUnit.Texture0); output.Bind(); IGL.Primary.Clear((int)ClearBufferMask.ColorBufferBit); IGL.Primary.Clear((int)ClearBufferMask.DepthBufferBit); if (renderQuad != null) { renderQuad.Draw(); } GLTextuer2D.Unbind(); output.Bind(); output.CopyFromFrameBuffer(width, height); GLTextuer2D.Unbind(); shader.SetUniform("horizontal", false); shader.SetUniform("intensity", (boxes[1] - 1.0f) / 2.0f); IGL.Primary.ActiveTexture((int)TextureUnit.Texture0); output.Bind(); IGL.Primary.Clear((int)ClearBufferMask.ColorBufferBit); IGL.Primary.Clear((int)ClearBufferMask.DepthBufferBit); if (renderQuad != null) { renderQuad.Draw(); } GLTextuer2D.Unbind(); /*output.Bind(); * output.CopyFromFrameBuffer(width, height); * GLTextuer2D.Unbind(); */ Blit(output, width, height); //begin third box shader.SetUniform("horizontal", true); shader.SetUniform("intensity", (boxes[2] - 1.0f) / 2.0f); IGL.Primary.ActiveTexture((int)TextureUnit.Texture0); output.Bind(); IGL.Primary.Clear((int)ClearBufferMask.ColorBufferBit); IGL.Primary.Clear((int)ClearBufferMask.DepthBufferBit); if (renderQuad != null) { renderQuad.Draw(); } GLTextuer2D.Unbind(); /*output.Bind(); * output.CopyFromFrameBuffer(width, height); * GLTextuer2D.Unbind(); */ Blit(output, width, height); shader.SetUniform("horizontal", false); shader.SetUniform("intensity", (boxes[2] - 1.0f) / 2.0f); IGL.Primary.ActiveTexture((int)TextureUnit.Texture0); output.Bind(); IGL.Primary.Clear((int)ClearBufferMask.ColorBufferBit); IGL.Primary.Clear((int)ClearBufferMask.DepthBufferBit); if (renderQuad != null) { renderQuad.Draw(); } GLTextuer2D.Unbind(); /*output.Bind(); * output.CopyFromFrameBuffer(width, height); * GLTextuer2D.Unbind();*/ Blit(output, width, height); } output.Bind(); output.Repeat(); GLTextuer2D.Unbind(); colorBuff.Bind(); colorBuff.Repeat(); GLTextuer2D.Unbind(); }