Exemplo n.º 1
0
        public override void Render(GuiElementMap map, float dt)
        {
            map.TranslateWorldPosToViewPos(waypoint.Position, ref viewPos);

            float x = (float)(map.Bounds.renderX + viewPos.X);
            float y = (float)(map.Bounds.renderY + viewPos.Y);

            ICoreClientAPI api = map.Api;

            IShaderProgram prog = api.Render.GetEngineShader(EnumShaderProgram.Gui);

            prog.Uniform("rgbaIn", color);
            prog.Uniform("extraGlow", 0);
            prog.Uniform("applyColor", 0);
            prog.Uniform("noTexture", 0f);
            prog.BindTexture2D("tex2d", Texture.TextureId, 0);

            api.Render.GlPushMatrix();
            api.Render.GlTranslate(x, y, 60);
            api.Render.GlScale(Texture.Width, Texture.Height, 0);
            api.Render.GlScale(0.5f, 0.5f, 0);

            prog.UniformMatrix("projectionMatrix", api.Render.CurrentProjectionMatrix);
            prog.UniformMatrix("modelViewMatrix", api.Render.CurrentModelviewMatrix);

            api.Render.RenderMesh(quadModel);
            api.Render.GlPopMatrix();
        }
Exemplo n.º 2
0
        public void OnRenderFrame(float deltaTime, EnumRenderStage stage)
        {
            if (prog.Disposed)
            {
                prog = capi.Shader.GetProgramByName("instanced");
            }

            capi.Render.GlDisableCullFace();

            if (stage == EnumRenderStage.Opaque)
            {
                capi.Render.GlToggleBlend(false); // Seems to break SSAO without
                prog.Use();
                prog.BindTexture2D("tex", capi.ItemTextureAtlas.Positions[0].atlasTextureId, 0);
                prog.Uniform("rgbaFogIn", capi.Render.FogColor);
                prog.Uniform("rgbaAmbientIn", capi.Render.AmbientColor);
                prog.Uniform("fogMinIn", capi.Render.FogMin);
                prog.Uniform("fogDensityIn", capi.Render.FogDensity);
                prog.UniformMatrix("projectionMatrix", capi.Render.CurrentProjectionMatrix);
                prog.UniformMatrix("modelViewMatrix", capi.Render.CameraMatrixOriginf);

                foreach (var val in renderers)
                {
                    val.Value.OnRenderFrame(deltaTime, prog);
                }

                prog.Stop();
            }

            capi.Render.GlEnableCullFace();
        }
Exemplo n.º 3
0
        public override void Render(GuiElementMap map, float dt)
        {
            map.TranslateWorldPosToViewPos(entity.Pos.XYZ, ref viewPos);

            float x = (float)(map.Bounds.renderX + viewPos.X);
            float y = (float)(map.Bounds.renderY + viewPos.Y);

            //api.Render.GlToggleBlend(true, EnumBlendMode.PremultipliedAlpha);
            ICoreClientAPI api = map.Api;

            IShaderProgram prog = api.Render.GetEngineShader(EnumShaderProgram.Gui);

            prog.Uniform("rgbaIn", ColorUtil.WhiteArgbVec);
            prog.Uniform("extraGlow", 0);
            prog.Uniform("applyColor", 0);
            prog.Uniform("noTexture", 0f);
            prog.BindTexture2D("tex2d", Texture.TextureId, 0);

            api.Render.GlPushMatrix();
            api.Render.GlTranslate(x, y, 60);
            api.Render.GlScale(Texture.Width, Texture.Height, 0);
            api.Render.GlScale(0.5f, 0.5f, 0);
            //api.Render.GlTranslate(1f, 1f, 0);
            api.Render.GlRotate(-entity.Pos.Yaw * GameMath.RAD2DEG + 90, 0, 0, 1);

            prog.UniformMatrix("projectionMatrix", api.Render.CurrentProjectionMatrix);
            prog.UniformMatrix("modelViewMatrix", api.Render.CurrentModelviewMatrix);


            api.Render.RenderMesh(quadModel);
            api.Render.GlPopMatrix();
        }
