Ejemplo n.º 1
0
 void renderTranspInt(ref int lightc, Frustum frustumToUse)
 {
     if (frustumToUse == null)
     {
         frustumToUse = camFrust;
     }
     if (TheClient.CVars.r_transplighting.ValueB)
     {
         RenderLights = true;
         for (int i = 0; i < Lights.Count; i++)
         {
             if (Lights[i] is SkyLight || frustumToUse == null || frustumToUse.ContainsSphere(Lights[i].EyePos.ToBVector(), Lights[i].MaxDistance))
             {
                 for (int x = 0; x < Lights[i].InternalLights.Count; x++)
                 {
                     lightc++;
                 }
             }
         }
         int c = 0;
         float[] l_dats1 = new float[LIGHTS_MAX * 16];
         float[] l_dats2 = new float[LIGHTS_MAX * 16];
         float[] s_mats = new float[LIGHTS_MAX * 16];
         for (int i = 0; i < Lights.Count; i++)
         {
             if (Lights[i] is SkyLight || frustumToUse == null || frustumToUse.ContainsSphere(Lights[i].EyePos.ToBVector(), Lights[i].MaxDistance))
             {
                 for (int x = 0; x < Lights[i].InternalLights.Count; x++)
                 {
                     Matrix4 lmat = Lights[i].InternalLights[x].GetMatrix();
                     float maxrange = (Lights[i].InternalLights[x] is LightOrtho) ? LightMaximum : Lights[i].InternalLights[x].maxrange;
                     Matrix4 matxyz = new Matrix4(Vector4.Zero, Vector4.Zero, Vector4.Zero, Vector4.Zero);
                     matxyz[0, 0] = maxrange <= 0 ? LightMaximum : maxrange;
                     // TODO: Diffuse Albedo
                     matxyz[0, 1] = 0.7f;
                     matxyz[0, 2] = 0.7f;
                     matxyz[0, 3] = 0.7f;
                     // TODO: Specular Albedo
                     matxyz[1, 0] = 0.7f;
                     matxyz[1, 3] = (Lights[i] is SpotLight) ? 1f : 0f;
                     matxyz[2, 0] = (Lights[i].InternalLights[x] is LightOrtho) ? 1f : 0f;
                     matxyz[2, 1] = 1f / TheClient.CVars.r_shadowquality.ValueI;
                     matxyz[2, 2] = 0.5f;
                     matxyz[2, 3] = (float)lightc;
                     matxyz[3, 0] = (float)ambient.X;
                     matxyz[3, 1] = (float)ambient.Y;
                     matxyz[3, 2] = (float)ambient.Z;
                     Matrix4 matabc = new Matrix4(Vector4.Zero, Vector4.Zero, Vector4.Zero, Vector4.Zero);
                     matabc[0, 0] = 0f;
                     matabc[0, 1] = 0f;
                     matabc[0, 2] = 0f;
                     matabc[1, 0] = (float)(Lights[i].EyePos.X - CameraPos.X);
                     matabc[1, 1] = (float)(Lights[i].EyePos.Y - CameraPos.Y);
                     matabc[1, 2] = (float)(Lights[i].EyePos.Z - CameraPos.Z);
                     matabc[2, 0] = MainEXP;
                     matabc[0, 3] = Lights[i].InternalLights[x].color.X;
                     matabc[2, 1] = Lights[i].InternalLights[x].color.Y;
                     matabc[2, 2] = Lights[i].InternalLights[x].color.Z;
                     for (int mx = 0; mx < 4; mx++)
                     {
                         for (int my = 0; my < 4; my++)
                         {
                             s_mats[c * 16 + mx * 4 + my] = lmat[mx, my];
                             l_dats1[c * 16 + mx * 4 + my] = matxyz[mx, my];
                             l_dats2[c * 16 + mx * 4 + my] = matabc[mx, my];
                         }
                     }
                     c++;
                     if (c >= LIGHTS_MAX)
                     {
                         goto lights_apply;
                     }
                 }
             }
         }
         lights_apply:
         CheckError("PreRenderTranspLights");
         if (TheClient.CVars.r_transpshadows.ValueB && TheClient.CVars.r_shadows.ValueB)
         {
             if (TheClient.CVars.r_transpll.ValueB)
             {
                 TheClient.s_transponlyvoxlitsh_ll = TheClient.s_transponlyvoxlitsh_ll.Bind();
             }
             else
             {
                 TheClient.s_transponlyvoxlitsh = TheClient.s_transponlyvoxlitsh.Bind();
             }
         }
         else
         {
             if (TheClient.CVars.r_transpll.ValueB)
             {
                 TheClient.s_transponlyvoxlit_ll = TheClient.s_transponlyvoxlit_ll.Bind();
             }
             else
             {
                 TheClient.s_transponlyvoxlit = TheClient.s_transponlyvoxlit.Bind();
             }
         }
         GL.UniformMatrix4(2, false, ref IdentityMatrix);
         GL.Uniform1(7, (float)TheClient.GlobalTickTimeLocal);
         GL.Uniform2(8, new Vector2(Width, Height));
         GL.Uniform1(9, (float)c);
         GL.UniformMatrix4(10, LIGHTS_MAX, false, s_mats);
         GL.UniformMatrix4(20, LIGHTS_MAX, false, l_dats1);
         GL.UniformMatrix4(30, LIGHTS_MAX, false, l_dats2);
         if (TheClient.CVars.r_transpshadows.ValueB && TheClient.CVars.r_shadows.ValueB)
         {
             if (TheClient.CVars.r_transpll.ValueB)
             {
                 TheClient.s_transponlylitsh_ll = TheClient.s_transponlylitsh_ll.Bind();
             }
             else
             {
                 TheClient.s_transponlylitsh = TheClient.s_transponlylitsh.Bind();
             }
         }
         else
         {
             if (TheClient.CVars.r_transpll.ValueB)
             {
                 TheClient.s_transponlylit_ll = TheClient.s_transponlylit_ll.Bind();
             }
             else
             {
                 TheClient.s_transponlylit = TheClient.s_transponlylit.Bind();
             }
         }
         GL.UniformMatrix4(2, false, ref IdentityMatrix);
         GL.Uniform2(8, new Vector2(Width, Height));
         GL.Uniform1(9, (float)c);
         GL.UniformMatrix4(10, LIGHTS_MAX, false, s_mats);
         GL.UniformMatrix4(20, LIGHTS_MAX, false, l_dats1);
         GL.UniformMatrix4(30, LIGHTS_MAX, false, l_dats2);
         GL.ActiveTexture(TextureUnit.Texture4);
         GL.BindTexture(TextureTarget.Texture2DArray, fbo_shadow_tex);
         GL.ActiveTexture(TextureUnit.Texture0);
         Render3D(this);
         CheckError("PostRenderTranspLights");
         GL.ActiveTexture(TextureUnit.Texture2);
         GL.BindTexture(TextureTarget.Texture2D, 0);
         GL.ActiveTexture(TextureUnit.Texture0);
         RenderLights = false;
     }
     else
     {
         if (TheClient.CVars.r_transpll.ValueB)
         {
             TheClient.s_transponlyvox_ll.Bind();
             // GL.UniformMatrix4(1, false, ref combined);
             GL.UniformMatrix4(2, false, ref IdentityMatrix);
             Matrix4 matabc = new Matrix4(Vector4.Zero, Vector4.Zero, Vector4.Zero, Vector4.Zero);
             matabc[0, 3] = (float)Width;
             matabc[1, 3] = (float)Height;
             GL.UniformMatrix4(9, false, ref matabc);
             TheClient.s_transponly_ll.Bind();
             //GL.UniformMatrix4(1, false, ref combined);
             GL.UniformMatrix4(2, false, ref IdentityMatrix);
             GL.UniformMatrix4(9, false, ref matabc);
         }
         else
         {
             TheClient.s_transponlyvox.Bind();
             //GL.UniformMatrix4(1, false, ref combined);
             GL.UniformMatrix4(2, false, ref IdentityMatrix);
             TheClient.s_transponly.Bind();
             //GL.UniformMatrix4(1, false, ref combined);
             GL.UniformMatrix4(2, false, ref IdentityMatrix);
         }
         Render3D(this);
     }
 }