Пример #1
0
        internal Effect(Shader shader)
        {
            Shader = shader;
            ParameterData = new byte[Shader.ParametersSize];

            EffectParameter[] parameters = new EffectParameter[Shader.Parameters.Count];
            for (int i = 0; i < Shader.Parameters.Count; i++)
                parameters[i] = new EffectParameter(this, Shader.Parameters[i]);

            EffectPass[] passes = new EffectPass[Shader.Passes.Count];
            for (int i = 0; i < Shader.Passes.Count; i++)
                passes[i] = new EffectPass(this, Shader.Passes[i]);

            Parameters = new EffectParameterCollection(parameters);
            Passes = new EffectPassCollection(passes);

            foreach (EffectParameter parameter in Parameters)
            {
                if (parameter.Class == EffectParameterClass.Sampler)
                {
                    int count = parameter.Parameter.Count == 0 ? 1 : parameter.Parameter.Count;
                    int[] units = new int[count];

                    for (int i = 0; i < count; i++)
                        units[i] = parameter.Parameter.TextureUnit + i;

                    parameter.SetValue(count);
                }
            }
        }
Пример #2
0
        public void Draw(SpriteBatch sb)
        {
            EffectTechnique      effectTechnique      = basicEffect.Techniques[0];
            EffectPassCollection effectPassCollection = effectTechnique.Passes;

            foreach (EffectPass pass in effectPassCollection)
            {
                pass.Apply();
                graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleStrip,
                                                  vertexPositionColors, 0, 3);
            }

            var pixel = new Texture2D(graphicsDevice, 1, 1);

            pixel.SetData(new Color[] { Color.White });
            for (int i = 0; i < vertexPositionColors.Length; i++)
            {
                var vert  = vertexPositionColors[i];
                var color = Color.Green;
                if (i == minIndex)
                {
                    color = Color.Blue;
                }
                else if (i == maxIndex)
                {
                    color = Color.Red;
                }
                sb.Draw(pixel, new Rectangle((int)vert.Position.X, (int)vert.Position.Y, 10, 10), color * 0.40f);
            }

            //var pixel = new Texture2D(graphicsDevice, 1, 1);
            //pixel.SetData(new Color[] { Color.Red });
            //sb.Draw(pixel, grossBox, Color.Red);
        }
Пример #3
0
        public void DrawQuads(CCRawList <CCV3F_C4B_T2F_Quad> quads, int start, int n)
        {
            if (n == 0)
            {
                return;
            }

            CheckQuadsIndexBuffer(start + n);
            CheckQuadsVertexBuffer(start + n);

            quadsBuffer.UpdateBuffer(quads, start, n);

            graphicsDevice.SetVertexBuffer(quadsBuffer.VertexBuffer);
            graphicsDevice.Indices = quadsIndexBuffer.IndexBuffer;

            ApplyEffectParams();

            EffectPassCollection passes = currentEffect.CurrentTechnique.Passes;

            for (int i = 0; i < passes.Count; i++)
            {
                passes[i].Apply();
                graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, n * 4, start * 6, n * 2);
            }

            graphicsDevice.SetVertexBuffer(null);
            graphicsDevice.Indices = null;
        }
Пример #4
0
        private void RenderDrawGroup(_2DDrawGroup group)
        {
            var effect = this.Effect;

            effect.pixelTexture = group.Pixel;
            if (group.Depth != null)
            {
                effect.depthTexture = group.Depth;
            }
            if (group.Mask != null)
            {
                effect.maskTexture = group.Mask;
            }

            effect.SetTechnique(group.Technique);
            EffectPassCollection passes = effect.CurrentTechnique.Passes;

            EffectPass pass = passes[Math.Min(passes.Count - 1, WorldConfig.Current.DirPassOffset)];

            pass.Apply();
            if (group.VertBuf != null)
            {
                Device.SetVertexBuffer(group.VertBuf);
                Device.Indices = group.IndexBuf;
                Device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, group.Primitives);
            }
            else
            {
                Device.DrawUserIndexedPrimitives <_2DSpriteVertex>(
                    PrimitiveType.TriangleList, group.Vertices, 0, group.Vertices.Length,
                    group.Indices, 0, group.Indices.Length / 3);
            }
        }
Пример #5
0
        private void Render()
        {
            if (this.vertexCount > 0)
            {
                if (this.declaration == null || this.declaration.IsDisposed)
                {
                    this.declaration = new VertexDeclaration(device, VertexPositionTexture.VertexElements);
                }

                device.VertexDeclaration = this.declaration;

                Effect effect = this.Effect;
                //  set the only parameter this effect takes.
                effect.Parameters["viewProjection"].SetValue(this.View * this.Projection);

                EffectTechnique technique = effect.CurrentTechnique;
                effect.Begin();
                EffectPassCollection passes = technique.Passes;
                for (int i = 0; i < passes.Count; i++)
                {
                    EffectPass pass = passes[i];
                    pass.Begin();

                    device.DrawUserIndexedPrimitives <VertexPositionTexture>(
                        PrimitiveType.TriangleList, this.vertices, 0, this.vertexCount,
                        this.indices, 0, this.indexCount / 3);

                    pass.End();
                }
                effect.End();

                this.vertexCount = 0;
                this.indexCount  = 0;
            }
        }
Пример #6
0
        private void RenderDrawGroup(_2DDrawGroup group)
        {
            var effect = this.Effect;

            effect.Parameters["pixelTexture"].SetValue(group.Pixel);
            if (group.Depth != null)
            {
                effect.Parameters["depthTexture"].SetValue(group.Depth);
            }
            if (group.Mask != null)
            {
                effect.Parameters["maskTexture"].SetValue(group.Mask);
            }

            effect.CurrentTechnique = group.Technique;
            EffectPassCollection passes = group.Technique.Passes;

            for (int i = 0; i < passes.Count; i++)
            {
                EffectPass pass = passes[i];
                pass.Apply();
                if (group.VertBuf != null)
                {
                    Device.SetVertexBuffer(group.VertBuf);
                    Device.Indices = group.IndexBuf;
                    Device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, group.Primitives);
                }
                else
                {
                    Device.DrawUserIndexedPrimitives <_2DSpriteVertex>(
                        PrimitiveType.TriangleList, group.Vertices, 0, group.Vertices.Length,
                        group.Indices, 0, group.Indices.Length / 3);
                }
            }
        }
