예제 #1
0
        public void Render(ModelShader shader)
        {
            if (!VertexBuffer.DataSet)
            {
                return;
            }

            GeometrySectionData geo = myGeometry[0];

            foreach (MaterialSplit mat in geo.MaterialSplits)
            {
                if (mat.Material.TextureCount > 0)
                {
                    TextureSectionData tex = mat.Material.Textures[0];
                    if (tex.Texture != null)
                    {
                        shader.SetTexture("tex_diffuse", tex.Texture);
                    }
                    if (tex.Mask != null)
                    {
                        shader.SetTexture("tex_mask", tex.Mask);
                        //shader.AlphaMask = true;
                    }
                    else
                    {
                        shader.AlphaMask = false;
                    }

                    shader.Colour = mat.Material.Colour;
                    GL.DrawElements(BeginMode.TriangleStrip, mat.VertexCount, DrawElementsType.UnsignedShort, mat.Offset * sizeof(UInt16));
                }
            }
        }
예제 #2
0
 public override void Render(ModelShader shader, RenderLayer layer)
 {
     foreach (Instance inst in myInstances)
     {
         inst.Render(shader);
     }
 }
예제 #3
0
        public static void BeginDrawModel(IVertexBuffer vertexBuffer, Matrix4 transform, MaterialInfo material)
        {
            ModelShader.Use();
            ModelShader.ModelMatrix.Set(transform);
            ModelShader.Material.Set(material);

            vertexBuffer.Bind();
            vertexBuffer.BindAttribute(ModelShader.Position, 0);
            vertexBuffer.BindAttribute(ModelShader.Normal, 12);
            vertexBuffer.BindAttribute(ModelShader.TexCoord, 24);
        }
예제 #4
0
 public static void InitializeResources()
 {
     ColorShader     = ProgramFactory.Create <ColorShaderProgram>();
     WireframeShader = ProgramFactory.Create <WireframeShaderProgram>();
     ModelShader     = ProgramFactory.Create <ModelShaderProgram>();
     ModelShader.Use();
     ModelShader.LightCount.Set(0);
     ModelShader.Lights.Set(new LightInfo[0]);
     WireframeShader2     = ProgramFactory.Create <WireframeShader2Program>();
     StudConnectionShader = ProgramFactory.Create <StudConnectionShaderProgram>();
     SimpleTextureShader  = ProgramFactory.Create <SimpleTextureShaderProgram>();
     GridShader           = ProgramFactory.Create <GridShaderProgram>();
 }
        public override void OnEnter(bool firstTime)
        {
            base.OnEnter(firstTime);

            GL.ClearColor(Color4.CornflowerBlue);

            CursorVisible = !myCaptureMouse;

            if (firstTime)
            {
                myCamera           = new Camera(MathHelper.Pi / 3.0f, (float)Width / (float)Height, stViewDists[myCurViewDist]);
                myShader           = new ModelShader();
                myShader.Camera    = myCamera;
                myShader.FogColour = Color4.CornflowerBlue;
                myCell             = ItemManager.GetCell(0);
                myTexDict          = ResourceManager.LoadTextureDictionary("ballyswater");
            }
        }
예제 #6
0
        public static void ReleaseResources()
        {
            if (ColorShader != null)
            {
                ColorShader.Dispose();
                ColorShader = null;
            }

            if (WireframeShader != null)
            {
                WireframeShader.Dispose();
                WireframeShader = null;
            }

            if (WireframeShader2 != null)
            {
                WireframeShader2.Dispose();
                WireframeShader2 = null;
            }

            if (ModelShader != null)
            {
                ModelShader.Dispose();
                ModelShader = null;
            }

            if (BoundingBoxBufffer != null)
            {
                BoundingBoxBufffer.Dispose();
                BoundingBoxBufffer = null;
            }

            if (StudConnectionShader != null)
            {
                StudConnectionShader.Dispose();
                StudConnectionShader = null;
            }

            if (SimpleTextureShader != null)
            {
                SimpleTextureShader.Dispose();
                SimpleTextureShader = null;
            }
        }
예제 #7
0
        public override void Render(ModelShader shader, RenderLayer layer)
        {
            float rx, rz;

            for (int x = 0; x < myGridWidth; ++x)
            {
                for (int z = 0; z < myGridDepth; ++z)
                {
                    ExteriorBlock blk = myInstGrid[x, z];

                    rx = blk.CenterPos.X - shader.Camera.Position.X;
                    rz = blk.CenterPos.Y - shader.Camera.Position.Z;

                    if ((rx * rx + rz * rz) < shader.Camera.ViewDistance2 + blk.Radius2)
                    {
                        blk.Render(shader, layer);
                    }
                }
            }
        }
예제 #8
0
        public static void InitializeMatrices(Camera camera)
        {
            var viewMatrix = camera.GetViewMatrix();
            var projection = camera.GetProjectionMatrix();

            WireframeShader.Use();
            WireframeShader.ViewMatrix.Set(viewMatrix);
            WireframeShader.Projection.Set(projection);

            WireframeShader2.Use();
            WireframeShader2.ViewMatrix.Set(viewMatrix);
            WireframeShader2.Projection.Set(projection);

            ColorShader.Use();
            ColorShader.ViewMatrix.Set(viewMatrix);
            ColorShader.Projection.Set(projection);

            ModelShader.Use();
            ModelShader.ViewMatrix.Set(viewMatrix);
            ModelShader.Projection.Set(projection);
            ModelShader.ViewPosition.Set(camera.Position);

            StudConnectionShader.Use();
            StudConnectionShader.ViewMatrix.Set(viewMatrix);
            StudConnectionShader.Projection.Set(projection);

            SimpleTextureShader.Use();
            SimpleTextureShader.ViewMatrix.Set(viewMatrix);
            SimpleTextureShader.Projection.Set(projection);

            if (UIRenderHelper.Freetype6Loaded)
            {
                UIRenderHelper.TextRenderer.ProjectionMatrix = projection;
                UIRenderHelper.TextRenderer.DrawingPrimitives.Clear();
            }

            TextViewMatrix = viewMatrix;

            GL.UseProgram(0);
        }
예제 #9
0
        public void Render(ModelShader shader)
        {
            float dist2 = (shader.Camera.Position - Position).LengthSquared;

            if ((Object.DrawDist >= 300.0f && !HasLOD && dist2 < shader.Camera.ViewDistance2) ||
                dist2 < Object.DrawDist2)
            {
                Culled = false;

                if (!Object.Loaded && !Object.ModelRequested)
                {
                    Object.RequestModel();
                }

                if (Object.Model != null)
                {
                    shader.ModelPos        = Position;
                    shader.ModelRot        = Rotation;
                    shader.BackfaceCulling = !Object.HasFlags(ObjectFlag.NoBackCull);

                    shader.Render(Object.Model);
                }
                else if (HasLOD)
                {
                    LOD.Render(shader);
                }
            }
            else
            {
                Culled = true;

                if (HasLOD)
                {
                    LOD.Render(shader);
                }
            }
        }
예제 #10
0
 public static void UnbindModelTexture()
 {
     ModelShader.Use();
     ModelShader.Texture.Set(TextureUnit.Texture0);
     ModelShader.UseTexture.Set(false);
 }
예제 #11
0
 public static void BindModelTexture(Texture2D texture, TextureUnit textureUnit)
 {
     ModelShader.Use();
     texture.Bind(textureUnit);
     ModelShader.Texture.BindTexture(textureUnit, texture);
 }
예제 #12
0
 public abstract void Render(ModelShader shader, RenderLayer layer);