internal static void Build(Type type) { if (GetShaderSourceData(type) != null) { return; } Debug.LogFormat("Building material {0}", type.FullName); if (!type.IsSubclassOf(typeof(ScriptableMaterial))) { Debug.LogErrorFormat("Can not build material {0}", type.FullName); return; } ShaderSourceData shaderSourceData = new ShaderSourceData(); foreach (ShaderType shaderType in typeof(ShaderType).GetEnumValues()) { var methodReference = type.GetTypeDefinition().FindMethod(shaderType.ToString()); string source = new ShaderCompiler().Compile(methodReference, out var uniformList); var description = string.Format("// {0} generated from {1}\n", shaderType.ToString(), type.FullName); shaderSourceData.codes[shaderType] = description + source; if (uniformList != null) { foreach (var uniform in uniformList) { shaderSourceData.uniforms.Add(uniform); } } } SetShaderSourceData(type, shaderSourceData); }
internal static void SetShaderSourceData(Type type, ShaderSourceData shaderSourceData) { ShaderSourceCache[type] = shaderSourceData; }