<commit_before>//
// This file is part of the game Voxalia, created by FreneticXYZ.
// This code is Copyright (C) 2016 FreneticXYZ under the terms of the MIT license.
// See README.md or LICENSE.txt for contents of the MIT license.
// If these are not available, see https://opensource.org/licenses/MIT
//

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL4;
using Voxalia.ClientGame.ClientMainSystem;
using Voxalia.Shared;
using System.Diagnostics;
using Voxalia.ClientGame.GraphicsSystems.LightingSystem;
using Voxalia.ClientGame.OtherSystems;

namespace Voxalia.ClientGame.GraphicsSystems
{
    public class View3D
    {
        /// <summary>
        /// Set this to whatever method call renders all 3D objects in this view.
        /// </summary>
        public Action<View3D> Render3D = null;

        public Action PostFirstRender = null;

        public bool ShadowsOnly = false;

        public bool ShadowingAllowed = false;

        public bool TranspShadows = false;

        public FBOID FBOid = FBOID.NONE;

        public int CurrentFBO = 0;

        public int CurrentFBOTexture = 0;

        public int CurrentFBODepth = 0;

        public bool RenderSpecular = false;

        public int Width;

        public int Height;

        public Material Headmat = Material.AIR;

        public Location SunLoc = Location.NaN;

        public Client TheClient;

        int fbo_texture;
        int fbo_main;

        int fbo_godray_main;
        int fbo_godray_texture;
        int fbo_godray_texture2;

        RenderSurface4Part RS4P;

        public double ShadowTime;
        public double FBOTime;
        public double LightsTime;
        public double TotalTime;

        public double ShadowSpikeTime;
        public double FBOSpikeTime;
        public double LightsSpikeTime;
        public double TotalSpikeTime;

        public Func<int> ShadowTexSize = () => 64;

        public Matrix4d OffsetWorld = Matrix4d.Identity;

        public const int MAT_LOC_VIEW = 1;

        public const int MAT_LOC_OBJECT = 2;

        public void SetMatrix(int mat_loc, Matrix4d mat)
        {
            Matrix4d temp = mat;
            if (!TheClient.IsOrtho)
            {
                temp = temp * OffsetWorld;
            }
            Matrix4 mat4f = new Matrix4((float)temp.M11, (float)temp.M12, (float)temp.M13, (float)temp.M14, (float)temp.M21, (float)temp.M22, (float)temp.M23, (float)temp.M24,
                (float)temp.M31, (float)temp.M32, (float)temp.M33, (float)temp.M34, (float)temp.M41, (float)temp.M42, (float)temp.M43, (float)temp.M44);
            GL.UniformMatrix4(mat_loc, false, ref mat4f);
        }

