void BeginCompile(PreviewRenderData renderData, string shaderStr, int shaderPass) { var shaderData = renderData.shaderData; ShaderUtil.UpdateShaderAsset(shaderData.shader, shaderStr, false); ShaderUtil.CompilePass(shaderData.mat, shaderPass); shaderData.isCompiling = true; renderData.NotifyPreviewChanged(); }
void BeginCompile(PreviewRenderData renderData, string shaderStr) { var shaderData = renderData.shaderData; ShaderUtil.ClearCachedData(shaderData.shader); ShaderUtil.UpdateShaderAsset(shaderData.shader, shaderStr, false); for (var i = 0; i < shaderData.mat.passCount; i++) { ShaderUtil.CompilePass(shaderData.mat, i); } shaderData.isCompiling = true; renderData.NotifyPreviewChanged(); }
void CompileNodeShader(AbstractMaterialNode node, GenerationMode mode, string nodeName) { var generator = new Generator(m_Graph, node, mode, nodeName, null); var shader = ShaderUtil.CreateShaderAsset(generator.generatedShader, true); shader.hideFlags = HideFlags.HideAndDontSave; var mat = new Material(shader) { hideFlags = HideFlags.HideAndDontSave }; ShaderUtil.CompilePass(mat, 0, true); }
void Apply() { UpdateSelection(); bool previousState = ShaderUtil.allowAsyncCompilation; ShaderUtil.allowAsyncCompilation = allowAsyncCompilation; for (int i = 0; i < materials.Count; i++) { if (materials[i] != null) { for (int j = 0; j < materials[i].passCount; j++) { ShaderUtil.CompilePass(materials[i], j, forceSync); } } } ShaderUtil.allowAsyncCompilation = previousState; }
void BeginCompile(PreviewRenderData renderData, string shaderStr) { using (BeginCompileMarker.Auto()) { var shaderData = renderData.shaderData; // want to ensure this so we don't get confused with multiple compile versions in flight Assert.IsTrue(shaderData.passesCompiling == 0); if (shaderData.shader == null) { shaderData.shader = ShaderUtil.CreateShaderAsset(shaderStr, false); shaderData.shader.hideFlags = HideFlags.HideAndDontSave; } else { ShaderUtil.ClearCachedData(shaderData.shader); ShaderUtil.UpdateShaderAsset(shaderData.shader, shaderStr, false); } if (shaderData.mat == null) { shaderData.mat = new Material(shaderData.shader) { hideFlags = HideFlags.HideAndDontSave }; } shaderData.passesCompiling = shaderData.mat.passCount; for (var i = 0; i < shaderData.mat.passCount; i++) { ShaderUtil.CompilePass(shaderData.mat, i); } m_NodesCompiling.Add(shaderData.node); } }
public void TestImportAsset(string unityLocalPath, string fullPath) { unityLocalPath = unityLocalPath.Replace("\\", "/"); Debug.Log("Testing file: " + unityLocalPath); // invoke an import AssetDatabase.ImportAsset(unityLocalPath, ImportAssetOptions.ForceSynchronousImport | ImportAssetOptions.ForceUpdate | ImportAssetOptions.DontDownloadFromCacheServer); // double check we can load it up and validate it string fileContents = File.ReadAllText(fullPath); Assert.Greater(fileContents.Length, 0); var graphGuid = AssetDatabase.AssetPathToGUID(unityLocalPath); var messageManager = new MessageManager(); GraphData graphData = new GraphData() { assetGuid = graphGuid, messageManager = messageManager }; MultiJson.Deserialize(graphData, fileContents); graphData.OnEnable(); graphData.ValidateGraph(); string fileExtension = Path.GetExtension(fullPath).ToLower(); bool isSubgraph = (fileExtension == "shadersubgraph"); if (isSubgraph) { // check that the SubGraphAsset is the same after versioning twice // this is important to ensure we're not importing subgraphs non-deterministically when they are out-of-date on disk AssetDatabase.ImportAsset(unityLocalPath, ImportAssetOptions.ForceSynchronousImport | ImportAssetOptions.ForceUpdate | ImportAssetOptions.DontDownloadFromCacheServer); var subGraph = AssetDatabase.LoadAssetAtPath <SubGraphAsset>(unityLocalPath); var serialized = EditorJsonUtility.ToJson(subGraph); AssetDatabase.ImportAsset(unityLocalPath, ImportAssetOptions.ForceSynchronousImport | ImportAssetOptions.ForceUpdate | ImportAssetOptions.DontDownloadFromCacheServer); var subGraph2 = AssetDatabase.LoadAssetAtPath <SubGraphAsset>(unityLocalPath); var serialized2 = EditorJsonUtility.ToJson(subGraph2); Assert.AreEqual(serialized, serialized2, $"Importing the subgraph {unityLocalPath} twice resulted in different subgraph assets."); } else { // check that the generated shader is the same after versioning twice // this is important to ensure we're not importing shaders non-deterministically when they are out-of-date on disk string fileNameNoExtension = Path.GetFileNameWithoutExtension(fullPath); var generator = new Generator(graphData, graphData.outputNode, GenerationMode.ForReals, fileNameNoExtension, null); string shader = generator.generatedShader; // version again GraphData graphData2 = new GraphData() { assetGuid = graphGuid, messageManager = messageManager }; MultiJson.Deserialize(graphData2, fileContents); graphData2.OnEnable(); graphData2.ValidateGraph(); var generator2 = new Generator(graphData2, graphData2.outputNode, GenerationMode.ForReals, fileNameNoExtension, null); string shader2 = generator2.generatedShader; Assert.AreEqual(shader, shader2, $"Importing the graph {unityLocalPath} twice resulted in different generated shaders."); // Texture test won't work on platforms that don't support more than 16 samplers bool isGL = (SystemInfo.graphicsDeviceType == GraphicsDeviceType.OpenGLCore) || (SystemInfo.graphicsDeviceType == GraphicsDeviceType.OpenGLES2) || (SystemInfo.graphicsDeviceType == GraphicsDeviceType.OpenGLES3); bool isOSX = (Application.platform == RuntimePlatform.OSXEditor) || (Application.platform == RuntimePlatform.OSXPlayer); bool samplersSupported = !(isOSX && isGL); if (!samplersSupported && fullPath.Contains("TextureTest")) { // skip the compile test -- we know this shader won't compile on these platforms } else { // now create a Unity Shader from the string var compiledShader = ShaderUtil.CreateShaderAsset(shader, true); compiledShader.hideFlags = HideFlags.HideAndDontSave; Assert.NotNull(compiledShader); // compile all the shader passes to see if there are any errors var mat = new Material(compiledShader) { hideFlags = HideFlags.HideAndDontSave }; for (int pass = 0; pass < mat.passCount; pass++) { ShaderUtil.CompilePass(mat, pass, true); } } } }