private void Отрисовка(Point _center) { #if DEBUG using (new Profiler()) #endif { using (new Profiler("DrawShadows(each)")) for (var i = 0; i < m_lightsCount; i++) { using (new FboWrapper.DrawHelper(m_fbo)) { DrawShadows(m_lights[i], new PointF(_center.X, _center.Y)); m_fbo.BlitTo(m_fboBlit, i); } } m_fbo.BlitTo(m_fboBlit, m_lightsCount + 1); if (false) { for (var a = 0; a < m_lightsCount + 1; ++a) { using (new FboWrapper.DrawHelper(m_fboBlit)) { GL.ReadBuffer(ReadBufferMode.ColorAttachment0 + a); FboWrapper.DrawHelper.Screenshot("e:\\1\\a" + a + ".png"); } } } using (new FboWrapper.DrawHelper(m_fbo)) { var ambient = World.TheWorld.Avatar.GeoInfo.Layer.Ambient; GL.ClearColor(ambient.R, ambient.G, ambient.B, 1f); GL.Clear(ClearBufferMask.ColorBufferBit); GL.Color3(1f, 1f, 1f); GL.Enable(EnableCap.Texture2D); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.One, BlendingFactorDest.OneMinusSrcColor); const float sz = MAP_SIZE; const float to = ((float)MAP_SIZE) / FboWrapper.SIZE; using (new Profiler("DrawShadows.lightShader(each)")) using (var sh = new ShaderWrapper.DrawHelper(m_lightShader)) { for (var a = 1; a < m_lightsCount; ++a) { sh.BindTexture(m_fboBlit[a], TextureUnit.Texture0, "_light"); sh.BindVec2(m_lights[a].Point, "_position"); GL.Begin(BeginMode.Quads); { GL.TexCoord2(0f, 0f); GL.Vertex2(0f, 0f); GL.TexCoord2(to, 0f); GL.Vertex2(sz, 0f); GL.TexCoord2(to, to); GL.Vertex2(sz, sz); GL.TexCoord2(0f, to); GL.Vertex2(0f, sz); } GL.End(); } } using (new Profiler("DrawShadows.sightShader")) using (var sh = new ShaderWrapper.DrawHelper(m_sightShader)) { sh.BindTexture(m_fboBlit[0], TextureUnit.Texture0, "_sight"); sh.BindVec2(m_lights[0].Point, "_position"); GL.BlendFunc(BlendingFactorSrc.DstColor, BlendingFactorDest.OneMinusSrcAlpha); GL.Begin(BeginMode.Quads); { GL.TexCoord2(0f, 0f); GL.Vertex2(0f, 0f); GL.TexCoord2(to, 0f); GL.Vertex2(sz, 0f); GL.TexCoord2(to, to); GL.Vertex2(sz, sz); GL.TexCoord2(0f, to); GL.Vertex2(0f, sz); } GL.End(); } m_fbo.BlitTo(m_fboBlit, 1); } } }
protected override void OnRenderFrame(FrameEventArgs _e) { base.OnRenderFrame(_e); GL.ClearColor(0f, 0f, 0f, 0f); GL.Clear(ClearBufferMask.ColorBufferBit); using (new FboWrapper.DrawHelper(m_fboWrapper)) { #region #1 //dfbo.BeginDrawIn(0); GL.ClearColor(0f, 0f, 0f, 0f); GL.Clear(ClearBufferMask.ColorBufferBit); GL.Disable(EnableCap.Texture2D); GL.Begin(BeginMode.Polygon); { const int center = Map.SIZE * SZ / 2; GL.Color3(1f, 1f, 0.7f); GL.Vertex2(center, center); GL.Color3(0f, 0f, 0f); const float step = (float)Math.PI / 10f; for (float f = 0; f < Math.PI * 2 + step; f += step) { var x = Math.Sin(f) * LIGHTRADIUS + center; var y = Math.Cos(f) * LIGHTRADIUS + center; GL.Vertex2(x, y); } GL.Color3(1f, 1f, 0.7f); GL.Vertex2(center, center); } GL.End(); #endregion m_fboWrapper.BlitTo(m_fboWrapperBlit, 0); } using (new FboWrapper.DrawHelper(m_fboWrapper)) { DrawShadows(new PointF(Mouse.X * SZ / VSZ, Mouse.Y * SZ / VSZ)); m_fboWrapper.BlitTo(m_fboWrapperBlit, 1); } const float sz = Map.SIZE * VSZ; //Map.SIZE; //512f / SZ; const float to = ((float)Map.SIZE * SZ) / FboWrapper.SIZE; if (true) { using (new FboWrapper.DrawHelper(m_fboWrapper)) { GL.Color4(1f, 1f, 1f, 1f); GL.Enable(EnableCap.Texture2D); m_fboWrapperBlit.BindTexture(1); GL.Begin(BeginMode.Quads); { GL.TexCoord2(0f, 0f); GL.Vertex2(0f, 0f); GL.TexCoord2(to, 0f); GL.Vertex2(sz, 0f); GL.TexCoord2(to, to); GL.Vertex2(sz, sz); GL.TexCoord2(0f, to); GL.Vertex2(0f, sz); } GL.End(); GL.BindTexture(TextureTarget.ProxyTexture2D, 0); GL.Disable(EnableCap.Texture2D); var arr = new FColor[Map.SIZE, Map.SIZE]; GL.ReadPixels(0, 0, Map.SIZE, Map.SIZE, PixelFormat.Rgba, PixelType.Float, arr); var bmp = new Bitmap(Map.SIZE, Map.SIZE, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); for (int i = 0; i < Map.SIZE; i++) { for (int j = 0; j < Map.SIZE; j++) { bmp.SetPixel(j, i, Color.FromArgb((int)(arr[i, j].A * 255), (int)(arr[i, j].R * 255), (int)(arr[i, j].G * 255), (int)(arr[i, j].B * 255))); } } bmp.Save("d:\\eee.png", ImageFormat.Png); } } GL.UseProgram(m_shaderProgramHandle); BindTexture(m_t2, TextureUnit.Texture1, "Shadow0"); BindTexture(m_t1, TextureUnit.Texture0, "Spot"); GL.Color3(1f, 1f, 1f); GL.Begin(BeginMode.Quads); { GL.TexCoord2(0f, 0f); GL.Vertex2(0f, 0f); GL.TexCoord2(to, 0f); GL.Vertex2(sz, 0f); GL.TexCoord2(to, to); GL.Vertex2(sz, sz); GL.TexCoord2(0f, to); GL.Vertex2(0f, sz); } GL.End(); GL.BindTexture(TextureTarget.Texture2D, 0); GL.Disable(EnableCap.Texture2D); GL.UseProgram(0); GL.Flush(); //var arr = new FColor[Map.SIZE, Map.SIZE]; //GL.ReadPixels(0, 0, Map.SIZE, Map.SIZE, PixelFormat.Rgba, PixelType.Float, arr); //var bmp = new Bitmap(Map.SIZE, Map.SIZE, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); //for (int i = 0; i < Map.SIZE; i++) //{ // for (int j = 0; j < Map.SIZE; j++) // { // bmp.SetPixel(j, i, Color.FromArgb((int)(arr[i, j].A * 255), (int)(arr[i, j].R * 255), (int)(arr[i, j].G * 255), (int)(arr[i, j].B * 255))); // } //} //bmp.Save("d:\\aaa.png",ImageFormat.Png); SwapBuffers(); Title = string.Format("fps:{0} per frame", Math.Round(1 / _e.Time)); }