Esempio n. 1
0
        /// <summary>
        /// aseta texturematriisit shadowmapping shaderia varten
        /// </summary>
        static void SetTextureMatrix()
        {
            Matrix4 projMatrix = GLExt.ProjectionMatrix, modelMatrix = GLExt.ModelViewMatrix;

            GLExt.MatrixMode(MatrixMode.Texture);
            GLExt.LoadIdentity();
            GLExt.Translate(0.5f, 0.5f, 0.5f); // remap from [-1,1]^2 to [0,1]^2
            GLExt.Scale(0.5f, 0.5f, 0.5f);
            GLExt.MultMatrix(ref projMatrix);
            GLExt.MultMatrix(ref modelMatrix);
            GLExt.MatrixMode(MatrixMode.Modelview);
        }
Esempio n. 2
0
        void Translate(Node node)
        {
            Node obj = node;

            if (node == null)
            {
                obj = this;
            }

            GLExt.Translate(obj.Position.X, obj.Position.Y, obj.Position.Z);
            GLExt.RotateZ(Rotation.Z);
            GLExt.RotateY(Rotation.Y);
            GLExt.RotateX(Rotation.X);
            GLExt.MultMatrix(ref OrigOrientationMatrix);
            GLExt.Scale(obj.Scale.X, obj.Scale.Y, obj.Scale.Z);
        }
Esempio n. 3
0
        public void RenderMesh()
        {
            if (Vbo == null)
            {
                return;
            }

            if (DoubleSided)
            {
                GL.Disable(EnableCap.CullFace);
            }
            if (VBO.FastRenderPass)
            {
                if (CastShadow)
                {
                    Vbo.Render();
                }
            }
            else
            {
                Material.SetMaterial();
                if (WorldMatrix != null)
                {
                    GLExt.MatrixMode(MatrixMode.Texture);
                    GLExt.PushMatrix();
                    GLExt.MultMatrix(ref WorldMatrix);
                    GLExt.MatrixMode(MatrixMode.Modelview);
                }

                Vbo.Render();

                if (WorldMatrix != null)
                {
                    GLExt.MatrixMode(MatrixMode.Texture);
                    GLExt.PopMatrix();
                    GLExt.MatrixMode(MatrixMode.Modelview);
                }
            }
            if (DoubleSided)
            {
                GL.Enable(EnableCap.CullFace);
            }
        }
