Ejemplo n.º 1
0
        public static void SetDefaultUniforms(this IShaderProgram prog, ICoreClientAPI capi)
        {
            ShaderTest shaderTest = capi.ModLoader.GetModSystem <ShaderTest>();

            float[] controls = shaderTest.controls;
            Vec3f[] vec3s    = shaderTest.vec3s;
            float[] floats   = shaderTest.floats;

            prog.Uniform("iTime", capi.World.ElapsedMilliseconds / 500f);
            prog.Uniform("iResolution", new Vec2f(capi.Render.FrameWidth, capi.Render.FrameHeight));
            prog.Uniform("iMouse", new Vec2f(capi.Input.MouseX, capi.Input.MouseY));
            prog.Uniform("iCamera", new Vec2f(capi.World.Player.CameraPitch, capi.World.Player.CameraYaw));
            prog.Uniform("iCameraPos", EntityPos.GetViewVector(capi.Input.MousePitch, capi.Input.MouseYaw));

            prog.Uniform("iControls1", new Vec4f(controls[0], controls[1], controls[2], controls[3]));
            prog.Uniform("iControls2", new Vec4f(controls[4], controls[5], controls[6], controls[7]));
            prog.Uniform("iControls3", new Vec4f(controls[8], controls[9], controls[10], controls[11]));
            prog.Uniform("iControls4", new Vec2f(controls[12], controls[13]));

            prog.Uniform("iSunPos", vec3s[0]);
            prog.Uniform("iMoonPos", vec3s[1]);
            prog.Uniform("iPlayerPosition", vec3s[2]);
            prog.Uniform("iLookBlockPos", vec3s[3]);
            prog.Uniform("iLookEntityPos", vec3s[4]);

            prog.Uniform("iMoonPhase", floats[0]);
            prog.Uniform("iTemperature", floats[1]);
            prog.Uniform("iRainfall", floats[2]);
            prog.Uniform("iCurrentHealth", floats[3]);
            prog.Uniform("iMaxHealth", floats[4]);
            prog.Uniform("iActiveItem", floats[5]);
            prog.Uniform("iLookingAtBlock", floats[6]);
            prog.Uniform("iLookingAtEntity", floats[7]);
            prog.Uniform("iActiveTool", floats[8]);
            prog.Uniform("iTempScalar", floats[9]);
        }
