public HexagonMeshItem8X16(Vector3 pos, int tileX, int tileY, Roughness rough = Roughness.Plain )
        {
            _pos = pos;
            _rough = rough;

            _texturePoints = HexagonTexture.GetPoints(tileX, tileY);
        }
Exemple #2
0
        public static BHX.Roughness ToGBXML(this Roughness roughness)
        {
            BHX.Roughness r = new BHX.Roughness();

            switch (roughness)
            {
            case Roughness.MediumRough:
                r.Value = "MediumRough";
                break;

            case Roughness.MediumSmooth:
                r.Value = "MediumSmooth";
                break;

            case Roughness.Rough:
                r.Value = "Rough";
                break;

            case Roughness.Smooth:
                r.Value = "Smooth";
                break;

            case Roughness.VeryRough:
                r.Value = "VeryRough";
                break;

            case Roughness.VerySmooth:
                r.Value = "VerySmooth";
                break;
            }

            return(r);
        }
Exemple #3
0
 /// <inheritdoc />
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         if (Ambient != null)
         {
             hashCode = hashCode * 59 + Ambient.GetHashCode();
         }
         if (Diffuse != null)
         {
             hashCode = hashCode * 59 + Diffuse.GetHashCode();
         }
         if (Specular != null)
         {
             hashCode = hashCode * 59 + Specular.GetHashCode();
         }
         if (Roughness != null)
         {
             hashCode = hashCode * 59 + Roughness.GetHashCode();
         }
         if (Fresnel != null)
         {
             hashCode = hashCode * 59 + Fresnel.GetHashCode();
         }
         return(hashCode);
     }
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="EnergyMaterialVegetation" /> class.
        /// </summary>
        /// <param name="roughness">roughness.</param>
        /// <param name="thickness">Thickness of the soil layer in meters. (default to 0.1D).</param>
        /// <param name="conductivity">Thermal conductivity of the dry soil in W/m-K. (default to 0.35D).</param>
        /// <param name="density">Density of the dry soil in kg/m3. (default to 1100D).</param>
        /// <param name="specificHeat">Specific heat of the dry soil in J/kg-K. (default to 1200D).</param>
        /// <param name="soilThermalAbsorptance">Fraction of incident long wavelength radiation that is absorbed by the soil. Default: 0.9. (default to 0.9D).</param>
        /// <param name="soilSolarAbsorptance">Fraction of incident solar radiation absorbed by the soil. Default: 0.7. (default to 0.7D).</param>
        /// <param name="soilVisibleAbsorptance">Fraction of incident visible wavelength radiation absorbed by the material. Default: 0.7. (default to 0.7D).</param>
        /// <param name="plantHeight">The height of plants in the vegetation in meters. (default to 0.2D).</param>
        /// <param name="leafAreaIndex">The projected leaf area per unit area of soil surface (aka. Leaf Area Index or LAI). Note that the fraction of vegetation cover is calculated directly from LAI using an empirical relation. (default to 1.0D).</param>
        /// <param name="leafReflectivity">The fraction of incident solar radiation that is reflected by the leaf surfaces. Solar radiation includes the visible spectrum as well as infrared and ultraviolet wavelengths. Typical values are 0.18 to 0.25. (default to 0.22D).</param>
        /// <param name="leafEmissivity">The ratio of thermal radiation emitted from leaf surfaces to that emitted by an ideal black body at the same temperature. (default to 0.95D).</param>
        /// <param name="minStomatalResist">The resistance of the plants to moisture transport [s/m]. Plants with low values of stomatal resistance will result in higher evapotranspiration rates than plants with high resistance. (default to 180D).</param>
        /// <param name="satVolMoistCont">The saturation moisture content of the soil by volume. (default to 0.3D).</param>
        /// <param name="residualVolMoistCont">The residual moisture content of the soil by volume. (default to 0.01D).</param>
        /// <param name="initVolMoistCont">The initial moisture content of the soil by volume. (default to 0.01D).</param>
        /// <param name="moistDiffModel">moistDiffModel.</param>
        /// <param name="identifier">Text string for a unique object ID. This identifier remains constant as the object is mutated, copied, and serialized to different formats (eg. dict, idf, osm). This identifier is also used to reference the object across a Model. It must be &lt; 100 characters, use only ASCII characters and exclude (, ; ! \\n \\t). (required).</param>
        /// <param name="displayName">Display name of the object with no character restrictions..</param>
        /// <param name="userData">Optional dictionary of user data associated with the object.All keys and values of this dictionary should be of a standard data type to ensure correct serialization of the object (eg. str, float, int, list)..</param>
        public EnergyMaterialVegetation
        (
            string identifier,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   // Required parameters
            string displayName = default, Object userData = default, Roughness roughness = Roughness.MediumRough, double thickness = 0.1D, double conductivity = 0.35D, double density = 1100D, double specificHeat = 1200D, double soilThermalAbsorptance = 0.9D, double soilSolarAbsorptance = 0.7D, double soilVisibleAbsorptance = 0.7D, double plantHeight = 0.2D, double leafAreaIndex = 1.0D, double leafReflectivity = 0.22D, double leafEmissivity = 0.95D, double minStomatalResist = 180D, double satVolMoistCont = 0.3D, double residualVolMoistCont = 0.01D, double initVolMoistCont = 0.01D, MoistureDiffusionModel moistDiffModel = MoistureDiffusionModel.Simple // Optional parameters
        ) : base(identifier: identifier, displayName: displayName, userData: userData)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           // BaseClass
        {
            this.Roughness              = roughness;
            this.Thickness              = thickness;
            this.Conductivity           = conductivity;
            this.Density                = density;
            this.SpecificHeat           = specificHeat;
            this.SoilThermalAbsorptance = soilThermalAbsorptance;
            this.SoilSolarAbsorptance   = soilSolarAbsorptance;
            this.SoilVisibleAbsorptance = soilVisibleAbsorptance;
            this.PlantHeight            = plantHeight;
            this.LeafAreaIndex          = leafAreaIndex;
            this.LeafReflectivity       = leafReflectivity;
            this.LeafEmissivity         = leafEmissivity;
            this.MinStomatalResist      = minStomatalResist;
            this.SatVolMoistCont        = satVolMoistCont;
            this.ResidualVolMoistCont   = residualVolMoistCont;
            this.InitVolMoistCont       = initVolMoistCont;
            this.MoistDiffModel         = moistDiffModel;

            // Set non-required readonly properties with defaultValue
            this.Type = "EnergyMaterialVegetation";

            // check if object is valid, only check for inherited class
            if (this.GetType() == typeof(EnergyMaterialVegetation))
            {
                this.IsValid(throwException: true);
            }
        }
        public HexagonMeshItem8X8(Vector3 pos, int index, Roughness rough = Roughness.Plain)
        {
            _pos = pos;
            _rough = rough;

            int tileX = index % 8;
            int tileY = index / 8;

            _texturePoints = HexagonTexture.GetPoints(tileX, tileY);
        }
