void Process() { GLTextuer2D i1 = (GLTextuer2D)input.Input.Data; if (i1 == null) { return; } if (i1.Id == 0) { return; } CreateBufferIfNeeded(); curveLUT.Bind(); curveLUT.SetData(lutBrush.Image, GLInterfaces.PixelFormat.Rgba, 256, 2); GLTextuer2D.Unbind(); processor.TileX = tileX; processor.TileY = tileY; processor.Process(width, height, i1, buffer); processor.Complete(); Updated(); Output.Data = buffer; Output.Changed(); }
private void Glview_Load(object sender, EventArgs e) { ViewContext.VerifyContext(glview); ViewContext.Context.MakeCurrent(glview.WindowInfo); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); if (quad == null) { quad = new FullScreenQuad(); } if (processor == null) { processor = new PreviewProcessor(); } blankTexture = new GLTextuer2D(GLInterfaces.PixelInternalFormat.Rgb); blankTexture.Bind(); blankTexture.SetData(IntPtr.Zero, GLInterfaces.PixelFormat.Rgb, 16, 16); GLTextuer2D.Unbind(); Invalidate(); }
void LoadDefaultTextures() { lightMat = new Material.PBRLight(); if (defaultBlack == null) { FloatBitmap black = new FloatBitmap(128, 128); Nodes.Helpers.Utils.Fill(black, 0, 0, 0f, 0f, 0f, 1); defaultBlack = new GLTextuer2D(PixelInternalFormat.Rgba8); defaultBlack.Bind(); defaultBlack.SetData(black.Image, GLInterfaces.PixelFormat.Rgba, 128, 128); defaultBlack.GenerateMipMaps(); defaultBlack.SetFilter((int)TextureMinFilter.LinearMipmapLinear, (int)TextureMagFilter.Linear); defaultBlack.SetWrap((int)TextureWrapMode.Repeat); GLTextuer2D.Unbind(); Materia.Nodes.Atomic.MeshNode.DefaultBlack = defaultBlack; } if (defaultWhite == null) { FloatBitmap black = new FloatBitmap(128, 128); Nodes.Helpers.Utils.Fill(black, 0, 0, 1f, 1f, 1f, 1); defaultWhite = new GLTextuer2D(PixelInternalFormat.Rgba8); defaultWhite.Bind(); defaultWhite.SetData(black.Image, GLInterfaces.PixelFormat.Rgba, 128, 128); defaultWhite.GenerateMipMaps(); defaultWhite.SetFilter((int)TextureMinFilter.LinearMipmapLinear, (int)TextureMagFilter.Linear); defaultWhite.SetWrap((int)TextureWrapMode.Repeat); GLTextuer2D.Unbind(); Materia.Nodes.Atomic.MeshNode.DefaultWhite = defaultWhite; } if (defaultGray == null) { FloatBitmap black = new FloatBitmap(128, 128); Nodes.Helpers.Utils.Fill(black, 0, 0, 0.5f, 0.5f, 0.5f, 1); defaultGray = new GLTextuer2D(PixelInternalFormat.Rgba8); defaultGray.Bind(); defaultGray.SetData(black.Image, GLInterfaces.PixelFormat.Rgba, 128, 128); defaultGray.GenerateMipMaps(); defaultGray.SetFilter((int)TextureMinFilter.LinearMipmapLinear, (int)TextureMagFilter.Linear); defaultGray.SetWrap((int)TextureWrapMode.Repeat); GLTextuer2D.Unbind(); } if (defaultDarkGray == null) { FloatBitmap black = new FloatBitmap(128, 128); Nodes.Helpers.Utils.Fill(black, 0, 0, 0.25f, 0.25f, 0.25f, 1); defaultDarkGray = new GLTextuer2D(PixelInternalFormat.Rgba8); defaultDarkGray.Bind(); defaultDarkGray.SetData(black.Image, GLInterfaces.PixelFormat.Rgba, 128, 128); defaultDarkGray.GenerateMipMaps(); defaultDarkGray.SetFilter((int)TextureMinFilter.LinearMipmapLinear, (int)TextureMagFilter.Linear); defaultDarkGray.SetWrap((int)TextureWrapMode.Repeat); GLTextuer2D.Unbind(); Materia.Nodes.Atomic.MeshNode.DefaultDarkGray = defaultDarkGray; } }
public void Process(int width, int height, GLTextuer2D tex, GLTextuer2D other, GLTextuer2D output) { base.Process(width, height, tex, output); if (shader != null) { GLTextuer2D tempColor = new GLTextuer2D(tex.InternalFormat); tempColor.Bind(); tempColor.SetData(IntPtr.Zero, PixelFormat.Rgba, tex.Width, tex.Height); if (tex.InternalFormat == PixelInternalFormat.R16f || tex.InternalFormat == PixelInternalFormat.R32f) { tempColor.SetSwizzleLuminance(); } else if (tex.IsRGBBased) { tempColor.SetSwizzleRGB(); } tempColor.SetFilter((int)TextureMinFilter.Linear, (int)TextureMagFilter.Linear); GLTextuer2D.Unbind(); ResizeViewTo(tex, tempColor, tex.Width, tex.Height, width, height); tex = tempColor; IGL.Primary.Clear((int)(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit)); ResizeViewTo(other, output, other.Width, other.Height, width, height); other = output; IGL.Primary.Clear((int)(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit)); Vector2 tiling = new Vector2(TileX, TileY); shader.Use(); shader.SetUniform2("tiling", ref tiling); shader.SetUniform("redChannel", RedChannel); shader.SetUniform("greenChannel", GreenChannel); shader.SetUniform("blueChannel", BlueChannel); shader.SetUniform("alphaChannel", AlphaChannel); shader.SetUniform("MainTex", 0); IGL.Primary.ActiveTexture((int)TextureUnit.Texture0); tex.Bind(); shader.SetUniform("Other", 1); IGL.Primary.ActiveTexture((int)TextureUnit.Texture1); other.Bind(); if (renderQuad != null) { renderQuad.Draw(); } GLTextuer2D.Unbind(); Blit(output, width, height); tempColor.Release(); } }
void Process() { GLTextuer2D i1 = (GLTextuer2D)input.Input.Data; GLTextuer2D i2 = null; if (input2.HasInput) { if (input2.Input.Data != null) { i2 = (GLTextuer2D)input2.Input.Data; } } if (i1 == null) { return; } if (i1.Id == 0) { return; } if (colorLUT == null || colorLUT.Id == 0) { colorLUT = new GLTextuer2D(PixelInternalFormat.Rgba8); } if (LUT == null) { LUT = new FloatBitmap(256, 2); } //generate gradient Utils.CreateGradient(LUT, gradient.positions, gradient.colors); colorLUT.Bind(); colorLUT.SetData(LUT.Image, PixelFormat.Rgba, 256, 2); colorLUT.SetFilter((int)TextureMinFilter.Linear, (int)TextureMagFilter.Linear); GLTextuer2D.Unbind(); CreateBufferIfNeeded(); processor.TileX = tileX; processor.TileY = tileY; processor.ColorLUT = colorLUT; processor.Mask = i2; processor.Process(width, height, i1, buffer); processor.Complete(); Output.Data = buffer; Output.Changed(); Updated(); }
public void Process(int width, int height, GLTextuer2D blur, GLTextuer2D orig, GLTextuer2D output) { base.Process(width, height, blur, output); if (shader != null) { GLTextuer2D tempColor = new GLTextuer2D(blur.InternalFormat); tempColor.Bind(); tempColor.SetData(IntPtr.Zero, PixelFormat.Rgba, blur.Width, blur.Height); if (blur.InternalFormat == PixelInternalFormat.R16f || blur.InternalFormat == PixelInternalFormat.R32f) { tempColor.SetSwizzleLuminance(); } else if (blur.IsRGBBased) { tempColor.SetSwizzleRGB(); } tempColor.SetFilter((int)TextureMinFilter.Linear, (int)TextureMagFilter.Linear); GLTextuer2D.Unbind(); ResizeViewTo(blur, tempColor, blur.Width, blur.Height, width, height); blur = tempColor; IGL.Primary.Clear((int)(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit)); ResizeViewTo(orig, output, orig.Width, orig.Height, width, height); orig = 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); IGL.Primary.ActiveTexture((int)TextureUnit.Texture0); blur.Bind(); shader.SetUniform("Original", 1); IGL.Primary.ActiveTexture((int)TextureUnit.Texture1); orig.Bind(); if (renderQuad != null) { renderQuad.Draw(); } GLTextuer2D.Unbind(); //output.Bind(); //output.CopyFromFrameBuffer(width, height); //GLTextuer2D.Unbind(); Blit(output, width, height); tempColor.Release(); } }
void LoadDefaultTextures() { if (defaultBlack == null) { FloatBitmap black = new FloatBitmap(128, 128); Nodes.Helpers.Utils.Fill(black, 0, 0, 0f, 0f, 0f, 1); defaultBlack = new GLTextuer2D(PixelInternalFormat.Rgba8); defaultBlack.Bind(); defaultBlack.SetData(black.Image, OpenTK.Graphics.OpenGL.PixelFormat.Rgba, 128, 128); defaultBlack.GenerateMipMaps(); defaultBlack.SetFilter((int)TextureMinFilter.LinearMipmapLinear, (int)TextureMagFilter.Linear); defaultBlack.SetWrap((int)TextureWrapMode.Repeat); GLTextuer2D.Unbind(); } if (defaultWhite == null) { FloatBitmap black = new FloatBitmap(128, 128); Nodes.Helpers.Utils.Fill(black, 0, 0, 1f, 1f, 1f, 1); defaultWhite = new GLTextuer2D(PixelInternalFormat.Rgba8); defaultWhite.Bind(); defaultWhite.SetData(black.Image, OpenTK.Graphics.OpenGL.PixelFormat.Rgba, 128, 128); defaultWhite.GenerateMipMaps(); defaultWhite.SetFilter((int)TextureMinFilter.LinearMipmapLinear, (int)TextureMagFilter.Linear); defaultWhite.SetWrap((int)TextureWrapMode.Repeat); GLTextuer2D.Unbind(); } if (defaultGray == null) { FloatBitmap black = new FloatBitmap(128, 128); Nodes.Helpers.Utils.Fill(black, 0, 0, 0.5f, 0.5f, 0.5f, 1); defaultGray = new GLTextuer2D(PixelInternalFormat.Rgba8); defaultGray.Bind(); defaultGray.SetData(black.Image, OpenTK.Graphics.OpenGL.PixelFormat.Rgba, 128, 128); defaultGray.GenerateMipMaps(); defaultGray.SetFilter((int)TextureMinFilter.LinearMipmapLinear, (int)TextureMagFilter.Linear); defaultGray.SetWrap((int)TextureWrapMode.Repeat); GLTextuer2D.Unbind(); } if (defaultDarkGray == null) { FloatBitmap black = new FloatBitmap(128, 128); Nodes.Helpers.Utils.Fill(black, 0, 0, 0.25f, 0.25f, 0.25f, 1); defaultDarkGray = new GLTextuer2D(PixelInternalFormat.Rgba8); defaultDarkGray.Bind(); defaultDarkGray.SetData(black.Image, OpenTK.Graphics.OpenGL.PixelFormat.Rgba, 128, 128); defaultDarkGray.GenerateMipMaps(); defaultDarkGray.SetFilter((int)TextureMinFilter.LinearMipmapLinear, (int)TextureMagFilter.Linear); defaultDarkGray.SetWrap((int)TextureWrapMode.Repeat); GLTextuer2D.Unbind(); } }
void Process() { if (!input.HasInput) { return; } GLTextuer2D i1 = (GLTextuer2D)input.Reference.Data; GLTextuer2D i2 = null; if (input2.HasInput) { i2 = (GLTextuer2D)input2.Reference.Data; } if (i1 == null) { return; } if (i1.Id == 0) { return; } if (processor == null) { return; } if (colorLUT == null || colorLUT.Id == 0) { colorLUT = new GLTextuer2D(PixelInternalFormat.Rgba8); } colorLUT.Bind(); colorLUT.SetData(LUT.Image, PixelFormat.Rgba, 256, 2); colorLUT.SetFilter((int)TextureMinFilter.Linear, (int)TextureMagFilter.Linear); GLTextuer2D.Unbind(); CreateBufferIfNeeded(); processor.TileX = tileX; processor.TileY = tileY; processor.ColorLUT = colorLUT; processor.Mask = i2; processor.Process(width, height, i1, buffer); processor.Complete(); Output.Data = buffer; TriggerTextureChange(); }
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(); } }
protected void CreateBuffersIfNeeded() { if (resizeProcessor == null) { resizeProcessor = new PreviewProcessor(); } if (renderBuff == null) { renderBuff = new GLRenderBuffer(); renderBuff.Bind(); renderBuff.SetBufferStorageAsDepth(4096, 4096); Console.WriteLine("render buff id: " + renderBuff.Id); GLRenderBuffer.Unbind(); } if (colorBuff == null) { //colorbuff part of the framebuffer is always Rgba32f to support all texture formats //that could be rendered into it colorBuff = new GLTextuer2D(PixelInternalFormat.Rgba32f); colorBuff.Bind(); colorBuff.SetData(new float[0], PixelFormat.Rgba, 4096, 4096); colorBuff.SetFilter((int)TextureMinFilter.Linear, (int)TextureMagFilter.Linear); Console.WriteLine("color buff id: " + colorBuff.Id); GLTextuer2D.Unbind(); } if (frameBuff == null) { frameBuff = new GLFrameBuffer(); Console.WriteLine("frame buff id: " + frameBuff.Id); frameBuff.Bind(); frameBuff.AttachColor(colorBuff); frameBuff.AttachDepth(renderBuff); GL.DrawBuffer(DrawBufferMode.ColorAttachment0); GL.ReadBuffer(ReadBufferMode.ColorAttachment0); if (!frameBuff.IsValid) { var status = GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer); Console.WriteLine("Framebuffer not complete!!! with status: " + status); GLFrameBuffer.Unbind(); return; } GLFrameBuffer.Unbind(); } }
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(); } }
protected void CreateBuffersIfNeeded() { if (resizeProcessor == null) { resizeProcessor = new PreviewProcessor(); } if (renderBuff == null) { renderBuff = new GLRenderBuffer(); renderBuff.Bind(); renderBuff.SetBufferStorageAsDepth(4096, 4096); GLRenderBuffer.Unbind(); } if (colorBuff == null) { //colorbuff part of the framebuffer is always Rgba32f to support all texture formats //that could be rendered into it colorBuff = new GLTextuer2D(PixelInternalFormat.Rgba32f); colorBuff.Bind(); colorBuff.SetData(IntPtr.Zero, PixelFormat.Rgba, 4096, 4096); colorBuff.Nearest(); colorBuff.Repeat(); GLTextuer2D.Unbind(); } if (frameBuff == null) { frameBuff = new GLFrameBuffer(); frameBuff.Bind(); frameBuff.AttachColor(colorBuff); frameBuff.AttachDepth(renderBuff); IGL.Primary.DrawBuffers(new int[] { (int)DrawBufferMode.ColorAttachment0 }); IGL.Primary.ReadBuffer((int)ReadBufferMode.ColorAttachment0); if (!frameBuff.IsValid) { var status = IGL.Primary.CheckFramebufferStatus((int)FramebufferTarget.Framebuffer); GLFrameBuffer.Unbind(); return; } GLFrameBuffer.Unbind(); } }
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(); } }
void Process() { //need a clean buffer //when drawing if (buffer != null) { buffer.Release(); buffer = null; } if (processor == null || lines == null) { return; } CreateBufferIfNeeded(); processor.Prepare(width, height, character, buffer); float px = 1.0f / width; float py = 1.0f / height; MVector pivot = new MVector(-1, 0); if (map != null && map.Count > 0 && transforms.Count > 0) { int tindex = 0; for (int i = 0; i < lines.Length; i++) { string line = lines[i]; float left = 0; float alignmentAdjustment = adjustments[i]; for (int j = 0; j < line.Length; j++) { if (tindex >= transforms.Count) { continue; } string ch = line.Substring(j, 1); FontManager.CharData data = null; if (map.TryGetValue(ch, out data)) { if (data.texture == null) { tindex++; continue; } CharacterTransform ct = transforms[tindex]; MVector finalPos = new MVector((ct.position.X + left * ct.scale.X) * width - alignmentAdjustment, (ct.position.Y + (i * data.bearing) * py * ct.scale.Y) * height); left += (data.size.X + pspacing) * px; character.Bind(); character.SetData(data.texture.Image, GLInterfaces.PixelFormat.Bgra, (int)Math.Ceiling(data.size.X), (int)Math.Ceiling(data.size.Y)); GLTextuer2D.Unbind(); processor.Translation = finalPos; processor.Angle = ct.angle; processor.Pivot = pivot; processor.Scale = ct.scale * (new MVector(data.size.X, data.size.Y) * 0.5f); processor.ProcessCharacter(width, height, character, buffer); } tindex++; } } } processor.Complete(); Updated(); Output.Data = buffer; Output.Changed(); }
public static async Task Load() { int index = selectedIndex; if (index < 0) { index = 0; } if (index > available.Count - 1) { index = available.Count - 1; } if (index >= 0 && index < available.Count) { string f = available[index]; string iradpath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Hdri", f, "irradiance.dds"); string prefpath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Hdri", f, "prefiltered.dds"); try { DDSImage rad = await DDSReader.DDSReader.ReadImageAsync(iradpath); DDSImage pre = await DDSReader.DDSReader.ReadImageAsync(prefpath); App.Current.Dispatcher.Invoke(() => { Collection <DDSMipMap> mips = (Collection <DDSMipMap>)rad.Frames; if (mips.Count > 0) { var mip = mips[0]; byte[] data = mip.MipmapData[0]; if (Irradiance != null) { Irradiance.Release(); } Irradiance = new GLTextuer2D(PixelInternalFormat.Rgb16f); Irradiance.Bind(); Irradiance.SetData(data, PixelFormat.Rgb, (int)mip.Width, (int)mip.Height); Irradiance.SetFilter((int)TextureMinFilter.Linear, (int)TextureMagFilter.Linear); Irradiance.SetWrap((int)TextureWrapMode.ClampToEdge); GLTextuer2D.Unbind(); } mips = (Collection <DDSMipMap>)pre.Frames; if (mips.Count > 0) { if (Prefiltered != null) { Prefiltered.Release(); } Prefiltered = new GLTextuer2D(PixelInternalFormat.Rgb16f); Prefiltered.Bind(); Prefiltered.SetMaxMipLevel(4); for (int i = 0; i < mips.Count; ++i) { var mip = mips[i]; byte[] data = mip.MipmapData[0]; Prefiltered.SetData(data, PixelFormat.Rgb, (int)mip.Width, (int)mip.Height, i); } Prefiltered.SetFilter((int)TextureMinFilter.LinearMipmapLinear, (int)TextureMagFilter.Linear); Prefiltered.SetWrap((int)TextureWrapMode.ClampToEdge); GLTextuer2D.Unbind(); } if (OnHdriLoaded != null) { OnHdriLoaded.Invoke(Irradiance, Prefiltered); } }); } catch (Exception e) { Log.Error(e); } } }
public void Process(int width, int height, GLTextuer2D tex, GLTextuer2D tex2, GLTextuer2D mask, GLTextuer2D output) { base.Process(width, height, tex, output); if (shader != null) { GLTextuer2D tempColor = new GLTextuer2D(tex.InternalFormat); GLTextuer2D tempColor2 = new GLTextuer2D(tex2.InternalFormat); tempColor.Bind(); tempColor.SetData(IntPtr.Zero, PixelFormat.Rgba, tex.Width, tex.Height); if (tex.InternalFormat == PixelInternalFormat.R16f || tex.InternalFormat == PixelInternalFormat.R32f) { tempColor.SetSwizzleLuminance(); } else if (tex.IsRGBBased) { tempColor.SetSwizzleRGB(); } tempColor.SetFilter((int)TextureMinFilter.Linear, (int)TextureMagFilter.Linear); GLTextuer2D.Unbind(); tempColor2.Bind(); tempColor2.SetData(IntPtr.Zero, PixelFormat.Rgba, tex2.Width, tex2.Height); if (tex2.InternalFormat == PixelInternalFormat.R16f || tex2.InternalFormat == PixelInternalFormat.R32f) { tempColor2.SetSwizzleLuminance(); } else if (tex.IsRGBBased) { tempColor.SetSwizzleRGB(); } tempColor2.SetFilter((int)TextureMinFilter.Linear, (int)TextureMagFilter.Linear); GLTextuer2D.Unbind(); ResizeViewTo(tex, tempColor, tex.Width, tex.Height, width, height); tex = tempColor; IGL.Primary.Clear((int)(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit)); ResizeViewTo(tex2, tempColor2, tex2.Width, tex2.Height, width, height); tex2 = tempColor2; IGL.Primary.Clear((int)(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit)); if (mask != null) { ResizeViewTo(mask, output, mask.Width, mask.Height, width, height); mask = output; IGL.Primary.Clear((int)(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit)); } Vector2 tiling = new Vector2(TileX, TileY); shader.Use(); shader.SetUniform2("tiling", ref tiling); shader.SetUniform("Foreground", 0); IGL.Primary.ActiveTexture((int)TextureUnit.Texture0); tex.Bind(); shader.SetUniform("Background", 1); IGL.Primary.ActiveTexture((int)TextureUnit.Texture1); tex2.Bind(); shader.SetUniform("blendMode", BlendMode); shader.SetUniform("alpha", Alpha); shader.SetUniform("alphaMode", AlphaMode); if (mask != null) { shader.SetUniform("Mask", 2); IGL.Primary.ActiveTexture((int)TextureUnit.Texture2); shader.SetUniform("hasMask", 1); mask.Bind(); } else { shader.SetUniform("hasMask", 0); } if (renderQuad != null) { renderQuad.Draw(); } GLTextuer2D.Unbind(); //output.Bind(); //output.CopyFromFrameBuffer(width, height); //GLTextuer2D.Unbind(); Blit(output, width, height); tempColor.Release(); tempColor2.Release(); } }
protected async Task LoadHdri(string folder) { string iradpath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Hdri", folder, "irradiance.dds"); string prefpath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Hdri", folder, "prefiltered.dds"); try { DDSImage rad = await DDSReader.DDSReader.ReadImageAsync(iradpath); DDSImage pre = await DDSReader.DDSReader.ReadImageAsync(prefpath); App.Current.Dispatcher.Invoke(() => { Collection <DDSMipMap> mips = (Collection <DDSMipMap>)rad.Frames; if (mips.Count > 0) { var mip = mips[0]; byte[] data = mip.MipmapData[0]; if (irradiance != null) { irradiance.Release(); } irradiance = new GLTextuer2D(PixelInternalFormat.Rgb8); irradiance.Bind(); irradiance.SetData(data, OpenTK.Graphics.OpenGL.PixelFormat.Rgb, (int)mip.Width, (int)mip.Height); irradiance.SetFilter((int)TextureMinFilter.Linear, (int)TextureMagFilter.Linear); irradiance.SetWrap((int)TextureWrapMode.ClampToEdge); GLTextuer2D.Unbind(); } mips = (Collection <DDSMipMap>)pre.Frames; if (mips.Count > 0) { if (prefiltered != null) { prefiltered.Release(); } prefiltered = new GLTextuer2D(PixelInternalFormat.Rgb8); prefiltered.Bind(); prefiltered.SetMaxMipLevel(4); for (int i = 0; i < mips.Count; i++) { var mip = mips[i]; byte[] data = mip.MipmapData[0]; prefiltered.SetData(data, OpenTK.Graphics.OpenGL.PixelFormat.Rgb, (int)mip.Width, (int)mip.Height, i); } prefiltered.SetFilter((int)TextureMinFilter.LinearMipmapLinear, (int)TextureMagFilter.Linear); prefiltered.SetWrap((int)TextureWrapMode.ClampToEdge); GLTextuer2D.Unbind(); } Invalidate(); }); } catch (Exception e) { Console.WriteLine(e.StackTrace); } }
void Process() { GLTextuer2D i1 = (GLTextuer2D)input.Input.Data; if (i1 == null) { return; } if (i1.Id == 0) { return; } CreateBufferIfNeeded(); try { List <Point> mids = curves[0]; List <Point> reds = curves[1]; List <Point> greens = curves[2]; List <Point> blues = curves[3]; foreach (Point p in reds) { int x = 255 - (int)Math.Floor(Math.Min(255, Math.Max(0, p.X * 255))); for (int i = 0; i < 2; i++) { int idx2 = (x + i * 256) * 4; lutBrush.Image[idx2] = (float)p.Y; } } foreach (Point p in greens) { int x = 255 - (int)Math.Floor(Math.Min(255, Math.Max(0, p.X * 255))); for (int i = 0; i < 2; i++) { int idx2 = (x + i * 256) * 4; lutBrush.Image[idx2 + 1] = (float)p.Y; } } foreach (Point p in blues) { int x = 255 - (int)Math.Floor(Math.Min(255, Math.Max(0, p.X * 255))); for (int i = 0; i < 2; i++) { int idx2 = (x + i * 256) * 4; lutBrush.Image[idx2 + 2] = (float)p.Y; } } foreach (Point p in mids) { int x = 255 - (int)Math.Floor(Math.Min(255, Math.Max(0, p.X * 255))); for (int i = 0; i < 2; i++) { int idx2 = (x + i * 256) * 4; lutBrush.Image[idx2 + 3] = (float)p.Y; } } curveLUT.Bind(); curveLUT.SetData(lutBrush.Image, OpenTK.Graphics.OpenGL.PixelFormat.Rgba, 256, 2); GLTextuer2D.Unbind(); } catch (Exception e) { Console.WriteLine(e.StackTrace); } processor.TileX = tileX; processor.TileY = tileY; processor.Process(width, height, i1, buffer); processor.Complete(); Updated(); Output.Data = buffer; Output.Changed(); }