Пример #7
0
        public static void DrawQuads(RawList <CCV3F_C4B_T2F_Quad> quads, int start, int n)
        {
            if (n == 0)
            {
                return;
            }

            CheckQuadsIndexBuffer(start + n);
            CheckQuadsVertexBuffer(start + n);

            SetQuadsToBuffer(m_quadsBuffer, quads, start, n);

            //DrawIndexedPrimitives(PrimitiveType.TriangleList, _vertices, 4 * start, 4 * n, _quadIndices, start * 6, 2 * n);

            graphicsDevice.SetVertexBuffer(m_quadsBuffer);
            graphicsDevice.Indices = m_quadsIndexBuffer;

            ApplyEffectParams();

            EffectPassCollection passes = m_currentEffect.CurrentTechnique.Passes;

            for (int i = 0; i < passes.Count; i++)
            {
                passes[i].Apply();
                graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, m_vertices.Length, start * 6, n * 2);
            }

            graphicsDevice.SetVertexBuffer(null);
            graphicsDevice.Indices = null;

            DrawCount++;
        }
Пример #8
0
        public void DrawImmediate(_2DStandaloneSprite sprite)
        {
            var effect = this.Effect;

            if (!FSOEnvironment.DirectX)
            {
                Device.Indices = null; //monogame why
                Device.Indices = SpriteIndices;
            }
            PPXDepthEngine.RenderPPXDepth(effect, false, (depth) =>
            {
                effect.pixelTexture = sprite.Pixel;
                if (sprite.Depth != null)
                {
                    effect.depthTexture = sprite.Depth;
                }
                if (sprite.Mask != null)
                {
                    effect.maskTexture = sprite.Mask;
                }

                EffectPassCollection passes = effect.CurrentTechnique.Passes;

                EffectPass pass = passes[Math.Min(passes.Count - 1, WorldConfig.Current.DirPassOffset)];
                pass.Apply();
                if (sprite.GPUVertices != null)
                {
                    Device.SetVertexBuffer(sprite.GPUVertices);
                    Device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 2);
                }
            });
        }
 internal EffectTechnique(
     Effect effect, string name, EffectPassCollection passes, EffectAnnotationCollection annotations)
 {
     Name        = name;
     Passes      = passes;
     Annotations = annotations;
 }
Пример #10
0
        public static void DrawQuadsBuffer(VertexBuffer vertexBuffer, int start, int n)
        {
            if (n == 0)
            {
                return;
            }

            CheckQuadsIndexBuffer(start + n);

            graphicsDevice.Indices = m_quadsIndexBuffer;
            graphicsDevice.SetVertexBuffer(vertexBuffer);

            ApplyEffectParams();

            EffectPassCollection passes = m_currentEffect.CurrentTechnique.Passes;

            for (int i = 0; i < passes.Count; i++)
            {
                passes[i].Apply();
                graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertexBuffer.VertexCount, start * 6, n * 2);
            }

            graphicsDevice.SetVertexBuffer(null);
            graphicsDevice.Indices = null;

            DrawCount++;
        }
Пример #11
0
        internal void DrawQuadsBuffer <T>(CCVertexBuffer <T> vertexBuffer, int start, int n) where T : struct, IVertexType
        {
            if (n == 0)
            {
                return;
            }

            CheckQuadsIndexBuffer(start + n);

            graphicsDevice.Indices = quadsIndexBuffer.IndexBuffer;
            graphicsDevice.SetVertexBuffer(vertexBuffer.VertexBuffer);

            ApplyEffectParams();

            EffectPassCollection passes = currentEffect.CurrentTechnique.Passes;

            for (int i = 0; i < passes.Count; i++)
            {
                passes[i].Apply();
                graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertexBuffer.VertexBuffer.VertexCount, start * 6, n * 2);
            }

            graphicsDevice.SetVertexBuffer(null);
            graphicsDevice.Indices = null;
        }
Пример #12
0
        public void DrawShadows(Tuple <GradVertex[], int[]> geom, int pass, LightData light)
        {
            var pointLight = light.LightPos;
            var effect     = this.GradEffect;

            effect.Parameters["Projection"].SetValue(Projection);
            GD.ScissorRectangle = DrawRect;
            GD.Clear(Color.Black);

            /*GD.SetRenderTarget(ShadowTarg);
             * if (!cleared)
             * {
             *  cleared = true;
             *  //GD.RasterizerState = new RasterizerState() { ScissorTestEnable = true, CullMode = CullMode.None };
             *  //GD.ScissorRectangle = new Rectangle((int)pointLight.X / 2 - 100, (int)pointLight.Y / 2 - 100, 200, 200);
             *  GD.Clear(Color.Black);
             * }*/
            effect.CurrentTechnique = effect.Techniques[0];
            EffectPassCollection passes = effect.Techniques[0].Passes;

            passes[pass].Apply();

            if (geom.Item1.Length > 0)
            {
                GD.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, geom.Item1, 0, geom.Item1.Length, geom.Item2, 0, geom.Item2.Length / 3);
            }
            //GD.SetRenderTarget(null);
        }
Пример #13
0
        public override void SetState(Material previousMaterial)
        {
            shader.CurrentTechnique = shader.Techniques[techniqueIndex];
            shaderPasses            = shader.CurrentTechnique.Passes;
            shader.ImageTexture     = waterTexture;
            shader.ReferenceAlpha   = 10;

            graphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;
            graphicsDevice.BlendState       = BlendState.NonPremultiplied;
        }
Пример #14
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime game_time)
        {
            //System.Console.WriteLine( "draw " + game_time.ElapsedGameTime.ToString() );

            GraphicsDevice.Clear(Color.CornflowerBlue);

            RasterizerState rasterizerState = new RasterizerState();

            rasterizerState.CullMode       = CullMode.None;
            GraphicsDevice.RasterizerState = rasterizerState;

            // simple draw only clients
            mMouse.RenderWorld(game_time);
            mMouse.RenderScreen(game_time);

            // simple draw world
            mBasicEffect_World.VertexColorEnabled = true;
            EffectTechnique      effectTechnique      = mBasicEffect_World.Techniques[0];
            EffectPassCollection effectPassCollection = effectTechnique.Passes;


            foreach (EffectPass pass in effectPassCollection)
            {
                // hopefully only one pass
                pass.Apply();

                // actually render simple draw stuff.  possible layers needed.
                mSimpleDraw_World.DrawAllPrimitives();

                // render clients who do their own rendering.  they should probably have pre-renders like simple draw, especially if there is more than one pass.
            }


            // simple draw screen
            mBasicEffect_Screen.VertexColorEnabled = true;
            effectTechnique      = mBasicEffect_Screen.Techniques[0];
            effectPassCollection = effectTechnique.Passes;

            foreach (EffectPass pass in effectPassCollection)
            {
                // hopefully only one pass
                pass.Apply();

                // actually render simple draw stuff.  possible layers needed.
                mSimpleDraw_Screen.DrawAllPrimitives();

                // render clients who do their own rendering.  they should probably have pre-renders like simple draw, especially if there is more than one pass.
            }


            base.Draw(game_time);
        }