Esempio n. 4
0
        public void RenderMesh()
        {
            if (DoubleSided)
            {
                GL.Disable(EnableCap.CullFace);
            }

            if (VBO.FastRenderPass == false)
            {
                Material.SetMaterial();
                GLExt.MatrixMode(MatrixMode.Texture);
                GL.ActiveTexture(TextureUnit.Texture0 + Settings.SHADOW_TEXUNIT);
                GLExt.PushMatrix();
                if (WorldMatrix != null)
                {
                    GLExt.MultMatrix(ref WorldMatrix);
                }
                GLExt.RotateX(-90);
                GLExt.MatrixMode(MatrixMode.Modelview);
            }

            if (VBO.FastRenderPass == false || CastShadow == true)
            {
                GLExt.RotateX(-90);

                for (int i = 0; i < model.Length; i++)
                {
                    if (model[i].vbo == null)
                    {
                        continue;
                    }

                    if (VBO.FastRenderPass == false)
                    {
                        model[i].texture.Bind(0);
                    }

                    // lasketaanko uusi asento (jos ei olla laskettu jo shadowpassis)
                    if (animCalculated == false)
                    {
                        // Interpolate skeletons between two frames
                        InterpolateSkeletons(ref curAnim.skelFrames, curAnim.curFrame, curAnim.nextFrame, curAnim.numJoints, curAnim.lastTime * curAnim.frameRate);
                        PrepareMesh();
                        animCalculated = true;
                    }
                    model[i].vbo.Render();
                }

                if (VBO.FastRenderPass == false)
                {
                    GLExt.MatrixMode(MatrixMode.Texture);
                    GL.ActiveTexture(TextureUnit.Texture0 + Settings.SHADOW_TEXUNIT);
                    GLExt.PopMatrix();
                    GLExt.MatrixMode(MatrixMode.Modelview);
                    animCalculated = false;
                }
            }
            if (DoubleSided)
            {
                GL.Enable(EnableCap.CullFace);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// renderoi partikkelit, sorttaa läpinäkyvät.
        /// </summary>
        public static new void Render()
        {
            GLExt.Color4(1f, 1, 1, 1f);
            GLExt.PushMatrix();
            GLExt.SetLighting(false);

            List <SortedList_Particles> slist = new List <SortedList_Particles>();

            GL.Disable(EnableCap.CullFace);

            int c = 0;

            // järjestetään taulukko kauimmaisesta lähimpään. pitää rendata siinä järjestyksessä.
            // vain läpikuultavat pitää järjestää. täysin näkyvät renderoidaan samantien.
            for (int q = 0; q < ParticleGroups.Count; q++)
            {
                Particles curpar = ParticleGroups[q];
                if (curpar.particles.Count <= 0)
                {
                    continue;
                }
                if (VBO.FastRenderPass == true)
                {
                    if (curpar.CastShadow == false)
                    {
                        continue;
                    }
                }

                curpar.particles[0].partTex.Bind(0);

                GLExt.PushMatrix();
                GLExt.MultMatrix(ref curpar.WorldMatrix);

                for (int w = 0; w < curpar.NumOfParticles; w++)
                {
                    Particle p = curpar.particles[w];
                    GLExt.PushMatrix();
                    GLExt.Translate(p.pos.X, p.pos.Y, p.pos.Z);
                    Matrix4 matrix = Matrix4.Identity;
                    matrix.Row3           = GLExt.ModelViewMatrix.Row3;
                    GLExt.ModelViewMatrix = matrix;

                    Vector3 v = curpar.WorldMatrix.Row3.Xyz + curpar.Position + p.pos;
                    if (Frustum.SphereInFrustum(v.X, v.Y, v.Z, 10) != 0)
                    {
                        if (VBO.FastRenderPass == true) // renderoi partikkeli depthbufferiin (varjostusta varten)
                        {
                            GLExt.Scale(p.size, p.size, p.size);
                            GLExt.RotateZ(p.zrot);
                            p.partTex.RenderBillboard();
                        }
                        else
                        {
                            c++;
                            if (p.isTransparent == true) // listaan renderoitavaks myöhemmin
                            {
                                float len = (Camera.cam.Position - matrix.Row3.Xyz).LengthSquared;
                                slist.Add(new SortedList_Particles(len, p, matrix));
                            }
                            else // rendataan se nyt, ei lisätä sortattavaks
                            {
                                GLExt.Scale(p.size, p.size, p.size);
                                GLExt.RotateZ(p.zrot);
                                GLExt.Color4(p.color.X, p.color.Y, p.color.Z, p.color.W);;
                                if (p.callBack != null)
                                {
                                    p.callBack(p);
                                }
                                p.partTex.RenderBillboard();
                            }
                        }
                    }
                    GLExt.PopMatrix();
                }
                GLExt.PopMatrix();
            }

            if (VBO.FastRenderPass == false)
            {
                slist.Sort(delegate(SortedList_Particles z1, SortedList_Particles z2) { return(z2.Len.CompareTo(z1.Len)); });
                GL.Enable(EnableCap.Blend);
                GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.One);

                // rendataan läpikuultavat
                GL.DepthMask(false); // ei kirjoiteta zbufferiin
                for (int q = 0; q < slist.Count; q++)
                {
                    Particle p = slist[q].Part;
                    if (VBO.FastRenderPass == false)
                    {
                        p.partTex.Bind(0);
                        GLExt.Color4(p.color.X, p.color.Y, p.color.Z, p.color.W);
                        if (p.callBack != null)
                        {
                            p.callBack(p);
                        }
                    }
                    GLExt.LoadMatrix(ref slist[q].Matrix);
                    GLExt.Scale(p.size, p.size, p.size);
                    GLExt.RotateZ(p.zrot);
                    p.partTex.RenderBillboard();
                }
                GL.DepthMask(true);
                GL.Disable(EnableCap.Blend);
            }
            GLExt.PopMatrix();

            GL.Enable(EnableCap.CullFace);
            GLExt.Color4(1, 1, 1, 1);
            GLExt.SetLighting(true);
            GameClass.NumOfObjects += c;
        }