Exemplo n.º 4
0
        public void OnRenderFrame(float deltaTime, EnumRenderStage stage)
        {
            UpdateCustomFloatBuffer();

            prog.Use();
            prog.BindTexture2D("tex", capi.BlockTextureAtlas.Positions[0].atlasTextureId, 0);
            prog.Uniform("rgbaFogIn", capi.Render.FogColor);
            prog.Uniform("rgbaAmbientIn", capi.Render.AmbientColor);
            prog.Uniform("fogMinIn", capi.Render.FogMin);
            prog.Uniform("fogDensityIn", capi.Render.FogDensity);
            prog.UniformMatrix("projectionMatrix", capi.Render.CurrentProjectionMatrix);
            prog.UniformMatrix("modelViewMatrix", capi.Render.CameraMatrixOriginf);

            if (quantityGearboxes > 0)
            {
                floatsPeg.Count  = quantityGearboxes * 20;
                floatsCage.Count = quantityGearboxes * 20;

                updateMesh.CustomFloats = floatsPeg;
                capi.Render.UpdateMesh(gearboxPeg, updateMesh);

                updateMesh.CustomFloats = floatsCage;
                capi.Render.UpdateMesh(gearboxCage, updateMesh);

                capi.Render.RenderMeshInstanced(gearboxPeg, quantityGearboxes);
                capi.Render.RenderMeshInstanced(gearboxCage, quantityGearboxes);
            }

            prog.Stop();

            /*capi.Render.RenderMeshInstanced(gearboxCage, quantityGearboxes);
             * capi.Render.RenderMeshInstanced(axle, quantityAxles);
             * capi.Render.RenderMeshInstanced(windmillRotor, quantityRotors);*/
        }