Пример #15
0
        internal void DrawRawBuffer <T>(T[] vertexBuffer, int vStart, int vCount, short[] indexBuffer, int iStart, int iCount)
            where T : struct, IVertexType
        {
            ApplyEffectParams();

            EffectPassCollection passes = currentEffect.CurrentTechnique.Passes;

            for (int i = 0; i < passes.Count; i++)
            {
                passes[i].Apply();
                graphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.TriangleList,
                                                         vertexBuffer, vStart, vCount,
                                                         indexBuffer, iStart, iCount);
            }
        }
Пример #16
0
        internal void DrawPrimitives <T>(PrimitiveType type, T[] vertices, int offset, int count) where T : struct, IVertexType
        {
            if (count <= 0)
            {
                return;
            }

            ApplyEffectParams();

            EffectPassCollection passes = currentEffect.CurrentTechnique.Passes;

            for (int i = 0; i < passes.Count; i++)
            {
                passes[i].Apply();
                graphicsDevice.DrawUserPrimitives(type, vertices, offset, count);
            }
        }
Пример #17
0
        public void DrawWallShadows(List <Vector2[]> walls, LightData pointLight)
        {
            if (pointLight.LightType == LightType.OUTDOORS && WallComp != null)
            {
                CreateOutsideIfMissing();
                LightEffect.Parameters["shadowMap"].SetValue(OutsideShadowTarg);

                if (OutShadowFloor == pointLight.Level)
                {
                    return;
                }
                OutShadowFloor = pointLight.Level;
                GD.SetRenderTarget(OutsideShadowTarg);
                var rect = new Rectangle(DrawRect.X * 2, DrawRect.Y * 2, DrawRect.Width * 2, DrawRect.Height * 2);
                GD.ScissorRectangle = rect;
                GD.Clear(Color.Black);
                var effect = this.GradEffect;

                effect.Parameters["Projection"].SetValue(Projection);

                var mat = GetSunlightMat(pointLight);

                GD.BlendState = MaxBlendRed;

                WallComp.DrawLMap(GD, pointLight, Projection, mat);
                Blueprint.Terrain.DrawLMap(GD, pointLight, Projection, mat);
                Blueprint.RoofComp.DrawLMap(GD, pointLight, Projection, mat);

                effect.CurrentTechnique = effect.Techniques[0];
                EffectPassCollection passes = effect.Techniques[0].Passes;
                passes[2].Apply();

                if (WorldConfig.Current.UltraLighting)
                {
                    Draw3DObjShadows(pointLight, false);
                }
            }
            else
            {
                GD.SetRenderTarget(ShadowTarg);
                var geom = ShadowGeometry.GenerateWallShadows(walls, pointLight);
                GD.BlendState = AddBlendRed;
                DrawShadows(geom, (pointLight.LightType == LightType.OUTDOORS) ? 2 : 0, pointLight);
            }
        }
Пример #18
0
        //* ────________________________________*
        //* methods ───────────────────────────────-*

        //* -----------------------------------------------------------------------*
        /// <summary>1フレーム分の描画処理を実行します。</summary>
        ///
        /// <param name="entity">この状態を適用されているオブジェクト。</param>
        /// <param name="privateMembers">
        /// オブジェクトと状態クラスのみがアクセス可能なフィールド。
        /// </param>
        /// <param name="gameTime">前フレームが開始してからの経過時間。</param>
        public override void draw(CEntity entity, CCursor privateMembers, GameTime gameTime)
        {
            Matrix world = privateMembers.world;

            effect.Parameters["World"].SetValue(world);
            effect.Begin();
            EffectPassCollection passes = effect.CurrentTechnique.Passes;

            for (int i = passes.Count; --i >= 0;)
            {
                EffectPass pass = passes[i];
                pass.Begin();
                device.DrawUserPrimitives <VertexPositionNormalTexture>(
                    PrimitiveType.TriangleStrip, vertex, 0, 2);
                pass.End();
            }
            effect.End();
        }
Пример #19
0
        public void DrawShadows(Tuple <GradVertex[], int[]> geom, int pass, LightData light)
        {
            var pointLight = light.LightPos;
            var effect     = this.GradEffect;

            effect.Projection   = Projection;
            GD.ScissorRectangle = DrawRect;
            GD.Clear(Color.Black);

            effect.CurrentTechnique = effect.Techniques[0];
            EffectPassCollection passes = effect.Techniques[0].Passes;

            passes[pass].Apply();

            if (geom.Item1.Length > 0)
            {
                GD.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, geom.Item1, 0, geom.Item1.Length, geom.Item2, 0, geom.Item2.Length / 3);
            }
        }
Пример #20
0
        internal void DrawIndexedPrimitives <T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int numVertices, short[] indexData,
                                                int indexOffset, int primitiveCount) where T : struct, IVertexType
        {
            if (primitiveCount <= 0)
            {
                return;
            }

            ApplyEffectParams();

            EffectPassCollection passes = currentEffect.CurrentTechnique.Passes;

            for (int i = 0; i < passes.Count; i++)
            {
                passes[i].Apply();
                graphicsDevice.DrawUserIndexedPrimitives(primitiveType, vertexData, vertexOffset, numVertices, indexData, indexOffset,
                                                         primitiveCount);
            }
        }
