protected override Material[] GenerateMasks(GraphicRequestRGB req, PatternDef pattern)
        {
            Texture2D mainTex = ContentFinder <Texture2D> .Get(req.path);

            Texture2D maskTex = ContentFinder <Texture2D> .Get(req.path + MaskSuffix, false);

            masks = Enumerable.Repeat(maskTex, MatCount).ToArray();
            var mats = new Material[MatCount];
            MaterialRequestRGB mReq = new MaterialRequestRGB()
            {
                mainTex          = mainTex,
                shader           = req.shader,
                properties       = pattern.properties,
                color            = pattern.properties.colorOne ?? req.color,
                colorTwo         = pattern.properties.colorTwo ?? req.colorTwo,
                colorThree       = pattern.properties.colorThree ?? req.colorThree,
                tiles            = req.tiles,
                isSkin           = pattern is SkinDef,
                maskTex          = maskTex,
                patternTex       = pattern?[Rot8.North],
                shaderParameters = req.shaderParameters
            };

            mats[0] = MaterialPoolExpanded.MatFrom(mReq);
            return(mats);
        }
Beispiel #2
0
 public bool Equals(MaterialRequestRGB other)
 {
     return(other.shader == shader && other.mainTex == mainTex && other.properties.colorOne == properties.colorOne &&
            other.properties.colorTwo == properties.colorTwo && other.properties.colorThree == properties.colorThree &&
            other.maskTex == maskTex && other.patternTex == patternTex && other.renderQueue == renderQueue &&
            other.shaderParameters == shaderParameters && other.isSkin == isSkin && other.tiles == tiles && other.displacement == displacement);
 }
Beispiel #3
0
 private void RecacheMaterials()
 {
     maskMaterials.Clear();
     foreach (PatternDef pattern in availableMasks)
     {
         MaterialRequestRGB req = new MaterialRequestRGB()
         {
             mainTex          = vehicle.VehicleGraphic.TexAt(Rot8.North),
             shader           = RGBShaderTypeDefOf.CutoutComplexPattern.Shader,
             properties       = pattern.properties,
             color            = pattern.properties.colorOne ?? CurrentColorOne.ToColor,
             colorTwo         = pattern.properties.colorTwo ?? CurrentColorTwo.ToColor,
             colorThree       = pattern.properties.colorThree ?? CurrentColorThree.ToColor,
             tiles            = 1,
             isSkin           = pattern is SkinDef,
             maskTex          = vehicle.VehicleGraphic.masks[Rot8.North.AsInt],
             patternTex       = pattern[Rot8.North],
             shaderParameters = null
         };
         Material patMat = MaterialPoolExpanded.MatFrom(req);
         maskMaterials.Add(patMat);
     }
 }
Beispiel #4
0
 public static Material MatFrom(MaterialRequestRGB req)
 {
     if (!UnityData.IsInMainThread)
     {
         Log.Error("Tried to get a material from a different thread.");
         return(null);
     }
     if (req.mainTex == null)
     {
         Log.Error("MatFrom with null sourceTex.");
         return(BaseContent.BadMat);
     }
     if (req.shader == null)
     {
         Log.Warning("Matfrom with null shader.");
         return(BaseContent.BadMat);
     }
     if (req.maskTex != null && !req.shader.SupportsRGBMaskTex())
     {
         Log.Error("MaterialRequest has maskTex but shader does not support it. req=" + req.ToString());
         req.maskTex = null;
     }
     if (!matDictionary.TryGetValue(req, out Material material))
     {
         material = new Material(req.shader)
         {
             name        = req.shader.name + "_" + req.mainTex.name,
             mainTexture = req.mainTex,
             color       = req.color
         };
         if (req.maskTex != null)
         {
             var patternTex = req.patternTex is null ? PatternDefOf.Default[Rot8.North] : req.patternTex;
             if (!req.properties.IsDefault)
             {
                 patternTex = Ext_Texture.WrapTexture(patternTex, TextureWrapMode.Repeat);
                 float tiles = req.tiles;
                 if (req.properties.tiles.TryGetValue("All", out float allTiles))
                 {
                     tiles *= allTiles;
                 }
                 if (tiles != 0)
                 {
                     material.SetFloat(AdditionalShaderPropertyIDs.TileNum, tiles);
                 }
                 //Add case for vehicle defName
                 if (req.properties.equalize)
                 {
                     float scaleX = 1;
                     float scaleY = 1;
                     if (req.mainTex.width > req.mainTex.height)
                     {
                         scaleY = (float)req.mainTex.height / req.mainTex.width;
                     }
                     else
                     {
                         scaleX = (float)req.mainTex.width / req.mainTex.height;
                     }
                     material.SetFloat(AdditionalShaderPropertyIDs.ScaleX, scaleX);
                     material.SetFloat(AdditionalShaderPropertyIDs.ScaleY, scaleY);
                 }
                 if (req.properties.dynamicTiling)
                 {
                     material.SetFloat(AdditionalShaderPropertyIDs.DisplacementX, req.displacement.x);
                     material.SetFloat(AdditionalShaderPropertyIDs.DisplacementY, req.displacement.y);
                 }
             }
             material.SetTexture(ShaderPropertyIDs.MaskTex, req.maskTex);
             material.SetTexture(AdditionalShaderPropertyIDs.PatternTex, patternTex);
             material.SetFloat(AdditionalShaderPropertyIDs.ReplaceTexture, req.isSkin ? 1 : 0);
             material.SetColor(AdditionalShaderPropertyIDs.ColorOne, req.color);
             material.SetColor(ShaderPropertyIDs.ColorTwo, req.colorTwo);
             material.SetColor(AdditionalShaderPropertyIDs.ColorThree, req.colorThree);
         }
         if (req.renderQueue != 0)
         {
             material.renderQueue = req.renderQueue;
         }
         if (!req.shaderParameters.NullOrEmpty())
         {
             for (int i = 0; i < req.shaderParameters.Count; i++)
             {
                 req.shaderParameters[i].Apply(material);
             }
         }
         matDictionary.Add(req, material);
     }
     return(material);
 }