Exemplo n.º 5
0
        public void OnRenderFrame(float dt, EnumRenderStage stage)
        {
            if (updateMesh == null)
            {
                return;
            }
            tickPhysics(dt);

            int count = 0;

            updateMesh.CustomFloats.Count = 0;

            foreach (var val in clothSystems)
            {
                if (!val.Value.Active)
                {
                    continue;
                }

                count += val.Value.UpdateMesh(updateMesh, dt);
                updateMesh.CustomFloats.Count = count * (4 + 16);
            }

            if (count > 0)
            {
                //float dt = 1.5f * deltaTime;
                if (prog.Disposed)
                {
                    prog = capi.Shader.GetProgramByName("instanced");
                }

                capi.Render.GlToggleBlend(false); // Seems to break SSAO without
                prog.Use();
                prog.BindTexture2D("tex", capi.ItemTextureAtlas.Positions[0].atlasTextureId, 0);
                prog.Uniform("rgbaFogIn", capi.Render.FogColor);
                prog.Uniform("rgbaAmbientIn", capi.Render.AmbientColor);
                prog.Uniform("fogMinIn", capi.Render.FogMin);
                prog.Uniform("fogDensityIn", capi.Render.FogDensity);
                prog.UniformMatrix("projectionMatrix", capi.Render.CurrentProjectionMatrix);
                prog.UniformMatrix("modelViewMatrix", capi.Render.CameraMatrixOriginf);

                updateMesh.CustomFloats.Count = count * (4 + 16);
                capi.Render.UpdateMesh(ropeMeshRef, updateMesh);
                capi.Render.RenderMeshInstanced(ropeMeshRef, count);

                prog.Stop();
            }


            foreach (var val in clothSystems)
            {
                if (!val.Value.Active)
                {
                    continue;
                }

                val.Value.CustomRender(dt);
            }
        }
        public override void Render(GuiElementMap map, float dt)
        {
            //if (Texture.Disposed) throw new Exception("Fatal. Trying to render a disposed texture");
            if (quadModel == null || quadModel.Disposed)
            {
                throw new Exception("Fatal. Trying to render a disposed meshref");
            }

            map.TranslateWorldPosToViewPos(waypoint.Position, ref viewPos);

            float x = (float)(map.Bounds.renderX + viewPos.X);
            float y = (float)(map.Bounds.renderY + viewPos.Y);

            if (waypoint.Pinned)
            {
                map.Api.Render.PushScissor(null);
                x = (float)GameMath.Clamp(x, map.Bounds.renderX + 2, map.Bounds.renderX + map.Bounds.InnerWidth - 2);
                y = (float)GameMath.Clamp(y, map.Bounds.renderY + 2, map.Bounds.renderY + map.Bounds.InnerHeight - 2);
            }

            ICoreClientAPI api = map.Api;

            IShaderProgram prog = api.Render.GetEngineShader(EnumShaderProgram.Gui);

            prog.Uniform("rgbaIn", color);
            prog.Uniform("extraGlow", 0);
            prog.Uniform("applyColor", 0);
            prog.Uniform("noTexture", 0f);

            LoadedTexture tex;

            float hover = (mouseOver ? 6 : 0) - 1.5f * Math.Max(1, 1 / map.ZoomLevel);


            if (wpLayer.texturesByIcon.TryGetValue(waypoint.Icon, out tex))
            {
                prog.BindTexture2D("tex2d", wpLayer.texturesByIcon[waypoint.Icon].TextureId, 0);
                mvMat
                .Set(api.Render.CurrentModelviewMatrix)
                .Translate(x, y, 60)
                .Scale(tex.Width + hover, tex.Height + hover, 0)
                .Scale(0.5f, 0.5f, 0)
                ;
                prog.UniformMatrix("projectionMatrix", api.Render.CurrentProjectionMatrix);
                prog.UniformMatrix("modelViewMatrix", mvMat.Values);

                api.Render.RenderMesh(quadModel);
            }

            if (waypoint.Pinned)
            {
                map.Api.Render.PopScissor();
            }
        }
        public override void Render(GuiElementMap map, float dt)
        {
            map.TranslateWorldPosToViewPos(waypoint.Position, ref viewPos);
            if (waypoint.Pinned)
            {
                map.Api.Render.PushScissor(null);
                map.ClampButPreserveAngle(ref viewPos, 2);
            }
            else
            {
                if (viewPos.X < -10 || viewPos.Y < -10 || viewPos.X > map.Bounds.OuterWidth + 10 || viewPos.Y > map.Bounds.OuterHeight + 10)
                {
                    return;
                }
            }

            float x = (float)(map.Bounds.renderX + viewPos.X);
            float y = (float)(map.Bounds.renderY + viewPos.Y);

            ICoreClientAPI api = map.Api;

            IShaderProgram prog = api.Render.GetEngineShader(EnumShaderProgram.Gui);

            prog.Uniform("rgbaIn", color);
            prog.Uniform("extraGlow", 0);
            prog.Uniform("applyColor", 0);
            prog.Uniform("noTexture", 0f);

            LoadedTexture tex;

            float hover = (mouseOver ? 6 : 0) - 1.5f * Math.Max(1, 1 / map.ZoomLevel);


            if (wpLayer.texturesByIcon.TryGetValue(waypoint.Icon, out tex))
            {
                prog.BindTexture2D("tex2d", wpLayer.texturesByIcon[waypoint.Icon].TextureId, 0);
                mvMat
                .Set(api.Render.CurrentModelviewMatrix)
                .Translate(x, y, 60)
                .Scale(tex.Width + hover, tex.Height + hover, 0)
                .Scale(0.5f, 0.5f, 0)
                ;
                prog.UniformMatrix("projectionMatrix", api.Render.CurrentProjectionMatrix);
                prog.UniformMatrix("modelViewMatrix", mvMat.Values);

                api.Render.RenderMesh(wpLayer.quadModel);
            }

            if (waypoint.Pinned)
            {
                map.Api.Render.PopScissor();
            }
        }
        public void OnRenderFrame(float deltaTime, EnumRenderStage stage)
        {
            if (prog.Disposed)
            {
                prog = capi.Shader.GetProgramByName("instanced");
            }

            capi.Render.GlDisableCullFace();

            if (stage == EnumRenderStage.Opaque)
            {
                capi.Render.GlToggleBlend(false); // Seems to break SSAO without
                prog.Use();
                prog.BindTexture2D("tex", capi.BlockTextureAtlas.Positions[0].atlasTextureId, 0);
                prog.Uniform("rgbaFogIn", capi.Render.FogColor);
                prog.Uniform("rgbaAmbientIn", capi.Render.AmbientColor);
                prog.Uniform("fogMinIn", capi.Render.FogMin);
                prog.Uniform("fogDensityIn", capi.Render.FogDensity);
                prog.UniformMatrix("projectionMatrix", capi.Render.CurrentProjectionMatrix);
                prog.UniformMatrix("modelViewMatrix", capi.Render.CameraMatrixOriginf);

                for (int i = 0; i < MechBlockRenderer.Count; i++)
                {
                    MechBlockRenderer[i].OnRenderFrame(deltaTime, prog);
                }

                prog.Stop();
            }
            else
            {
                // TODO: Needs a custom shadow map shader

                /*IRenderAPI rapi = capi.Render;
                 * rapi.CurrentActiveShader.BindTexture2D("tex2d", capi.BlockTextureAtlas.Positions[0].atlasTextureId, 0);
                 *
                 * float[] mvpMat = Mat4f.Mul(Mat4f.Create(), capi.Render.CurrentProjectionMatrix, capi.Render.CurrentModelviewMatrix);
                 *
                 * capi.Render.CurrentActiveShader.UniformMatrix("mvpMatrix", mvpMat);
                 * //capi.Render.CurrentActiveShader.Uniform("origin", new Vec3f());
                 *
                 * for (int i = 0; i < MechBlockRenderer.Count; i++)
                 * {
                 *  MechBlockRenderer[i].OnRenderFrame(deltaTime, prog);
                 * }*/
            }


            capi.Render.GlEnableCullFace();
        }
