public void Render(float deltaTime, bool drawSun) { if (Master.Sun != null) { sun = Master.Sun; sun.LightPower = 1; } StateManager.Disable(EnableCap.DepthTest); shader.Start(); shader.LoadMatrix4("projectionMatrix", Camera.Active.ProjectionMatrix); shader.LoadMatrix4("viewMatrix", Camera.Active.ViewMatrix.ClearTranslation()); shader.LoadVector3("sunPosition", Master.Sun != null ? Master.Sun.Position : Vector3.Zero); //shader.LoadColor3("fogColor", master.FogColor); //currentHour += (deltaTime); if (currentHour > 24) { currentHour -= 24; } else if (currentHour < 0) { currentHour += 24; } // http://i.imgur.com/Uj45YN2.png float timeP = currentHour / 24; /* * timeP timeT * midnight: 0 | 0.75 * noon: 0.5 | 0.25 * mid-sun-set: 0.75 | 0.5 * mid-sun-rise: 0.25 | 0 */ float timeT = timeP - 0.25f; if (timeT < 0) { timeT += 1; } else if (timeT > 1) { timeT -= 1; } timeT = timeT * MathHelper.TwoPi; float sunY = (float)Math.Sin(timeT); Master.LightFalloff = Interpolation.CubicBezier(0, 1, 1, 1, MathHelper.Clamp(sunY + 0.2f, 0, 1f)); Master.ShadowVisibility = sunY > 0 ? 1f : 0f;// MathHelper.Clamp(sunY, 0, 1f); float shadowMinBias = 0.0005f; float shadowMaxBias = 0.0015f; float shadowBiasRange = shadowMaxBias - shadowMinBias; Master.ShadowBias = MathHelper.Clamp( (((1.4f - sunY) * shadowMaxBias) - shadowMinBias), shadowMinBias, shadowMaxBias); if (Master.Sun != null) { sun.Position = new Vector3((float)Math.Cos(timeT), sunY, 0); } // 12 - 12 = 0 / 12 = 0 // 0 - 12 = -12 / 12 = -1 // 24 - 12 = 12 / 12 = 1 //float n = Math.Abs((currentHour - 12) / 12) * 1.5f; //float mapOff = MathHelper.Clamp(n * n, 0, 1); //Diagnostics.DashCMD.WriteLine("Hour: {0:N2}, Off: {1:N2}, Fade: {2:N2}", currentHour, mapOff, mapFade); //skyMapOffset = mapOff; shader.LoadFloat("skyMapOffset", 1f - Master.LightFalloff); shader.LoadFloat("skyMapFade", 1f); shader.LoadBool("renderSun", drawSun); GL.ActiveTexture(TextureUnit.Texture0); skyMap.Bind(); cube.Bind(); shader.EnableAttributes(); if (Master.GlobalWireframe) { StateManager.EnableWireframe(); } GL.DrawArrays(BeginMode.Triangles, 0, cube.VertexCount); StateManager.DisableWireframe(); shader.DisableAttributes(); GL.BindVertexArray(0); shader.Stop(); StateManager.Enable(EnableCap.DepthTest); }