public override void Draw(double deltaTime) { RenderTexture rt = RenderTexture; if (rt == null) { if (Camera == null) { return; } else { rt = Camera.TargetTexture; } } if (!rt.Loaded) { return; } // HDR抽出 hdrRT.Bind(Color4.Black); hdrShader.UseShader(); hdrShader.SetParameter(hdrShader.loc_resolution, hdrRT.Size.ToVector2().Inverse()); hdrShader.SetParameter(hdrShader.loc_threshold, HDRThreshold); hdrShader.SetParameter(hdrShader.loc_mvp, ref orthoMatrix, false); hdrShader.SetParameter(TextureUnit.Texture0, rt.ColorDst0); Drawer.DrawTextureMesh(); hdrShader.UnuseShader(); // HDR画像のぼかし画像を生成 // line for (var i = 0; i < BlurNum; i++) { blurs[i].Direction = Direction; blurs[i].RenderTexture = blurRT1s[i]; if (i == 0) { blurs[i].SrcTexture = hdrRT.ColorDst0; } else { blurs[i].SrcTexture = blurRT1s[i - 1].ColorDst0; } blurs[i].Draw(deltaTime); } if (GlareType == GlareBlur.GlareType.Plus) { var dir = new Vector2(-Direction.Y, Direction.X); for (var i = 0; i < BlurNum; i++) { blurs[i].Direction = dir; blurs[i].RenderTexture = blurRT2s[i]; if (i == 0) { blurs[i].SrcTexture = hdrRT.ColorDst0; } else { blurs[i].SrcTexture = blurRT2s[i - 1].ColorDst0; } blurs[i].Draw(deltaTime); } } else if (GlareType == GlareBlur.GlareType.Star) { var dir1 = new Vector2((Direction.X * cos60) - (Direction.Y * sin60), (Direction.X * sin60) + (Direction.Y * cos60)); var dir2 = new Vector2((Direction.X * cos120) - (Direction.Y * sin120), (Direction.X * sin120) + (Direction.Y * cos120)); for (var i = 0; i < BlurNum; i++) { blurs[i].Direction = dir1; blurs[i].RenderTexture = blurRT2s[i]; if (i == 0) { blurs[i].SrcTexture = hdrRT.ColorDst0; } else { blurs[i].SrcTexture = blurRT2s[i - 1].ColorDst0; } blurs[i].Draw(deltaTime); } for (var i = 0; i < BlurNum; i++) { blurs[i].Direction = dir2; blurs[i].RenderTexture = blurRT3s[i]; if (i == 0) { blurs[i].SrcTexture = hdrRT.ColorDst0; } else { blurs[i].SrcTexture = blurRT3s[i - 1].ColorDst0; } blurs[i].Draw(deltaTime); } } // Glare処理 glareRT.Bind(Color4.Black); glareShader.UseShader(); glareShader.SetParameter(glareShader.loc_resolution, glareRT.Size.ToVector2().Inverse()); glareShader.SetParameter(glareShader.loc_mvp, ref orthoMatrix, false); glareShader.SetParameter(glareShader.loc_intensity, Intensity); glareShader.SetParameter(TextureUnit.Texture0, rt.ColorDst0); var units = new TextureUnit[][] { new TextureUnit[] { TextureUnit.Texture1, TextureUnit.Texture2, TextureUnit.Texture3, }, new TextureUnit[] { TextureUnit.Texture4, TextureUnit.Texture5, TextureUnit.Texture6, }, new TextureUnit[] { TextureUnit.Texture7, TextureUnit.Texture8, TextureUnit.Texture9, }, }; // line for (var i = 0; i < 3; i++) { if (i < BlurNum) { glareShader.SetParameter(units[0][i], blurRT1s[i].ColorDst0); } else { glareShader.SetParameter(units[0][i], glareShader.black); } } // plus for (var i = 0; i < 3; i++) { if (i < BlurNum && GlareType > GlareBlur.GlareType.Line) { glareShader.SetParameter(units[1][i], blurRT2s[i].ColorDst0); } else { glareShader.SetParameter(units[1][i], glareShader.black); } } // star for (var i = 0; i < 3; i++) { if (i < BlurNum && GlareType > GlareBlur.GlareType.Plus) { glareShader.SetParameter(units[2][i], blurRT3s[i].ColorDst0); } else { glareShader.SetParameter(units[2][i], glareShader.black); } } Drawer.DrawTextureMesh(); glareShader.UnuseShader(); // 書き出し rt.Bind(); Drawer.DrawTexture(glareRT.ColorDst0); GL.BindTexture(TextureTarget.Texture2D, 0); }
public override void Draw(double deltaTime) { RenderTexture rt = RenderTexture; if (rt == null) { if (Camera == null) { return; } else { rt = Camera.TargetTexture; } } if (!rt.Loaded) { return; } // HDR抽出 hdrRT.Bind(Color4.Black); hdrShader.UseShader(); hdrShader.SetParameter(hdrShader.loc_resolution, hdrRT.Size.ToVector2().Inverse()); hdrShader.SetParameter(hdrShader.loc_mvp, ref orthoMatrix, false); hdrShader.SetParameter(hdrShader.loc_threshold, Threshold); hdrShader.SetParameter(TextureUnit.Texture0, rt.ColorDst0); Drawer.DrawTextureMesh(); hdrShader.UnuseShader(); // HDR画像のぼかし画像を生成 for (var i = 0; i < BlurNum; i++) { if (i == 0) { blurs[i].SrcTexture = hdrRT.ColorDst0; } else { blurs[i].SrcTexture = blurRTs[i - 1].ColorDst0; } blurs[i].Draw(deltaTime); } // Bloom処理 bloomRT.Bind(Color4.Black); bloomShader.UseShader(); bloomShader.SetParameter(bloomShader.loc_resolution, bloomRT.Size.ToVector2().Inverse()); bloomShader.SetParameter(bloomShader.loc_mvp, ref orthoMatrix, false); bloomShader.SetParameter(bloomShader.loc_intensity, Intensity); bloomShader.SetParameter(TextureUnit.Texture0, rt.ColorDst0); var units = new TextureUnit[] { TextureUnit.Texture1, TextureUnit.Texture2, TextureUnit.Texture3, TextureUnit.Texture4, TextureUnit.Texture5, }; for (var i = 0; i < 5; i++) { if (i < BlurNum) { bloomShader.SetParameter(units[i], blurRTs[i].ColorDst0); } else { bloomShader.SetParameter(units[i], bloomShader.black); } } Drawer.DrawTextureMesh(); bloomShader.UnuseShader(); // 書き出し rt.Bind(); Drawer.DrawTexture(bloomRT.ColorDst0); GL.BindTexture(TextureTarget.Texture2D, 0); }