// キャッシュにテクスチャソースを保持する private void FilterTexture(Texture2D texture, FilterParam filter) { TextureHolder orgTex = originalTexCache.GetOrAdd(texture); orgTex.dirty = false; filter.ClearDirtyFlag(); FilterTexture(texture, orgTex.texture, filter); }
private void FilterTexture( Dictionary <string, List <Material> > slotMaterials, List <Texture2D> textures, Maid maid, string slotName, int materialIndex, string propName ) { Material material = null; Texture2D texture = null; { List <Material> materials; if (slotMaterials.TryGetValue(slotName, out materials) && materials != null) { material = materials.ElementAtOrDefault(materialIndex); if (material != null) { texture = material.GetTexture(propName) as Texture2D; } } } if (material == null || texture == null) { return; } FilterParam filterParam = Get(maid, slotName, material, propName); if (!filterParam.Dirty.Value) { return; } originalTextureCache.SetDirty(texture); filterParam.ClearDirtyFlag(); float outputBase = filterParam.OutputMin * 0.01f; float outputScale = (filterParam.OutputMax - filterParam.OutputMin) * 0.01f; float inputExp = Mathf.Log(filterParam.InputMid * 0.01f) / Mathf.Log(0.5f); float inputBase = (-filterParam.InputMin / (filterParam.InputMax - filterParam.InputMin)); float inputScale = 1f / ((filterParam.InputMax - filterParam.InputMin) * 0.01f); float hue = filterParam.Hue / 360f; float saturation = filterParam.Saturation / 100f; float lightness = filterParam.Lightness / 100f; Filter(texture, originalTextureCache.GetOriginalTexture(texture), (color) => { Color c = color; c.r = Mathf.Clamp01(c.r * inputScale + inputBase); c.g = Mathf.Clamp01(c.g * inputScale + inputBase); c.b = Mathf.Clamp01(c.b * inputScale + inputBase); c.r = Mathf.Pow(c.r, inputExp); c.g = Mathf.Pow(c.g, inputExp); c.b = Mathf.Pow(c.b, inputExp); Vector4 hsl = ColorUtil.ColorToHsl(c); hsl.x = (hsl.x + hue) % 1f; hsl.y *= saturation; hsl.z *= lightness; c = ColorUtil.HslToColor(hsl); c.r = c.r * outputScale + outputBase; c.g = c.g * outputScale + outputBase; c.b = c.b * outputScale + outputBase; return(c); }); }