Ejemplo n.º 1
0
        private void RenderRecipeOutLine()
        {
            if (recipeOutlineMeshRef == null || api.HideGuis)
            {
                return;
            }
            IRenderAPI           rpi         = api.Render;
            IClientWorldAccessor worldAccess = api.World;
            EntityPos            plrPos      = worldAccess.Player.Entity.Pos;
            Vec3d camPos = worldAccess.Player.Entity.CameraPos;

            ModelMat.Set(rpi.CameraMatrixOriginf).Translate(pos.X - camPos.X, pos.Y - camPos.Y, pos.Z - camPos.Z);
            outLineColorMul.A = 1 - GameMath.Clamp((float)Math.Sqrt(plrPos.SquareDistanceTo(pos.X, pos.Y, pos.Z)) / 5 - 1f, 0, 1);

            rpi.LineWidth = 2;
            rpi.GLEnableDepthTest();
            rpi.GlToggleBlend(true);

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

            prog.Use();
            prog.UniformMatrix("projectionMatrix", rpi.CurrentProjectionMatrix);
            prog.UniformMatrix("modelViewMatrix", ModelMat.Values);
            prog.Uniform("colorIn", outLineColorMul);
            rpi.RenderMesh(recipeOutlineMeshRef);
            prog.Stop();
        }
Ejemplo n.º 2
0
        public void OnRenderFrame(float deltaTime, EnumRenderStage stage)
        {
            IShaderProgram curShader = capi.Render.CurrentActiveShader;

            Vec4f color = new Vec4f(1, 1, 1, 1);

            // Render rectangle
            curShader.Uniform("rgbaIn", color);
            curShader.Uniform("extraGlow", 0);
            curShader.Uniform("applyColor", 0);
            curShader.Uniform("tex2d", 0);
            curShader.Uniform("noTexture", 1f);

            mvMatrix
            .Set(capi.Render.CurrentModelviewMatrix)
            .Translate(10, 10, 50)
            .Scale(100, 20, 0)
            .Translate(0.5f, 0.5f, 0)
            .Scale(0.5f, 0.5f, 0)
            ;

            curShader.UniformMatrix("projectionMatrix", capi.Render.CurrentProjectionMatrix);
            curShader.UniformMatrix("modelViewMatrix", mvMatrix.Values);

            capi.Render.RenderMesh(whiteRectangleRef);


            // Render progress bar
            float width = (capi.World.ElapsedMilliseconds / 10f) % 100;

            mvMatrix
            .Set(capi.Render.CurrentModelviewMatrix)
            .Translate(10, 10, 50)
            .Scale(width, 20, 0)
            .Translate(0.5f, 0.5f, 0)
            .Scale(0.5f, 0.5f, 0)
            ;

            curShader.UniformMatrix("projectionMatrix", capi.Render.CurrentProjectionMatrix);
            curShader.UniformMatrix("modelViewMatrix", mvMatrix.Values);

            capi.Render.RenderMesh(progressQuadRef);
        }
        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();
            }
        }
Ejemplo n.º 5
0
        void updateLocalEyePosImmersiveFpMode()
        {
            AttachmentPointAndPose apap = AnimManager.Animator.GetAttachmentPointPose("Eyes");
            AttachmentPoint        ap   = apap.AttachPoint;

            float[] ModelMat    = Mat4f.Create();
            Matrixf tmpModelMat = new Matrixf();

            float bodyYaw   = BodyYaw;
            float rotX      = Properties.Client.Shape != null ? Properties.Client.Shape.rotateX : 0;
            float rotY      = Properties.Client.Shape != null ? Properties.Client.Shape.rotateY : 0;
            float rotZ      = Properties.Client.Shape != null ? Properties.Client.Shape.rotateZ : 0;
            float bodyPitch = WalkPitch;

            float lookOffset = (SidedPos.Pitch - GameMath.PI) / 9f;

            bool wasHoldPos = holdPosition;

            holdPosition = false;

            for (int i = 0; i < AnimManager.Animator.RunningAnimations.Length; i++)
            {
                RunningAnimation anim = AnimManager.Animator.RunningAnimations[i];
                if (anim.Running && anim.EasingFactor > anim.meta.HoldEyePosAfterEasein)
                {
                    if (!wasHoldPos)
                    {
                        prevAnimModelMatrix = (float[])apap.AnimModelMatrix.Clone();
                    }
                    holdPosition = true;
                    break;
                }
            }


            tmpModelMat
            .Set(ModelMat)
            .RotateX(SidedPos.Roll + rotX * GameMath.DEG2RAD)
            .RotateY(bodyYaw + (180 + rotY) * GameMath.DEG2RAD)
            .RotateZ(bodyPitch + rotZ * GameMath.DEG2RAD)
            .Mul(holdPosition ? prevAnimModelMatrix : apap.AnimModelMatrix)
            .Scale(Properties.Client.Size, Properties.Client.Size, Properties.Client.Size)
            .Translate(-0.5f, 0, -0.5f)
            .Translate(ap.PosX / 16f - lookOffset, ap.PosY / 16f - lookOffset / 1.3f, ap.PosZ / 16f)
            ;

            float[] pos = new float[4] {
                0, 0, 0, 1
            };
            float[] endVec = Mat4f.MulWithVec4(tmpModelMat.Values, pos);

            LocalEyePos.Set(endVec[0], endVec[1], endVec[2]);
        }
