/// <summary>
        /// Constructs a new plane primitive, with the specified size.
        /// </summary>
        public PlanePrimitive(Renderer Renderer, float width, float length, int tessellationU, int tessellationV)
        {
            this.Renderer = Renderer;
            Vector3 normal = new Vector3(0, 1, 0);
            CollisionShape = new BoxShape(new Vector3(width / 2, 0.001f, length / 2));
            for (int v = 0; v < tessellationV+1; v++)
            {
                for (int u = 0; u < tessellationU+1; u++)
                {
                    GeometryData.AddVertex(new Vector3((((float)u / (float)tessellationU) * width) - (width / 2), 0, (((float)v / (float)tessellationV) * length) - (length / 2)), normal, new Vector2(((float)width / (float)tessellationU) * u, ((float)length / (float)tessellationV) * v));
                }
            }
            for (int v = 0; v < tessellationV - 0; v++)
            {
                for (int u = 0; u < tessellationU - 0; u++)
                {
                    GeometryData.AddIndex(u + 0 + ((tessellationU + 1) * v));
                    GeometryData.AddIndex(u + 1 + ((tessellationU + 1) * v));
                    GeometryData.AddIndex(u + 0 + tessellationU + 1 + ((tessellationU + 1) * v));

                    GeometryData.AddIndex(u + 0 + tessellationU + 1 + ((tessellationU + 1) * v));
                    GeometryData.AddIndex(u + 1 + ((tessellationU + 1) * v));
                    GeometryData.AddIndex(u + 1 + tessellationU + 1 + ((tessellationU + 1) * v));
                }
            }
            InitializePrimitive();
        }
 public LightShader(Renderer Renderer)
 {
     this.Renderer = Renderer;
     Samplers = new List<SamplerState>();
     ShaderResources = new List<ShaderResourceView>();
     ConstantBuffers = new List<ConstantBufferWrapper>();
 }
 /// <summary>
 /// Constructs a new box primitive, with the specified dimensions.
 /// </summary>
 public BoxPrimitive(Renderer Renderer, Vector3 dimensions)
 {
     this.Renderer = Renderer;
     this.Dimensions = dimensions;
     CollisionShape = new BoxShape(new Vector3(dimensions.X / 2, dimensions.Y / 2, dimensions.Z / 2));
     GeometryData = GenerateGeometry();
 }
 /// <summary>
 /// Constructs a new sphere primitive,
 /// with the specified size and tessellation level.
 /// </summary>
 public SpherePrimitive(Renderer Renderer, float radius, int tessellation)
 {
     this.Renderer = Renderer;
     this.CollisionShape = new SphereShape(radius);
     this.Tessellation = tessellation - (tessellation % 2);
     if (Tessellation < 3)
         this.Tessellation = 3;
     this.Radius = radius;
     this.GeometryData = GenerateGeometry();
 }
 public ConstantBufferWrapper(Renderer Renderer, int SizeInBytes, ShaderType ShaderType, int slot)
 {
     this.Renderer = Renderer;
     this.SizeInBytes = SizeInBytes;
     this.ShaderType = ShaderType;
     this.ResourceSlot = slot;
     CBuffer = new Buffer(Renderer.Device, new BufferDescription()
     {
         Usage = ResourceUsage.Dynamic,
         BindFlags = BindFlags.ConstantBuffer,
         CpuAccessFlags = CpuAccessFlags.Write,
         OptionFlags = ResourceOptionFlags.None,
         SizeInBytes = SizeInBytes,
         StructureByteStride = 0,
     });
     this.Semantics = new List<Semantic>();
 }
        /// <summary>
        /// Constructs a new skinned mesh primitive, with given vertices and indices
        /// </summary>
        /// <param name="device">Device to create primitive with.</param>
        /// <param name="VerticesArray">An array of vertices</param>
        /// <param name="IndicesArray">An array of indices</param>
        public SkinnedMeshPrimitive(Renderer Renderer, Vertex[] VerticesArray, int[] IndicesArray, Bone[] Bones)
        {
            this.Renderer = Renderer;
            this.CollisionShape = new EmptyShape();
            this.AnimationClips = new List<AnimationClip>();
            this.Bones = new List<Bone>();
            this.BonesSID = new Dictionary<string, Bone>();

            List<Vector3> vertices = new List<Vector3>();
            List<int> triIndex = new List<int>();
            foreach (Vertex v in VerticesArray)
            {
                GeometryData.AddVertex(v);
            }
            for (int i = 0; i < IndicesArray.Length; i++)
            {
                GeometryData.AddIndex(IndicesArray[i]);
            }
            foreach (Bone b in Bones)
            {
                this.Bones.Add(b);
                BonesSID.Add(b.Name, b);
            }

            BufferDescription BBDesc = new BufferDescription()
            {
                Usage = ResourceUsage.Dynamic,
                BindFlags = BindFlags.ConstantBuffer,
                CpuAccessFlags = CpuAccessFlags.Write,
                OptionFlags = ResourceOptionFlags.None,
                SizeInBytes = MaxBones * (sizeof(float) * 4 * 4),
                StructureByteStride = 0,
            };
            BoneBuffer = new Buffer(Renderer.Device, BBDesc);

            InitializePrimitive();
        }
 public static ConstantBufferWrapper FromDescription(Renderer Renderer, ConstantBufferWrapperDescription desc)
 {
     ConstantBufferWrapper w = new ConstantBufferWrapper(Renderer, desc.SizeInBytes, desc.ShaderType, desc.ResourceSlot);
     w.Semantics = desc.Semantics;
     return w;
 }
 /// <summary>
 /// Constructs a new sphere primitive, using default settings.
 /// </summary>
 public SpherePrimitive(Renderer Renderer)
     : this(Renderer, 1, 16)
 {
 }
        static MaterialShader GenerateDefaultMaterial(Renderer Renderer)
        {
            string path = @"R:\Users\Rox Cox\Documents\Visual Studio 2013\Projects\LightingEngine_v2\LightingEngine_v2\LightingD3D11\HLSL\";
            ShaderFlags flags = ShaderFlags.Debug | ShaderFlags.EnableStrictness | ShaderFlags.PackMatrixRowMajor;
            MaterialShader m = new MaterialShader(Renderer);
            m.StaticMeshVertexDefinition = new VertexDefinition()
            {
                Parameters = new List<VertexParameterType>()
                {
                    VertexParameterType.Position,
                    VertexParameterType.Normal,
                    VertexParameterType.TextureCoordinate,
                    VertexParameterType.Tangent,
                    VertexParameterType.Binormal,
                }
            };
            using (ShaderBytecode bytecode = ShaderBytecode.CompileFromFile(path + "materialVS.hlsl", "VS", "vs_5_0", flags, EffectFlags.None))
            {
                m.VertexShader = new VertexShader(Renderer.Device, bytecode);
                m.StaticMeshInputLayout = m.StaticMeshVertexDefinition.GetInputLayout(bytecode);
            }
            /*using (ShaderBytecode bytecode = ShaderBytecode.CompileFromFile(path + "materialPS.hlsl", "ps_5_0"))
            {
                m.PixelShader = new PixelShader(Renderer.Device, bytecode);
            }*/
            m.Topology = PrimitiveTopology.TriangleList;
            m.Samplers.Add(SamplerState.FromDescription(Renderer.Device, new SamplerDescription()
            {
                AddressU = TextureAddressMode.Wrap,
                AddressV = TextureAddressMode.Wrap,
                AddressW = TextureAddressMode.Wrap,
                BorderColor = new Color4(1, 1, 1, 1),
                ComparisonFunction = Comparison.Never,
                Filter = Filter.Anisotropic,
                MaximumAnisotropy = 16,
                MaximumLod = float.MaxValue,
                MinimumLod = float.MinValue,
                MipLodBias = 0,
            }));
            ConstantBufferWrapper bf0 = new ConstantBufferWrapper(Renderer, sizeof(float) * 64, ShaderType.VertexShader, 0);
            bf0.Semantics.Add(Semantic.World);
            bf0.Semantics.Add(Semantic.ViewProj);
            bf0.Semantics.Add(Semantic.View);
            bf0.Semantics.Add(Semantic.WorldView);
            m.ConstantBuffers.Add(bf0);
            using (Texture2D tex = ContentHelper.TextureFromBitmap(Properties.Resources.notexture))
            {
                m.ShaderResources.Add(new ShaderResourceView(Renderer.Device, tex));
            }
            using (Texture2D tex = ContentHelper.TextureFromBitmap(Properties.Resources.notexture_NORM))
            {
                m.ShaderResources.Add(new ShaderResourceView(Renderer.Device, tex));
            }

            return m;
        }
 public static MaterialShader DefaultMaterial(Renderer Renderer)
 {
     if (defaultMaterial == null)
         defaultMaterial = GenerateDefaultMaterial(Renderer);
     return defaultMaterial;
 }
 public static MaterialShader BasicMaterial(Renderer Renderer, Texture2D DiffuseMap, Texture2D NormalMap)
 {
     MaterialShader m = GenerateDefaultMaterial(Renderer);
     m.ShaderResources[0].Dispose();
     m.ShaderResources[0] = new ShaderResourceView(Renderer.Device, DiffuseMap);
     m.ShaderResources[0].DebugName = DiffuseMap.DebugName;
     m.ShaderResources[1].Dispose();
     m.ShaderResources[1] = new ShaderResourceView(Renderer.Device, NormalMap);
     m.ShaderResources[1].DebugName = DiffuseMap.DebugName;
     return m;
 }
        public void SetBoneMatrices(Renderer renderer)
        {
            BoneMatrices = new Matrix[Bones.Count];

            //Gets and saves transforms
            for (int i = 0; i < Bones.Count; i++)
            {
                if (Ragdoll != null)
                    BoneMatrices[i] = Ragdoll.GetTransforms(Bones[i]);
                else
                    BoneMatrices[i] = Bones[i].Transforms;
            }

            //Passes skinning data to skinning buffer
            renderer.Context.MapSubresource(BoneBuffer, MapMode.WriteDiscard, MapFlags.None).Data.WriteRange(BoneMatrices);
            renderer.Context.UnmapSubresource(BoneBuffer, 0);
        }
 /// <summary>
 /// Constructs a new plane primitive, using default settings.
 /// </summary>
 public PlanePrimitive(Renderer Renderer)
     : this(Renderer, 1, 1, 1, 1)
 {
 }