public void Render() { for (int i = 0; i < Shaders.Count; i++) { Shader shader = Shaders[i]; mesh.Use(); shader.Use(); shader.SetInt("sourceTexture", 0); GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.Texture2D, framebuffer.GetTexture(FramebufferAttachment.ColorAttachment0)); shader.SetInt("sourceDepth", 1); GL.ActiveTexture(TextureUnit.Texture1); GL.BindTexture(TextureTarget.Texture2D, framebuffer.GetTexture(FramebufferAttachment.DepthAttachment)); if (i != 0) { shader.SetInt("lastStageTexture", 2); GL.ActiveTexture(TextureUnit.Texture2); GL.BindTexture(TextureTarget.Texture2D, stageReadFramebuffer.GetTexture(FramebufferAttachment.ColorAttachment0)); } if (i != Shaders.Count - 1) { stageDrawFramebuffer.Begin(); GL.Clear(ClearBufferMask.ColorBufferBit); } GL.DrawElements(PrimitiveType.Triangles, mesh.IndicesCount, DrawElementsType.UnsignedInt, 0); if (i != Shaders.Count - 1) { stageDrawFramebuffer.End(); } { Framebuffer temp = stageDrawFramebuffer; stageDrawFramebuffer = stageReadFramebuffer; stageReadFramebuffer = temp; } } }
public void Begin() { framebuffer.Begin(); }
public override void Render() { if (Camera.Main == null) { return; } DataManager.CurrentScene.SceneRootEntities.ForEach(en => en.Transform.CalculateModelMatrixRecursively()); DataManager.EngineReservedEntities.ForEach(en => en.Transform.CalculateModelMatrixRecursively()); //shadow mapping if (DirectionalLight.Main == null) { goto RenderOpaque; } Matrix4 lView; Matrix4 lProjection; DirectionalLight.Main.CalculateViewProjection(out lView, out lProjection, shadowMapSize, Camera.Main.BaseTransform.Position); LightingGlobals.LightView = lView; LightingGlobals.LightProjection = lProjection; DataManager.CurrentScene.SceneRootEntities.ForEach(en => en.RecursivelyRenderShadowMap(LightingGlobals.LightView, LightingGlobals.LightProjection)); DataManager.EngineReservedEntities.ForEach(en => en.RecursivelyRenderShadowMap(LightingGlobals.LightView, LightingGlobals.LightProjection)); GL.Viewport(0, 0, shadowMapRes, shadowMapRes); shadowMapFramebuffer.Begin(); GL.Clear(ClearBufferMask.DepthBufferBit); GL.Enable(EnableCap.DepthTest); GL.Enable(EnableCap.CullFace); GL.CullFace(CullFaceMode.Back); GL.FrontFace(FrontFaceDirection.Ccw); DrawDrawList(drawLists[DrawType.ShadowMap]); shadowMapFramebuffer.End(); LightingGlobals.ShadowMap = shadowMapFramebuffer.GetTexture(FramebufferAttachment.DepthAttachment); //render opaque RenderOpaque: Camera.Main.CalculateViewProjection(out Matrix4 view, out Matrix4 projection); //call all render funcs DataManager.CurrentScene.SceneRootEntities.ForEach(en => en.RecursivelyRender(view, projection)); DataManager.EngineReservedEntities.ForEach(en => en.RecursivelyRender(view, projection)); GL.Viewport(0, 0, ViewportSize.X, ViewportSize.Y); postProcessor.Begin(); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.Enable(EnableCap.DepthTest); GL.Enable(EnableCap.CullFace); GL.CullFace(CullFaceMode.Back); GL.FrontFace(FrontFaceDirection.Ccw); DrawDrawList(drawLists[DrawType.Opaque]); //render transparent GL.DepthMask(false); GL.Disable(EnableCap.CullFace); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); DrawDrawList(drawLists[DrawType.Transparent]); postProcessor.End(); //reset states GL.DepthMask(true); GL.Disable(EnableCap.DepthTest); GL.Disable(EnableCap.CullFace); postProcessor.Render(); ClearDrawList(); }