private string ModifyShaderText(string text, string newFileSuffix)
        {
            text = ShaderCustomizationUtils.AdjustShaderName(text, _nameReplacementPrefix, newFileSuffix);

            text = ShaderCustomizationUtils.ReplaceDefinition(text, "IN_IMITATION", 1);

            var includeLines = new List <string>();

            foreach (var setting in FeatureSettings)
            {
                Preconditions.Assert(setting.Feature.Details().SupportedDetectionModes.Contains(setting.DetectionMode), $"For feature {setting.Feature} mode {setting.DetectionMode} is not supported");
                text = ShaderCustomizationUtils.ReplaceDefinition(text, $"IN_{setting.Feature.Details().Token}_FEATURE_DETECTION_MODE", setting.DetectionMode.Details().Index);
                text = ShaderCustomizationUtils.ReplaceDefinition(text, $"IN_{setting.Feature.Details().Token}_FEATURE_APPLY_MODE", setting.ApplyMode.Details().Index);
                text = ShaderCustomizationUtils.ReplaceDefinition(text, $"IN_{setting.Feature.Details().Token}_TARGET_INDEX", setting.TargetTextureIndex);

                includeLines.Add($"#include \"../Features/{setting.Feature.Details().Token}_feature.txt\"");
            }

            foreach (var aspectSetting in AspectSettings)
            {
                Preconditions.Assert(aspectSetting.Aspect.Details().SupportedModes.Contains(aspectSetting.AspectMode), $"For feature {aspectSetting.Aspect} mode {aspectSetting.AspectMode} is not supported");
                text = ShaderCustomizationUtils.ReplaceDefinition(text, $"IN_{aspectSetting.Aspect.Details().Token}_ASPECT_MODE", aspectSetting.AspectMode.Details().Index);

                includeLines.Add($"#include \"../Aspects/{aspectSetting.Aspect.Details().Token}_aspect.txt\"");
            }

            foreach (var toggleSetting in ToggleSettings)
            {
                int valueToSet = 0;
                if (toggleSetting.IsEnabled)
                {
                    valueToSet = 1;
                }
                text = ShaderCustomizationUtils.ReplaceDefinition(text, $"IN_USE_{toggleSetting.Toggle.Details().Token}", valueToSet);

                foreach (var line in toggleSetting.Toggle.Details().LinesToDisablePrefix)
                {
                    text = ShaderCustomizationUtils.SetEnabilityLine(text, line, toggleSetting.IsEnabled);
                }
            }

            string[] lines = text.Split(
                new[] { "\r\n", "\r", "\n" },
                StringSplitOptions.None
                );
            includeLines.ForEach(c => ShaderCustomizationUtils.ReplaceLine(lines, "IMITATION INCLUDE LINE", c));
            ChangeMacroDesignations(lines, FeatureSettings.Select(c => c.Feature).ToList(), AspectSettings.Select(c => c.Aspect).ToList());


            var outString = lines.Aggregate((i, j) => i + "\r\n" + j);

            Debug.Log(outString);
            return(outString);
        }
Exemplo n.º 2
0
        private string ModifyShaderText(String text)
        {
            var locationsDict = FactorLocations.ToDictionary(c => c.Factor, c => c);

            text = ShaderCustomizationUtils.AdjustShaderName(text, "Custom/NPR/", GetInstanceID().ToString());
            text = ShaderCustomizationUtils.ReplaceDefinition(text, $"IN_IMITATION", 1);

            Preconditions.Assert(UsageSettings.Count <= 5, "E864 Maximum usage count is 5");
            int usageIndex      = 0;
            var generationLines = new List <string>();
            var includeLines    = new List <string>();
            var applyLines      = new List <string>();
            var usageLines      = new List <string>();

            foreach (var pair in locationsDict)
            {
                usageLines.Add($"#define IN_{pair.Key.Details().Token}_TEXTURE_INDEX {pair.Value.TextureIndex.ToString()}");
                usageLines.Add($"#define IN_{pair.Key.Details().Token}_TEXTURE_SUFFIX {pair.Value.Suffix}");
                if (!pair.Key.Details().IsFilter)
                {
                    includeLines.Add($"#include \"../PPFeatures/{pair.Key.Details().Token}_ppFeature.txt\"");
                }
            }

            foreach (var usage in UsageSettings)
            {
                if (usage.Factor.Details().IsFilter)
                {
                    var newGenerationLine = $"pp_generate_filter_{usage.Filter.Details().Token}({usage.Factor.Details().Token})";
                    if (!generationLines.Contains(newGenerationLine))
                    {
                        generationLines.Add(newGenerationLine);
                    }
                    usageLines.Add($"#define IN_filter{usageIndex}_COLOR {Vector4ToShaderString(usage.Color)}");
                    if (usage.UseDebugSliderForTreshold)
                    {
                        usageLines.Add($"#define IN_filter{usageIndex}_TRESHOLD _DebugSlider");
                    }
                    else
                    {
                        usageLines.Add($"#define IN_filter{usageIndex}_TRESHOLD {usage.Treshold}");
                    }
                    usageLines.Add($"#define IN_filter{usageIndex}_DESTINATION_TEXTURE_INDEX {usage.DestinationTextureIndex}");
                    usageLines.Add($"#define IN_filter{usageIndex}_DESTINATION_TEXTURE_SUFFIX {usage.DestinationTextureSuffix}");

                    applyLines.Add($"pp_apply_usage({usageIndex}, {usage.Factor.Details().Token}, {usage.Filter.Details().Token}, i.uv, inColors);");
                }
                else
                {
                    usageLines.Add($"#define IN_{usage.Factor.Details().Token}_DESTINATION_TEXTURE_INDEX {usage.DestinationTextureIndex}");
                    usageLines.Add($"#define IN_{usage.Factor.Details().Token}_DESTINATION_TEXTURE_SUFFIX {usage.DestinationTextureSuffix}");
                    applyLines.Add($"{usage.Factor.Details().Token}_ppApplication(uv, inColors);");
                }

                usageIndex++;
            }

            string[] lines = text.Split(
                new[] { "\r\n", "\r", "\n" },
                StringSplitOptions.None
                );
            generationLines.ForEach(c => ShaderCustomizationUtils.ReplaceLine(lines, "IMITATION GENERATION LINE", c));
            includeLines.ForEach(c => ShaderCustomizationUtils.ReplaceLine(lines, "IMITATION INCLUDE LINE", c));
            applyLines.ForEach(c => ShaderCustomizationUtils.ReplaceLine(lines, "IMITATION APPLY LINE", c));
            usageLines.ForEach(c => ShaderCustomizationUtils.ReplaceLine(lines, "IMITATION USAGE LINE", c));

            return(lines.Aggregate((i, j) => i + "\r\n" + j));
        }