Example #1
0
        public void Draw()
        {
            if (samplePositions.Count <= 0)
            {
                return;
            }
            HelperGeometryManager.GetInstance().AddLineStartEnd(startPosition, startPosition + startNormal, 1);
            //LineHelperManager.AddLineStartEnd(startPosition, startPosition + reflectVector * 10, 1, Color.AliceBlue, Color.Aqua);

            for (int index = 0; index < samplePositions.Count - 1; index++)
            {
                Vector3 v0 = samplePositions[index];
                Vector3 v1 = samplePositions[index + 1];
                HelperGeometryManager.GetInstance().AddLineStartEnd(v0, v1, 1, Color.Yellow, Color.Red);

                HelperGeometryManager.GetInstance().AddLineStartEnd(v0, sampleTests[index], 1, Color.Blue, Color.Violet);
            }

            //if(samplePositions.Count>0)
            //LineHelperManager.AddLineStartEnd(samplePositions[samplePositions.Count-1], sampleTests[samplePositions.Count - 1], 1, Color.Blue, Color.Violet);
        }
Example #2
0
        public void DrawBillboards(List <Decal> decals, List <PointLight> lights, List <DirectionalLight> dirLights, EnvironmentSample envSample, List <DebugEntity> debug, Matrix staticViewProjection, Matrix view, EditorLogic.EditorSendData sendData)
        {
            _graphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;
            _graphicsDevice.SetVertexBuffer(_billboardBuffer.VBuffer);
            _graphicsDevice.Indices = (_billboardBuffer.IBuffer);

            Shaders.BillboardEffect.CurrentTechnique = Shaders.BillboardEffectTechnique_Billboard;

            Shaders.BillboardEffectParameter_IdColor.SetValue(Color.Gray.ToVector3());

            //Decals

            Shaders.BillboardEffectParameter_Texture.SetValue(_assets.IconDecal);
            for (int index = 0; index < decals.Count; index++)
            {
                var decal = decals[index];
                DrawBillboard(decal, staticViewProjection, view, sendData);
            }

            //Lights

            Shaders.BillboardEffectParameter_Texture.SetValue(_assets.IconLight);
            for (int index = 0; index < lights.Count; index++)
            {
                var light = lights[index];
                DrawBillboard(light, staticViewProjection, view, sendData);
            }

            //DirectionalLights
            for (var index = 0; index < dirLights.Count; index++)
            {
                DirectionalLight light = dirLights[index];
                DrawBillboard(light, staticViewProjection, view, sendData);

                HelperGeometryManager.GetInstance()
                .AddLineStartDir(light.Position, light.Direction * 10, 1, Color.Black, light.Color);
                HelperGeometryManager.GetInstance()
                .AddLineStartDir(light.Position + Vector3.UnitX * 10, light.Direction * 10, 1, Color.Black,
                                 light.Color);
                HelperGeometryManager.GetInstance()
                .AddLineStartDir(light.Position - Vector3.UnitX * 10, light.Direction * 10, 1, Color.Black,
                                 light.Color);
                HelperGeometryManager.GetInstance()
                .AddLineStartDir(light.Position + Vector3.UnitY * 10, light.Direction * 10, 1, Color.Black,
                                 light.Color);
                HelperGeometryManager.GetInstance()
                .AddLineStartDir(light.Position - Vector3.UnitY * 10, light.Direction * 10, 1, Color.Black,
                                 light.Color);
                HelperGeometryManager.GetInstance()
                .AddLineStartDir(light.Position + Vector3.UnitZ * 10, light.Direction * 10, 1, Color.Black,
                                 light.Color);
                HelperGeometryManager.GetInstance()
                .AddLineStartDir(light.Position - Vector3.UnitZ * 10, light.Direction * 10, 1, Color.Black,
                                 light.Color);

                if (light.CastShadows)
                {
                    BoundingFrustum boundingFrustumShadow = new BoundingFrustum(light.LightViewProjection);

                    HelperGeometryManager.GetInstance().CreateBoundingBoxLines(boundingFrustumShadow);
                }
            }

            //EnvMap

            Shaders.BillboardEffectParameter_Texture.SetValue(_assets.IconEnvmap);

            DrawBillboard(envSample, staticViewProjection, view, sendData);

            //Dbg
            for (int index = 0; index < debug.Count; index++)
            {
                var dbgEntity = debug[index];
                DrawBillboard(dbgEntity, staticViewProjection, view, sendData);
            }
        }
