public void Create(GLItemsList items, GLRenderProgramSortedList rObjects, List <SystemClass> incomingsys, float bookmarksize, GLStorageBlock findbufferresults, bool depthtest)
        {
            if (ridisplay == null)
            {
                //var vert = new GLPLVertexScaleLookat(rotate: dorotate, rotateelevation: doelevation, commontransform: false, texcoords: true,      // a look at vertex shader
                //
                //                var vert = new GLPLVertexShaderWorldCoord();
                var vert = new GLPLVertexScaleLookat(rotatetoviewer: dorotate, rotateelevation: doelevation, texcoords: true, generateworldpos: true,
                                                     autoscale: 500, autoscalemin: 1f, autoscalemax: 20f);            // below 500, 1f, above 500, scale up to 20x


                const int texbindingpoint = 1;
                var       frag            = new GLPLFragmentShaderTexture(texbindingpoint); // binding - simple texturer based on vs model coords

                objectshader = new GLShaderPipeline(vert, null, null, null, frag);
                items.Add(objectshader);

                var objtex = items.NewTexture2D("Bookmarktex", TestOpenTk.Properties.Resources.dotted2, OpenTK.Graphics.OpenGL4.SizedInternalFormat.Rgba8);

                objectshader.StartAction += (s, m) =>
                {
                    objtex.Bind(texbindingpoint);   // bind tex array to, matching above
                };

                bookmarkposbuf = items.NewBuffer();         // where we hold the vertexes for the suns, used by renderer and by finder

                GLRenderState rt = GLRenderState.Tri();
                rt.DepthTest = depthtest;

                bookmarksize *= 10;

                // 0 is model pos, 1 is world pos by a buffer, 2 is tex co-ords
                ridisplay = GLRenderableItem.CreateVector4Vector4Vector2(items, OpenTK.Graphics.OpenGL4.PrimitiveType.TriangleStrip, rt,
                                                                         GLShapeObjectFactory.CreateQuadTriStrip(bookmarksize, bookmarksize), // quad2 4 vertexts as the model positions
                                                                         bookmarkposbuf, 0,                                                   // world positions come from here - not filled as yet
                                                                         GLShapeObjectFactory.TexTriStripQuad,
                                                                         ic: 0, seconddivisor: 1);

                rObjects.Add(objectshader, "bookmarks", ridisplay);

                var geofind = new GLPLGeoShaderFindTriangles(findbufferresults, 16);//, forwardfacing:false);
                findshader = items.NewShaderPipeline(null, vert, null, null, geofind, null, null, null);

                // hook to modelworldbuffer, at modelpos and worldpos.  UpdateEnables will fill in instance count
                rifind = GLRenderableItem.CreateVector4Vector4Vector2(items, OpenTK.Graphics.OpenGL4.PrimitiveType.TriangleStrip, rt,
                                                                      GLShapeObjectFactory.CreateQuadTriStrip(bookmarksize, bookmarksize),   // quad2 4 vertexts as the model positions
                                                                      bookmarkposbuf, 0,
                                                                      GLShapeObjectFactory.TexTriStripQuad,
                                                                      ic: 0, seconddivisor: 1);
            }

            bookmarkposbuf.AllocateFill(incomingsys.Select(x => new Vector4((float)x.X, (float)x.Y, (float)x.Z, 1)).ToArray());
            ridisplay.InstanceCount = rifind.InstanceCount = incomingsys.Count;
        }
Example #2
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="tesselation">Tesselation amount</param>
        /// <param name="amplitude">Amplitude of sinewave</param>
        /// <param name="repeats">Repeats across object</param>
        /// <param name="rotate">To rotate to viewer in azimuth</param>
        /// <param name="rotateelevation">to rotate to viewer in elevation</param>
        /// <param name="commontransformuniform">Common transform uniform. 0 means off</param>
        /// <param name="autoscale">To autoscale distance. Sets the 1.0 scale point.</param>
        /// <param name="autoscalemin">Minimum to scale to</param>
        /// <param name="autoscalemax">Maximum to scale to</param>
        ///
        public GLTesselationShaderSinewaveAutoscale(float tesselation, float amplitude, float repeats, bool rotate = false, bool rotateelevation = true,
                                                    int commontransformuniform = 0, float autoscale = 0, float autoscalemin = 0.1f, float autoscalemax = 3f)
        {
            var vert = new GLPLVertexScaleLookat(rotate, rotateelevation, commontransformuniform, false, false, autoscale, autoscalemin, autoscalemax);
            var tcs  = new GLPLTesselationControl(tesselation);

            tes = new GLPLTesselationEvaluateSinewave(amplitude, repeats);
            var frag = new GLPLFragmentShaderTexture2DDiscard();

            AddVertexTCSTESGeoFragment(vert, tcs, tes, null, frag);
        }