Exemplo n.º 9
0
        public void OnRenderFrame(float deltaTime, EnumRenderStage stage)
        {
            if (prog.Disposed)
            {
                return;
            }

            BlockPos       Pos       = capi.World.Player.Entity.Pos.AsBlockPos;
            IShaderProgram curShader = capi.Render.CurrentActiveShader;

            curShader.Stop();

            prog.Use();

            capi.Render.GlToggleBlend(true);
            prog.SetDefaultUniforms(capi);
            prog.BindTexture2D("iDepthBuffer", capi.Render.FrameBuffers[(int)EnumFrameBuffer.Primary].DepthTextureId, 0);
            prog.BindTexture2D("iColor", capi.Render.FrameBuffers[(int)EnumFrameBuffer.Primary].ColorTextureIds[0], 1);
            prog.BindTexture2D("iLight", capi.Render.FrameBuffers[(int)EnumFrameBuffer.Primary].ColorTextureIds[1], 2);

            capi.Render.RenderMesh(quadRef);
            prog.Stop();
            curShader.Use();
        }
Exemplo n.º 10
0
        public override void Render(GuiElementMap map, float dt)
        {
            if ((entity as EntityPlayer)?.Player?.WorldData?.CurrentGameMode == EnumGameMode.Spectator == true)
            {
                return;
            }

            map.TranslateWorldPosToViewPos(entity.Pos.XYZ, ref viewPos);

            float x = (float)(map.Bounds.renderX + viewPos.X);
            float y = (float)(map.Bounds.renderY + viewPos.Y);

            ICoreClientAPI api = map.Api;

            if (Texture.Disposed)
            {
                throw new Exception("Fatal. Trying to render a disposed texture");
            }
            if (quadModel.Disposed)
            {
                throw new Exception("Fatal. Trying to render a disposed texture");
            }

            capi.Render.GlToggleBlend(true);

            IShaderProgram prog = api.Render.GetEngineShader(EnumShaderProgram.Gui);

            prog.Uniform("rgbaIn", ColorUtil.WhiteArgbVec);
            prog.Uniform("extraGlow", 0);
            prog.Uniform("applyColor", 0);
            prog.Uniform("noTexture", 0f);
            prog.BindTexture2D("tex2d", Texture.TextureId, 0);

            mvMat
            .Set(api.Render.CurrentModelviewMatrix)
            .Translate(x, y, 60)
            .Scale(Texture.Width, Texture.Height, 0)
            .Scale(0.5f, 0.5f, 0)
            .RotateZ(-entity.Pos.Yaw + 90 * GameMath.DEG2RAD)
            ;

            prog.UniformMatrix("projectionMatrix", api.Render.CurrentProjectionMatrix);
            prog.UniformMatrix("modelViewMatrix", mvMat.Values);

            api.Render.RenderMesh(quadModel);
        }
        public void OnRenderFrame(float deltaTime, EnumRenderStage stage)
        {
            prog.Use();
            prog.BindTexture2D("tex", capi.BlockTextureAtlas.Positions[0].atlasTextureId, 0);
            prog.Uniform("rgbaFogIn", capi.Render.FogColor);
            prog.Uniform("rgbaAmbientIn", capi.Render.AmbientColor);
            prog.Uniform("fogMinIn", capi.Render.FogMin);
            prog.Uniform("fogDensityIn", capi.Render.FogDensity);
            prog.UniformMatrix("projectionMatrix", capi.Render.CurrentProjectionMatrix);
            prog.UniformMatrix("modelViewMatrix", capi.Render.CameraMatrixOriginf);

            for (int i = 0; i < MechBlockRenderer.Count; i++)
            {
                MechBlockRenderer[i].OnRenderFrame(deltaTime, prog);
            }

            prog.Stop();
        }
