//private void LoadMappingOptions private void UpdateShadersList() { LLEditorInternal.LoadMappingXML(false); nonRemappedShaders = 0; //Get mappings shadersMapping = new List <SceneShaderMapping>(); List <string> shadersUsed = new List <string>(); //Renderer[] allRenderers = GameObject.FindObjectsOfType( typeof(Renderer) ) as Renderer[]; //foreach (Renderer rend in allRenderers) { foreach (string curShaderName in GetAllShaderNamesInAScene()) { //Check for duplicates if (!shadersUsed.Contains(curShaderName)) { //Ignore LL shaders #if GO_LINEAR_TOOL if (curShaderName.Contains("Linear Lighting/")) { continue; } #elif GO_HDR_TOOL if (curShaderName.Contains("GoHDR/")) { continue; } #endif if (curShaderName.Contains("Hidden/")) { continue; } if (LLHelper.IsNullOrWhiteSpace(curShaderName)) { continue; } //Debug.Log("Adding " + shaderName); SceneShaderMapping sMapping = new SceneShaderMapping(); sMapping.origShaderName = curShaderName; //for (int i = 0; i < 10; i++) { shadersMapping.Add(sMapping); shadersUsed.Add(curShaderName); //} } } BuildMappingOptions(); builtShadersList = true; }
private void FixShader(Shader _shader) { if (null == _shader) { ParseAllShadersInDirectory(LLHelper.AssetPathToFilePath("Assets/GoHDR/Shaders/DefaultResourcesExtra")); return; } bool res = LLEditorInternal.FixShader(_shader, false, true); if (!res) { Debug.LogError("Failed to fix the shader '" + _shader.name + "'"); } }
private void ParseAllShadersInDirectory(string _path) { System.DateTime startTime = System.DateTime.Now; if (!System.IO.Directory.Exists(_path)) { Debug.LogError("Directory at path '" + _path + "' doesn't exist."); return; } string[] shadersPaths = System.IO.Directory.GetFiles(_path, "*.shader", System.IO.SearchOption.AllDirectories); if (shadersPaths.Length <= 0) { Debug.LogError("No shaders found at path '" + _path + "'."); return; } List <string> failedShaders = new List <string>(); foreach (string shaderPath in shadersPaths) { string shaderAssetPath = LLHelper.FilePathToAssetPath(shaderPath); Debug.Log("Fixing shader '" + shaderAssetPath + "'"); bool res = LLEditorInternal.FixShaderAtAssetPath(shaderAssetPath, false, true); if (!res) { Debug.LogError("Failed shader " + shaderAssetPath); failedShaders.Add(shaderPath); } //break; } Debug.Log("Done fixing shaders at '" + _path + "' in " + (System.DateTime.Now - startTime).TotalSeconds + "seconds. Success rate: " + (shadersPaths.Length - failedShaders.Count) + "/" + shadersPaths.Length); if (failedShaders.Count > 0) { Debug.Log("Failed shaders:"); } foreach (string shaderName in failedShaders) { Debug.Log("\t\tFailed: " + shaderName); } }
private void ParseAll() { foreach (SceneShaderMapping sMapping in shadersMapping) { if (sMapping.remappedShaderIndex == 0) //Option = parse { string shaderName = sMapping.origShaderName; Shader origShader = Shader.Find(shaderName); if (null == origShader) { Debug.LogError("Unable to find the shader '" + shaderName + "'"); } if (LLEditorInternal.FixShader(origShader, false, true)) { //int mappingIndex = -1; string mappingName = LLEditorInternal.GetShaderMapping(sMapping.origShaderName); //Debug.Log("mappingName: " + mappingName + "; mappingIndex: " + mappingIndex); if (!LLHelper.IsNullOrWhiteSpace(mappingName)) { //sMapping.remappedShaderIndex = mappingIndex + 2; sMapping.remappedShaderName = mappingName; } } else { sMapping.remappedShaderIndex = 1; //Skip } } } BuildMappingOptions(); }
private void BuildMappingOptions() { //Debug.Log("BuildMappingOptions"); //Fill available shaders List <string> mappingOptions = new List <string>(); mappingOptions.Add("parse"); mappingOptions.Add("skip"); foreach (string dstShaderName in LLEditorInternal.GetAllShaderMappingsDst()) { mappingOptions.Add(dstShaderName); } allMappingOptions = mappingOptions.ToArray(); //LLHelper.PrintArray("allMappingOptions", allMappingOptions); //Load for all shaders List <SceneShaderMapping> nonMappedShaders = new List <SceneShaderMapping>(); //Automatically map to the correct shader foreach (SceneShaderMapping sMapping in shadersMapping) { string dstShaderName = LLEditorInternal.GetShaderMapping(sMapping.origShaderName); //int dstShaderIndex; if (dstShaderName != null) { sMapping.remappedShaderName = dstShaderName; sMapping.remappedShaderIndex = System.Array.IndexOf(allMappingOptions, dstShaderName); if (sMapping.remappedShaderIndex == -1) { Debug.LogError("Cannot find shader '" + dstShaderName + "' in allMappingOptions."); sMapping.remappedShaderIndex = 0; } } else { // Debug.Log("No mapping found for " + sMapping.origShaderName); sMapping.remappedShaderName = "none"; sMapping.remappedShaderIndex = 0; //Parse nonRemappedShaders++; } if (null == dstShaderName) { nonMappedShaders.Add(sMapping); } //Debug.Log(sMapping.origShaderName + " => " + sMapping.remappedShaderName + ", index: " + sMapping.remappedShaderIndex); /* * if (sMapping.remappedShaderIndex < 0) { * Debug.LogError("Cannot find a shader with name " + sMapping.remappedShaderName); * sMapping.remappedShaderIndex = 1; * }*/ } //Remove empty mappings foreach (SceneShaderMapping sMapping in nonMappedShaders) { shadersMapping.Remove(sMapping); } //Add empty mappings to the beginning foreach (SceneShaderMapping sMapping in nonMappedShaders) { shadersMapping.Insert(0, sMapping); } ReadShadersToSkip(); }
private void RestoreAll() { Renderer[] allRenderers = GameObject.FindObjectsOfType(typeof(Renderer)) as Renderer[]; foreach (Renderer rend in allRenderers) { foreach (Material mat in rend.sharedMaterials) { string matPath = AssetDatabase.GetAssetPath(mat); //Debug.Log("material " + mat.name + " path is " + matPath); if (null != matPath) { string matGUID = AssetDatabase.AssetPathToGUID(matPath); if (!LLHelper.IsNullOrWhiteSpace(matGUID)) { string originalShaderName = LLEditorInternal.GetOrigMaterialShader(matGUID); if (!LLHelper.IsNullOrWhiteSpace(originalShaderName)) { Shader origShader = Shader.Find(originalShaderName); if (null != origShader) { mat.shader = origShader; } else { Debug.LogWarning("Unable to find shader '" + originalShaderName + "'. Skipping."); } } else { //Debug.LogError("Material '" + mat.name + "' originalShaderName is null. Skipping."); } } else { Debug.LogWarning("GUID of material '" + mat.name + "' is null. Skipping."); } } } } //Skyboxes Skybox[] allSkyboxes = GameObject.FindObjectsOfType(typeof(Skybox)) as Skybox[]; foreach (Skybox skybox in allSkyboxes) { if (null == skybox.material) { continue; } string matPath = AssetDatabase.GetAssetPath(skybox.material); //Debug.Log("material " + mat.name + " path is " + matPath); if (null != matPath) { string matGUID = AssetDatabase.AssetPathToGUID(matPath); if (!LLHelper.IsNullOrWhiteSpace(matGUID)) { string originalShaderName = LLEditorInternal.GetOrigMaterialShader(matGUID); if (!LLHelper.IsNullOrWhiteSpace(originalShaderName)) { Shader origShader = Shader.Find(originalShaderName); if (null != origShader) { skybox.material.shader = origShader; } else { Debug.LogWarning("Unable to find shader '" + originalShaderName + "'. Skipping."); } } else { //Debug.LogError("Material '" + mat.name + "' originalShaderName is null. Skipping."); } } else { Debug.LogWarning("GUID of material '" + skybox.material.name + "' is null. Skipping."); } } } if (null != RenderSettings.skybox) { string matPath = AssetDatabase.GetAssetPath(RenderSettings.skybox); //Debug.Log("material " + mat.name + " path is " + matPath); if (null != matPath) { string matGUID = AssetDatabase.AssetPathToGUID(matPath); if (!LLHelper.IsNullOrWhiteSpace(matGUID)) { string originalShaderName = LLEditorInternal.GetOrigMaterialShader(matGUID); if (!LLHelper.IsNullOrWhiteSpace(originalShaderName)) { Shader origShader = Shader.Find(originalShaderName); if (null != origShader) { RenderSettings.skybox.shader = origShader; } else { Debug.LogWarning("Unable to find shader '" + originalShaderName + "'. Skipping."); } } else { //Debug.LogError("Material '" + mat.name + "' originalShaderName is null. Skipping."); } } else { Debug.LogWarning("GUID of material '" + RenderSettings.skybox.name + "' is null. Skipping."); } } } //Terrains foreach (Terrain ter in GameObject.FindObjectsOfType(typeof(Terrain)) as Terrain[]) { if (null != ter.materialTemplate) { if (null != ter.materialTemplate.shader) { string matPath = AssetDatabase.GetAssetPath(ter.materialTemplate); //Debug.Log("material " + mat.name + " path is " + matPath); if (null != matPath) { string matGUID = AssetDatabase.AssetPathToGUID(matPath); if (!LLHelper.IsNullOrWhiteSpace(matGUID)) { string originalShaderName = LLEditorInternal.GetOrigMaterialShader(matGUID); if (!LLHelper.IsNullOrWhiteSpace(originalShaderName)) { Shader origShader = Shader.Find(originalShaderName); if (null != origShader) { ter.materialTemplate.shader = origShader; } else { Debug.LogWarning("Unable to find shader '" + originalShaderName + "'. Skipping."); } } else { //Debug.LogError("Material '" + mat.name + "' originalShaderName is null. Skipping."); } } else { ter.materialTemplate = null; // Debug.LogWarning("GUID of material '" + ter.materialTemplate.name + "' is null. Skipping."); } } } } else //Default shader { } } UpdateShadersList(); }
private void ReplaceAllShadersInAScene(string _src, string _dst) { Shader dstShader = Shader.Find(_dst); if (null == dstShader) { Debug.LogError("Unable to find the shader '" + _dst + "'"); return; } Renderer[] allRenderers = GameObject.FindObjectsOfType(typeof(Renderer)) as Renderer[]; foreach (Renderer rend in allRenderers) { if (null == rend.sharedMaterials) { continue; } foreach (Material mat in rend.sharedMaterials) { if (mat.shader.name != _src) { continue; } //Store original shader name for restoring string matPath = AssetDatabase.GetAssetPath(mat); //Debug.Log("material " + mat.name + " path is " + matPath); if (null != matPath) { string matGUID = AssetDatabase.AssetPathToGUID(matPath); if (!LLHelper.IsNullOrWhiteSpace(matGUID)) { LLEditorInternal.AddMaterialMapping(matGUID, mat.name, mat.shader.name, false); } } mat.shader = dstShader; } } //Skyboxes Skybox[] allSkyboxes = GameObject.FindObjectsOfType(typeof(Skybox)) as Skybox[]; foreach (Skybox skybox in allSkyboxes) { if (null == skybox.material) { continue; } if (skybox.material.shader.name != _src) { continue; } skybox.material.shader = dstShader; string matPath = AssetDatabase.GetAssetPath(skybox.material); if (null != matPath) { string matGUID = AssetDatabase.AssetPathToGUID(matPath); if (!LLHelper.IsNullOrWhiteSpace(matGUID)) { LLEditorInternal.AddMaterialMapping(matGUID, skybox.material.name, skybox.material.shader.name, false); } } } if (null != RenderSettings.skybox) { if (RenderSettings.skybox.shader.name == _src) { RenderSettings.skybox.shader = dstShader; } } //Terrains foreach (Terrain ter in GameObject.FindObjectsOfType(typeof(Terrain)) as Terrain[]) { if (null != ter.materialTemplate) { if (null != ter.materialTemplate.shader) { if (ter.materialTemplate.shader.name == _src) { ter.materialTemplate = new Material(dstShader); string matPath = AssetDatabase.GetAssetPath(ter.materialTemplate); if (null != matPath) { string matGUID = AssetDatabase.AssetPathToGUID(matPath); if (!LLHelper.IsNullOrWhiteSpace(matGUID)) { LLEditorInternal.AddMaterialMapping(matGUID, ter.materialTemplate.name, ter.materialTemplate.shader.name, false); } } } } } else //Default shader { if (_src == "Nature/Terrain/Diffuse") { ter.materialTemplate = new Material(dstShader); } } } }