Пример #21
0
        internal void DrawQuads(CCRawList <CCV3F_C4B_T2F_Quad> quads, int start, int n)
        {
            if (n == 0)
            {
                return;
            }

            ApplyEffectParams();

            // We unbox our quads into our vertex array that is passed onto MonoGame
            // Our vertex array is of a fixed size, so split up into multiple draw calls if required
            while (n > 0)
            {
                int nIteration = Math.Min(n, MaxNumQuads);

                int i4 = 0;
                for (int i = start, N = start + nIteration; i < N; i++)
                {
                    quadsVertices[i4 + 0] = quads[i].TopLeft;
                    quadsVertices[i4 + 1] = quads[i].BottomLeft;
                    quadsVertices[i4 + 2] = quads[i].TopRight;
                    quadsVertices[i4 + 3] = quads[i].BottomRight;

                    i4 += 4;
                }

                EffectPassCollection passes = currentEffect.CurrentTechnique.Passes;
                for (int i = 0; i < passes.Count; i++)
                {
                    try {
                        passes [i].Apply();
                        graphicsDevice.DrawUserIndexedPrimitives(
                            PrimitiveType.TriangleList, quadsVertices, 0, nIteration * NumOfVerticesPerQuad, quadsIndices, 0, nIteration * 2);
                    }
                    catch (Exception e) {
                        // don't crash
                    }
                }

                n     -= nIteration;
                start += nIteration;
            }
        }
Пример #22
0
        public void MultiplyOutdoors(Rectangle bigBounds)
        {
            DrawRect = bigBounds;
            DrawRect.Offset(ScissorBase);
            for (int i = 0; i < (LightMapDirection != null ? 4 : 1); i++)
            {
                GD.SetRenderTarget((i == 0)?LightMap:LightMapDirection);
                if (i == 1)
                {
                    DrawRect = ScaleDirectionScissor(DrawRect);
                }
                GD.ScissorRectangle = DrawRect;

                var effect = LightEffect;
                var tech   = (i == 1) ? 1 : 0;
                effect.CurrentTechnique = effect.Techniques[tech];
                EffectPassCollection passes = effect.Techniques[tech].Passes;
                var l = Blueprint.OutsideColor.ToVector4();
                l.W = (l.X + l.Y + l.Z) / 3;
                if (i >= 2)
                {
                    effect.LightColor = new Vector4(new Vector3(Math.Abs(SunVector.Z), Math.Abs(SunVector.Y), Math.Abs(SunVector.X)) * l.W * ((i == 3)?-1:1), l.W);
                }
                else
                {
                    effect.LightColor = l;
                }
                GD.BlendState = MulBlend;
                passes[2].Apply();

                if (i == 2)
                {
                    GD.BlendState = MinBlend;
                }
                else if (i == 3)
                {
                    GD.BlendState = MaxBlend;
                }

                GD.SetVertexBuffer(LightBuf);
                GD.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
            }
        }
Пример #23
0
        internal void DrawBuffer <T, T2>(CCVertexBuffer <T> vertexBuffer, CCIndexBuffer <T2> indexBuffer, int start, int count)
            where T : struct, IVertexType
            where T2 : struct
        {
            graphicsDevice.Indices = indexBuffer.IndexBuffer;
            graphicsDevice.SetVertexBuffer(vertexBuffer.VertexBuffer);

            ApplyEffectParams();

            EffectPassCollection passes = currentEffect.CurrentTechnique.Passes;

            for (int i = 0; i < passes.Count; i++)
            {
                passes[i].Apply();
                graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertexBuffer.VertexBuffer.VertexCount, start, count);
            }

            graphicsDevice.SetVertexBuffer(null);
            graphicsDevice.Indices = null;
        }
Пример #24
0
        public static void DrawBuffer(VertexBuffer vertexBuffer, IndexBuffer indexBuffer, int start, int count)
        {
            graphicsDevice.Indices = indexBuffer;
            graphicsDevice.SetVertexBuffer(vertexBuffer);

            ApplyEffectParams();

            EffectPassCollection passes = m_currentEffect.CurrentTechnique.Passes;

            for (int i = 0; i < passes.Count; i++)
            {
                passes[i].Apply();
                graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertexBuffer.VertexCount, start, count);
            }

            graphicsDevice.SetVertexBuffer(null);
            graphicsDevice.Indices = null;

            DrawCount++;
        }
Пример #25
0
        public void MultiplyOutdoors(Rectangle bigBounds)
        {
            GD.SetRenderTarget(LightMap);
            DrawRect = bigBounds;
            DrawRect.Offset(ScissorBase);
            GD.ScissorRectangle = DrawRect;

            var effect = LightEffect;

            effect.CurrentTechnique = effect.Techniques[0];
            EffectPassCollection passes = effect.Techniques[0].Passes;
            var l = Blueprint.OutsideColor.ToVector4();

            l.W = (l.X + l.Y + l.Z) / 3;
            effect.Parameters["LightColor"].SetValue(l);
            GD.BlendState = MulBlend;
            passes[2].Apply();

            GD.SetVertexBuffer(LightBuf);
            GD.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
        }
Пример #26
0
 internal EffectTechnique(Effect effect, string name)
 {
     Name = name;
     this.effect = effect;
     Passes = new EffectPassCollection();
 }
Пример #27
0
        public void Draw3DObjShadows(LightData pointLight, bool clear)
        {
            var effect = WorldContent.RCObject;

            //we doubled the shadow resolution, so this is different.
            var dr = DrawRect;

            GD.ScissorRectangle = new Rectangle(dr.X * 2, dr.Y * 2, dr.Width * 2, dr.Height * 2);
            GD.BlendState       = MaxBlendGreen;
            if (clear)
            {
                GD.Clear(Color.Black);
            }

            effect.SetTechnique(RCObjectTechniques.LMapDraw);
            EffectPassCollection passes = effect.Techniques[0].Passes;

            passes[0].Apply();

            var outside = pointLight.LightType == LightType.OUTDOORS;

            if (outside)
            {
                effect.ViewProjection = Matrix.CreateScale(1 / 3f, -1 / 9f, 1 / 3f) * Matrix.CreateRotationX((float)Math.PI / -2) * GetSunlightMat(pointLight) * Projection;
            }
            else
            {
                effect.ViewProjection = Matrix.CreateScale(1 / 3f, -1 / 3f, 1 / 3f) * Matrix.CreateRotationX((float)Math.PI / -2) * GetLightMat(pointLight);
            }

            var lp16 = pointLight.LightPos / 16f;
            var li16 = pointLight.LightSize / 16f;

            List <ObjectComponent> objs;

            if (outside)
            {
                objs = new List <ObjectComponent>();
                for (int i = 0; i < Blueprint.Rooms.Count; i++)
                {
                    var room = Blueprint.Rooms[i];
                    if (room.IsOutside && room.Base == i)
                    {
                        //add components from this room to obj list
                        objs.AddRange(Blueprint.Light[i].Components);
                    }
                }
            }
            else
            {
                objs = Blueprint.Light[pointLight.Room].Components;
            }

            foreach (var obj in objs)
            {
                if ((outside && obj.Level > pointLight.Level) || (Math.Abs(obj.Position.X - lp16.X) + Math.Abs(obj.Position.Y - lp16.Y) < li16))
                {
                    obj.DrawLMap(GD, pointLight.Level);
                }
            }
        }
