private static void GatherNoiseTypes() { List <INoiseType> instances = new List <INoiseType>(); List <string> names = new List <string>(); List <Type> types = new List <Type>(); foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies()) { Type[] assemblyTypes = null; try { assemblyTypes = asm.GetTypes(); } catch (Exception) { Debug.Log("NoiseLib::GatherNoiseTypes: Failed to get types from assembly: " + asm); assemblyTypes = null; } if (assemblyTypes != null) { types.AddRange(GetSubclassesOfGenericType(assemblyTypes, typeof(NoiseType <>))); } } foreach (Type t in types) { PropertyInfo propertyInfo = t.GetProperty("instance", s_bindingFlags); MethodInfo methodInfo = propertyInfo.GetGetMethod(); INoiseType instance = (INoiseType)methodInfo.Invoke(null, null); NoiseTypeDescriptor desc = instance.GetDescription(); if (string.IsNullOrEmpty(desc.name)) { Debug.LogError("NoiseType name cannot be null or empty! Skipping noise type: " + t); continue; } instances.Add(instance); names.Add(desc.name); } s_noiseTypes = instances.ToArray(); s_noiseNames = names.ToArray(); }
public GeneratedShaderInfo(IFractalType fractalType, INoiseType noiseType) { this.fractalDesc = fractalType.GetDescription(); this.noiseDesc = noiseType.GetDescription(); this.noiseIncludeStr = string.Format("#include \"{0}\"", noiseDesc.sourcePath); if (!string.IsNullOrEmpty(fractalDesc.name)) { this.variantName = string.Format("{0}{1}", fractalDesc.name, noiseDesc.name); } else { this.variantName = noiseDesc.name; } // set the path of the generated file. this will be used when writing the file // to disk and when adding the include in any generated shaders that use this // fractal and noise type variant this.generatedIncludePath = string.Format("{0}/{1}/{2}.hlsl", noiseDesc.outputDir, fractalDesc.name, noiseDesc.name); this.outputDir = string.Format("{0}/{1}", noiseDesc.outputDir, fractalDesc.name); fractalStructName = string.Format("{0}FractalInput", fractalDesc.name); noiseStructName = string.Format("{0}NoiseInput", noiseDesc.name); numFractalInputs = fractalDesc.inputStructDefinition == null ? 0 : fractalDesc.inputStructDefinition.Count; numNoiseInputs = noiseDesc.inputStructDefinition == null ? 0 : noiseDesc.inputStructDefinition.Count; fractalParamStr = null; noiseParamStr = null; functionInputStr = ""; // construct include paths string additionalIncludePaths = "\n"; for (int i = 0; i < fractalDesc.additionalIncludePaths.Count; ++i) { additionalIncludePaths += $"#include \"{ fractalDesc.additionalIncludePaths[ i ] }\"\n"; } additionalIncludePaths += "\n"; // generate the string for the fractal type structure as it would appear as a parameter // in an HLSL function declaration if (numFractalInputs > 0) { fractalParamStr = string.Format("{0} {1}", fractalStructName, "fractalInput"); } // generate the string for the noise type structure as it would appear as a parameter // in an HLSL function declaration if (numNoiseInputs > 0) { noiseParamStr = string.Format("{0} {1}", noiseStructName, "noiseInput"); } // generate the argument string for an HLSL function declaration that would be // using this combination of noise and fractal type structure definitions functionParamStr = ""; if (fractalParamStr != null) { functionParamStr += fractalParamStr; functionInputStr += "fractalInput"; } if (fractalParamStr != null && noiseParamStr != null) { functionParamStr += ", "; functionInputStr += ", "; } if (noiseParamStr != null) { functionParamStr += noiseParamStr; functionInputStr += "noiseInput"; } fractalStructDef = ""; if (numFractalInputs > 0) { fractalStructDef = NoiseLib.BuildStructString(fractalStructName, fractalDesc.inputStructDefinition); string getDefaultFuncStr = NoiseLib.GetDefaultFunctionString(fractalStructName, fractalDesc.inputStructDefinition); fractalStructDef += $"\n\n{ getDefaultFuncStr }\n\n"; } noiseStructDef = ""; if (numNoiseInputs > 0) { noiseStructDef = NoiseLib.BuildStructString(noiseStructName, noiseDesc.inputStructDefinition); } // get input str construction getInputsStr = ""; getFractalInputStr = NoiseLib.GetInputFunctionCallString(fractalStructName); getNoiseInputStr = NoiseLib.GetInputFunctionCallString(fractalStructName); if (numFractalInputs > 0) { getInputsStr += getFractalInputStr; } if (numFractalInputs > 0 && numNoiseInputs > 0) { getInputsStr += ", "; } if (numNoiseInputs > 0) { getInputsStr += getNoiseInputStr; } // get default input str construction getDefaultInputsStr = ""; getDefaultFractalInputStr = NoiseLib.GetDefaultInputFunctionCallString(fractalStructName); getDefaultNoiseInputStr = NoiseLib.GetDefaultInputFunctionCallString(noiseStructName); if (numFractalInputs > 0) { getDefaultInputsStr += getDefaultFractalInputStr; } if (numFractalInputs > 0 && numNoiseInputs > 0) { getDefaultInputsStr += ", "; } if (numNoiseInputs > 0) { getDefaultInputsStr += getDefaultNoiseInputStr; } fractalPropertyDefStr = ""; if (fractalDesc.inputStructDefinition != null && fractalDesc.inputStructDefinition.Count > 0) { fractalPropertyDefStr = NoiseLib.GetPropertyDefinitionStr(fractalDesc.name, fractalDesc.inputStructDefinition); fractalPropertyDefStr += "\n" + NoiseLib.GetPropertyFunctionStr(fractalStructName, fractalDesc.name, fractalDesc.inputStructDefinition); } }