private void WaterTarget(GameTime obj)
        {
            var graphics = Main.graphics.GraphicsDevice;

            if (CatherdalWaterTarget is null || CatherdalWaterTarget.Size() != new Vector2(Main.screenWidth, Main.screenHeight))
            {
                CatherdalWaterTarget = new RenderTarget2D(graphics, Main.screenWidth, Main.screenHeight, default, default, default, default, RenderTargetUsage.PreserveContents);
示例#2
0
        private void TestLighting(GameTime obj)
        {
            if (Main.dedServ)
            {
                return;
            }
            if (!Main.gameMenu)
            {
                lightingTest.DebugDraw();
            }

            GraphicsDevice graphics = Main.instance.GraphicsDevice;

            graphics.SetRenderTarget(VerletChainInstance.target);
            graphics.Clear(Color.Transparent);

            foreach (var i in VerletChainInstance.toDraw)
            {
                i.DrawStrip();
            }

            graphics.SetRenderTarget(null);

            graphics.SetRenderTarget(vitricBackgroundBannerTarget);
            graphics.Clear(Color.Transparent);

            BackgroundBanner.DrawStrip(Main.screenPosition + new Vector2(0, 50));

            graphics.SetRenderTarget(null);

            //TODO: move all below
            if (CatherdalWaterTarget is null || CatherdalWaterTarget.Size() != new Vector2(Main.screenWidth, Main.screenHeight))
            {
                CatherdalWaterTarget = new RenderTarget2D(graphics, Main.screenWidth, Main.screenHeight, default, default, default, default, RenderTargetUsage.PreserveContents);
        private void RenderLightingQuad()
        {
            if (Main.dedServ)
            {
                return;
            }

            if (lightingQuadBuffer == null)
            {
                SetupLightingQuadBuffer(); //a bit hacky, but if we do this on load we can end up with black textures for full screen users, and full screen does not fire set display mode events
            }
            Effect upscaleEffect = Filters.Scene["LightShader"].GetShader().Shader;

            GraphicsDevice graphics = Main.instance.GraphicsDevice;

            graphics.SetVertexBuffer(lightingQuadBuffer);
            graphics.RasterizerState = new RasterizerState()
            {
                CullMode = CullMode.None
            };

            Vector2 offset = (Main.screenPosition - TileLightingCenter) / new Vector2(Main.screenWidth, Main.screenHeight);


            upscaleEffect.Parameters["screenSize"].SetValue(new Vector2(Main.screenWidth, Main.screenHeight));
            upscaleEffect.Parameters["fullBufferSize"].SetValue(TileLightingTexture.Size() * 16);
            upscaleEffect.Parameters["offset"].SetValue(offset);
            upscaleEffect.Parameters["sampleTexture"].SetValue(TileLightingTexture);

            foreach (EffectPass pass in upscaleEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                graphics.DrawPrimitives(PrimitiveType.TriangleList, 0, 2);
            }
        }
示例#4
0
        private void HotspringTarget(On.Terraria.Main.orig_CheckMonoliths orig)
        {
            orig();

            if (Main.gameMenu)
            {
                return;
            }

            var graphics = Main.graphics.GraphicsDevice;

            if (hotspringMapTarget is null || hotspringMapTarget.Size() != new Vector2(Main.screenWidth, Main.screenHeight))
            {
                hotspringMapTarget = new RenderTarget2D(graphics, Main.screenWidth, Main.screenHeight, default, default, default, default, RenderTargetUsage.PreserveContents);
示例#5
0
        private void WaterTarget(On.Terraria.Main.orig_CheckMonoliths orig)
        {
            orig();

            if (Main.dedServ)
            {
                return;
            }

            var graphics = Main.graphics.GraphicsDevice;

            if (CatherdalWaterTarget is null || CatherdalWaterTarget.Size() != new Vector2(Main.screenWidth, Main.screenHeight))
            {
                CatherdalWaterTarget = new RenderTarget2D(graphics, Main.screenWidth, Main.screenHeight, default, default, default, default, RenderTargetUsage.PreserveContents);
        private void RenderLightingQuad()
        {
            if (upscaleEffect is null)
            {
                return;
            }

            GraphicsDevice graphics = Main.instance.GraphicsDevice;

            VertexPositionColorTexture[] verticies = new VertexPositionColorTexture[6];

            verticies[0] = new VertexPositionColorTexture(new Vector3(-1, -1, 0), Color.White, new Vector2(0, 1));
            verticies[1] = new VertexPositionColorTexture(new Vector3(1, -1, 0), Color.Red, new Vector2(1, 1));
            verticies[2] = new VertexPositionColorTexture(new Vector3(1, 1, 0), Color.White, new Vector2(1, 0));

            verticies[3] = new VertexPositionColorTexture(new Vector3(-1, -1, 0), Color.White, new Vector2(0, 1));
            verticies[4] = new VertexPositionColorTexture(new Vector3(-1, 1, 0), Color.Red, new Vector2(0, 0));
            verticies[5] = new VertexPositionColorTexture(new Vector3(1, 1, 0), Color.White, new Vector2(1, 0));

            VertexBuffer buffer = new VertexBuffer(graphics, typeof(VertexPositionColorTexture), 6, BufferUsage.WriteOnly);

            buffer.SetData(verticies);

            graphics.SetVertexBuffer(buffer);
            graphics.RasterizerState = new RasterizerState()
            {
                CullMode = CullMode.None
            };

            Vector2 offset = (Main.screenPosition + new Vector2(Main.screenWidth, Main.screenHeight) / 2f - TileLightingCenter - Vector2.One * 64) / new Vector2(Main.screenWidth, Main.screenHeight);

            upscaleEffect.Parameters["screenSize"].SetValue(new Vector2(Main.screenWidth, Main.screenHeight));
            upscaleEffect.Parameters["fullBufferSize"].SetValue(TileLightingTexture.Size() * 16);
            upscaleEffect.Parameters["offset"].SetValue(offset);
            upscaleEffect.Parameters["sampleTexture"].SetValue(TileLightingTexture);

            foreach (EffectPass pass in upscaleEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                graphics.DrawPrimitives(PrimitiveType.TriangleList, 0, 2);
            }
        }
示例#7
0
        public void DrawPlayerHead(
            Camera camera,
            Player drawPlayer,
            Vector2 position,
            float alpha       = 1f,
            float scale       = 1f,
            Color borderColor = default(Color))
        {
            PlayerHeadDrawRenderTargetContent playerRender = this._playerRenders[drawPlayer.whoAmI];

            playerRender.UsePlayer(drawPlayer);
            playerRender.UseColor(borderColor);
            playerRender.Request();
            this._anyDirty = true;
            this._drawData.Clear();
            if (!playerRender.IsReady)
            {
                return;
            }
            RenderTarget2D target = playerRender.GetTarget();

            this._drawData.Add(new DrawData((Texture2D)target, position, new Rectangle?(), Color.White, 0.0f, target.Size() / 2f, scale, SpriteEffects.None, 0));
            this.RenderDrawData(drawPlayer);
        }
示例#8
0
        public void DrawWithOutlines(
            Entity entity,
            int headId,
            Vector2 position,
            Color color,
            float rotation,
            float scale,
            SpriteEffects effects)
        {
            if (this._contents[headId] == null)
            {
                this._contents[headId] = new NPCHeadDrawRenderTargetContent();
                this._contents[headId].SetTexture(this._matchingArray[headId].Value);
            }
            NPCHeadDrawRenderTargetContent content = this._contents[headId];

            if (content.IsReady)
            {
                RenderTarget2D target = content.GetTarget();
                Main.spriteBatch.Draw((Texture2D)target, position, new Rectangle?(), color, rotation, target.Size() / 2f, scale, effects, 0.0f);
            }
            else
            {
                content.Request();
            }
        }
示例#9
0
        public static void DrawToRenderTarget()
        {
            if (Main.dedServ || shadowParticlesDrawTime < 1)
            {
                return;
            }

            RenderTargetBinding[] binds = Main.graphics.GraphicsDevice.GetRenderTargets();


            //Draw additive white particles

            Main.graphics.GraphicsDevice.SetRenderTarget(shadowSurface);
            Main.graphics.GraphicsDevice.Clear(Color.Transparent);

            //Main.spriteBatch.End();
            Main.spriteBatch.Begin(SpriteSortMode.Texture, BlendState.Additive, Main.DefaultSamplerState, DepthStencilState.None, RasterizerState.CullCounterClockwise, null, Main.GameViewMatrix.TransformationMatrix);

            //Gains a different look when the Hellion Core spawns it
            int fogtype = NPC.CountNPCS(ModContent.NPCType <HellionCore>()) > 0 ? 0 : 1;

            Color fogTo      = Color.DarkMagenta;
            Color fogFrom    = Color.Black;
            float edging     = 0.10f;
            int   smokecount = fogtype == 0 ? 16 : 32;


            foreach (ShadowParticle particle in particles)
            {
                Vector2 size  = particle.CloudTexture.Size();
                float   alpha = (float)Math.Sin((particle.timeLeft / (float)particle.maxTimeLeft) * MathHelper.Pi);
                Main.spriteBatch.Draw(particle.CloudTexture, (particle.position - Main.screenPosition) / 2f, null, Color.White * MathHelper.Clamp(alpha * particle.alpha * particle.fadePercent, 0f, 1f), particle.rotation, size / 2f, particle.scale / 2f, SpriteEffects.None, 0f);
            }

            Main.spriteBatch.End();

            //Now, draw the interior effect using the above as texture mask

            Main.graphics.GraphicsDevice.SetRenderTarget(shadowSurfaceShaderApplied);
            Main.graphics.GraphicsDevice.Clear(Color.Transparent);

            //Main.spriteBatch.End();
            Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullCounterClockwise, null, Matrix.Identity);

            ShadowEffect.Parameters["overlayTexture"].SetValue(shadowSurface);
            ShadowEffect.Parameters["colorAmmount"].SetValue(smokecount);
            ShadowEffect.Parameters["screenSize"].SetValue(shadowSurface.Size());
            //Color.DarkMagenta
            //Color.Black
            ShadowEffect.Parameters["colorFrom"].SetValue((fogTo).ToVector4() * (fogtype == 0 ? 1f : 0.01f));
            ShadowEffect.Parameters["colorTo"].SetValue((fogFrom).ToVector4() * 1f);
            ShadowEffect.Parameters["colorOutline"].SetValue((Color.Transparent).ToVector4() * 1f);

            ShadowEffect.Parameters["edgeSmooth"].SetValue(edging);
            ShadowEffect.Parameters["noiseTexture"].SetValue(shadowHellion);
            ShadowEffect.Parameters["invertLuma"].SetValue(false);
            ShadowEffect.Parameters["alpha"].SetValue(1f);


            //Show through
            float percent = 1f;

            ShadowEffect.Parameters["noisePercent"].SetValue(percent);
            ShadowEffect.Parameters["noiseScalar"].SetValue(new Vector4(0, 0, 1f, 1f));

            ShadowEffect.CurrentTechnique.Passes["ColorFilter"].Apply();

            Main.graphics.GraphicsDevice.SamplerStates[1] = SamplerState.PointClamp;
            Main.spriteBatch.Draw(shadowSurface, Vector2.Zero, new Rectangle(0, 0, Main.screenWidth / 2, Main.screenHeight / 2), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0f);

            Main.spriteBatch.End();

            if (percent > 0)
            {
                Main.graphics.GraphicsDevice.SetRenderTarget(shadowHellion);
                Main.graphics.GraphicsDevice.Clear(Color.Transparent);

                //Main.spriteBatch.End();
                Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.Default, RasterizerState.CullNone, null, Matrix.Identity);

                Vector2 parallex = new Vector2(0, 0);

                Effect effect = SGAmod.TrailEffect;

                Terraria.Utilities.UnifiedRandom rando = new Terraria.Utilities.UnifiedRandom(1);

                float timer = rando.NextFloat(MathHelper.TwoPi);

                for (int i = 0; i < 12; i += 1)
                {
                    //Used to pulse in and out, didn't think it was needed in the end thou
                    float alpha = 1f * starAlpha;
                    #region oldcode
                    // MathHelper.Clamp(0.40f + (float)Math.Sin(((SGAWorld.modtimer / 35f) + rando.NextFloat(MathHelper.TwoPi)) * rando.NextFloat(0.25f, 0.75f))*0.80f, 0f, 1f);
                    //if (alpha <= 0 && i > 0)
                    //    continue;
                    #endregion

                    Matrix rotation  = Matrix.CreateRotationZ(timer);
                    Matrix rotation2 = Matrix.CreateRotationZ((-timer));
                    Matrix rotation3 = Matrix.CreateRotationZ((timer - MathHelper.Pi));

                    Matrix rotationOffset = Matrix.CreateTranslation(-shadowSurface.Width / 2, -shadowSurface.Height / 2, 0) * Matrix.CreateScale(3, 3f, 1f) * rotation * Matrix.CreateTranslation(shadowSurface.Width / 2, shadowSurface.Height / 2, 0);

                    if (i > 0)
                    {
                        Vector2 pos2            = ((Main.screenPosition / ((8000f + (i * 4000f))) * 1f) + new Vector2(rando.NextFloat(1f), rando.NextFloat(1f)));
                        Vector2 pos             = -Vector2.One + new Vector2(pos2.X % 1f, pos2.Y % 1f) * 2f;
                        Matrix  rotationOffset2 = Matrix.CreateTranslation(pos.X, pos.Y, 0) * rotation2;
                        parallex = Vector2.Transform(Vector2.One / 2f, rotationOffset2);
                    }
                    if (fogtype == 1)
                    {
                        effect.Parameters["rainbowCoordOffset"].SetValue(new Vector2(rando.NextFloat(1f), rando.NextFloat(1f)));
                        effect.Parameters["rainbowCoordMultiplier"].SetValue(new Vector2(1f, 1f));
                        effect.Parameters["rainbowColor"].SetValue(new Vector3(SGAWorld.modtimer / 300f, 1f, 0.75f));
                        effect.Parameters["rainbowScale"].SetValue(1f);
                        effect.Parameters["rainbowTexture"].SetValue(SGAmod.Instance.GetTexture("TiledPerlin"));
                    }

                    effect.Parameters["WorldViewProjection"].SetValue(WVP.View(Vector2.One) * WVP.Projection());
                    effect.Parameters["imageTexture"].SetValue(i < 1 ? SGAmod.Instance.GetTexture("TiledPerlin") : SGAmod.Instance.GetTexture("Space"));
                    effect.Parameters["coordOffset"].SetValue(parallex);
                    effect.Parameters["coordMultiplier"].SetValue(i < 1 ? new Vector2(2f, 1.5f) * 3f : (new Vector2(3f, 2f) + new Vector2(rando.NextFloat(-0.5f, 0.5f), rando.NextFloat(-0.5f, 0.5f))) * 3f);
                    effect.Parameters["strength"].SetValue(i == 0 ? 0.50f : (1.75f * alpha) / (1f + (i / 4f)));

                    VertexPositionColorTexture[] vertices = new VertexPositionColorTexture[6];
                    VertexBuffer vertexBuffer;

                    Vector3 screenPos = new Vector3(-16, 0, 0);

                    Color colorsa = fogtype == 0 ? Color.Lerp(fogFrom, fogTo, 0.50f) : Color.White;

                    if (i > 0)
                    {
                        colorsa = fogtype == 0 ? Color.Lerp(fogTo, fogFrom, (float)i / 16f) : Color.White * (1f - ((float)i / 48f));
                    }

                    vertices[0] = new VertexPositionColorTexture(Vector3.Transform(screenPos + new Vector3(-16, -16, 0), rotationOffset), colorsa, new Vector2(0, 0));
                    vertices[1] = new VertexPositionColorTexture(Vector3.Transform(screenPos + new Vector3(-16, Main.screenHeight + 16, 0), rotationOffset), colorsa, new Vector2(0, 1));
                    vertices[2] = new VertexPositionColorTexture(Vector3.Transform(screenPos + new Vector3(Main.screenWidth + 16, -16, 0), rotationOffset), colorsa, new Vector2(1, 0));

                    vertices[3] = new VertexPositionColorTexture(Vector3.Transform(screenPos + new Vector3(Main.screenWidth + 16, Main.screenHeight + 16, 0), rotationOffset), colorsa, new Vector2(1, 1));
                    vertices[4] = new VertexPositionColorTexture(Vector3.Transform(screenPos + new Vector3(-16, Main.screenHeight + 16, 0), rotationOffset), colorsa, new Vector2(0, 1));
                    vertices[5] = new VertexPositionColorTexture(Vector3.Transform(screenPos + new Vector3(Main.screenWidth + 16, -16, 0), rotationOffset), colorsa, new Vector2(1, 0));

                    vertexBuffer = new VertexBuffer(Main.graphics.GraphicsDevice, typeof(VertexPositionColorTexture), vertices.Length, BufferUsage.WriteOnly);
                    vertexBuffer.SetData <VertexPositionColorTexture>(vertices);

                    Main.graphics.GraphicsDevice.SetVertexBuffer(vertexBuffer);

                    RasterizerState rasterizerState = new RasterizerState();
                    rasterizerState.CullMode = CullMode.None;
                    Main.graphics.GraphicsDevice.RasterizerState = rasterizerState;

                    effect.CurrentTechnique.Passes[i < 1 ? (fogtype == 1 ? "RainbowEffectPass" : "BasicEffectPass") : (fogtype == 1 ? "RainbowEffectAlphaPass" : "BasicEffectAlphaPass")].Apply();
                    Main.graphics.GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, 2);
                }


                Main.spriteBatch.End();
                Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.Default, RasterizerState.CullNone, null, Main.GameViewMatrix.TransformationMatrix);

                //originally, the worms were drawn INSIDE the rendertarget, but this has since been changed
                #region oldcode

                /*foreach(NPC hellionarm in Main.npc.Where(testby => testby.active && (testby.type == ModContent.NPCType<HellionCore>() || testby.type == ModContent.NPCType<HellionMonolog>())))
                 * {
                 *  Hellion.HellionTeleport(Main.spriteBatch, (Main.screenPosition+hellionarm.Center)/2f, 0.5f, 48);
                 *  //((HellionWorm)(hellionarm.modNPC as HellionWorm)).DrawMe(Main.spriteBatch,Color.White,0.5f);
                 * }*/

                //Main.spriteBatch.Draw(hellionTex, -reallyHellion.velocity + new Vector2(0, 10) + (reallyHellion.Center - Main.screenPosition) / 2f, null, Color.White * (settings != null ? settings.HelliontransparencyRate : 0.15f), 0, hellionTex.Size() / 2f, 0.50f, SpriteEffects.None, 0f);
                #endregion

                Main.spriteBatch.End();
            }

            Main.graphics.GraphicsDevice.SetRenderTargets(binds);
        }