Beispiel #1
0
        public SibenikMaterial(Device device, TweakBar bar, String name)
            : base(device, bar, name)
        {
            bar.AddColor(Prefix + "diffuse", "Diffuse", name, new Color3(1, 1, 1));
            bar.AddColor(Prefix + "specular", "Specular", name, new Color3(1, 1, 1));
            bar.AddFloat(Prefix + "shininess", "Shininess", name, 1, 256, 64, 0.1, 2);
            bar.AddFloat(Prefix + "brightness", "Brightness", name, 0, 15000, 5, 50, 2);

            pixelShader = Material.CompileShader(device, "sibenik");

            constantBuffer = Material.AllocateMaterialBuffer(device, BufferSize);

            sampler = new SamplerState(device, new SamplerStateDescription()
            {
                ComparisonFunction = Comparison.Always,
                AddressU = TextureAddressMode.Wrap,
                AddressV = TextureAddressMode.Wrap,
                AddressW = TextureAddressMode.Wrap,
                Filter = Filter.Anisotropic,
                BorderColor = Color4.Black,
                MaximumAnisotropy = 16,
                MaximumLod = 15,
                MinimumLod = 0,
                MipLodBias = 0,
            });
        }
Beispiel #2
0
        public GroundMaterial(Device device, TweakBar bar, String name)
            : base(device, bar, name)
        {
            bar.AddFloat(Prefix + "albedo", "Albedo", name, 0, 100, 30, 0.1, 2);

            pixelShader = Material.CompileShader(device, "ground");

            constantBuffer = Material.AllocateMaterialBuffer(device, BufferSize);

            sampler = new SamplerState(device, new SamplerStateDescription()
            {
                ComparisonFunction = Comparison.Always,
                AddressU = TextureAddressMode.Wrap,
                AddressV = TextureAddressMode.Wrap,
                AddressW = TextureAddressMode.Wrap,
                Filter = Filter.Anisotropic,
                BorderColor = Color4.Black,
                MaximumAnisotropy = 16,
                MaximumLod = 15,
                MinimumLod = 0,
                MipLodBias = 0,
            });
        }
Beispiel #3
0
 /// <summary>
 /// Creates any required tweak bars.
 /// </summary>
 /// <param name="window">The window to draw into.</param>
 private void SetupTweakBars(RenderForm window)
 {
     materialBar = new TweakBar(null, "Material Settings");
 }
Beispiel #4
0
        private void InitializeTweakBar()
        {
            if (!TweakBar.InitializeLibrary(device)) throw new ExternalException("Failed to initialize AntTweakBar!");
            else
            {
                mainBar = new TweakBar(null, "Configuration Options");

                /* Configuration options go below. */

                mainBar.AddFloat("gamma", "Gamma", "General", 1, 3, 2.2, 0.05, 3, "Gamma response to calibrate to the monitor.");
                mainBar.AddFloat("exposure", "Exposure", "General", 0.001, 1.5, 0.001, 0.001, 3, "Exposure level at which to render the scene.");
                mainBar.AddBoolean("diffraction", "Enable", "Diffraction", "Yes", "No", true, "Whether to display diffraction effects or not.");
                mainBar.AddInteger("quality", "Quality", "Diffraction", 1, 4, (int)Settings.quality, 1, "The quality of the diffraction effects (from 1 to 4).");
                mainBar.AddFloat("fnumber", "f-number", "Diffraction", 1, 16, 1.5, 0.05, 2, "The f-number at which to simulate the aperture.");
                mainBar.AddFloat("glare", "Glare", "Diffraction", 0, 1, 0, 0.01, 2);
                mainBar.AddFloat("size", "Size", "Diffraction", 0, 1, 0.5, 0.01, 2);

                mainBar.AddBoolean("scale_correct", "Scale Correction", "Diffraction", "Yes", "No", true);

                mainBar.AddFloat("rotation_sensitivity", "Rotation", "Navigation", 0, 5, Settings.rotationSensitivity, 0.01, 2, "The sensitivity of mouse rotation.");
                mainBar.AddFloat("movement_sensitivity", "Movement", "Navigation", 0, 1, Settings.movementSensitivity, 0.01, 2, "The sensitivity of keyboard movement.");

                mainBar.AddFloat("field_of_view", "Field Of View", "Navigation", 10, 120, 75, 1, 2, "The sensitivity of keyboard movement.");

                /* TweakBar listeners go below. */

                mainBar["quality"].VariableChange += QualityChange;

                mainBar["exposure"].VariableChange += ExposureChange;
                mainBar["gamma"].VariableChange += GammaChange;

                mainBar["fnumber"].VariableChange += FNumberChange;
                mainBar["glare"].VariableChange += GlareChange;
                mainBar["size"].VariableChange += SizeChange;
                mainBar["scale_correct"].VariableChange += ScaleCorrectChange;

                mainBar["rotation_sensitivity"].VariableChange += RotationChange;
                mainBar["movement_sensitivity"].VariableChange += MovementChange;
                mainBar["field_of_view"].VariableChange += FieldOfViewChange;
            }
        }
