예제 #1
0
파일: Node.cs 프로젝트: hglei/Materia
 protected virtual void CreateBufferIfNeeded()
 {
     if (buffer == null || buffer.Id == 0)
     {
         buffer = new GLTextuer2D((GLInterfaces.PixelInternalFormat)((int)internalPixelType));
         buffer.Bind();
         buffer.SetData(IntPtr.Zero, GLInterfaces.PixelFormat.Rgba, width, height);
         buffer.Linear();
         buffer.Repeat();
         if (internalPixelType == GraphPixelType.Luminance16F || internalPixelType == GraphPixelType.Luminance32F)
         {
             buffer.SetSwizzleLuminance();
         }
         GLTextuer2D.Unbind();
     }
 }
예제 #2
0
파일: FXNode.cs 프로젝트: kergalym/Materia
        protected override void CreateBufferIfNeeded()
        {
            base.CreateBufferIfNeeded();

            if (temp == null || temp.Id == 0)
            {
                temp = new GLTextuer2D((GLInterfaces.PixelInternalFormat)((int)internalPixelType));
                temp.Bind();
                temp.SetData(IntPtr.Zero, GLInterfaces.PixelFormat.Rgba, width, height);
                temp.Linear();
                temp.Repeat();
                if (internalPixelType == GraphPixelType.Luminance16F || internalPixelType == GraphPixelType.Luminance32F)
                {
                    temp.SetSwizzleLuminance();
                }
                GLTextuer2D.Unbind();
            }
        }
예제 #3
0
        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);
        }
예제 #4
0
        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();
            }
        }