Exemplo n.º 12
0
        public void OnRenderFrame(float deltaTime, EnumRenderStage stage)
        {
            if (prog.Disposed)
            {
                return;
            }
            IShaderProgram curShader = capi.Render.CurrentActiveShader;

            curShader.Stop();

            prog.Use();
            capi.Render.GlToggleBlend(true);
            prog.SetDefaultUniforms(capi);
            prog.BindTexture2D("iColor", capi.Render.FrameBuffers[(int)EnumFrameBuffer.Primary].ColorTextureIds[0], 0);

            capi.Render.RenderMesh(quadRef);
            prog.Stop();
            curShader.Use();
        }
        public void OnRenderFrame(float dt, EnumRenderStage stage)
        {
            if (!ShouldRender)
            {
                return;
            }

            bool shadowPass = stage != EnumRenderStage.Opaque;

            EntityPlayer entityPlayer = capi.World.Player.Entity;

            Mat4f.Identity(ModelMat);
            Mat4f.Translate(ModelMat, ModelMat, (float)(pos.X - entityPlayer.CameraPos.X), (float)(pos.Y - entityPlayer.CameraPos.Y), (float)(pos.Z - entityPlayer.CameraPos.Z));

            Mat4f.Translate(ModelMat, ModelMat, 0.5f, 0, 0.5f);
            Mat4f.RotateY(ModelMat, ModelMat, rotation.Y * GameMath.DEG2RAD);
            Mat4f.Translate(ModelMat, ModelMat, -0.5f, 0, -0.5f);

            IRenderAPI rpi = capi.Render;


            IShaderProgram prevProg = rpi.CurrentActiveShader;

            prevProg?.Stop();


            IShaderProgram prog = rpi.GetEngineShader(shadowPass ? EnumShaderProgram.Shadowmapentityanimated : EnumShaderProgram.Entityanimated);

            prog.Use();
            Vec4f lightrgbs = capi.World.BlockAccessor.GetLightRGBs((int)pos.X, (int)pos.Y, (int)pos.Z);

            rpi.GlToggleBlend(true, EnumBlendMode.Standard);

            if (!shadowPass)
            {
                prog.Uniform("rgbaAmbientIn", rpi.AmbientColor);
                prog.Uniform("rgbaFogIn", rpi.FogColor);
                prog.Uniform("fogMinIn", rpi.FogMin);
                prog.Uniform("fogDensityIn", rpi.FogDensity);
                prog.Uniform("rgbaLightIn", lightrgbs);
                prog.Uniform("renderColor", ColorUtil.WhiteArgbVec);
                prog.Uniform("alphaTest", 0.1f);
                prog.UniformMatrix("modelMatrix", ModelMat);
                prog.UniformMatrix("viewMatrix", rpi.CameraMatrixOriginf);
                prog.Uniform("windWaveIntensity", (float)0);
                prog.Uniform("skipRenderJointId", -2);
                prog.Uniform("skipRenderJointId2", -2);
                prog.Uniform("glitchEffectStrength", 0f);
            }
            else
            {
                prog.UniformMatrix("modelViewMatrix", Mat4f.Mul(new float[16], capi.Render.CurrentModelviewMatrix, ModelMat));
            }

            prog.BindTexture2D("entityTex", textureId, 0);
            prog.UniformMatrix("projectionMatrix", rpi.CurrentProjectionMatrix);

            prog.Uniform("addRenderFlags", 0);


            prog.UniformMatrices(
                "elementTransforms",
                GlobalConstants.MaxAnimatedElements,
                animator.Matrices
                );

            capi.Render.RenderMesh(meshref);

            prog.Stop();
            prevProg?.Use();
        }