Example #3
0
        public void Start(GLItemsList items, GLRenderProgramSortedList rObjects, float bookmarksize, GLStorageBlock findbufferresults, bool depthtest)
        {
            var vert = new GLPLVertexScaleLookat(rotatetoviewer: dorotate, rotateelevation: doelevation, texcoords: true, generateworldpos: true,
                                                 autoscale: 30, autoscalemin: 1f, autoscalemax: 30f);            // above autoscale, 1f

            const int texbindingpoint = 1;
            var       frag            = new GLPLFragmentShaderTexture(texbindingpoint); // binding - simple texturer based on vs model coords

            objectshader = new GLShaderPipeline(vert, null, null, null, frag);
            items.Add(objectshader);

            var objtex = items.NewTexture2D("Bookmarktex", BaseUtils.Icons.IconSet.GetBitmap("GalMap.Bookmark"), OpenTK.Graphics.OpenGL4.SizedInternalFormat.Rgba8);

            objectshader.StartAction += (s, m) =>
            {
                objtex.Bind(texbindingpoint);   // bind tex array to, matching above
            };

            bookmarkposbuf = items.NewBuffer();         // where we hold the vertexes for the suns, used by renderer and by finder

            GLRenderState rt = GLRenderState.Tri();

            rt.DepthTest = depthtest;

            // 0 is model pos, 1 is world pos by a buffer, 2 is tex co-ords
            ridisplay = GLRenderableItem.CreateVector4Vector4Vector2(items, OpenTK.Graphics.OpenGL4.PrimitiveType.TriangleStrip, rt,
                                                                     GLShapeObjectFactory.CreateQuadTriStrip(bookmarksize, bookmarksize), // quad2 4 vertexts as the model positions
                                                                     bookmarkposbuf, 0,                                                   // world positions come from here - not filled as yet
                                                                     GLShapeObjectFactory.TexTriStripQuad,
                                                                     ic: 0, seconddivisor: 1);

            rObjects.Add(objectshader, "bookmarks", ridisplay);

            var geofind = new GLPLGeoShaderFindTriangles(findbufferresults, 16);//, forwardfacing:false);

            findshader = items.NewShaderPipeline(null, vert, null, null, geofind, null, null, null);

            // hook to modelworldbuffer, at modelpos and worldpos.  UpdateEnables will fill in instance count
            rifind = GLRenderableItem.CreateVector4Vector4Vector2(items, OpenTK.Graphics.OpenGL4.PrimitiveType.TriangleStrip, rt,
                                                                  GLShapeObjectFactory.CreateQuadTriStrip(bookmarksize, bookmarksize),   // quad2 4 vertexts as the model positions
                                                                  bookmarkposbuf, 0,
                                                                  GLShapeObjectFactory.TexTriStripQuad,
                                                                  ic: 0, seconddivisor: 1);
        }