Ejemplo n.º 6
0
        public void CustomRender(float dt)
        {
            if (LineDebug && capi != null)
            {
                BlockPos originPos = CenterPosition.AsBlockPos;

                for (int i = 0; i < Constraints.Count; i++)
                {
                    ClothPoint p1 = Constraints[i].Point1;
                    ClothPoint p2 = Constraints[i].Point2;

                    debugUpdateMesh.xyz[i * 6 + 0] = (float)(p1.Pos.X - originPos.X);
                    debugUpdateMesh.xyz[i * 6 + 1] = (float)(p1.Pos.Y - originPos.Y) + 0.005f;
                    debugUpdateMesh.xyz[i * 6 + 2] = (float)(p1.Pos.Z - originPos.Z);

                    debugUpdateMesh.xyz[i * 6 + 3] = (float)(p2.Pos.X - originPos.X);
                    debugUpdateMesh.xyz[i * 6 + 4] = (float)(p2.Pos.Y - originPos.Y) + 0.005f;
                    debugUpdateMesh.xyz[i * 6 + 5] = (float)(p2.Pos.Z - originPos.Z);
                }


                capi.Render.UpdateMesh(debugMeshRef, debugUpdateMesh);

                IShaderProgram prog = capi.Shader.GetProgram((int)EnumShaderProgram.Autocamera);
                prog.Use();

                capi.Render.LineWidth = 6;
                capi.Render.BindTexture2d(0);

                capi.Render.GLDisableDepthTest();

                Vec3d cameraPos = capi.World.Player.Entity.CameraPos;

                mat.Set(capi.Render.CameraMatrixOrigin);
                mat.Translate(
                    (float)(originPos.X - cameraPos.X),
                    (float)(originPos.Y - cameraPos.Y),
                    (float)(originPos.Z - cameraPos.Z)
                    );

                prog.UniformMatrix("projectionMatrix", capi.Render.CurrentProjectionMatrix);
                prog.UniformMatrix("modelViewMatrix", mat.Values);

                capi.Render.RenderMesh(debugMeshRef);

                prog.Stop();


                capi.Render.GLEnableDepthTest();
            }
        }