Exemple #6
0
        private void Update(EvaluationContext context)
        {
            // Parameters
            var parameterBufferContent = new PbrMaterialParams
            {
                BaseColor     = BaseColor.GetValue(context),
                EmissiveColor = EmissiveColor.GetValue(context),
                Roughness     = Roughness.GetValue(context),
                Specular      = Specular.GetValue(context),
                Metal         = Metal.GetValue(context)
            };

            ResourceManager.Instance().SetupConstBuffer(parameterBufferContent, ref _parameterBuffer);

            // Textures
            var resourceManager = ResourceManager.Instance();
            var device          = resourceManager.Device;

            Utilities.Dispose(ref _baseColorMapSrv);
            var tex = BaseColorMap.GetValue(context) ?? PbrContextSettings.WhitePixelTexture;

            _baseColorMapSrv = new ShaderResourceView(device, tex);
            context.PbrMaterialTextures.AlbedoColorMap = _baseColorMapSrv;

            Utilities.Dispose(ref _normalMapSrv);
            var tex2 = NormalMap.GetValue(context) ?? PbrContextSettings.NormalFallbackTexture;

            _normalMapSrv = new ShaderResourceView(device, tex2);
            context.PbrMaterialTextures.NormalMap = _normalMapSrv;

            Utilities.Dispose(ref _rsmoMapSrv);
            var tex3 = RoughnessSpecularMetallicOcclusionMap.GetValue(context) ?? PbrContextSettings.RsmoFallbackTexture;

            _rsmoMapSrv = new ShaderResourceView(device, tex3);
            context.PbrMaterialTextures.RoughnessSpecularMetallicOcclusionMap = _rsmoMapSrv;

            Utilities.Dispose(ref _emissiveColorMapSrv);
            var tex4 = EmissiveColorMap.GetValue(context) ?? PbrContextSettings.WhitePixelTexture;

            _emissiveColorMapSrv = new ShaderResourceView(device, tex4);
            context.PbrMaterialTextures.EmissiveColorMap = _emissiveColorMapSrv;

            var previousParameters = context.PbrMaterialParams;

            context.PbrMaterialParams = _parameterBuffer;


            SubTree.GetValue(context);
            context.PbrMaterialParams = previousParameters;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="EnergyMaterialNoMass" /> class.
        /// </summary>
        /// <param name="rValue">The thermal resistance (R-value) of the material layer [m2-K/W]. (required).</param>
        /// <param name="roughness">roughness.</param>
        /// <param name="thermalAbsorptance">Fraction of incident long wavelength radiation that is absorbed by the material. Default value is 0.9. (default to 0.9D).</param>
        /// <param name="solarAbsorptance">Fraction of incident solar radiation absorbed by the material. Default value is 0.7. (default to 0.7D).</param>
        /// <param name="visibleAbsorptance">Fraction of incident visible wavelength radiation absorbed by the material. Default value is 0.7. (default to 0.7D).</param>
        /// <param name="identifier">Text string for a unique object ID. This identifier remains constant as the object is mutated, copied, and serialized to different formats (eg. dict, idf, osm). This identifier is also used to reference the object across a Model. It must be &lt; 100 characters, use only ASCII characters and exclude (, ; ! \\n \\t). (required).</param>
        /// <param name="displayName">Display name of the object with no character restrictions..</param>
        public EnergyMaterialNoMass
        (
            string identifier, double rValue,                                                                                                                                             // Required parameters
            string displayName = default, Roughness roughness = Roughness.MediumRough, double thermalAbsorptance = 0.9D, double solarAbsorptance = 0.7D, double visibleAbsorptance = 0.7D // Optional parameters
        ) : base(identifier: identifier, displayName: displayName)                                                                                                                        // BaseClass
        {
            this.RValue             = rValue;
            this.Roughness          = roughness;
            this.ThermalAbsorptance = thermalAbsorptance;
            this.SolarAbsorptance   = solarAbsorptance;
            this.VisibleAbsorptance = visibleAbsorptance;

            // Set non-required readonly properties with defaultValue
            this.Type = "EnergyMaterialNoMass";
        }
Exemple #8
0
        /// <inheritdoc />
        public bool Equals([AllowNull] Lighting other)
        {
            if (other == null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     VertexNormalsEpsilon == other.VertexNormalsEpsilon ||
                     VertexNormalsEpsilon != null &&
                     VertexNormalsEpsilon.Equals(other.VertexNormalsEpsilon)
                     ) &&
                 (
                     FaceNormalsEpsilon == other.FaceNormalsEpsilon ||
                     FaceNormalsEpsilon != null &&
                     FaceNormalsEpsilon.Equals(other.FaceNormalsEpsilon)
                 ) &&
                 (
                     Ambient == other.Ambient ||
                     Ambient != null &&
                     Ambient.Equals(other.Ambient)
                 ) &&
                 (
                     Diffuse == other.Diffuse ||
                     Diffuse != null &&
                     Diffuse.Equals(other.Diffuse)
                 ) &&
                 (
                     Specular == other.Specular ||
                     Specular != null &&
                     Specular.Equals(other.Specular)
                 ) &&
                 (
                     Roughness == other.Roughness ||
                     Roughness != null &&
                     Roughness.Equals(other.Roughness)
                 ) &&
                 (
                     Fresnel == other.Fresnel ||
                     Fresnel != null &&
                     Fresnel.Equals(other.Fresnel)
                 ));
        }
 /// <summary>
 /// Test to see if this material is equal to another.
 /// </summary>
 /// <param name="other">The material to test against.</param>
 /// <returns>True if the object is equal to this one. False, otherwise.</returns>
 public bool Equals(MeshStandardMaterial other)
 {
     if (other == null)
     {
         return(false);
     }
     return(Roughness.Equals(other.Roughness) &&
            Metalness.Equals(other.Metalness) &&
            Ambient.Equals(other.Ambient) &&
            Color.Equals(other.Color) &&
            Emissive.Equals(other.Emissive) &&
            Map == other.Map &&
            BumpMap == other.BumpMap &&
            AlphaMap == other.AlphaMap &&
            EnvironmentMap == other.EnvironmentMap);
 }
