Example #1
0
        public void Render(Camera camera, int depthmap, Matrix4 lightMatrix, Matrix4 modelMatrix, bool specialWireFrame = false)
        {
            if (!Checked)
            {
                return;
            }
            Shader shader;

            if (Runtime.renderType != Runtime.RenderTypes.Shaded)
            {
                shader = Runtime.shaders["NUD_Debug"];
            }
            else
            {
                shader = Runtime.shaders["NUD"];
            }
            GL.UseProgram(shader.programID);

            int renderType = (int)Runtime.renderType;

            Matrix4 mvpMatrix = camera.getMVPMatrix();

            GL.UniformMatrix4(shader.getAttribute("mvpMatrix"), false, ref mvpMatrix);

            // Perform the calculations here to reduce render times in shader
            Matrix4 sphereMapMatrix = camera.getModelViewMatrix();

            sphereMapMatrix.Invert();
            sphereMapMatrix.Transpose();
            GL.UniformMatrix4(shader.getAttribute("sphereMapMatrix"), false, ref sphereMapMatrix);

            #region MBN Uniforms

            shader = Runtime.shaders["MBN"];
            GL.UseProgram(shader.programID);

            if (Runtime.cameraLight)
            {
                GL.Uniform3(shader.getAttribute("difLightDirection"), Vector3.TransformNormal(new Vector3(0f, 0f, -1f), camera.getMVPMatrix().Inverted()).Normalized());
            }
            else
            {
                GL.Uniform3(shader.getAttribute("difLightDirection"), Lights.diffuseLight.direction);
            }

            #endregion

            #region DAT uniforms
            shader = Runtime.shaders["DAT"];
            GL.UseProgram(shader.programID);

            GL.Uniform3(shader.getAttribute("difLightColor"), Lights.diffuseLight.difR, Lights.diffuseLight.difG, Lights.diffuseLight.difB);
            GL.Uniform3(shader.getAttribute("ambLightColor"), Lights.diffuseLight.ambR, Lights.diffuseLight.ambG, Lights.diffuseLight.ambB);

            #endregion

            {
                if (BCH != null)
                {
                    foreach (BCH_Model mo in BCH.Models.Nodes)
                    {
                        mo.Render(camera.getMVPMatrix());
                    }
                }

                if (dat_melee != null && Runtime.shaders["DAT"].shadersCompiledSuccessfully())
                {
                    dat_melee.Render(camera.getMVPMatrix());
                }

                if (NUD != null && Runtime.shaders["NUD"].shadersCompiledSuccessfully() && Runtime.shaders["NUD_Debug"].shadersCompiledSuccessfully())
                {
                    if (Runtime.renderType != Runtime.RenderTypes.Shaded)
                    {
                        shader = Runtime.shaders["NUD_Debug"];
                    }
                    else
                    {
                        shader = Runtime.shaders["NUD"];
                    }

                    GL.UseProgram(shader.programID);

                    SetRenderSettingsUniforms(shader);
                    SetLightingUniforms(shader, camera);

                    GL.ActiveTexture(TextureUnit.Texture2);
                    GL.BindTexture(TextureTarget.TextureCubeMap, RenderTools.cubeMapHigh);
                    GL.Uniform1(shader.getAttribute("cmap"), 2);

                    GL.ActiveTexture(TextureUnit.Texture11);
                    GL.BindTexture(TextureTarget.Texture2D, depthmap);
                    GL.Uniform1(shader.getAttribute("shadowMap"), 11);

                    GL.Uniform1(shader.getAttribute("renderType"), renderType);
                    GL.Uniform1(shader.getAttribute("debugOption"), (int)Runtime.uvChannel);

                    GL.Uniform1(shader.getAttribute("elapsedTime"), (DateTime.Now.Second / 60f) * 100);

                    GL.UniformMatrix4(shader.getAttribute("modelMatrix"), false, ref modelMatrix);
                    GL.UniformMatrix4(shader.getAttribute("lightSpaceMatrix"), false, ref lightMatrix);

                    if (specialWireFrame)
                    {
                        Runtime.renderModelWireframe = true;
                        Runtime.renderModel          = false;
                    }

                    NUD.Render(VBN, camera);
                }
            }
        }