Ejemplo n.º 2
0
        public void Update(float dt, ICoreClientAPI capi)
        {
            IGameCalendar calendar = capi.World.Calendar;

            dt *= calendar.SpeedOfTime / 60f;
            if (capi.IsGamePaused)
            {
                dt = 0;
            }

            WaterStillCounter = (WaterStillCounter + dt / 1.5f) % 2f;
            WaterFlowCounter  = (WaterFlowCounter + dt / 1.5f) % 6000f;
            WaterWaveCounter  = (WaterWaveCounter + dt * 0.75f) % 6000f;

            WindWaveCounter = (WindWaveCounter + (0.5f + 5 * GlobalConstants.CurrentWindSpeedClient.X * (1 - GlitchStrength)) * dt) % 6000f;
            WindSpeed       = GlobalConstants.CurrentWindSpeedClient.X;

            float freq = (0.4f + WindSpeed / 10);

            WindWaveCounterHighFreq = (WindWaveCounterHighFreq + freq * (0.5f + 5 * GlobalConstants.CurrentWindSpeedClient.X * (1 - GlitchStrength)) * dt) % 6000f;


            TimeCounter += dt;

            FogWaveCounter += 0.1f * dt;


            plrPos.Set(capi.World.Player.Entity.Pos.XInt, capi.World.Player.Entity.Pos.YInt, capi.World.Player.Entity.Pos.ZInt);

            // For godrays shader
            PlayerViewVector = EntityPos.GetViewVector(capi.Input.MousePitch, capi.Input.MouseYaw);

            Dusk = capi.World.Calendar.Dusk ? 1 : 0;


            PlayerToSealevelOffset = (float)capi.World.Player.Entity.Pos.Y - capi.World.SeaLevel;
            SeaLevel         = capi.World.SeaLevel;
            FrameWidth       = capi.Render.FrameWidth;
            BlockAtlasHeight = capi.BlockTextureAtlas.Size.Height;

            int y = plrPos.Y;

            plrPos.Y = capi.World.SeaLevel;
            ClimateCondition nowConds = capi.World.BlockAccessor.GetClimateAt(plrPos, EnumGetClimateMode.NowValues);

            plrPos.Y          = y;
            SeasonTemperature = (DescaleTemperature(nowConds.Temperature) - DescaleTemperature(nowConds.WorldGenTemperature)) / 255f;
            //Console.WriteLine(SeasonTemperature);

            // We might need to do the hemisphere thing as a single bit for every vertex
            SeasonRel = capi.World.Calendar.GetSeasonRel(plrPos);


            // updated by ClientWorldMap.cs
            // ColorMapRects

            // updated by RenderSkyColor.cs
            // DitherSeed, SkyTextureId, GlowTextureId, SkyDaylight

            // updated by RenderSunMoon.cs
            // SunPositionScreen, SunPosition3D, sunSpecularIntensity

            // updated by RenderShadowMap.cs:
            // ShadowRangeNear, ShadowZExtendNear, DropShadowIntensity
            // ToShadowMapSpaceMatrixNear, ShadowRangeFar, ShadowZExtendFar, ToShadowMapSpaceMatrixFar

            // updated by RenderPlayerEffects.cs:
            // DamageVignetting, PointLights*
        }
Ejemplo n.º 3
0
        public void CullInvisibleChunks()
        {
            if (!ClientSettings.Occlusionculling || game.WorldMap.chunks.Count < 100)
            {
                return;
            }

            Vec3d camPos = game.player.Entity.CameraPos;

            centerpos.Set((int)(camPos.X / chunksize), (int)(camPos.Y / chunksize), (int)(camPos.Z / chunksize));

            isAboveHeightLimit = centerpos.Y >= game.WorldMap.ChunkMapSizeY;

            playerViewVec = EntityPos.GetViewVector(game.mousePitch, game.mouseYaw).Normalize();

            lock (game.WorldMap.chunksLock)
            {
                foreach (var val in game.WorldMap.chunks)
                {
                    val.Value.SetVisible(false);
                }

                // We sometimes have issues with chunks adjacent to the player getting culled, so lets make these always visible
                for (int dx = -1; dx <= 1; dx++)
                {
                    for (int dy = -1; dy <= 1; dy++)
                    {
                        for (int dz = -1; dz <= 1; dz++)
                        {
                            long        index3d = game.WorldMap.ChunkIndex3D(dx + centerpos.X, dy + centerpos.Y, dz + centerpos.Z);
                            ClientChunk chunk   = null;

                            if (game.WorldMap.chunks.TryGetValue(index3d, out chunk))
                            {
                                chunk.SetVisible(true);
                            }
                        }
                    }
                }
            }


            // Add some 15 extra degrees to the field of view angle for safety
            float fov = GameMath.Cos(game.MainCamera.Fov + 15 * GameMath.DEG2RAD);

            for (int i = 0; i < cubicShellPositions.Length; i++)
            {
                Vec3i vec = cubicShellPositions[i];

                float dotProd = playerViewVec.Dot(cubicShellPositionsNormalized[i]);
                if (dotProd <= fov / 2)
                {
                    // Outside view frustum
                    continue;
                }

                // It seems that one trace can cause issues where chunks are culled when they shouldn't
                // 2 traces with a y-offset seems to mitigate most of that issue
                TraverseRayAndMarkVisible(centerpos, vec, 0.25);
                TraverseRayAndMarkVisible(centerpos, vec, 0.75);
            }
        }