Exemple #10
0
 public virtual void Release()
 {
     if (Albedo != null)
     {
         Albedo.Release();
         Albedo = null;
     }
     if (Height != null)
     {
         Height.Release();
         Height = null;
     }
     if (Normal != null)
     {
         Normal.Release();
         Normal = null;
     }
     if (Metallic != null)
     {
         Metallic.Release();
         Metallic = null;
     }
     if (Roughness != null)
     {
         Roughness.Release();
         Roughness = null;
     }
     if (Occlusion != null)
     {
         Occlusion.Release();
         Occlusion = null;
     }
     if (Thickness != null)
     {
         Thickness.Release();
         Thickness = null;
     }
     if (Emission != null)
     {
         Emission.Release();
         Emission = null;
     }
 }
Exemple #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EnergyMaterialNoMass" /> class.
        /// </summary>
        /// <param name="rValue">The thermal resistance (R-value) of the material layer [m2-K/W]. (required).</param>
        /// <param name="roughness">roughness.</param>
        /// <param name="thermalAbsorptance">Fraction of incident long wavelength radiation that is absorbed by the material. Default: 0.9. (default to 0.9D).</param>
        /// <param name="solarAbsorptance">Fraction of incident solar radiation absorbed by the material. Default: 0.7. (default to 0.7D).</param>
        /// <param name="visibleAbsorptance">Fraction of incident visible wavelength radiation absorbed by the material. Default: 0.7. (default to 0.7D).</param>
        /// <param name="identifier">Text string for a unique object ID. This identifier remains constant as the object is mutated, copied, and serialized to different formats (eg. dict, idf, osm). This identifier is also used to reference the object across a Model. It must be &lt; 100 characters, use only ASCII characters and exclude (, ; ! \\n \\t). (required).</param>
        /// <param name="displayName">Display name of the object with no character restrictions..</param>
        /// <param name="userData">Optional dictionary of user data associated with the object.All keys and values of this dictionary should be of a standard data type to ensure correct serialization of the object (eg. str, float, int, list)..</param>
        public EnergyMaterialNoMass
        (
            string identifier, double rValue,                                                                                                                                                                        // Required parameters
            string displayName = default, Object userData = default, Roughness roughness = Roughness.MediumRough, double thermalAbsorptance = 0.9D, double solarAbsorptance = 0.7D, double visibleAbsorptance = 0.7D // Optional parameters
        ) : base(identifier: identifier, displayName: displayName, userData: userData)                                                                                                                               // BaseClass
        {
            this.RValue             = rValue;
            this.Roughness          = roughness;
            this.ThermalAbsorptance = thermalAbsorptance;
            this.SolarAbsorptance   = solarAbsorptance;
            this.VisibleAbsorptance = visibleAbsorptance;

            // Set non-required readonly properties with defaultValue
            this.Type = "EnergyMaterialNoMass";

            // check if object is valid, only check for inherited class
            if (this.GetType() == typeof(EnergyMaterialNoMass))
            {
                this.IsValid(throwException: true);
            }
        }
