Example #1
0
 public unsafe void SetWorld(WorldMatrixHandle world)
 {
     if (world.Source == (Matrix4x4 *)0)
     {
         var id = Matrix4x4.Identity;
         if (worldPosition != -1)
         {
             shader.SetMatrix(worldPosition, ref id);
         }
         if (normalMatrixPosition != -1)
         {
             shader.SetMatrix(normalMatrixPosition, ref id);
         }
     }
     else if (shader.UserTag != world.ID)
     {
         shader.UserTag = world.ID;
         if (worldPosition != -1)
         {
             shader.SetMatrix(worldPosition, (IntPtr)world.Source);
         }
         if (normalMatrixPosition != -1)
         {
             shader.SetMatrix(normalMatrixPosition, (IntPtr)(&world.Source[1]));
         }
     }
 }
Example #2
0
        public void DrawBuffer(int level, ResourceManager res, CommandBuffer buffer, Matrix4x4 world, ref Lighting lights, MaterialAnimCollection mc, Material overrideMat = null)
        {
            if (Levels == null || Levels.Length <= level)
            {
                return;
            }
            var l = Levels[level];

            if (l == null)
            {
                return;
            }
            WorldMatrixHandle wm = buffer.WorldBuffer.SubmitMatrix(ref world);

            for (int i = 0; i < l.Length; i++)
            {
                var          dc  = l[i];
                MaterialAnim ma  = null;
                Material     mat = overrideMat;
                if (mat == null)
                {
                    mat = dc.GetMaterial(res);
                    if (mat != null)
                    {
                        ma = dc.GetMaterialAnim(mc);
                    }
                    else
                    {
                        mat = res.DefaultMaterial;
                    }
                }
                float z = 0;
                if (mat.Render.IsTransparent)
                {
                    z = RenderHelpers.GetZ(world, mat.Render.Camera.Position, Center);
                }
                WorldMatrixHandle worldHandle = wm;
                if (dc.HasScale)
                {
                    Matrix4x4 tr = dc.Scale * world;
                    worldHandle = buffer.WorldBuffer.SubmitMatrix(ref tr);
                }

                buffer.AddCommand(mat.Render,
                                  ma,
                                  worldHandle,
                                  lights,
                                  dc.Buffer,
                                  PrimitiveTypes.TriangleList,
                                  dc.BaseVertex,
                                  dc.StartIndex,
                                  dc.PrimitiveCount,
                                  SortLayers.OBJECT,
                                  z
                                  );
            }
        }
Example #3
0
 public void AddCommand(RenderMaterial material, MaterialAnim anim, WorldMatrixHandle world, Lighting lights, VertexBuffer buffer, PrimitiveTypes primitive, int baseVertex, int start, int count, int layer, float z = 0, DfmSkinning skinning = null)
 {
     if (material.IsTransparent)
     {
         Transparents[transparentCommand++] = new RenderCommand()
         {
             Source       = material,
             MaterialAnim = anim,
             Lights       = lights,
             Buffer       = buffer,
             BaseVertex   = baseVertex,
             Start        = start,
             Count        = count,
             Primitive    = primitive,
             CmdType      = RenderCmdType.Material,
             World        = world,
             SortLayer    = layer,
             Z            = z
         };
     }
     else
     {
         if (skinning != null)
         {
             material.Bones        = BonesBuffer;
             material.BufferOffset = skinning.BufferOffset;
         }
         else
         {
             material.Bones = null;
         }
         material.MaterialAnim = anim;
         material.World        = world;
         material.Use(rstate, buffer.VertexType, ref lights);
         buffer.Draw(primitive, baseVertex, start, count);
         if (material.DoubleSided)
         {
             material.FlipNormals = true;
             material.UpdateFlipNormals();
             rstate.CullFace = CullFaces.Front;
             buffer.Draw(primitive, baseVertex, start, count);
             rstate.CullFace      = CullFaces.Back;
             material.FlipNormals = false;
         }
     }
 }