        public void FinalHDRGrab()
        {
            if (TheClient.CVars.r_hdr.ValueB)
            {
                float[] rd = new float[HDR_SPREAD * HDR_SPREAD];
                GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
                GL.BindFramebuffer(FramebufferTarget.ReadFramebuffer, hdrfbo);
                GL.ReadBuffer(ReadBufferMode.ColorAttachment0);
                GL.ReadPixels(0, 0, HDR_SPREAD, HDR_SPREAD, PixelFormat.Red, PixelType.Float, rd);
                GL.BindFramebuffer(FramebufferTarget.ReadFramebuffer, 0);
                GL.ReadBuffer(ReadBufferMode.None);
                float exp = FindExp(rd);
                exp = Math.Max(Math.Min(exp, 4.0f), 0.25f);
                exp = 1.0f / exp;
                float stepUp = (float)TheClient.gDelta * 0.05f;
                float stepDown = stepUp * 5.0f;
                float relative = Math.Abs(MainEXP - exp);
                float modder = 4f * relative;
                stepUp *= modder;
                stepDown *= modder;
                if (exp > MainEXP + stepUp)
                {
                    MainEXP += stepUp;
                }<commit_msg>lighting/HDR adjustments<commit_after>//
// This file is part of the game Voxalia, created by FreneticXYZ.
// This code is Copyright (C) 2016 FreneticXYZ under the terms of the MIT license.
// See README.md or LICENSE.txt for contents of the MIT license.
// If these are not available, see https://opensource.org/licenses/MIT
//

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL4;
using Voxalia.ClientGame.ClientMainSystem;
using Voxalia.Shared;
using System.Diagnostics;
using Voxalia.ClientGame.GraphicsSystems.LightingSystem;
using Voxalia.ClientGame.OtherSystems;

namespace Voxalia.ClientGame.GraphicsSystems
{
    public class View3D
    {
        /// <summary>
        /// Set this to whatever method call renders all 3D objects in this view.
        /// </summary>
        public Action<View3D> Render3D = null;

        public Action PostFirstRender = null;

        public bool ShadowsOnly = false;

        public bool ShadowingAllowed = false;

        public bool TranspShadows = false;

        public FBOID FBOid = FBOID.NONE;

        public int CurrentFBO = 0;

        public int CurrentFBOTexture = 0;

        public int CurrentFBODepth = 0;

        public bool RenderSpecular = false;

        public int Width;

        public int Height;

        public Material Headmat = Material.AIR;

        public Location SunLoc = Location.NaN;

        public Client TheClient;

        int fbo_texture;
        int fbo_main;

        int fbo_godray_main;
        int fbo_godray_texture;
        int fbo_godray_texture2;

        RenderSurface4Part RS4P;

        public double ShadowTime;
        public double FBOTime;
        public double LightsTime;
        public double TotalTime;

        public double ShadowSpikeTime;
        public double FBOSpikeTime;
        public double LightsSpikeTime;
        public double TotalSpikeTime;

        public Func<int> ShadowTexSize = () => 64;

        public Matrix4d OffsetWorld = Matrix4d.Identity;

        public const int MAT_LOC_VIEW = 1;

        public const int MAT_LOC_OBJECT = 2;

        public void SetMatrix(int mat_loc, Matrix4d mat)
        {
            Matrix4d temp = mat;
            if (!TheClient.IsOrtho)
            {
                temp = temp * OffsetWorld;
            }
            Matrix4 mat4f = new Matrix4((float)temp.M11, (float)temp.M12, (float)temp.M13, (float)temp.M14, (float)temp.M21, (float)temp.M22, (float)temp.M23, (float)temp.M24,
                (float)temp.M31, (float)temp.M32, (float)temp.M33, (float)temp.M34, (float)temp.M41, (float)temp.M42, (float)temp.M43, (float)temp.M44);
            GL.UniformMatrix4(mat_loc, false, ref mat4f);
        }

        public void FinalHDRGrab()
        {
            if (TheClient.CVars.r_hdr.ValueB)
            {
                float[] rd = new float[HDR_SPREAD * HDR_SPREAD];
                GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
                GL.BindFramebuffer(FramebufferTarget.ReadFramebuffer, hdrfbo);
                GL.ReadBuffer(ReadBufferMode.ColorAttachment0);
                GL.ReadPixels(0, 0, HDR_SPREAD, HDR_SPREAD, PixelFormat.Red, PixelType.Float, rd);
                GL.BindFramebuffer(FramebufferTarget.ReadFramebuffer, 0);
                GL.ReadBuffer(ReadBufferMode.None);
                float exp = FindExp(rd);
                exp = Math.Max(Math.Min(exp, 3.0f), 0.33333f);
                exp = 1.0f / exp;
                float stepUp = (float)TheClient.gDelta * 0.05f;
                float stepDown = stepUp * 5.0f;
                float relative = Math.Abs(MainEXP - exp);
                float modder = 3f * relative;
                stepUp *= modder;
                stepDown *= modder;
                if (exp > MainEXP + stepUp)
                {
                    MainEXP += stepUp;
                }
{'fraction_non_alphanumeric': 0.08671914677501269, 'fraction_numerical': 0.020187912646013204, 'mean_word_length': 2.0902314633189487, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3621003', 'n_tokens_mistral': 2502, 'n_tokens_neox': 2297, 'n_words': 597}