Exemplo n.º 14
0
        public void OnRenderFrame(float deltaTime, EnumRenderStage stage)
        {
            if (fallTime < -1)
            {
                capi.Event.UnregisterRenderer(this, stage);
                Dispose();
                return;
            }

            float percent = fallTime / startFallTime;

            IRenderAPI rpi    = capi.Render;
            Vec3d      camPos = capi.World.Player.Entity.CameraPos;

            if (isLeaves)
            {
                rpi.GlDisableCullFace();
            }

            rpi.GlToggleBlend(true);

            bool shadowPass = stage != EnumRenderStage.Opaque;

            IShaderProgram prevProg = rpi.CurrentActiveShader;

            prevProg?.Stop();

            IShaderProgram sProg = shadowPass ? rpi.GetEngineShader(EnumShaderProgram.Shadowmapentityanimated) : rpi.PreparedStandardShader(pos.X, pos.Y, pos.Z);

            var mat = ModelMat
                      .Identity()
                      .Translate(pos.X - camPos.X, pos.Y - camPos.Y, pos.Z - camPos.Z)
            ;

            switch (fallDirection.Code)
            {
            case "north":
                mat.RotateXDeg(GameMath.Max(percent * 90.0f - 90.0f, -90.0f));
                break;

            case "south":
                mat.Translate(0, 0, 1);
                mat.RotateXDeg(GameMath.Min(percent * -90.0f + 90.0f, 90.0f));
                mat.Translate(0, 0, -1);
                break;

            case "east":
                mat.Translate(1, 0, 1);
                mat.RotateZDeg(GameMath.Max(percent * 90.0f - 90.0f, -90.0f));
                mat.Translate(-1, 0, -1);
                break;

            case "west":
                mat.Translate(0, 0, 1);
                mat.RotateZDeg(GameMath.Min(percent * -90.0f + 90.0f, 90.0f));
                mat.Translate(0, 0, -1);
                break;

            default:
                break;
            }

            var matVals = mat.Values;

            if (!shadowPass)
            {
                var prog = (IStandardShaderProgram)sProg;

                prog.Tex2D       = capi.BlockTextureAtlas.AtlasTextureIds[0];
                prog.ModelMatrix = matVals;

                prog.AlphaTest = 0.4f;

                prog.ViewMatrix       = rpi.CameraMatrixOriginf;
                prog.ProjectionMatrix = rpi.CurrentProjectionMatrix;
                if (fallTime < 0)
                {
                    prog.RgbaTint = new Vec4f(1, 1, 1, 1.0f - Math.Abs(fallTime));
                }
            }
            else
            {
                sProg.Use();
                sProg.BindTexture2D("entityTex", capi.BlockTextureAtlas.AtlasTextureIds[0], 1);
                sProg.UniformMatrix("projectionMatrix", rpi.CurrentProjectionMatrix);
                sProg.UniformMatrix("modelViewMatrix", Mat4f.Mul(new float[16], capi.Render.CurrentModelviewMatrix, matVals));
            }

            rpi.RenderMesh(treeMesh);
            sProg.Stop();

            prevProg?.Use();

            fallTime -= deltaTime;
        }