Beispiel #5
0
 /// <summary>
 /// Allocates a new material instance, under a given tweak bar and group. The material should
 /// create a sensible group inside the tweak bar it is provided, and place its options there.
 /// </summary>
 /// <param name="device">The graphics device to associate this new material instance to.</param>
 /// <param name="bar">The tweak bar to use. Can be null if this instance should not be configurable.</param>
 /// <param name="name">The material instance's name, which is guaranteed to be unique over all material instances.</param>
 public Material(Device device, TweakBar bar, String name)
 {
     Device = device;
     Name = name;
     Bar = bar;
 }
Beispiel #6
0
        /// <summary>
        /// Attempts to parse a definition file, which maps a set of
        /// mesh names with their corresponding material and initial
        /// attribute values. Will throw an exception on failure.
        /// </summary>
        /// <param name="definition">The definition file, line per line.</param>
        /// <returns>A mapping between mesh names and materials.</returns>
        public static Dictionary<String, Material> Parse(Device device, TweakBar bar, IEnumerable<String> definition)
        {
            try
            {
                Dictionary<String, Material> materials = new Dictionary<String, Material>();

                using (IEnumerator<String> data = definition.GetEnumerator())
                {
                    String currentMesh = null;

                    while (data.MoveNext())
                    {
                        String[] tokens = data.Current.Split('#');
                        if (tokens.Length == 0) continue;
                        String line = tokens[0].Trim();
                        if (line.Length == 0) continue;

                        if (line.StartsWith("mtl "))
                        {
                            if (TrimSplit(line).Length == 5)
                            {
                                String meshName = TrimSplit(line)[1];
                                String materialName = TrimSplit(line)[2];
                                String materialClass = TrimSplit(line)[3];
                                String materialVisibility = TrimSplit(line)[4];
                                Type materialType = Type.GetType(materialClass); /* Needs to be namespace-qualified. */
                                if (materialType == null) throw new ArgumentException("no such material (" + materialClass + ")");

                                if ((materialVisibility != "show") && (materialVisibility != "hide"))
                                    throw new ArgumentException("expected material visibility");
                                bool visible = (materialVisibility == "show");

                                if (meshName == "-") meshName = random.NextLong().ToString();

                                materials.Add(meshName, (Material)Activator.CreateInstance(materialType, device, bar, materialName));
                                if (!visible) AntTweakBar.TwDefine("'" + bar.Name + "'" + "/" + materialName + " visible=false");
                                currentMesh = meshName;
                            }
                            else throw new ArgumentException("invalid mesh material declaration");
                        }
                        else
                        {
                            if (currentMesh == null) throw new ArgumentException("no mesh material declared");

                            if (TrimSplit(line, '=').Length == 2)
                            {
                                String header        = TrimSplit(line, '=')[0].Trim();    /* [ATTRTYPE ATTRNAME] = ATTRVALUE */
                                String attribute     = TrimSplit(line, '=')[1].Trim();    /* ATTRTYPE ATTRNAME = [ATTRVALUE] */

                                if (TrimSplit(header, ' ').Length == 2)
                                {
                                    String attributeType = TrimSplit(header, ' ')[0].Trim();  /* [ATTRTYPE] ATTRNAME = ATTRVALUE */
                                    String attributeName = TrimSplit(header, ' ')[1].Trim();  /* ATTRTYPE [ATTRNAME] = ATTRVALUE */

                                    materials[currentMesh][attributeName] = ParseAttribute(attributeType, attribute);
                                }
                                else throw new ArgumentException("invalid material attribute declaration");
                            }
                            else throw new ArgumentException("invalid material attribute declaration");
                        }
                    }
                }

                return materials;
            }
            catch (Exception ex)
            {
                throw new ArgumentException("Failed to parse definition file: " + ex.Message + ".", ex);
            }
        }