Exemple #12
0
        public void ComputeScatteringFunctions(SurfaceInteraction si,
                                               IObjectArena arena,
                                               TransportMode mode,
                                               bool allowMultipleLobes)
        {
            BumpMap?.Bump(si);

            si.BSDF.Initialize(si);

            // Diffuse
            var c = Color.Evaluate(si).Clamp();
            var metallicWeight = Metallic.Evaluate(si);
            var e             = Eta.Evaluate(si);
            var strans        = SpecTrans.Evaluate(si);
            var diffuseWeight = (1f - metallicWeight) * (1f - strans);
            var dt            = DiffTrans.Evaluate(si) / 2f;
            var rough         = Roughness.Evaluate(si);
            var lum           = c.YComponent();
            var Ctint         = lum > 0f ? c / lum : Spectrum.One;

            if (diffuseWeight > 0f)
            {
                if (IsThin)
                {
                    var flat = Flatness.Evaluate(si);
                    si.BSDF.Add(arena.Create <DisneyDiffuse>().Initialize(diffuseWeight * (1f - flat) * (1 - dt) * c));
                    si.BSDF.Add(arena.Create <DisneyFakeSS>().Initialize(diffuseWeight * flat * (1f - dt) * c, rough));
                }
                else
                {
                    var sd = ScatterDistance.Evaluate(si);
                    if (sd.IsBlack())
                    {
                        si.BSDF.Add(arena.Create <DisneyDiffuse>().Initialize(diffuseWeight * c));
                    }
                    else
                    {
                        // The line below was the original code but produces some odd results.
                        si.BSDF.Add(arena.Create <SpecularTransmission>().Initialize(Spectrum.One, 1f, e, mode));
                        si.BSSRDF = arena.Create <DisneyBSSRDF>().Initialize(diffuseWeight * c, sd, si, e, this, mode);
                    }
                }

                // Retro-reflection.
                si.BSDF.Add(arena.Create <DisneyRetro>().Initialize(diffuseWeight * c, rough));

                // Sheen
                var sheenWeight = Sheen.Evaluate(si);
                if (sheenWeight > 0f)
                {
                    var stint  = SheenTint.Evaluate(si);
                    var Csheen = Spectrum.Lerp(Spectrum.One, Ctint, stint);
                    si.BSDF.Add(arena.Create <DisneySheen>().Initialize(diffuseWeight * sheenWeight * Csheen));
                }
            }

            // Microfacet distribution
            var aspect = Sqrt(1f - Anisotropic.Evaluate(si) * 0.9f);
            var ax     = Max(0.001f, Sqr(rough) / aspect);
            var ay     = Max(0.001f, Sqr(rough) * aspect);
            var dist   = arena.Create <DisneyMicrofacetDistribution>().Initialize(ax, ay);

            // Specular = Trowbridge-Reitz with modified Fresnel function.
            var specTint = SpecularTint.Evaluate(si);
            var Cspec0   = Spectrum.Lerp(SchlickR0FromEta(e) * Spectrum.Lerp(Spectrum.One, Ctint, specTint), c,
                                         metallicWeight);
            var fresnel = arena.Create <DisneyFresnel>().Initialize(Cspec0, metallicWeight, e);

            si.BSDF.Add(arena.Create <MicrofacetReflection>().Initialize(c, dist, fresnel));

            // Clearcoat
            var cc = Clearcoat.Evaluate(si);

            if (cc > 0f)
            {
                si.BSDF.Add(arena.Create <DisneyClearcoat>()
                            .Initialize(cc, Lerp(0.1f, 0.001f, ClearcoatGloss.Evaluate(si))));
            }

            // BTDF
            if (strans > 0f)
            {
                // Walter et al's model, with the provided transmissive term scaled
                // by sqrt(color), so that after two refractions, we're back to the
                // provided color.
                var T = strans * c.Sqrt();
                if (IsThin)
                {
                    var rScaled    = (0.65f * e - 0.35f) * rough;
                    var atx        = Max(0.001f, Sqr(rScaled) / aspect);
                    var aty        = Max(0.001f, Sqr(rScaled) * aspect);
                    var scaledDist = arena.Create <TrowbridgeReitzDistribution>().Initialize(atx, aty);
                    si.BSDF.Add(arena.Create <MicrofacetTransmission>().Initialize(T, scaledDist, 1f, e, mode));
                }
                else
                {
                    si.BSDF.Add(arena.Create <MicrofacetTransmission>().Initialize(T, dist, 1f, e, mode));
                }
            }

            if (IsThin)
            {
                si.BSDF.Add(arena.Create <LambertianTransmission>().Initialize(dt * c));
            }
        }
