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();
        }
Exemple #2
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();
        }