Ejemplo n.º 7
0
        public void OnRenderFrame(float deltaTime, EnumRenderStage stage)
        {
            if (meshref == null || be.HammerStack == null)
            {
                return;
            }

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

            rpi.GlDisableCullFace();

            float rotY = be.facing.HorizontalAngleIndex * 90;
            float offx = be.facing == BlockFacing.NORTH || be.facing == BlockFacing.WEST ? -1 / 16f : 17 / 16f;

            ModelMat
            .Identity()
            .Translate(pos.X - camPos.X, pos.Y - camPos.Y, pos.Z - camPos.Z)
            .RotateYDeg(rotY)
            .Translate(offx, 12.5f / 16f, 0.5f)
            .RotateZ(AngleRad)
            .Translate(-offx, -12.5f / 16f, -0.5f)
            .RotateYDeg(-rotY)
            ;

            if (stage == EnumRenderStage.Opaque)
            {
                IStandardShaderProgram prog = rpi.PreparedStandardShader(pos.X, pos.Y, pos.Z);
                prog.Tex2D = api.BlockTextureAtlas.AtlasTextureIds[0];

                prog.ModelMatrix      = ModelMat.Values;
                prog.ViewMatrix       = rpi.CameraMatrixOriginf;
                prog.ProjectionMatrix = rpi.CurrentProjectionMatrix;
                rpi.RenderMesh(meshref);
                prog.Stop();

                AngleRad = be.Angle;
            }
            else
            {
                IRenderAPI rapi = api.Render;
                shadowMvpMat.Set(rapi.CurrentProjectionMatrix).Mul(rapi.CurrentModelviewMatrix).Mul(ModelMat.Values);

                rapi.CurrentActiveShader.BindTexture2D("tex2d", api.BlockTextureAtlas.AtlasTextureIds[0], 0);
                rapi.CurrentActiveShader.UniformMatrix("mvpMatrix", shadowMvpMat.Values);
                rapi.CurrentActiveShader.Uniform("origin", new Vec3f());

                rpi.RenderMesh(meshref);
            }
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// If an attachment point called "Center" exists, then this method
        /// offsets the creatures collision box so that the Center attachment point is the center of the collision box.
        /// </summary>
        public void AdjustCollisionBoxToAnimation(float dtFac)
        {
            float[] hitboxOff = new float[4] {
                0, 0, 0, 1
            };

            AttachmentPointAndPose apap = entity.AnimManager.Animator.GetAttachmentPointPose("Center");

            if (apap == null)
            {
                return;
            }

            AttachmentPoint ap = apap.AttachPoint;

            float rotX = entity.Properties.Client.Shape != null ? entity.Properties.Client.Shape.rotateX : 0;
            float rotY = entity.Properties.Client.Shape != null ? entity.Properties.Client.Shape.rotateY : 0;
            float rotZ = entity.Properties.Client.Shape != null ? entity.Properties.Client.Shape.rotateZ : 0;

            float[] ModelMat = Mat4f.Create();
            Mat4f.Identity(ModelMat);
            Mat4f.Translate(ModelMat, ModelMat, 0, entity.CollisionBox.Y2 / 2, 0);

            double[] quat = Quaterniond.Create();
            Quaterniond.RotateX(quat, quat, entity.Pos.Pitch + rotX * GameMath.DEG2RAD);
            Quaterniond.RotateY(quat, quat, entity.Pos.Yaw + (rotY + 90) * GameMath.DEG2RAD);
            Quaterniond.RotateZ(quat, quat, entity.Pos.Roll + rotZ * GameMath.DEG2RAD);

            float[] qf = new float[quat.Length];
            for (int k = 0; k < quat.Length; k++)
            {
                qf[k] = (float)quat[k];
            }
            Mat4f.Mul(ModelMat, ModelMat, Mat4f.FromQuat(Mat4f.Create(), qf));

            float scale = entity.Properties.Client.Size;

            Mat4f.Translate(ModelMat, ModelMat, 0, -entity.CollisionBox.Y2 / 2, 0f);
            Mat4f.Scale(ModelMat, ModelMat, new float[] { scale, scale, scale });
            Mat4f.Translate(ModelMat, ModelMat, -0.5f, 0, -0.5f);

            tmpModelMat
            .Set(ModelMat)
            .Mul(apap.AnimModelMatrix)
            .Translate(ap.PosX / 16f, ap.PosY / 16f, ap.PosZ / 16f)
            ;

            EntityPos epos = entity.SidedPos;

            float[] endVec = Mat4f.MulWithVec4(tmpModelMat.Values, hitboxOff);

            float motionX = endVec[0] - (entity.CollisionBox.X1 - entity.OriginCollisionBox.X1);
            float motionZ = endVec[2] - (entity.CollisionBox.Z1 - entity.OriginCollisionBox.Z1);

            if (Math.Abs(motionX) > 0.00001 || Math.Abs(motionZ) > 0.00001)
            {
                EntityPos posMoved = epos.Copy();
                posMoved.Motion.X = motionX;
                posMoved.Motion.Z = motionZ;

                moveDelta.Set(posMoved.Motion.X, posMoved.Motion.Y, posMoved.Motion.Z);

                collisionTester.ApplyTerrainCollision(entity, posMoved, dtFac, ref outposition);

                double reflectX = outposition.X - epos.X - motionX;
                double reflectZ = outposition.Z - epos.Z - motionZ;

                epos.Motion.X = reflectX;
                epos.Motion.Z = reflectZ;

                entity.CollisionBox.Set(entity.OriginCollisionBox);
                entity.CollisionBox.Translate(endVec[0], 0, endVec[2]);
            }
            //Console.WriteLine("{0}/{1}", reflectX, reflectZ);
        }
Ejemplo n.º 10
0
        protected void RenderHeldItem(float dt, bool isShadowPass, bool right)
        {
            IRenderAPI rapi  = capi.Render;
            ItemSlot   slot  = right ? eagent?.RightHandItemSlot : eagent?.LeftHandItemSlot;
            ItemStack  stack = slot?.Itemstack;

            AttachmentPointAndPose apap = entity.AnimManager.Animator.GetAttachmentPointPose(right ? "RightHand" : "LeftHand");

            if (apap == null || stack == null)
            {
                return;
            }

            AttachmentPoint        ap         = apap.AttachPoint;
            ItemRenderInfo         renderInfo = rapi.GetItemStackRenderInfo(slot, right ? EnumItemRenderTarget.HandTp : EnumItemRenderTarget.HandTpOff);
            IStandardShaderProgram prog       = null;

            if (renderInfo?.Transform == null)
            {
                return;                                // Happens with unknown items/blocks
            }
            ItemModelMat
            .Set(ModelMat)
            .Mul(apap.AnimModelMatrix)
            .Translate(renderInfo.Transform.Origin.X, renderInfo.Transform.Origin.Y, renderInfo.Transform.Origin.Z)
            .Scale(renderInfo.Transform.ScaleXYZ.X, renderInfo.Transform.ScaleXYZ.Y, renderInfo.Transform.ScaleXYZ.Z)
            .Translate(ap.PosX / 16f + renderInfo.Transform.Translation.X, ap.PosY / 16f + renderInfo.Transform.Translation.Y, ap.PosZ / 16f + renderInfo.Transform.Translation.Z)
            .RotateX((float)(ap.RotationX + renderInfo.Transform.Rotation.X) * GameMath.DEG2RAD)
            .RotateY((float)(ap.RotationY + renderInfo.Transform.Rotation.Y) * GameMath.DEG2RAD)
            .RotateZ((float)(ap.RotationZ + renderInfo.Transform.Rotation.Z) * GameMath.DEG2RAD)
            .Translate(-(renderInfo.Transform.Origin.X), -(renderInfo.Transform.Origin.Y), -(renderInfo.Transform.Origin.Z))
            ;


            if (isShadowPass)
            {
                rapi.CurrentActiveShader.BindTexture2D("tex2d", renderInfo.TextureId, 0);
                float[] mvpMat = Mat4f.Mul(ItemModelMat.Values, capi.Render.CurrentModelviewMatrix, ItemModelMat.Values);
                Mat4f.Mul(mvpMat, capi.Render.CurrentProjectionMatrix, mvpMat);

                capi.Render.CurrentActiveShader.UniformMatrix("mvpMatrix", mvpMat);
                capi.Render.CurrentActiveShader.Uniform("origin", new Vec3f());
            }
            else
            {
                prog = rapi.StandardShader;
                prog.Use();
                prog.DontWarpVertices = 0;
                prog.AddRenderFlags   = 0;
                prog.NormalShaded     = 1;
                prog.Tex2D            = renderInfo.TextureId;
                prog.RgbaTint         = ColorUtil.WhiteArgbVec;
                prog.AlphaTest        = renderInfo.AlphaTest;
                prog.DamageEffect     = renderInfo.DamageEffect;

                prog.OverlayOpacity = renderInfo.OverlayOpacity;
                if (renderInfo.OverlayTexture != null && renderInfo.OverlayOpacity > 0)
                {
                    prog.Tex2dOverlay2D     = renderInfo.OverlayTexture.TextureId;
                    prog.OverlayTextureSize = new Vec2f(renderInfo.OverlayTexture.Width, renderInfo.OverlayTexture.Height);
                    prog.BaseTextureSize    = new Vec2f(renderInfo.TextureSize.Width, renderInfo.TextureSize.Height);
                    TextureAtlasPosition texPos = rapi.GetTextureAtlasPosition(stack);
                    prog.BaseUvOrigin = new Vec2f(texPos.x1, texPos.y1);
                }


                int     temp      = (int)stack.Collectible.GetTemperature(capi.World, stack);
                float[] glowColor = ColorUtil.GetIncandescenceColorAsColor4f(temp);

                /*lightrgbs[0] += glowColor[0];
                *  lightrgbs[1] += glowColor[1];
                *  lightrgbs[2] += glowColor[2];*/

                var gi = GameMath.Clamp((temp - 500) / 3, 0, 255);
                prog.ExtraGlow     = gi;
                prog.RgbaAmbientIn = rapi.AmbientColor;
                prog.RgbaLightIn   = lightrgbs;
                prog.RgbaGlowIn    = new Vec4f(glowColor[0], glowColor[1], glowColor[2], gi / 255f);
                prog.RgbaFogIn     = rapi.FogColor;
                prog.FogMinIn      = rapi.FogMin;
                prog.FogDensityIn  = rapi.FogDensity;
                prog.NormalShaded  = renderInfo.NormalShaded ? 1 : 0;

                prog.ProjectionMatrix = rapi.CurrentProjectionMatrix;
                prog.ViewMatrix       = rapi.CameraMatrixOriginf;
                prog.ModelMatrix      = ItemModelMat.Values;
            }


            if (!renderInfo.CullFaces)
            {
                rapi.GlDisableCullFace();
            }

            rapi.RenderMesh(renderInfo.ModelRef);

            if (!renderInfo.CullFaces)
            {
                rapi.GlEnableCullFace();
            }

            if (!isShadowPass)
            {
                prog.DamageEffect = 0;
            }

            if (!isShadowPass)
            {
                prog.Stop();

                AdvancedParticleProperties[] ParticleProperties = stack.Collectible?.ParticleProperties;

                if (stack.Collectible != null && !capi.IsGamePaused)
                {
                    Vec4f        pos          = ItemModelMat.TransformVector(new Vec4f(stack.Collectible.TopMiddlePos.X, stack.Collectible.TopMiddlePos.Y, stack.Collectible.TopMiddlePos.Z, 1));
                    EntityPlayer entityPlayer = capi.World.Player.Entity;
                    accum += dt;
                    if (ParticleProperties != null && ParticleProperties.Length > 0 && accum > 0.025f)
                    {
                        accum = accum % 0.025f;

                        for (int i = 0; i < ParticleProperties.Length; i++)
                        {
                            AdvancedParticleProperties bps = ParticleProperties[i];
                            bps.basePos.X = pos.X + entity.Pos.X + -(entity.Pos.X - entityPlayer.CameraPos.X);
                            bps.basePos.Y = pos.Y + entity.Pos.Y + -(entity.Pos.Y - entityPlayer.CameraPos.Y);
                            bps.basePos.Z = pos.Z + entity.Pos.Z + -(entity.Pos.Z - entityPlayer.CameraPos.Z);

                            eagent.World.SpawnParticles(bps);
                        }
                    }
                }
            }
        }
Ejemplo n.º 11
0
        public void OnRenderFrame(float deltaTime, EnumRenderStage stage)
        {
            if (!renderClouds)
            {
                return;
            }

            if (!capi.IsGamePaused)
            {
                CloudTick(deltaTime);
            }

            if (capi.Render.FrameWidth == 0)
            {
                return;
            }

            prog.Use();
            prog.Uniform("sunPosition", capi.World.Calendar.SunPositionNormalized);


            double plrPosX = capi.World.Player.Entity.Pos.X;
            double plrPosZ = capi.World.Player.Entity.Pos.Z;

            double offsetX = committedState.CenterTilePos.X * CloudTileSize - plrPosX + windOffsetX;
            double offsetZ = committedState.CenterTilePos.Z * CloudTileSize - plrPosZ + windOffsetZ;


            prog.Uniform("sunColor", capi.World.Calendar.SunColor);
            prog.Uniform("dayLight", Math.Max(0, capi.World.Calendar.DayLightStrength - capi.World.Calendar.MoonLightStrength * 0.95f));
            prog.Uniform("windOffset", new Vec3f((float)offsetX, 0, (float)offsetZ));



            prog.Uniform("rgbaFogIn", capi.Ambient.BlendedFogColor);
            prog.Uniform("fogMinIn", capi.Ambient.BlendedFogMin);
            prog.Uniform("fogDensityIn", capi.Ambient.BlendedFogDensity);
            prog.Uniform("playerPos", capi.Render.ShaderUniforms.PlayerPos);
            prog.Uniform("tileOffset", new Vec2f((committedState.CenterTilePos.X - committedState.TileOffsetX) * CloudTileSize, (committedState.CenterTilePos.Z - committedState.TileOffsetZ) * CloudTileSize));

            prog.Uniform("cloudTileSize", CloudTileSize);
            prog.Uniform("cloudsLength", (float)CloudTileSize * CloudTileLength);

            prog.Uniform("globalCloudBrightness", blendedGlobalCloudBrightness);

            float yTranslate = (float)(weatherSys.CloudsYPosition * capi.World.BlockAccessor.MapSizeY + 0.5 - capi.World.Player.Entity.CameraPos.Y);

            prog.Uniform("cloudYTranslate", yTranslate);
            prog.Uniform("cloudCounter", (float)((capi.World.Calendar.TotalHours * 20) % 578f));

            prog.UniformMatrix("projectionMatrix", capi.Render.CurrentProjectionMatrix);

            //int cnt = capi.Render.PointLightsCount;
            //prog.Uniform("pointLightQuantity", cnt);
            //shv.PointLightsArray(cnt, ScreenManager.Platform.PointLights3);
            //shv.PointLightColorsArray(cnt, ScreenManager.Platform.PointLightColors3);

            prog.Uniform("flatFogDensity", capi.Ambient.BlendedFlatFogDensity);
            prog.Uniform("flatFogStart", capi.Ambient.BlendedFlatFogYPosForShader);


            mvMat
            .Set(capi.Render.MvMatrix.Top)
            .FollowPlayer()
            .Translate(offsetX, yTranslate, offsetZ)
            ;


            prog.UniformMatrix("modelViewMatrix", mvMat.Values);
            capi.Render.RenderMeshInstanced(cloudTilesMeshRef, QuantityCloudTiles);


            // Very slightly rotate all the clouds so it looks better when they pass through blocks
            // Putting this line before translate = Clouds no longer centered around the player
            // Putting it after the translate = Clouds hop by a few pixels on every reload
            // Need to find a correct solution for this
            // Mat4.Rotate(mv, mv, 0.04f, new float[] { 0, 1, 0 });

            prog.Stop();
        }
Ejemplo n.º 12
0
        public void OnRenderFrame(float deltaTime, EnumRenderStage stage)
        {
            if (!renderAurora)
            {
                return;
            }

            if (capi.Render.FrameWidth == 0)
            {
                return;
            }



            quarterSecAccum += deltaTime;
            if (quarterSecAccum > 0.25f)
            {
                plrPos.X = (int)capi.World.Player.Entity.CameraPos.X;
                plrPos.Y = capi.World.SeaLevel;
                plrPos.Z = (int)capi.World.Player.Entity.CameraPos.Z;

                clientClimateCond = capi.World.BlockAccessor.GetClimateAt(plrPos);
                quarterSecAccum   = 0;
            }

            if (clientClimateCond == null)
            {
                return;
            }

            float tempfac = GameMath.Clamp((Math.Max(0, -clientClimateCond.Temperature) - 5) / 15f, 0, 1);

            col.W = GameMath.Clamp(1 - 1.5f * capi.World.Calendar.DayLightStrength, 0, 1) * tempfac;

            if (col.W <= 0)
            {
                return;
            }

            prog.Use();
            prog.Uniform("color", col);
            prog.Uniform("rgbaFogIn", capi.Ambient.BlendedFogColor);
            prog.Uniform("fogMinIn", capi.Ambient.BlendedFogMin);
            prog.Uniform("fogDensityIn", capi.Ambient.BlendedFogDensity);
            prog.UniformMatrix("projectionMatrix", capi.Render.CurrentProjectionMatrix);

            prog.Uniform("flatFogDensity", capi.Ambient.BlendedFlatFogDensity);
            prog.Uniform("flatFogStart", capi.Ambient.BlendedFlatFogYPosForShader);

            float speedmul = capi.World.Calendar.SpeedOfTime / 60f;

            prog.Uniform("auroraCounter", (float)(capi.InWorldEllapsedMilliseconds / 4000.0 * speedmul) % 579f);


            mvMat
            .Set(capi.Render.MvMatrix.Top)
            .FollowPlayer()
            .Translate(
                0, //    capi.World.BlockAccessor.MapSizeX/2,
                (1.1f * capi.World.BlockAccessor.MapSizeY + 0.5 - capi.World.Player.Entity.CameraPos.Y),
                0  //   capi.World.BlockAccessor.MapSizeZ/2
                )
            ;

            prog.UniformMatrix("modelViewMatrix", mvMat.Values);
            capi.Render.RenderMesh(quadTilesRef);

            prog.Stop();
        }
Ejemplo n.º 13
0
        void RenderHeldItem(bool isShadowPass)
        {
            IRenderAPI rapi  = capi.Render;
            ItemStack  stack = (entity as IEntityAgent).RightHandItemSlot?.Itemstack;

            BlendEntityAnimator    bea  = curAnimator as BlendEntityAnimator;
            AttachmentPointAndPose apap = null;

            bea.AttachmentPointByCode.TryGetValue("RightHand", out apap);

            if (apap == null || stack == null)
            {
                return;
            }


            AttachmentPoint        ap           = apap.AttachPoint;
            ItemRenderInfo         renderInfo   = rapi.GetItemStackRenderInfo(stack, EnumItemRenderTarget.HandTp);
            IStandardShaderProgram prog         = null;
            EntityPlayer           entityPlayer = capi.World.Player.Entity;


            ItemModelMat
            .Set(ModelMat)
            .Mul(apap.Pose.AnimModelMatrix)
            .Translate(renderInfo.Transform.Origin.X, renderInfo.Transform.Origin.Y, renderInfo.Transform.Origin.Z)
            .Scale(renderInfo.Transform.ScaleXYZ.X, renderInfo.Transform.ScaleXYZ.Y, renderInfo.Transform.ScaleXYZ.Z)
            .Translate(ap.PosX / 16f + renderInfo.Transform.Translation.X, ap.PosY / 16f + renderInfo.Transform.Translation.Y, ap.PosZ / 16f + renderInfo.Transform.Translation.Z)
            .RotateX((float)(ap.RotationX + renderInfo.Transform.Rotation.X) * GameMath.DEG2RAD)
            .RotateY((float)(ap.RotationY + renderInfo.Transform.Rotation.Y) * GameMath.DEG2RAD)
            .RotateZ((float)(ap.RotationZ + renderInfo.Transform.Rotation.Z) * GameMath.DEG2RAD)
            .Translate(-(renderInfo.Transform.Origin.X), -(renderInfo.Transform.Origin.Y), -(renderInfo.Transform.Origin.Z))
            ;



            if (isShadowPass)
            {
                rapi.CurrentActiveShader.BindTexture2D("tex2d", renderInfo.TextureId, 0);
                float[] mvpMat = Mat4f.Mul(ItemModelMat.Values, capi.Render.CurrentModelviewMatrix, ItemModelMat.Values);
                Mat4f.Mul(mvpMat, capi.Render.CurrentProjectionMatrix, mvpMat);

                capi.Render.CurrentActiveShader.UniformMatrix("mvpMatrix", mvpMat);
                capi.Render.CurrentActiveShader.Uniform("origin", new Vec3f());
            }
            else
            {
                prog = rapi.StandardShader;
                prog.Use();
                prog.WaterWave = 0;
                prog.Tex2D     = renderInfo.TextureId;
                prog.RgbaTint  = ColorUtil.WhiteArgbVec;

                BlockPos pos       = entity.Pos.AsBlockPos;
                Vec4f    lightrgbs = capi.World.BlockAccessor.GetLightRGBs(pos.X, pos.Y, pos.Z);
                int      temp      = (int)stack.Collectible.GetTemperature(capi.World, stack);
                float[]  glowColor = ColorUtil.GetIncandescenceColorAsColor4f(temp);
                lightrgbs[0] += 2 * glowColor[0];
                lightrgbs[1] += 2 * glowColor[1];
                lightrgbs[2] += 2 * glowColor[2];

                prog.ExtraGlow     = GameMath.Clamp((temp - 500) / 3, 0, 255);
                prog.RgbaAmbientIn = rapi.AmbientColor;
                prog.RgbaLightIn   = lightrgbs;
                prog.RgbaBlockIn   = ColorUtil.WhiteArgbVec;
                prog.RgbaFogIn     = rapi.FogColor;
                prog.FogMinIn      = rapi.FogMin;
                prog.FogDensityIn  = rapi.FogDensity;

                prog.ProjectionMatrix = rapi.CurrentProjectionMatrix;
                prog.ViewMatrix       = rapi.CameraMatrixOriginf;
                prog.ModelMatrix      = ItemModelMat.Values;
            }


            if (!renderInfo.CullFaces)
            {
                rapi.GlDisableCullFace();
            }

            rapi.RenderMesh(renderInfo.ModelRef);

            if (!renderInfo.CullFaces)
            {
                rapi.GlEnableCullFace();
            }


            if (!isShadowPass)
            {
                prog.Stop();
            }
        }