Example #4
0
 //TODO: Implement MaterialAnim for asteroids
 public unsafe void AddCommandFade(RenderMaterial material, WorldMatrixHandle world, Lighting lights, VertexBuffer buffer, PrimitiveTypes primitive, int start, int count, int layer, Vector2 fadeParams, float z = 0)
 {
     Transparents[transparentCommand++] = new RenderCommand()
     {
         Key          = RenderCommand.MakeKey(RenderType.Transparent, material.Key, layer, z, 0),
         Source       = material,
         MaterialAnim = null,
         Lights       = lights,
         Buffer       = buffer,
         Start        = start,
         Count        = count,
         Primitive    = primitive,
         CmdType      = RenderCmdType.MaterialFade,
         BaseVertex   = *(int *)(&fadeParams.X),
         Index        = *(int *)(&fadeParams.Y),
         World        = world,
     };
 }
Example #5
0
 public void AddCommand(RenderMaterial material, MaterialAnim anim, WorldMatrixHandle world, Lighting lights, VertexBuffer buffer, PrimitiveTypes primitive, int baseVertex, int start, int count, int layer, float z = 0, DfmSkinning skinning = null)
 {
     if (material.IsTransparent)
     {
         Transparents[transparentCommand++] = new RenderCommand()
         {
             Key          = RenderCommand.MakeKey(RenderType.Transparent, material.Key, layer, z, 0),
             Source       = material,
             MaterialAnim = anim,
             Lights       = lights,
             Buffer       = buffer,
             BaseVertex   = baseVertex,
             Start        = start,
             Count        = count,
             Primitive    = primitive,
             CmdType      = RenderCmdType.Material,
             World        = world,
         };
     }
     else
     {
         if (skinning != null)
         {
             material.Bones        = BonesBuffer;
             material.BufferOffset = skinning.BufferOffset;
         }
         else
         {
             material.Bones = null;
         }
         material.MaterialAnim = anim;
         material.World        = world;
         material.Use(rstate, buffer.VertexType, ref lights);
         if (material.DoubleSided)
         {
             rstate.Cull = false;
         }
         buffer.Draw(primitive, baseVertex, start, count);
         if (material.DoubleSided)
         {
             rstate.Cull = true;
         }
     }
 }
Example #6
0
 public void AddCommand(Shader shader, ShaderAction setup, Action <RenderState> cleanup, WorldMatrixHandle world, RenderUserData user, VertexBuffer buffer, PrimitiveTypes primitive, int start, int count, bool transparent, int layer, float z = 0)
 {
     if (transparent)
     {
         Transparents[transparentCommand++] = new RenderCommand()
         {
             Source      = shader,
             ShaderSetup = setup,
             World       = world,
             UserData    = user,
             Cleanup     = cleanup,
             Buffer      = buffer,
             Start       = start,
             Count       = count,
             Primitive   = primitive,
             CmdType     = RenderCmdType.Shader,
             BaseVertex  = -1,
             SortLayer   = transparent ? layer : SortLayers.OPAQUE,
             Z           = z
         };
     }
     else
     {
         throw new InvalidOperationException();
     }
 }
Example #7
0
 public void AddCommand(Shader shader, ShaderAction setup, Action <RenderContext> cleanup, WorldMatrixHandle world, RenderUserData user, VertexBuffer buffer, PrimitiveTypes primitive, int start, int count, bool transparent, int layer, float z = 0, int renIndex = 0)
 {
     if (transparent)
     {
         Transparents[transparentCommand++] = new RenderCommand()
         {
             Key         = RenderCommand.MakeKey(RenderType.Transparent, 0, layer, z, renIndex),
             Source      = shader,
             ShaderSetup = setup,
             World       = world,
             UserData    = user,
             Cleanup     = cleanup,
             Buffer      = buffer,
             Start       = start,
             Count       = count,
             Primitive   = primitive,
             CmdType     = RenderCmdType.Shader,
             BaseVertex  = -1,
         };
     }
     else
     {
         throw new InvalidOperationException();
     }
 }