Example #1
0
        private void Viewport_Paint()
        {
            lock (RenderSync)
            {
                Viewport.MakeCurrent();

                Membrane.MeshProgram.Use();
                {
                    Membrane.MeshProgram.SetUniform("worldViewProjMatrix", Viewport.Camera.GetViewProj());
                    Membrane.MeshProgram.SetUniform("surfaceOffset",
                                                    (float)SurfaceOffset * MainWindow.Options.PixelScale.X);

                    if (Membrane.TomogramTexture != null)
                    {
                        Membrane.MeshProgram.SetUniform("useVolume", 1f);
                        Membrane.MeshProgram.SetUniform("volScale", OpenGLHelper.Reciprocal(Membrane.TomogramTexture.Scale));
                        Membrane.MeshProgram.SetUniform("volOffset", Membrane.TomogramTexture.Offset);
                        Membrane.MeshProgram.SetUniform("texSize", OpenGLHelper.Reciprocal(Membrane.TomogramTexture.Size));

                        GL.ActiveTexture(TextureUnit.Texture0);
                        GL.BindTexture(TextureTarget.Texture3D, Membrane.TomogramTexture.Handle);
                    }
                    else
                    {
                        Membrane.MeshProgram.SetUniform("useVolume", 0f);
                    }

                    GL.ActiveTexture(TextureUnit.Texture1);
                    GL.BindTexture(TextureTarget.Texture2D, Membrane.SelectionTexture.Handle);

                    float TraceStart  = TraceDepthOffset;
                    float TraceLength = TraceDepth;
                    Membrane.MeshProgram.SetUniform("traceParams", new Vector2(TraceStart, TraceLength));
                    Membrane.MeshProgram.SetUniform("traceSharpening", (float)TraceSharpening / 100f);

                    float RangeMin = (float)Math.Min(OutputRangeMin, OutputRangeMax),
                          RangeMax = (float)Math.Max(OutputRangeMin, OutputRangeMax);
                    Membrane.MeshProgram.SetUniform("normalizeParams", new Vector2(RangeMin, RangeMax - RangeMin));

                    Vector3 LightDirection = Viewport.Camera.GetDirection();
                    Membrane.MeshProgram.SetUniform("lightDirection", LightDirection);
                    Membrane.MeshProgram.SetUniform("lightIntensity", 0.0f);

                    SurfaceMesh?.Draw();
                }

                Membrane.PointProgram.Use();
                {
                    Membrane.PointProgram.SetUniform("worldViewProjMatrix",
                                                     MainWindow.Options.Viewport.Camera.GetViewProj());

                    // Draw back faces first, then front, to ensure correct transparency (locally)
                    GL.Enable(EnableCap.CullFace);
                    GL.CullFace(CullFaceMode.Front);
                    foreach (PointGroup group in PointGroups.Where(g => g.IsVisible && g.Points.Count > 0))
                    {
                        Membrane.PointProgram.SetUniform("cubeSize",
                                                         (float)group.Size * MainWindow.Options.PixelScale.X);
                        group.PointCloud.Draw();
                    }
                    GL.CullFace(CullFaceMode.Back);
                    foreach (PointGroup group in PointGroups.Where(g => g.IsVisible && g.Points.Count > 0))
                    {
                        Membrane.PointProgram.SetUniform("cubeSize",
                                                         (float)group.Size * MainWindow.Options.PixelScale.X);
                        group.PointCloud.Draw();
                    }
                    GL.Disable(EnableCap.CullFace);
                }
            }
        }