Exemple #13
0
        public override void ImportFromUsd()
        {
            Material mat = Material;

            if (DiffuseMap)
            {
                mat.SetTexture("_MainTex", DiffuseMap);
                // Albedo texture is modulated by the material color, so setting to white preserves the pure
                // texture color.
                mat.color = Color.white;
            }
            else
            {
                mat.color = Diffuse.GetValueOrDefault(mat.color);
            }

            if (NormalMap)
            {
                mat.SetTexture("_BumpMap", NormalMap);
                mat.EnableKeyword("_NORMALMAP");
            }
            else
            {
                // TODO: Unity has no notion of a constant normal map.
            }

            if (DisplacementMap)
            {
                mat.SetTexture("_ParallaxMap", DisplacementMap);
                mat.EnableKeyword("_PARALLAXMAP");
            }
            else
            {
                // TODO: Unity has no notion of a parallax map.
            }

            if (OcclusionMap)
            {
                mat.SetTexture("_OcclusionMap", OcclusionMap);
            }
            else
            {
                // TODO: Unity has no notion of a constant occlusion value.
            }

            if (EmissionMap)
            {
                mat.SetTexture("_EmissionMap", EmissionMap);
                mat.SetColor("_EmissionColor", Color.white);
                mat.globalIlluminationFlags = MaterialGlobalIlluminationFlags.BakedEmissive;
                mat.EnableKeyword("_EMISSION");
            }
            else
            {
                var rgb = Emission.GetValueOrDefault(Color.black);
                mat.SetColor("_EmissionColor", rgb);
                if (rgb.r > 0 || rgb.g > 0 || rgb.b > 0)
                {
                    mat.EnableKeyword("_EMISSION");
                }
            }

            if (IsSpecularWorkflow)
            {
                if (SpecularMap)
                {
                    mat.SetTexture("_SpecGlossMap", SpecularMap);
                    mat.EnableKeyword("_SPECGLOSSMAP");
                }
                else
                {
                    var rgb = Specular.GetValueOrDefault(Color.gray);
                    mat.SetColor("_SpecColor", rgb);
                }

                if (RoughnessMap)
                {
                    // Roughness for spec setup is tricky, since it may require merging two textures.
                    // For now, just detect that case and issue a warning (e.g. when roughness has a map,
                    // but isn't the albedo or spec map).
                    // Roughness also needs to be converted to glossiness.
                    if (RoughnessMap != SpecularMap && SpecularMap != null)
                    {
                        var specGlossTex = MaterialImporter.CombineRoughness(SpecularMap, RoughnessMap, "specGloss");
                        mat.SetTexture("_SpecGlossMap", specGlossTex);
                        mat.EnableKeyword("_SPECGLOSSMAP");
                    }
                    else if (SpecularMap == null && RoughnessMap != DiffuseMap)
                    {
                        var mainGlossTex = MaterialImporter.CombineRoughness(DiffuseMap, RoughnessMap, "specGloss");
                        mat.SetTexture("_SpecGlossMap", mainGlossTex);
                        mat.EnableKeyword("_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A");
                    }
                    else
                    {
                        // TODO: create a new texture with constant spec value, combined with roughness texture.
                    }
                }
                else
                {
                    float smoothness = 1 - Roughness.GetValueOrDefault(.5f);
                    mat.SetFloat("_Glossiness", smoothness);
                    mat.SetFloat("_GlossMapScale", smoothness);
                }
            }
            else
            {
                if (MetallicMap)
                {
                    mat.SetTexture("_MetallicGlossMap", MetallicMap);
                    mat.EnableKeyword("_METALLICGLOSSMAP");
                }
                else
                {
                    mat.SetFloat("_Metallic", Metallic.GetValueOrDefault(0));
                }

                float smoothness = 1 - Roughness.GetValueOrDefault(.5f);
                mat.SetFloat("_Glossiness", smoothness);
                mat.SetFloat("_GlossMapScale", smoothness);

                if (RoughnessMap)
                {
                    var metalicRough = MaterialImporter.CombineRoughness(MetallicMap, RoughnessMap, "metalicRough");
                    // In this case roughness get its own map, but still must be converted to glossiness.
                    mat.SetTexture("_MetallicGlossMap", metalicRough);
                    mat.EnableKeyword("_METALLICGLOSSMAP");

                    // The scalar Glossiness modulates the roughness/glossiness map, however USD has no
                    // concept of this, so setting it to 1.0 effectively disables the scalar effect when
                    // the map is present.
                    mat.SetFloat("_Glossiness", 1.0f);
                    mat.SetFloat("_GlossMapScale", 1.0f);
                }
            }
        }
Exemple #14
0
        public bool Equals([AllowNull] Lighting other)
        {
            if (other == null)
            {
                return(false);
            }

            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return((Ambient == other.Ambient && Ambient != null && other.Ambient != null && Ambient.Equals(other.Ambient)) &&
                   (Diffuse == other.Diffuse && Diffuse != null && other.Diffuse != null && Diffuse.Equals(other.Diffuse)) &&
                   (Specular == other.Specular && Specular != null && other.Specular != null && Specular.Equals(other.Specular)) &&
                   (Roughness == other.Roughness && Roughness != null && other.Roughness != null && Roughness.Equals(other.Roughness)) &&
                   (Fresnel == other.Fresnel && Fresnel != null && other.Fresnel != null && Fresnel.Equals(other.Fresnel)));
        }