Пример #28
0
        public void DrawRoom(Room room, RoomLighting lighting, bool clear)
        {
            var size = Blueprint.Width - borderSize;

            LightEffect.Parameters["TargetRoom"].SetValue((float)room.RoomID);
            var bigBounds = new Rectangle(lighting.Bounds.X * resPerTile, lighting.Bounds.Y * resPerTile, lighting.Bounds.Width * resPerTile, lighting.Bounds.Height * resPerTile);

            bigBounds          = Rectangle.Intersect(bigBounds, new Rectangle(0, 0, size * resPerTile, size * resPerTile));
            GD.RasterizerState = new RasterizerState()
            {
                ScissorTestEnable = true, CullMode = CullMode.None
            };
            if (clear)
            {
                GD.SetRenderTarget(LightMap);
                DrawRect = bigBounds;
                DrawRect.Offset(ScissorBase);
                GD.ScissorRectangle = DrawRect;

                var effect = LightEffect;
                effect.CurrentTechnique = effect.Techniques[0];
                EffectPassCollection passes = effect.Techniques[0].Passes;
                effect.Parameters["LightColor"].SetValue(Vector4.One * (Blueprint.MinOut.A / 255f));
                GD.BlendState = BlendState.Opaque;
                passes[2].Apply();

                GD.SetVertexBuffer(LightBuf);
                GD.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
            }
            var outFactor = 1 - (Blueprint.MinOut.A / 255f);

            var factor = 16f / resPerTile;


            if (room.IsOutside || WallComp != null)
            {
                var res = (Blueprint.Width - borderSize) * resPerTile;
                if (!room.IsOutside)
                {
                    DrawRect = new Rectangle(0, 0, res, res);
                }
                else
                {
                    DrawRect = bigBounds;
                }
                if (OutdoorsLight == null)
                {
                    BuildOutdoorsLight(Blueprint.OutsideTime);
                }
                var light = OutdoorsLight;
                //generate shadows
                light.Level = (sbyte)(room.Floor);
                DrawWallShadows(room.WallLines, light);
                if (room.IsOutside && !WorldConfig.Current.UltraLighting)
                {
                    DrawObjShadows(lighting.ObjectFootprints, light);
                }

                //draw the light onto the lightmap
                GD.SetRenderTarget(LightMap);
                DrawRect.Offset(ScissorBase);
                GD.ScissorRectangle = DrawRect;
                LightEffect.Parameters["LightColor"].SetValue(Color.White.ToVector4() * outFactor);
                LightEffect.Parameters["ShadowPowers"].SetValue(new Vector2(0.75f, 0.6f) * light.ShadowMultiplier);

                LightEffect.Parameters["LightPosition"].SetValue(light.LightPos / (size * 16f)); //in position space (0,1)
                LightEffect.Parameters["LightSize"].SetValue(float.MaxValue);                    //in position space (0,1)
                LightEffect.Parameters["IsOutdoors"]?.SetValue(true);

                var effect = LightEffect;
                effect.CurrentTechnique = effect.Techniques[0];
                EffectPassCollection passes = effect.Techniques[0].Passes;
                passes[room.IsOutside ? ((WallComp == null) ? 1 : 4) : 3].Apply();

                GD.SetVertexBuffer(LightBuf);
                GD.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
                LightEffect.Parameters["shadowMap"].SetValue(ShadowTarg);
            }

            var order         = lighting.Lights.OrderBy(x => x.OutdoorsColor ? 0 : 1);
            var hasMulOutside = false;

            foreach (var light in order)
            {
                if (!light.OutdoorsColor && !hasMulOutside)
                {
                    MultiplyOutdoors(bigBounds);
                    hasMulOutside = true;
                }
                if (light.WindowRoom != -1)
                {
                    var wroom = Blueprint.Light[Blueprint.Rooms[light.WindowRoom].Base];
                    light.LightIntensity = wroom.AmbientLight / 150f;
                }
                if (light.LightIntensity < 0.2f)
                {
                    continue;
                }

                DrawRect = new Rectangle((int)(light.LightBounds.X / factor), (int)(light.LightBounds.Y / factor), (int)(light.LightBounds.Width / factor), (int)(light.LightBounds.Height / factor));
                DrawRect = Rectangle.Intersect(DrawRect, bigBounds);

                //generate shadows

                DrawWallShadows(room.WallLines, light);
                DrawObjShadows(lighting.ObjectFootprints, light);

                //draw the light onto the lightmap
                GD.SetRenderTarget(LightMap);
                DrawRect.Offset(ScissorBase);
                GD.ScissorRectangle = DrawRect;
                LightEffect.Parameters["ShadowPowers"].SetValue(new Vector2(1f, 1f));

                LightEffect.Parameters["LightPosition"].SetValue(light.LightPos / (size * 16f)); //in position space (0,1)
                LightEffect.Parameters["LightSize"].SetValue(light.LightSize / (size * 16f));    //in position space (0,1)
                var l = light.LightColor.ToVector4();
                l.W = (l.X + l.Y + l.Z) / 3;
                if (light.OutdoorsColor)
                {
                    l *= outFactor;
                }
                else
                {
                    l *= 0.70f;
                }
                LightEffect.Parameters["LightColor"].SetValue(l);
                LightEffect.Parameters["IsOutdoors"]?.SetValue(light.OutdoorsColor);
                LightEffect.Parameters["LightIntensity"]?.SetValue(light.LightIntensity);

                var effect = LightEffect;
                effect.CurrentTechnique = effect.Techniques[0];
                EffectPassCollection passes = effect.Techniques[0].Passes;

                if (WorldConfig.Current.UltraLighting)
                {
                    LightEffect.Parameters["BlurMin"].SetValue((light.OutdoorsColor)?(1 / (75f * 9)):0);
                    LightEffect.Parameters["BlurMax"].SetValue((1 / (75f * 5)));
                    passes[5].Apply();
                }
                else
                {
                    passes[0].Apply();
                }

                GD.SetVertexBuffer(LightBuf);
                GD.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
            }
            if (!hasMulOutside)
            {
                MultiplyOutdoors(bigBounds);
            }
        }
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.LightGray);
            var elapsed = gameTime.ElapsedGameTime.Milliseconds;

            if (IsWorking && TotalTimeElapsed >= 1000 / Speed) //i iz doing animation
            {
                TotalTimeElapsed = 0;
                if (positions == null || positions.Count == StepCounter)
                {
                    PositionBegin = PositionEnd;
                    PositionEnd   = FileHelper.ReadNextLine(Brick.Resolution);

                    tmpPos = new Vector3(PositionEnd.X * Brick.Unit * Brick.Resolution, PositionEnd.Y * Brick.Unit * Brick.Resolution + (FileHelper.Diameter * Brick.Unit * Brick.Resolution / 2), PositionEnd.Z * Brick.Unit * Brick.Resolution);
                    vertexPositionColors[count] = new VertexPositionColor(tmpPos, Color.Red);
                    count++;

                    if (PositionEnd.X == -100 && PositionEnd.Y == -100 && PositionEnd.Z == -100)
                    {
                        PositionEnd = PositionBegin;
                        count--;
                    }
                    positions   = FileHelper.GetPositions(PositionBegin, PositionEnd, Brick.Resolution);
                    StepCounter = 0;
                }
                if (positions.Count != 0) //WOOOOT?
                {
                    Brick.MoveFrezStep(positions[StepCounter], FileHelper.Diameter, FileHelper.Frez, CriticalMillingDepth);
                    Cutter1.Position = positions[StepCounter] * Brick.Unit;
                    Cutter1.Diameter = FileHelper.Diameter * (Brick.Unit * Brick.Resolution);
                    Cutter1.Type     = FileHelper.Frez;
                    StepCounter++;
                }
            }

            /*if (FileHelper.Frez == FileHelper.FrezType.F)
             * {
             *  if (PositionBegin.Y != PositionEnd.Y)
             *  {
             *      var dialog = new MessageDialog("K-frez cannot move along Y axis");
             *      dialog.ShowAsync();
             *  }
             * }*/

            TotalTimeElapsed += elapsed;
            Brick.Draw(CameraArc, Effect);
            Cutter1.Draw(CameraArc, Effect);
            MillingLimit.Draw(Matrix.CreateTranslation(pos), CameraArc.View, CameraArc.Projection, Color.Red);

            EffectTechnique      effectTechnique      = Effect.Techniques[0];
            EffectPassCollection effectPassCollection = effectTechnique.Passes;

            foreach (EffectPass pass in effectPassCollection)
            {
                pass.Apply();
                if (showPath && count > 1)
                {
                    GraphicsDevice.DrawUserPrimitives(PrimitiveType.LineStrip, vertexPositionColors, 0, count - 1);
                }
            }

            base.Draw(gameTime);
        }