Exemplo n.º 15
0
        public void OnRenderFrame(float deltaTime, EnumRenderStage stage)
        {
            var plrPos = capi.World.Player.Entity.Pos;
            var bh     = capi.World.Player.Entity.GetBehavior <EntityBehaviorTemporalStabilityAffected>();

            if (bh != null)
            {
                bh.stabilityOffset = 0;
            }

            if (modsys.nearestRifts.Length > 0)
            {
                Rift rift = modsys.nearestRifts[0];

                float dist   = Math.Max(0, GameMath.Sqrt(plrPos.SquareDistanceTo(rift.Position)) - 1 - rift.Size / 2f);
                float f      = Math.Max(0, 1 - dist / 3f);
                float jitter = capi.World.Rand.NextDouble() < 0.25 ? f * ((float)capi.World.Rand.NextDouble() - 0.5f) / 1f : 0;

                GlobalConstants.GuiGearRotJitter = jitter;

                capi.ModLoader.GetModSystem <SystemTemporalStability>().modGlitchStrength = Math.Min(1, f * 1.3f);

                if (bh != null)
                {
                    bh.stabilityOffset = -Math.Pow(Math.Max(0, 1 - dist / 3), 2) * 20;
                }
            }
            else
            {
                capi.ModLoader.GetModSystem <SystemTemporalStability>().modGlitchStrength = 0;
            }

            counter += deltaTime;
            if (capi.World.Rand.NextDouble() < 0.012)
            {
                counter += 20 * (float)capi.World.Rand.NextDouble();
            }

            capi.Render.GLDepthMask(false);

            prog.Use();
            prog.BindTexture2D("primaryFb", capi.Render.FrameBuffers[(int)EnumFrameBuffer.Primary].ColorTextureIds[0], 0);
            prog.BindTexture2D("depthTex", capi.Render.FrameBuffers[(int)EnumFrameBuffer.Primary].DepthTextureId, 1);
            prog.UniformMatrix("projectionMatrix", capi.Render.CurrentProjectionMatrix);


            int width  = capi.Render.FrameWidth;
            int height = capi.Render.FrameHeight;

            prog.Uniform("counter", counter);
            float bf = 200 + (float)GameMath.Sin(capi.InWorldEllapsedMilliseconds / 24000.0) * 100;

            prog.Uniform("counterSmooth", bf);
            prog.Uniform("invFrameSize", new Vec2f(1f / width, 1f / height));
            int riftIndex = 0;

            cnt = (cnt + 1) % 3;

            foreach (var rift in rifts)
            {
                if (cnt == 0)
                {
                    rift.Visible = capi.World.BlockAccessor.GetChunkAtBlockPos((int)rift.Position.X, (int)rift.Position.Y, (int)rift.Position.Z) != null;
                }

                riftIndex++;
                matrixf.Identity();

                float dx = (float)(rift.Position.X - plrPos.X);
                float dy = (float)(rift.Position.Y - plrPos.Y);
                float dz = (float)(rift.Position.Z - plrPos.Z);

                matrixf.Translate(dx, dy, dz);
                matrixf.ReverseMul(capi.Render.CameraMatrixOriginf);

                matrixf.Values[0] = 1f;
                matrixf.Values[1] = 0f;
                matrixf.Values[2] = 0f;

                //matrixf.Values[4] = 0f;
                //matrixf.Values[5] = 1f;
                //matrixf.Values[6] = 0f;

                matrixf.Values[8]  = 0f;
                matrixf.Values[9]  = 0f;
                matrixf.Values[10] = 1f;

                float size = rift.GetNowSize(capi);
                matrixf.Scale(size, size, size);

                prog.UniformMatrix("modelViewMatrix", matrixf.Values);
                prog.Uniform("riftIndex", riftIndex);

                capi.Render.RenderMesh(meshref);

                if (dx * dx + dy * dy + dz * dz < 40 * 40)
                {
                    Vec3d ppos = rift.Position;
                    capi.World.SpawnParticles(0.1f, ColorUtil.ColorFromRgba(21 / 2, 70 / 2, 116 / 2, 128), ppos, ppos, new Vec3f(-0.125f, -0.125f, -0.125f), new Vec3f(0.125f, 0.125f, 0.125f), 5, 0, (0.125f / 2 + (float)capi.World.Rand.NextDouble() * 0.25f) / 2);
                }
            }


            counter = GameMath.Mod(counter + deltaTime, GameMath.TWOPI * 100f);

            prog.Stop();

            capi.Render.GLDepthMask(true);
        }