Example #4
0
        public void CreateObjects(GLItemsList items, GLRenderProgramSortedList rObjects, GalacticMapping galmap, GLStorageBlock findbufferresults, bool depthtest)
        {
            this.galmap = galmap;

            // first gets the images and make a 2d array texture for them

            Bitmap[] images = galmap.RenderableMapTypes.Select(x => x.Image as Bitmap).ToArray();
            // 256 is defined normal size
            var        objtex   = new GLTexture2DArray(images, bmpmipmaplevels: 1, wantedmipmaplevels: 3, texturesize: new Size(256, 256), internalformat: OpenTK.Graphics.OpenGL4.SizedInternalFormat.Rgba8, alignment: ContentAlignment.BottomCenter);
            IGLTexture texarray = items.Add(objtex, "GalObjTex");

            // now build the shaders

            const int texbindingpoint = 1;
            var       vert            = new GLPLVertexScaleLookat(rotatetoviewer: dorotate, rotateelevation: doelevation, // a look at vertex shader
                                                                  autoscale: 500, autoscalemin: 1f, autoscalemax: 20f);   // below 500, 1f, above 500, scale up to 20x
            var tcs = new GLPLTesselationControl(40f);

            tes = new GLPLTesselationEvaluateSinewave(1f, 2f);                  // this uses the world position from the vertex scaler to position the image, w controls image + animation (b16)
            var frag = new GLPLFragmentShaderTexture2DDiscard(texbindingpoint); // binding - takes image pos from tes. imagepos < 0 means discard

            objectshader = new GLShaderPipeline(vert, tcs, tes, null, frag);
            items.Add(objectshader);

            objectshader.StartAction += (s, m) =>
            {
                texarray.Bind(texbindingpoint);   // bind tex array to, matching above
            };

            // now the RenderControl for the objects

            GLRenderState rt = GLRenderState.Patches(4);

            rt.DepthTest = depthtest;

            // create a quad and all entries of the renderable map objects, zero at this point, with a zero instance count. UpdateEnables will fill it in later
            // but we need to give it the maximum buffer length at this point

            const float objsize = 10.0f;        // size of object on screen

            ridisplay = GLRenderableItem.CreateVector4Vector4(items, OpenTK.Graphics.OpenGL4.PrimitiveType.Patches, rt,
                                                              GLShapeObjectFactory.CreateQuadTriStrip(objsize, objsize), // quad2 4 vertexts
                                                              new Vector4[galmap.RenderableMapObjects.Length],           // world positions
                                                              ic: 0, seconddivisor: 1);

            modelworldbuffer = items.LastBuffer();
            int modelpos = modelworldbuffer.Positions[0];

            worldpos = modelworldbuffer.Positions[1];

            rObjects.Add(objectshader, "galmapobj", ridisplay);

            // add a find shader to look them up

            var geofind = new GLPLGeoShaderFindTriangles(findbufferresults, 16);

            findshader = items.NewShaderPipeline(null, vert, tcs, tes, geofind, null, null, null);


            // hook to modelworldbuffer, at modelpos and worldpos.  UpdateEnables will fill in instance count
            rifind = GLRenderableItem.CreateVector4Vector4(items, OpenTK.Graphics.OpenGL4.PrimitiveType.Patches, GLRenderState.Patches(4), modelworldbuffer, modelpos, ridisplay.DrawCount,
                                                           modelworldbuffer, worldpos, null, ic: 0, seconddivisor: 1);

            GLStatics.Check();

            // Text renderer for the labels

            textrenderer = new GLBitmaps("bm-galmapobjects", rObjects, new Size(128, 40), depthtest: depthtest, cullface: false, textureformat: OpenTK.Graphics.OpenGL4.SizedInternalFormat.Rgba8);
            items.Add(textrenderer);

            // now make the text up for all the objects above

            using (Font fnt = new Font("Arial", 8.5F))
            {
                using (StringFormat fmt = new StringFormat())
                {
                    fmt.Alignment = StringAlignment.Center;

                    var renderablegalmapobjects = galmap.RenderableMapObjects; // list of enabled entries

                    List <Vector3> posset = new List <Vector3>();

                    float offscale = objsize * (0.5f + (float)textrenderer.BitmapSize.Height / (float)textrenderer.BitmapSize.Width / 2);       // this is the nominal centre of the text bitmap, offset in Y to the object

                    for (int i = 0; i < renderablegalmapobjects.Length; i++)
                    {
                        var   o      = renderablegalmapobjects[i];
                        float offset = -offscale;

                        for (int j = 0; j < i; j++)     // look up previous ones and see if we labeled it before
                        {
                            var d1   = new Vector3(o.points[0].X, o.points[0].Y + offset, o.points[0].Z);
                            var d2   = posset[j];   // where it was placed.
                            var diff = d1 - d2;

                            if (diff.Length < offscale) // close
                            {
                                if (offset > 0)         // if offset is positive, flip below and increase again
                                {
                                    offset = -offset - offscale;
                                }
                                else
                                {
                                    offset *= -1;       // flip over top
                                }
                                // System.Diagnostics.Debug.WriteLine($"close {renderablegalmapobjects[i].name} {d1} to {renderablegalmapobjects[j].name} {d2} {diff} select {offset}");
                            }
                        }

                        Vector3 pos = new Vector3(o.points[0].X, o.points[0].Y + offset, o.points[0].Z);
                        posset.Add(pos);
                        //System.Diagnostics.Debug.WriteLine($"{renderablegalmapobjects[i].name} at {pos} {offset}");

                        textrenderer.Add(o.id, o.name, fnt,
                                         Color.White, Color.FromArgb(0, 255, 0, 255),
                                         pos,
                                         new Vector3(objsize, 0, 0), new Vector3(0, 0, 0), textformat: fmt, rotatetoviewer: dorotate, rotateelevation: doelevation,
                                         alphafadescalar: -100, alphafadepos: 500); // fade in, alpha = 0 at >500, 1 at 400
                    }
                }
            }

            UpdateEnables();      // fill in worldpos's and update instance count, taking into
        }