Пример #30
0
        public void DrawWallShadows(List <Vector2[]> walls, LightData pointLight)
        {
            if (pointLight.LightType == LightType.OUTDOORS && WallComp != null)
            {
                CreateOutsideIfMissing();
                LightEffect.shadowMap = OutsideShadowTarg;

                if (OutShadowFloor == pointLight.Level)
                {
                    return;
                }
                OutShadowFloor = pointLight.Level;
                GD.SetRenderTarget(OutsideShadowTarg);
                var rect = new Rectangle(DrawRect.X * 2, DrawRect.Y * 2, DrawRect.Width * 2, DrawRect.Height * 2);
                GD.ScissorRectangle = rect;
                GD.Clear(Color.Black);
                var effect = this.GradEffect;

                effect.Projection = Projection;

                var mat = GetSunlightMat(pointLight);

                GD.BlendState = MaxBlendRed;

                WallComp.DrawLMap(GD, pointLight, Projection, mat);

                GD.BlendState = MaxBlendRed;
                Blueprint.Terrain.DrawLMap(GD, pointLight, Projection, mat);
                Blueprint.RoofComp.DrawLMap(GD, pointLight, Projection, mat);

                effect.CurrentTechnique = effect.Techniques[0];
                EffectPassCollection passes = effect.Techniques[0].Passes;
                passes[2].Apply();

                if (WorldConfig.Current.UltraLighting)
                {
                    Draw3DObjShadows(pointLight, false);
                }

                //blit outside shadows onto post target (for blur)

                if (OutsideShadowTargPost != null)
                {
                    var blend   = GD.BlendState;
                    var rast    = GD.RasterizerState;
                    var seffect = WorldContent.SpriteEffect;

                    //seffect.blurAmount = 0.7f / Blueprint.Width);
                    //seffect.blurAmount = 0.4f / Blueprint.Width);
                    //seffect.heightMultiplier = pointLight.FalloffMultiplier);

                    var blur   = (0.2f / Blueprint.Width) * (float)Math.Pow(pointLight.FalloffMultiplier, 0.8f);
                    var height = Math.Max(pointLight.FalloffMultiplier / 1.5f, 1);
                    var harden = 0.03f * (float)Math.Sqrt(pointLight.FalloffMultiplier);

                    //lower shadow target quality as blur size increases (to save on memory bandwidth)
                    if (pointLight.FalloffMultiplier > 6)
                    {
                        ShadowTargQualityDivider = 4;
                    }
                    if (pointLight.FalloffMultiplier > 3)
                    {
                        ShadowTargQualityDivider = 2;
                    }
                    else
                    {
                        ShadowTargQualityDivider = 1;
                    }

                    seffect.blurAmount       = new Vector2(blur, blur * 2 / 5f);
                    seffect.heightMultiplier = new Vector2(height, height * 5 / 2f);
                    seffect.hardenBias       = new Vector2(harden, harden * 0.5f);
                    seffect.noiseTexture     = TextureGenerator.GetUniformNoise(GD);

                    for (int i = 0; i < 4; i++)
                    {
                        seffect.SetTechnique((int)SpriteEffectTechniques.ShadowSeparableBlit1 + i);
                        RenderTarget2D tex;
                        if (i % 2 == 0)
                        {
                            GD.SetRenderTarget(OutsideShadowTargPost);
                            tex = OutsideShadowTarg;
                        }
                        else
                        {
                            GD.SetRenderTarget(OutsideShadowTarg);
                            tex = OutsideShadowTargPost;
                        }

                        ShadowTargBlit.Begin(blendState: (i == 1)? OpaqueBA : BlendState.Opaque, effect: seffect, samplerState: SamplerState.PointClamp);
                        ShadowTargBlit.Draw(tex, new Rectangle(0, 0, tex.Width, tex.Height), Color.White);
                        ShadowTargBlit.End();
                    }

                    /*
                     * ShadowTargBlit.Begin(blendState: BlendState.Opaque, effect: seffect);
                     * seffect.CurrentTechnique = seffect.Techniques["ShadowBlurBlit"];
                     * seffect.blurAmount = 0.7f / Blueprint.Width);
                     * seffect.heightMultiplier = pointLight.FalloffMultiplier);
                     * seffect.noiseTexture"]?.SetValue(TextureGenerator.GetUniformNoise(GD));
                     * ShadowTargBlit.Draw(OutsideShadowTarg, new Rectangle(0, 0, OutsideShadowTarg.Width, OutsideShadowTarg.Height), Color.White);
                     * ShadowTargBlit.End();
                     */

                    GD.SetRenderTarget(OutsideShadowTarg);
                    GD.RasterizerState = rast;
                    GD.BlendState      = blend;
                }
            }
            else
            {
                GD.SetRenderTarget(ShadowTarg);
                var geom = ShadowGeometry.GenerateWallShadows(walls, pointLight);
                GD.BlendState = AddBlendRed;
                DrawShadows(geom, (pointLight.LightType == LightType.OUTDOORS) ? 2 : 0, pointLight);
            }
        }
