/// <summary> /// /// </summary> /// <param name="rs"></param> /// <param name="maxTextures"></param> internal MaterialInstance ( RenderSystem rs, ContentManager content, MaterialData parameters, IEnumerable<TextureMapBind> textureBinds, SurfaceFlags surfaceFlags ) { if (rs==null) { throw new ArgumentNullException("rs"); } if (textureBinds.Count()<0 || textureBinds.Count()>MaxTextures) { throw new ArgumentException("textureCount", "Must be less or equal to " + MaxTextures.ToString() ); } // // Pipeline states : // var factory = rs.SceneRenderer.Factory; var gbufferRigid = SurfaceFlags.GBUFFER | SurfaceFlags.RIGID | surfaceFlags ; var gbufferSkinned = SurfaceFlags.GBUFFER | SurfaceFlags.SKINNED | surfaceFlags ; var shadowRigid = SurfaceFlags.SHADOW | SurfaceFlags.RIGID | surfaceFlags ; var shadowSkinned = SurfaceFlags.SHADOW | SurfaceFlags.SKINNED | surfaceFlags ; GBufferRigid = factory[ (int)gbufferRigid ]; GBufferSkinned = factory[ (int)gbufferSkinned ]; ShadowRigid = factory[ (int)shadowRigid ]; ShadowSkinned = factory[ (int)shadowSkinned ]; // // Textures : // var textures = textureBinds .Select( texBind => texBind.TextureMap.LoadTexture( content, texBind.FallbackPath ) ); var uvMods = new Vector4[MaxTextures]; textureBinds .Select( tb => tb.TextureMap ) .Select( tm => new Vector4( tm.ScaleU, tm.ScaleV, tm.OffsetU, tm.OffsetV ) ) .ToArray() .CopyTo( uvMods, 0 ); shaderResources = textures.Select( tex => tex.Srv ).ToArray(); // // Constants : // constBufferParams = new ConstantBuffer( rs.Device, typeof(MaterialData) ); constBufferParams.SetData( parameters ); constBufferUVMods = new ConstantBuffer( rs.Device, typeof(Vector4), MaxTextures ); constBufferUVMods.SetData( uvMods ); }
/// <summary> /// Creates gpu material /// </summary> /// <param name="rs"></param> /// <returns></returns> internal MaterialInstance CreateMaterialInstance ( RenderSystem rs, ContentManager content ) { var data = new MaterialData(); GetMaterialData( ref data ); var mtrl = new MaterialInstance( rs, content, data, GetTextureBindings(), GetSurfaceFlags() ); return mtrl; }
/// <summary> /// Updates MaterialData. /// </summary> /// <param name="data"></param> protected virtual void GetMaterialData ( ref MaterialData data ) { data.ColorLevel = ColorLevel ; data.SpecularLevel = SpecularLevel ; data.EmissionLevel = EmissionLevel ; data.RoughnessMinimum = RoughnessMinimum; data.RoughnessMaximum = RoughnessMaximum; data.DirtLevel = DirtLevel; }