Exemplo n.º 16
0
        public void OnRenderFrame(float dt, EnumRenderStage stage)
        {
            if (!ShouldRender)
            {
                return;
            }

            animator.OnFrame(activeAnimationsByAnimCode, dt);

            EntityPlayer entityPlayer = capi.World.Player.Entity;

            Mat4f.Identity(ModelMat);
            Mat4f.Translate(ModelMat, ModelMat, (float)(pos.X - entityPlayer.CameraPos.X), (float)(pos.Y - entityPlayer.CameraPos.Y), (float)(pos.Z - entityPlayer.CameraPos.Z));

            Mat4f.Translate(ModelMat, ModelMat, 0.5f, 0, 0.5f);
            Mat4f.RotateY(ModelMat, ModelMat, rotation.Y * GameMath.DEG2RAD);
            Mat4f.Translate(ModelMat, ModelMat, -0.5f, 0, -0.5f);

            IRenderAPI rpi = capi.Render;


            IShaderProgram prevProg = rpi.CurrentActiveShader;

            prevProg?.Stop();


            IShaderProgram prog = rpi.GetEngineShader(EnumShaderProgram.Entityanimated);

            prog.Use();

            prog.Uniform("rgbaAmbientIn", rpi.AmbientColor);
            prog.Uniform("rgbaFogIn", rpi.FogColor);
            prog.Uniform("fogMinIn", rpi.FogMin);
            prog.Uniform("fogDensityIn", rpi.FogDensity);
            prog.BindTexture2D("entityTex", textureId, 0);
            prog.Uniform("alphaTest", 0.1f);
            prog.UniformMatrix("projectionMatrix", rpi.CurrentProjectionMatrix);


            rpi.GlToggleBlend(true, EnumBlendMode.Standard);


            Vec4f lightrgbs = capi.World.BlockAccessor.GetLightRGBs((int)pos.X, (int)pos.Y, (int)pos.Z);

            prog.Uniform("rgbaLightIn", lightrgbs);
            //prog.Uniform("extraGlow", entity.Properties.Client.GlowLevel);
            prog.UniformMatrix("modelMatrix", ModelMat);
            prog.UniformMatrix("viewMatrix", rpi.CameraMatrixOriginf);
            prog.Uniform("addRenderFlags", 0);
            prog.Uniform("windWaveIntensity", (float)0);

            /*color[0] = (entity.RenderColor >> 16 & 0xff) / 255f;
             * color[1] = ((entity.RenderColor >> 8) & 0xff) / 255f;
             * color[2] = ((entity.RenderColor >> 0) & 0xff) / 255f;
             * color[3] = ((entity.RenderColor >> 24) & 0xff) / 255f;
             *
             * prog.Uniform("renderColor", color);*/

            prog.Uniform("renderColor", ColorUtil.WhiteArgbVec);


            prog.UniformMatrices(
                "elementTransforms",
                GlobalConstants.MaxAnimatedElements,
                animator.Matrices
                );

            capi.Render.RenderMesh(meshref);

            prog.Stop();
            prevProg?.Use();
        }