Exemple #15
0
        public static Material GasMaterial(string name = "", double density = 0.0, double conductivity = 0.0, double specificHeat = 0.0, double vapourResistivity = 0.0, string description = "", Roughness roughness = Roughness.Undefined, double refraction = 0.0, double convectionCoefficient = 0.0, Gas gas = Gas.Undefined)
        {
            GasMaterial gasProperties = new GasMaterial
            {
                Name                  = name,
                Density               = density,
                Conductivity          = conductivity,
                SpecificHeat          = specificHeat,
                VapourResistivity     = vapourResistivity,
                Description           = description,
                Roughness             = roughness,
                Refraction            = refraction,
                ConvectionCoefficient = convectionCoefficient,
                Gas = gas,
            };

            return(BH.Engine.Physical.Create.Material(name, new List <IMaterialProperties> {
                gasProperties
            }));
        }
Exemple #16
0
        public static Material SolidMaterial(string name = "", double density = 0.0, double conductivity = 0.0, double specificHeat = 0.0, double additionalHeatTransfer = 0.0, double vapourResistivity = 0.0, string description = "", Roughness roughness = Roughness.Undefined, double refraction = 0.0, double solarReflectanceExternal = 0.0, double solarReflectanceInternal = 0.0, double solarTransmittance = 0.0, double lightReflectanceExternal = 0.0, double lightReflectanceInternal = 0.0, double lightTransmittance = 0.0, double emissivityExternal = 0.0, double emissivityInternal = 0.0, double specularity = 0.0, double transmittedDiffusivity = 0.0, double transmittedSpecularity = 0.0, bool ignoreInUValueCalculation = false)
        {
            SolidMaterial solidProperties = new SolidMaterial
            {
                Name                      = name,
                Density                   = density,
                Conductivity              = conductivity,
                SpecificHeat              = specificHeat,
                VapourResistivity         = vapourResistivity,
                Description               = description,
                Roughness                 = roughness,
                Refraction                = refraction,
                SolarReflectanceExternal  = solarReflectanceExternal,
                SolarReflectanceInternal  = solarReflectanceInternal,
                SolarTransmittance        = solarTransmittance,
                LightReflectanceExternal  = lightReflectanceExternal,
                LightReflectanceInternal  = lightReflectanceInternal,
                LightTransmittance        = lightTransmittance,
                EmissivityExternal        = emissivityExternal,
                EmissivityInternal        = emissivityInternal,
                Specularity               = specularity,
                TransmittedDiffusivity    = transmittedDiffusivity,
                TransmittedSpecularity    = transmittedSpecularity,
                IgnoreInUValueCalculation = ignoreInUValueCalculation,
            };

            return(BH.Engine.Physical.Create.Material(name, new List <IMaterialProperties> {
                solidProperties
            }));
        }
Exemple #17
0
        public override void ImportFromUsd()
        {
            Material mat = Material;

            if (DiffuseMap)
            {
                Debug.Log("here");
                mat.SetTexture("_BaseColorMap", DiffuseMap);
                mat.SetColor("_BaseColor", Color.white);
            }
            else
            {
                mat.SetColor("_BaseColor", Diffuse.GetValueOrDefault(mat.color));
            }

            // TODO: What about opacity map?

            if (!IsSpecularWorkflow)
            {
                // Robustness: It would be ideal if this parameter were provided by HDRP, however that
                // would require this asset package having a dependency on the HDRP package itself,
                // which is (yet) not desirable.
                mat.SetFloat("_MaterialID", /*Standard Metallic*/ 1);
            }
            else
            {
                mat.SetFloat("_MaterialID", /*Spec Color*/ 4);
                mat.EnableKeyword("_MATERIAL_FEATURE_SPECULAR_COLOR");
                mat.EnableKeyword("_SPECULARCOLORMAP");
            }

            // R=Metallic, G=Occlusion, B=Displacement, A=Roughness(Smoothness)
            var MaskMap = BuildMaskMap(!IsSpecularWorkflow ? MetallicMap : null, OcclusionMap, DisplacementMap, RoughnessMap);

            if (MaskMap)
            {
                mat.SetTexture("_MaskMap", MaskMap);
                mat.EnableKeyword("_MASKMAP");
            }

            if (!IsSpecularWorkflow)
            {
                if (!MetallicMap)
                {
                    mat.SetFloat("_Metallic", Metallic.GetValueOrDefault());
                }
            }
            else
            {
                if (SpecularMap)
                {
                    mat.SetTexture("_SpecularColorMap", SpecularMap);
                }
                else
                {
                    mat.SetColor("_SpecularColor", Specular.GetValueOrDefault());
                }
            }

            if (!RoughnessMap)
            {
                var smoothness = 1 - Roughness.GetValueOrDefault();
                mat.SetFloat("_Smoothness", smoothness);
                // HDRP Lit does not seem to respect smoothness, so just clamp to the correct value.
                mat.SetFloat("_SmoothnessRemapMin", smoothness);
                mat.SetFloat("_SmoothnessRemapMax", smoothness);
            }

            if (!OcclusionMap)
            {
                mat.SetFloat("_AORemapMin", Occlusion.GetValueOrDefault());
                mat.SetFloat("_AORemapMax", Occlusion.GetValueOrDefault());
            }

            // Single displacement scalar value not supported.

            if (ClearcoatMap)
            {
                mat.SetTexture("_CoatMaskMap", ClearcoatMap);
                mat.EnableKeyword("_MATERIAL_FEATURE_CLEAR_COAT");
            }
            mat.SetFloat("_CoatMask", ClearcoatRoughness.GetValueOrDefault());

            if (NormalMap)
            {
                mat.SetTexture("_NormalMap", NormalMap);
                mat.EnableKeyword("_NORMALMAP");
            }

            if (EmissionMap)
            {
                mat.SetTexture("_EmissionMap", EmissionMap);
                mat.EnableKeyword("_EMISSIVE_COLOR_MAP");
            }
            else
            {
                mat.SetColor("_EmissionColor", Emission.GetValueOrDefault());
            }
        }
