Page 1 of 1

Multiple SurfaceGridSeries3D and transparency

Posted: Wed Dec 07, 2016 8:45 pm
by Greg9504
Is there anyway around this problem:

I have multiple surfaces, I want the user to be able to vary the transparency of a surface. However when I do this the surface is not transparent, see the example screen shots. This seems related to the order that the surface was added to the View3D. In the example the top surface was added first. If I were to change the transparency of the bottom surface (added second) then everything appears to work.

The code to set the transparency is
gridSeries.Data[i, j].Color.A = surface.AlphaValue;

Re: Multiple SurfaceGridSeries3D and transparency

Posted: Thu Dec 08, 2016 5:33 am
by ArctionPasi
Hi Greg,

The rendering order matters here. Alpha test is made against stuff already rendered on the backbuffer. The Surface series are rendered in the order they exist in the View3D.SurfaceGridSeries collection. Please change the order of the collection, that should help :)

Re: Multiple SurfaceGridSeries3D and transparency

Posted: Fri Dec 09, 2016 4:23 am
by Greg9504
Just changing the rendering order doesn't work. What happens when their are 3 surfaces??? Vary the transparency of the middle surface and you wont be able to see either the surface below or above, depending on what order they were added.

If you notice there is a slider used to vary the alpha transparency. This means that on each property change event I need to:

- removal all surfaces
- rerender all other surfaces
- update alpha value for selected surface
- rerender surface.

Hopefully it wont be slow... just tested this code:

Code: Select all

private void UpdateSurfaceAlpha(SurfaceModel surface, IntensitySurfaceGridSeries3D gridSeries)
        {
            SurfaceGridSeries3DCollection allseries = new SurfaceGridSeries3DCollection();
            allseries.AddRange(m_chart.View3D.SurfaceGridSeries3D);
            //remov all surfaces
            m_chart.View3D.SurfaceGridSeries3D.Clear();
            //add back all surfaces but the one that the alpha is changing
            foreach (SurfaceGridSeries3D series in allseries)
            {
                if (series != gridSeries)
                {
                    m_chart.View3D.SurfaceGridSeries3D.Add(series);
                }
            }
            //modify the alpha value of the series
            for (int i = 0; i < gridSeries.Data.GetLength(0); i++)
            {
                for (int j = 0; j < gridSeries.Data.GetLength(1); j++)
                {
                    gridSeries.Data[i, j].Color.A = surface.AlphaValue;
                }
            }
            gridSeries.InvalidateData();//this must be done to get the updated alpha value
            m_chart.View3D.SurfaceGridSeries3D.Add(gridSeries);

        }
and it appears to run fast enough to vary the transparency with the slider. At least with 2 surfaces, will have to test with more to be sure.

Thanks
Greg.

Re: Multiple SurfaceGridSeries3D and transparency

Posted: Fri Dec 09, 2016 3:13 pm
by ArctionPasi
Transparency has serious limitations in 3D. It depends on the object order in the series collections and camera angle. You can use max 1 transparent or translucent series in the chart.

Re: Multiple SurfaceGridSeries3D and transparency

Posted: Fri Dec 09, 2016 4:52 pm
by Greg9504
Hello Pasi,

I now see the problem even with my changes. Not sure why you didn't mention this first. So no alpha blending. Should mention this in the documentation.