Пример #31
0
        /// <summary>
        /// Draws the current frame
        /// </summary>
        /// <param name="gameTime">The game time</param>
        public override void Draw(GameTime gameTime)
        {
            try
            {
                int index = 0;
                // Update all the effects with the palette and world and draw the meshes
                for (int i = 0; i < numMeshes; i++)
                {
                    ModelMesh mesh = model.Meshes[i];
                    // The starting index for the modelEffects array
                    int effectStartIndex = index;
                    if (matrixPaletteParams[index] != null)
                    {
                        foreach (Effect effect in mesh.Effects)
                        {
                            worldParams[index].SetValue(

                                world);


                            matrixPaletteParams[index].SetValue(palette[i]);
                            index++;
                        }
                    }
                    else
                    {
                        foreach (Effect effect in mesh.Effects)
                        {
                            worldParams[index].SetValue(pose[mesh.ParentBone.Index] * world);
                            index++;
                        }
                    }
                    int            numParts = mesh.MeshParts.Count;
                    GraphicsDevice device   = mesh.VertexBuffer.GraphicsDevice;
                    device.Indices = mesh.IndexBuffer;
                    for (int j = 0; j < numParts; j++)
                    {
                        ModelMeshPart currentPart = mesh.MeshParts[j];
                        if (currentPart.NumVertices == 0 || currentPart.PrimitiveCount == 0)
                        {
                            continue;
                        }
                        Effect currentEffect = modelEffects[effectStartIndex + j];


                        device.VertexDeclaration = currentPart.VertexDeclaration;
                        device.Vertices[0].SetSource(mesh.VertexBuffer, currentPart.StreamOffset,
                                                     currentPart.VertexStride);

                        currentEffect.Begin();
                        EffectPassCollection passes = currentEffect.CurrentTechnique.Passes;
                        int numPasses = passes.Count;
                        for (int k = 0; k < numPasses; k++)
                        {
                            EffectPass pass = passes[k];
                            pass.Begin();
                            device.DrawIndexedPrimitives(PrimitiveType.TriangleList, currentPart.BaseVertex,
                                                         0, currentPart.NumVertices, currentPart.StartIndex, currentPart.PrimitiveCount);
                            pass.End();
                        }

                        currentEffect.End();
                    }
                }
            }
            catch (NullReferenceException)
            {
                throw new InvalidOperationException("The effects on the model for a " +
                                                    "ModelAnimator were changed without calling ModelAnimator.InitializeEffectParams().");
            }
            catch (InvalidCastException)
            {
                throw new InvalidCastException("ModelAnimator has thrown an InvalidCastException.  This is " +
                                               "likely because the model uses too many bones for the matrix palette.  The default palette size "
                                               + "is 56 for windows and 40 for Xbox.");
            }
        }