Exemple #18
0
        public override void ImportFromUsd()
        {
            Material mat = Material;

            if (DiffuseMap)
            {
                mat.SetTexture("_MainTex", DiffuseMap);
            }
            else
            {
                mat.color = Diffuse.GetValueOrDefault(mat.color);
            }

            if (NormalMap)
            {
                mat.SetTexture("_BumpMap", NormalMap);
                mat.EnableKeyword("_NORMALMAP");
            }
            else
            {
                // TODO: Unity has no notion of a constant normal map.
            }

            if (DisplacementMap)
            {
                mat.SetTexture("_ParallaxMap", DisplacementMap);
                mat.EnableKeyword("_PARALLAXMAP");
            }
            else
            {
                // TODO: Unity has no notion of a parallax map.
            }

            if (OcclusionMap)
            {
                mat.SetTexture("_OcclusionMap", OcclusionMap);
            }
            else
            {
                // TODO: Unity has no notion of a constant occlusion value.
            }

            if (EmissionMap)
            {
                mat.SetTexture("_EmissionMap", EmissionMap);
                mat.EnableKeyword("_EMISSION");
            }
            else
            {
                var rgb = Emission.GetValueOrDefault(Color.black);
                mat.SetColor("_EmissionColor", rgb);
                if (rgb.r > 0 || rgb.g > 0 || rgb.b > 0)
                {
                    mat.EnableKeyword("_EMISSION");
                }
            }

            if (!IsMetallicWorkflow)
            {
                if (SpecularMap)
                {
                    mat.SetTexture("_SpecGlossMap", SpecularMap);
                    mat.EnableKeyword("_SPECGLOSSMAP");
                }
                else
                {
                    var rgb = Specular.GetValueOrDefault(Color.gray);
                    mat.SetColor("_SpecColor", rgb);
                }

                if (RoughnessMap)
                {
                    // Roughness for spec setup is tricky, since it may require merging two textures.
                    // For now, just detect that case and issue a warning (e.g. when roughness has a map,
                    // but isn't the albedo or spec map).
                    // Roughness also needs to be converted to glossiness.
                    if (RoughnessMap != SpecularMap && SpecularMap != null)
                    {
                        var specGlossTex = MaterialImporter.CombineRoughnessToGloss(SpecularMap, RoughnessMap);
                        mat.SetTexture("_SpecGlossMap", specGlossTex);
                        mat.EnableKeyword("_SPECGLOSSMAP");
                    }
                    else if (SpecularMap == null && RoughnessMap != DiffuseMap)
                    {
                        var mainGlossTex = MaterialImporter.CombineRoughnessToGloss(DiffuseMap, RoughnessMap);
                        mat.SetTexture("_SpecGlossMap", mainGlossTex);
                        mat.EnableKeyword("_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A");
                    }
                    else
                    {
                        // TODO: create a new texture with constant spec value, combined with roughness texture.
                    }
                }
                else
                {
                    float smoothness = 1 - Roughness.GetValueOrDefault(.5f);
                    mat.SetFloat("_Glossiness", smoothness);
                    mat.SetFloat("_GlossMapScale", smoothness);
                }
            }
            else
            {
                if (MetallicMap)
                {
                    mat.SetTexture("_MetallicGlossMap", MetallicMap);
                    mat.EnableKeyword("_METALLICGLOSSMAP");
                }
                else
                {
                    mat.SetFloat("_Metallic", Metallic.GetValueOrDefault(0));
                }

                if (RoughnessMap)
                {
                    // In this case roughness get its own map, but still must be converted to glossiness.
                    mat.SetTexture("_SpecGlossMap", RoughnessMap);
                }
                else
                {
                    float smoothness = 1 - Roughness.GetValueOrDefault(.5f);
                    mat.SetFloat("_Glossiness", smoothness);
                    mat.SetFloat("_GlossMapScale", smoothness);
                }
            }
        }
 public bool Equals(SurfaceEllipsoid other) => Orientation.Equals(other.Orientation) && Roughness.Equals(other.Roughness) && IncomingDirection.Equals(other.IncomingDirection);
