Exemplo n.º 1
0
        public void Draw(IRenderState renderState, ITransformation camera, Dictionary <Enums.EntityType, int> instanceCounts, Dictionary <Enums.EntityType, ITexture2D> textures, Dictionary <Enums.EntityType, ITexture2D> normalMaps, Dictionary <Enums.EntityType, ITexture2D> heightMaps, Dictionary <Enums.EntityType, Vector4> intensityMap, List <Enums.EntityType> disableBackFaceCulling, float time)
        {
            _deferredSurface.Activate();
            renderState.Set(new DepthTest(true));
            GL.ClearColor(System.Drawing.Color.FromArgb(0, 0, 0, 0));
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            GL.ClearBuffer(ClearBuffer.Color, 2, new float[] { 1000 });
            GL.ClearBuffer(ClearBuffer.Color, 4, new float[] { 0, 0, 0, 0 });
            GL.DrawBuffers(5, new[] { DrawBuffersEnum.ColorAttachment0, DrawBuffersEnum.ColorAttachment1, DrawBuffersEnum.ColorAttachment2, DrawBuffersEnum.ColorAttachment3, DrawBuffersEnum.ColorAttachment4 });

            _deferredProgram.Activate();

            _deferredProgram.Uniform("camera", camera);
            Matrix4x4.Invert(camera.Matrix, out var invert);
            _deferredProgram.Uniform("camPos", invert.Translation / invert.M44);

            //TODO: Can be accelerated with sorting the normal map and not normal map useage beforhand
            foreach (var type in _geometries.Keys)
            {
                if (instanceCounts[type] == 0 || type == Enums.EntityType.NvidiaParticle || type == Enums.EntityType.RadeonParticle)
                {
                    continue;
                }

                if (normalMaps.ContainsKey(type))
                {
                    _deferredProgram.ActivateTexture("normalMap", 1, normalMaps[type]);

                    if (heightMaps.ContainsKey(type))
                    {
                        _deferredProgram.ActivateTexture("heightMap", 2, heightMaps[type]);
                        _deferredProgram.Uniform("normalMapping", 0f);
                        _deferredProgram.Uniform("paralaxMapping", 1f);
                    }
                    else
                    {
                        _deferredProgram.ActivateTexture("heightMap", 2, _defaultMap);
                        _deferredProgram.Uniform("normalMapping", 1f);
                        _deferredProgram.Uniform("paralaxMapping", 0f);
                    }
                }
                else
                {
                    //_deferredProgram.ActivateTexture("normalMap", 1, _defaultMap);
                    //_deferredProgram.ActivateTexture("heightMap", 2, _defaultMap);
                    _deferredProgram.Uniform("normalMapping", 0f);
                    _deferredProgram.Uniform("paralaxMapping", 0f);
                }

                if (textures.ContainsKey(type))
                {
                    _deferredProgram.ActivateTexture("tex", 0, textures[type]);
                    _deferredProgram.Uniform("textured", 1f);
                }
                else
                {
                    switch (type)
                    {
                    case Enums.EntityType.Voronoi:
                        _deferredProgram.Uniform("materialColor", System.Drawing.Color.FromArgb(255, 41, 49, 51));
                        break;

                    case Enums.EntityType.Crystal1:
                        _deferredProgram.Uniform("materialColor", System.Drawing.Color.Pink);
                        break;

                    case Enums.EntityType.Crystal2:
                        _deferredProgram.Uniform("materialColor", System.Drawing.Color.Cyan);
                        break;

                    default:
                        _deferredProgram.Uniform("materialColor", System.Drawing.Color.LightGray);
                        break;
                    }

                    _deferredProgram.Uniform("textured", 0f);
                }

                renderState.Set(disableBackFaceCulling.Contains(type)
                    ? new BackFaceCulling(false)
                    : new BackFaceCulling(true));

                _deferredProgram.Uniform("intensity", intensityMap[type]);

                _geometries[type].Draw(instanceCounts[type]);

                if (textures.ContainsKey(type))
                {
                    _deferredProgram.DeactivateTexture(0, textures[type]);
                }

                if (normalMaps.ContainsKey(type))
                {
                    if (heightMaps.ContainsKey(type))
                    {
                        _deferredProgram.DeactivateTexture(2, heightMaps[type]);
                    }
                    _deferredProgram.DeactivateTexture(1, normalMaps[type]);
                }
                //else
                //{
                //    _deferredProgram.DeactivateTexture(2, _defaultMap);
                //    _deferredProgram.DeactivateTexture(1, _defaultMap);
                //}
            }

            renderState.Set(new DepthTest(false));
            renderState.Set(new BackFaceCulling(true));
            _deferredSurface.Deactivate();

            _projectilesGenerationNvidia.Draw(renderState, camera, instanceCounts[Enums.EntityType.NvidiaParticle], intensityMap[Enums.EntityType.NvidiaParticle], time);
            _addProjectilesNvidia.Draw(_deferredSurface.Textures[2], _projectilesGenerationNvidia.Depth, _deferredSurface.Textures[0], _projectilesGenerationNvidia.Color, _deferredSurface.Textures[1], _projectilesGenerationNvidia.Normal, _deferredSurface.Textures[3], _projectilesGenerationNvidia.Position, _deferredSurface.Textures[4], _projectilesGenerationNvidia.IntensityMap);

            _projectilesGenerationRadeon.Draw(renderState, camera, instanceCounts[Enums.EntityType.RadeonParticle], intensityMap[Enums.EntityType.RadeonParticle], time);
            _addProjectilesRadeon.Draw(_addProjectilesNvidia.Depth, _projectilesGenerationRadeon.Depth, _addProjectilesNvidia.Color, _projectilesGenerationRadeon.Color, _addProjectilesNvidia.Normal, _projectilesGenerationRadeon.Normal, _addProjectilesNvidia.Position, _projectilesGenerationRadeon.Position, _addProjectilesNvidia.IntensityMap, _projectilesGenerationRadeon.IntensityMap);

            //_tesselation.Draw(renderState, camera, time);
            //_addTesselation.Draw(_addProjectilesRadeon.Depth, _tesselation.Depth, _addProjectilesRadeon.Color, _tesselation.Color, _addProjectilesRadeon.Normal, _tesselation.Normal, _addProjectilesRadeon.Position, _tesselation.Position, _addProjectilesRadeon.IntensityMap, _tesselation.IntensityMap);
        }
        public void Draw(IRenderState renderState, ITransformation camera, int trianglesCount, Vector4 intensity, float time)
        {
            _outputSurface.Activate();

            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            _projectileGenerationProgram.Activate();

            Matrix4x4.Invert(camera.Matrix, out var invert);
            _projectileGenerationProgram.Uniform("camPos", invert.Translation / invert.M44);
            _projectileGenerationProgram.Uniform("camera", camera);
            _projectileGenerationProgram.Uniform("time", time);
            _projectileGenerationProgram.Uniform("normalMapping", 0f);
            _projectileGenerationProgram.Uniform("paralaxMapping", 0f);
            _projectileGenerationProgram.Uniform("intensity", intensity);

            switch (_triangleType)
            {
            case Enums.EntityType.NvidiaParticle:
                _projectileGenerationProgram.Uniform("materialColor", new Vector4(0, 100, 0, 5));
                break;

            case Enums.EntityType.RadeonParticle:
                _projectileGenerationProgram.Uniform("materialColor", new Vector4(100, 0, 0, 5));
                break;

            default:
                Console.WriteLine("No origin for triangle found");
                _projectileGenerationProgram.Uniform("materialColor", System.Drawing.Color.Blue);
                break;
            }

            _projectileGenerationProgram.Uniform("textured", 0f);

            GL.ClearColor(System.Drawing.Color.FromArgb(0, 0, 0, 0));
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            GL.ClearBuffer(ClearBuffer.Color, 2, new float[] { 1000 });
            GL.DrawBuffers(DrawBuffers.Length, DrawBuffers);

            _trianglesGeometry.Draw(trianglesCount);



            _projectileGenerationProgram.Deactivate();

            _outputSurface.Deactivate();


            _wireSurface.Activate();

            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            _projectileGenerationProgram.Activate();

            _projectileGenerationProgram.Uniform("camPos", invert.Translation / invert.M44);
            _projectileGenerationProgram.Uniform("camera", camera);
            _projectileGenerationProgram.Uniform("time", time);
            _projectileGenerationProgram.Uniform("normalMapping", 0f);
            _projectileGenerationProgram.Uniform("paralaxMapping", 0f);
            _projectileGenerationProgram.Uniform("intensity", intensity);

            switch (_triangleType)
            {
            case Enums.EntityType.NvidiaParticle:
                _projectileGenerationProgram.Uniform("materialColor", System.Drawing.Color.DarkGreen);
                break;

            case Enums.EntityType.RadeonParticle:
                _projectileGenerationProgram.Uniform("materialColor", System.Drawing.Color.DarkRed);
                break;

            default:
                Console.WriteLine("No origin for triangle found");
                _projectileGenerationProgram.Uniform("materialColor", System.Drawing.Color.DarkBlue);
                break;
            }

            _projectileGenerationProgram.Uniform("textured", 0f);

            GL.ClearColor(System.Drawing.Color.FromArgb(0, 0, 0, 0));
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            GL.ClearBuffer(ClearBuffer.Color, 2, new float[] { 1000 });
            GL.DrawBuffers(DrawBuffers.Length, DrawBuffers);

            GL.PolygonMode(MaterialFace.Front, PolygonMode.Line);

            _trianglesGeometry.Draw(trianglesCount);

            GL.PolygonMode(MaterialFace.Front, PolygonMode.Fill);



            _projectileGenerationProgram.Deactivate();

            _wireSurface.Deactivate();

            _add.Draw(_outputSurface.Textures[2], _wireSurface.Textures[2], _outputSurface.Textures[0], _wireSurface.Textures[0], _outputSurface.Textures[0], _wireSurface.Textures[0], _outputSurface.Textures[0], _wireSurface.Textures[0], _outputSurface.Textures[0], _wireSurface.Textures[0], -0.01f);
        }