Пример #32
0
        public void DrawRoom(Room room, RoomLighting lighting, bool clear)
        {
            var size = Blueprint.Width - borderSize;

            //TODO: set floor shadow map here to stop surrounding light issues
            LightEffect.floorShadowMap = ObjShadowTarg;
            LightEffect.TargetRoom     = (float)room.RoomID;
            var bigBounds = new Rectangle(lighting.Bounds.X * resPerTile, lighting.Bounds.Y * resPerTile, lighting.Bounds.Width * resPerTile, lighting.Bounds.Height * resPerTile);

            bigBounds          = Rectangle.Intersect(bigBounds, new Rectangle(0, 0, size * resPerTile, size * resPerTile));
            GD.RasterizerState = Scissor;
            if (clear)
            {
                GD.SetRenderTarget(LightMap);
                DrawRect = bigBounds;
                DrawRect.Offset(ScissorBase);
                GD.ScissorRectangle = DrawRect;

                var effect = LightEffect;
                effect.CurrentTechnique = effect.Techniques[0];
                EffectPassCollection passes = effect.Techniques[0].Passes;
                effect.LightColor = Vector4.One * (Blueprint.MinOut.A / 255f);
                GD.BlendState     = BlendState.Opaque;
                passes[2].Apply();

                GD.SetVertexBuffer(LightBuf);
                GD.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);

                if (LightMapDirection != null)
                {
                    GD.SetRenderTarget(LightMapDirection);
                    DrawRect                = ScaleDirectionScissor(DrawRect);
                    GD.ScissorRectangle     = DrawRect;
                    effect.CurrentTechnique = effect.Techniques[1];
                    passes            = effect.Techniques[1].Passes;
                    effect.LightColor = Vector4.Zero;
                    GD.BlendState     = BlendState.Opaque;
                    passes[2].Apply();
                    GD.SetVertexBuffer(LightBuf);
                    GD.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
                }
            }
            var outFactor = Vector4.One - Blueprint.MinOut.ToVector4();

            var factor = 16f / resPerTile;

            var colorTech = 0; //
            var dirTech   = 1; //

            if (room.IsOutside || WallComp != null)
            {
                var res = (Blueprint.Width - borderSize) * resPerTile;
                if (!room.IsOutside)
                {
                    DrawRect = new Rectangle(0, 0, res, res);
                }
                else
                {
                    DrawRect = bigBounds;
                }
                if (OutdoorsLight == null)
                {
                    BuildOutdoorsLight(Blueprint.OutsideTime);
                }
                var light = OutdoorsLight;
                //generate shadows
                light.Level = (sbyte)(room.Floor);
                DrawWallShadows(room.WallLines, light);
                if (room.IsOutside && !WorldConfig.Current.UltraLighting)
                {
                    DrawObjShadows(lighting.ObjectFootprints, light);
                }

                //draw the light onto the lightmap
                GD.SetRenderTarget(LightMap);
                DrawRect.Offset(ScissorBase);
                GD.ScissorRectangle      = DrawRect;
                LightEffect.LightColor   = Color.White.ToVector4() * outFactor.W;
                LightEffect.ShadowPowers = new Vector2(0.75f, 0.6f) * light.ShadowMultiplier;
                LightEffect.LightHeight  = 1f / (float)Blueprint.Width;

                LightEffect.LightPosition  = light.LightPos / (size * 16f); //in position space (0,1)
                LightEffect.LightDirection = new Vector3(-SunVector.Z, SunVector.Y * -1, SunVector.X);
                LightEffect.LightSize      = float.MaxValue;                //in position space (0,1)
                LightEffect.IsOutdoors     = true;

                var effect = LightEffect;
                effect.CurrentTechnique = effect.Techniques[colorTech];
                EffectPassCollection passes = effect.Techniques[colorTech].Passes;
                passes[room.IsOutside ? ((WallComp == null) ? 1 : 4) : 3].Apply();

                GD.SetVertexBuffer(LightBuf);
                GD.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);

                if (LightMapDirection != null)
                {
                    GD.SetRenderTarget(LightMapDirection);
                    effect.CurrentTechnique = effect.Techniques[dirTech];
                    passes              = effect.Techniques[dirTech].Passes;
                    DrawRect            = ScaleDirectionScissor(DrawRect);
                    GD.ScissorRectangle = DrawRect;

                    passes[room.IsOutside ? ((WallComp == null) ? 1 : 4) : 3].Apply();

                    GD.SetVertexBuffer(LightBuf);
                    GD.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
                }

                LightEffect.shadowMap = ShadowTarg;
            }

            var order         = lighting.Lights.OrderBy(x => x.OutdoorsColor ? 0 : 1);
            var hasMulOutside = false;

            foreach (var light in order)
            {
                if (!light.OutdoorsColor && !hasMulOutside)
                {
                    MultiplyOutdoors(bigBounds);
                    hasMulOutside = true;
                }
                if (light.WindowRoom != -1)
                {
                    var wroom = Blueprint.Light[Blueprint.Rooms[light.WindowRoom].Base];
                    light.LightIntensity = wroom.AmbientLight / 150f;
                }
                if (light.LightIntensity < 0.2f)
                {
                    continue;
                }

                DrawRect = new Rectangle((int)(light.LightBounds.X / factor), (int)(light.LightBounds.Y / factor), (int)(light.LightBounds.Width / factor), (int)(light.LightBounds.Height / factor));
                DrawRect = Rectangle.Intersect(DrawRect, bigBounds);

                //generate shadows

                DrawWallShadows(room.WallLines, light);
                DrawObjShadows(lighting.ObjectFootprints, light);

                //draw the light onto the lightmap
                GD.SetRenderTarget(LightMap);
                DrawRect.Offset(ScissorBase);
                GD.ScissorRectangle      = DrawRect;
                LightEffect.ShadowPowers = new Vector2(1f, 1f);

                LightEffect.LightPosition = light.LightPos / (size * 16f);  //in position space (0,1)
                LightEffect.LightSize     = light.LightSize / (size * 16f); //in position space (0,1)
                var l = light.LightColor.ToVector4();
                l.W = (l.X + l.Y + l.Z) / 3;

                if (light.OutdoorsColor)
                {
                    l = Vector4.Multiply(l, outFactor);
                }
                else
                {
                    l *= 0.70f;
                }
                LightEffect.LightColor     = l;
                LightEffect.IsOutdoors     = light.OutdoorsColor;
                LightEffect.LightIntensity = light.LightIntensity;

                var effect = LightEffect;
                effect.CurrentTechnique = effect.Techniques[colorTech];
                EffectPassCollection passes = effect.Techniques[colorTech].Passes;

                if (WorldConfig.Current.UltraLighting)
                {
                    LightEffect.BlurMin = (light.OutdoorsColor)?(1 / (Blueprint.Width * 9f)):0;
                    LightEffect.BlurMax = (1 / (Blueprint.Width * 5f));
                    passes[5].Apply();
                }
                else
                {
                    passes[0].Apply();
                }

                GD.SetVertexBuffer(LightBuf);
                GD.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);

                if (LightMapDirection != null)
                {
                    GD.SetRenderTarget(LightMapDirection);
                    effect.CurrentTechnique = effect.Techniques[dirTech];
                    passes   = effect.Techniques[dirTech].Passes;
                    DrawRect = ScaleDirectionScissor(DrawRect);

                    passes[0].Apply();

                    GD.SetVertexBuffer(LightBuf);
                    GD.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
                }
            }
            if (!hasMulOutside)
            {
                MultiplyOutdoors(bigBounds);
            }
        }
Пример #33
0
        /// <summary>
        ///   Initializes a new instance of the <see cref="EffectPass" /> class.
        /// </summary>
        /// <param name="logger">The logger used to log errors.</param>
        /// <param name="effect"> The effect. </param>
        /// <param name="pass"> The pass. </param>
        /// <param name="name"> The name. </param>
        internal EffectPass(Logger logger, Effect effect, EffectTechnique technique, EffectData.Pass pass, string name)
            : base(name)
        {
            this.Technique = technique;
            this.pass = pass;
            this.Effect = effect;
            this.graphicsDevice = effect.GraphicsDevice;
            pipeline = new PipelineBlock()
                           {
                               Stages = new StageBlock[EffectPass.StageCount],
                           };

            Attributes = PrepareAttributes(logger, pass.Attributes);
            IsSubPass = pass.IsSubPass;
            // Don't create SubPasses collection for subpass.
            if (!IsSubPass)
                SubPasses = new EffectPassCollection();
        }
Пример #34
0
 internal EffectTechnique(Effect effect, string name, EffectPassCollection passes, EffectAnnotationCollection annotations)
 {
   this.Name = name;
   this.Passes = passes;
   this.Annotations = annotations;
 }