Exemple #20
0
 public virtual void Release()
 {
     if (UI3DPreview.Instance != null)
     {
         var prev = UI3DPreview.Instance;
         if (Albedo != null && Albedo != prev.defaultBlack && Albedo != prev.defaultDarkGray && Albedo != prev.defaultGray && Albedo != prev.defaultWhite)
         {
             Albedo.Release();
             Albedo = null;
         }
         if (Height != null && Height != prev.defaultBlack && Height != prev.defaultDarkGray && Height != prev.defaultGray && Height != prev.defaultWhite)
         {
             Height.Release();
             Height = null;
         }
         if (Normal != null && Normal != prev.defaultBlack && Normal != prev.defaultDarkGray && Normal != prev.defaultGray && Normal != prev.defaultWhite)
         {
             Normal.Release();
             Normal = null;
         }
         if (Metallic != null && Metallic != prev.defaultBlack && Metallic != prev.defaultDarkGray && Metallic != prev.defaultGray && Metallic != prev.defaultWhite)
         {
             Metallic.Release();
             Metallic = null;
         }
         if (Roughness != null && Roughness != prev.defaultBlack && Roughness != prev.defaultDarkGray && Roughness != prev.defaultGray && Roughness != prev.defaultWhite)
         {
             Roughness.Release();
             Roughness = null;
         }
         if (Occlusion != null && Occlusion != prev.defaultBlack && Occlusion != prev.defaultDarkGray && Occlusion != prev.defaultGray && Occlusion != prev.defaultWhite)
         {
             Occlusion.Release();
             Occlusion = null;
         }
     }
     else
     {
         if (Albedo != null)
         {
             Albedo.Release();
             Albedo = null;
         }
         if (Height != null)
         {
             Height.Release();
             Height = null;
         }
         if (Normal != null)
         {
             Normal.Release();
             Normal = null;
         }
         if (Metallic != null)
         {
             Metallic.Release();
             Metallic = null;
         }
         if (Roughness != null)
         {
             Roughness.Release();
             Roughness = null;
         }
         if (Occlusion != null)
         {
             Occlusion.Release();
             Occlusion = null;
         }
     }
 }
Exemple #21
0
    public VehicleModel()
    {
        VehicleOverview = new VehicleOverview();
        engine          = new Engine();
        starter         = new Starter();
        gearBox         = new GearBox();
        vehGearNum      = 0;
        for (int i = 0; i < subGears.Length; i++)
        {
            subGears[i] = new SubGear();
        }
        windForce      = new WindForce();
        steeringFactor = new SteeringFactor();
        steering       = new Steering();
        fuelTank       = new FuelTank();

        for (int i = 0; i < otherSteerings.Length; i++)
        {
            otherSteerings[i] = new OtherSteering();
        }
        carVibration        = new CarVibration();
        brakesCommon        = new Brakes();
        physicsCrashSetting = new PhysicsCrashSetting();
        ignoreHeadCollision = false;
        exhaust             = new Exhaust();
        roughness           = new Roughness();
        engineHealth        = new EngineHealth();
        fuelTankOnCrash     = 0;
        engineParticles     = new EngineParticles();
        gearboxSettings     = new GearboxSettings();
        wheels                       = new Wheel();
        body                         = new Body();
        bumper                       = new Bumper();
        windowGlass                  = new WindowGlass();
        light                        = new Light();
        licencePlate                 = new LicencePlate();
        mirror                       = new Mirror();
        wing                         = new Wing();
        door                         = new Door();
        roof                         = new Roof();
        unknown                      = new Unknown();
        engineSoundSet               = new EngineSoundSet();
        engineSound1                 = new EngineSound();
        engineSound2                 = new EngineSound();
        engineSound3                 = new EngineSound();
        engineSound4                 = new EngineSound4();
        insideSoundSet               = new InsideSoundSet();
        carSmallHitType              = new CarSmallHitType();
        carShortCrashTypeB1          = new CarShortCrashType();
        carShortCrashWithGlassTypeC1 = new CarShortCrashType();
        unknownSound1                = "";
        unknownSound2                = "";
        engineStartSound             = new EngineStartSound();
        engineSoundDriving           = new EngineSoundDriving();
        for (int i = 0; i < engineSoundOnGears.Length; i++)
        {
            engineSoundOnGears[i] = new EngineSoundOnGear();
        }
        engineSoundIdle             = new EngineSoundIdle();
        wheelSoundWhilePunctured    = new WheelSoundWhilePunctured();
        carSmallHitType1            = new CarSmallHitType();
        carLongCrashType1           = new CarLongCrashType();
        carShortCrashWithGlassType1 = new CarShortCrashType();
        doorOpenCloseSound          = new DoorOpenCloseSound();
        insideSoundSet               = new InsideSoundSet();
        carSmallHitType              = new CarSmallHitType();
        carLongCrashType2            = new CarLongCrashType();
        carShortCrashTypeB1          = new CarShortCrashType();
        carShortCrashWithGlassTypeC1 = new CarShortCrashType();
        unknownSound1               = "";
        unknownSound2               = "";
        carShortCrashTypeB2         = new CarShortCrashType();
        carShortCrashWithGlassType1 = new CarShortCrashType();
        doorOpenCloseSound          = new DoorOpenCloseSound();
    }