Example #3
0
        public void Update(VolumeTextureEntity volumeTex, GraphicsDevice graphics)
        {
            HelperGeometryManager manager = HelperGeometryManager.GetInstance();

            //foreach (var point in points)
            //{
            //    manager.AddOctahedron(point, Vector4.One);
            //}

            //Show normals
            //foreach (var tri in triangles)
            //{
            //    manager.AddLineStartDir(tri.a, tri.n, 1, Color.Red, Color.Blue);
            //}


            if (!DebugScreen.ConsoleOpen && Input.WasKeyPressed(Keys.J) && generateTris != null && generateTris.IsCompleted)
            {
                setup        = true;
                generateTask = Task.Factory.StartNew(() =>
                {
                    volumeTex.NeedsUpdate = false;

                    const float stepssize = 2.5f;

                    int xsteps = (int)(volumeTex.SizeX * 2 / stepssize) + 1;
                    int ysteps = (int)(volumeTex.SizeY * 2 / stepssize) + 1;
                    int zsteps = (int)(volumeTex.SizeZ * 2 / stepssize) + 1;

                    texture?.Dispose();
                    texture = new Texture2D(graphics, xsteps * zsteps, ysteps, false, SurfaceFormat.Single);

                    float[] data = new float[xsteps * ysteps * zsteps];

                    Stopwatch stopwatch = Stopwatch.StartNew();

                    int numberOfThreads = GameSettings.sdf_threads;

                    if (numberOfThreads > 1)
                    {
                        Task[] threads = new Task[numberOfThreads - 1];

                        //Make local datas

                        float[][] dataArray = new float[numberOfThreads][];

                        for (int index = 0; index < threads.Length; index++)
                        {
                            int i = index;
                            dataArray[index + 1] = new float[xsteps * ysteps * zsteps];
                            threads[i]           = Task.Factory.StartNew(() =>
                            {
                                GenerateData(xsteps, ysteps, zsteps, stepssize, volumeTex, ref dataArray[i + 1], i + 1,
                                             numberOfThreads);
                            });
                        }

                        dataArray[0] = data;
                        GenerateData(xsteps, ysteps, zsteps, stepssize, volumeTex, ref dataArray[0], 0, numberOfThreads);

                        Task.WaitAll(threads);

                        for (var index2 = 0; index2 < threads.Length; index2++)
                        {
                            threads[index2].Dispose();
                        }

                        for (int i = 0; i < data.Length; i++)
                        {
                            data[i] = dataArray[i % numberOfThreads][i];
                        }
                    }
                    else
                    {
                        GenerateData(xsteps, ysteps, zsteps, stepssize, volumeTex, ref data, 0, numberOfThreads);
                    }


                    stopwatch.Stop();

                    Debug.Write("\nSDF generated in " + stopwatch.ElapsedMilliseconds + "ms with " + GameSettings.sdf_threads + " thread(s)");

                    string path = "sponza_sdf.sdff";

                    //Store
                    DataStream.SaveImageData(data, xsteps, ysteps, zsteps, path);

                    texture.SetData(data);

                    volumeTex.Resolution = new Vector3(xsteps, ysteps, zsteps);

                    //Stream stream = File.Create("volumetex");
                    //texture.SaveAsPng(stream, texture.Width, texture.Height);
                    //stream.Dispose();

                    GameStats.sdf_load = 0;
                });
            }

            if (setup && generateTask != null && generateTask.IsCompleted)
            {
                setup             = false;
                volumeTex.Texture = texture;
                generateTask.Dispose();
            }


            //foreach (var sample in points)
            //{
            //    manager.AddOctahedron(sample.p, Vector4.One * sample.sdf);
            //}
        }
Example #4
0
 public void Draw(GraphicsDevice graphics, Matrix viewProjection)
 {
     HelperGeometryManager.GetInstance()
     .Draw(graphics, viewProjection, _worldViewProjParam, _globalColorParam, _vertexColorPass,
           _globalColorPass);
 }