private TextureSet getSet(PartVariant variant) { string setName = variant.GetExtraInfoValue("textureSet"); TextureSet set = null; if (!string.IsNullOrEmpty(setName)) { set = TexturesUnlimitedLoader.getTextureSet(setName); textureSet = setName; modelShaderSet = string.Empty; return(set); } setName = variant.GetExtraInfoValue("modelShader"); if (!string.IsNullOrEmpty(setName)) { set = TexturesUnlimitedLoader.getModelShaderTextureSet(setName); modelShaderSet = setName; textureSet = string.Empty; return(set); } //if nothing found, clear out references if (TexturesUnlimitedLoader.logErrors || TexturesUnlimitedLoader.logAll) { MonoBehaviour.print("Could not load texture set for part variant: " + variant?.Name + " for part: " + part.name); } modelShaderSet = textureSet = string.Empty; return(null); }
/// <summary> /// Sets the shader and properties to the input material /// </summary> /// <param name="material"></param> public void apply(Material material) { material.shader = TexturesUnlimitedLoader.getShader(shader); TextureSet.updateMaterialProperties(material, shaderProperties); TextureSet.fillEmptyStockTextureSlots(material); material.renderQueue = TexturesUnlimitedLoader.isTransparentMaterial(material) ? TexturesUnlimitedLoader.transparentTextureRenderQueue : TexturesUnlimitedLoader.diffuseTextureRenderQueue; }
internal static void fillEmptyTextureSlot(Material mat, string slot, string textureColor) { if (mat.HasProperty(slot) && mat.GetTexture(slot) == null) { Log.replacement("Replacing empty textureslot: " + slot + " with color: " + textureColor); mat.SetTexture(slot, TexturesUnlimitedLoader.getTextureColor(textureColor)); } }
public TextureSetContainer(PartModule pm, BaseField textureSetField, BaseField persistentDataField, string[] textureSetNames) { this.pm = pm; this.textureSetField = textureSetField; this.persistentDataField = persistentDataField; loadPersistentData(persistentData); this.textureSets = TexturesUnlimitedLoader.getTextureSets(textureSetNames); }
public TransparentShaderData(ConfigNode node) { string shaderName = node.GetStringValue("name"); shader = TexturesUnlimitedLoader.getShader(shaderName); alwaysTransparent = node.GetBoolValue("alwaysTransparent", true); transparentKeywords = node.GetStringValues("keyword"); }
private void updateWindow(int id) { ReflectionManager manager = ReflectionManager.Instance; bool galaxy = manager.renderGalaxy; bool atmo = manager.renderAtmo; bool scaled = manager.renderScaled; bool scenery = manager.renderScenery; GUILayout.BeginVertical(); manager.reflectionsEnabled = addButtonRowToggle("Reflections Enabled", manager.reflectionsEnabled); manager.renderGalaxy = addButtonRowToggle("Render Galaxy", galaxy); manager.renderAtmo = addButtonRowToggle("Render Atmo", atmo); manager.renderScaled = addButtonRowToggle("Render Scaled", scaled); manager.renderScenery = addButtonRowToggle("Render Scenery", scenery); TexturesUnlimitedLoader.alternateRender = addButtonRowToggle("Alternate Render", TexturesUnlimitedLoader.alternateRender); manager.eveInstalled = addButtonRowToggle("Eve Fix", manager.eveInstalled); if (GUILayout.Button("Toggle Debug Sphere")) { manager.toggleDebugSphere(); } if (GUILayout.Button("Force Reflection Probe Update")) { manager.forceReflectionUpdate(); } if (GUILayout.Button("Export Debug Cube Maps")) { manager.renderDebugCubes(); } if (GUILayout.Button("Export Debug Cube Layer")) { manager.renderDebugLayers(); } if (GUILayout.Button("Dump world data")) { Utils.dumpWorldHierarchy(); } if (GUILayout.Button("Dump cam data")) { Utils.dumpCameraData(); } if (GUILayout.Button("Dump Stock Refl Data")) { Utils.dumpReflectionData(); } if (GUILayout.Button("Dump model UV Maps")) { TexturesUnlimitedLoader.dumpUVMaps(true); } if (GUILayout.Button("Calculate Normalization Data")) { NormMaskCreation.processBatch(); } GUILayout.EndVertical(); }
public void Start() { Log.log("TexturesUnlimitedLoader - Start()"); INSTANCE = this; DontDestroyOnLoad(this); if (partListLoadedEvent == null) { partListLoadedEvent = new EventVoid.OnEvent(onPartListLoaded); GameEvents.OnPartLoaderLoaded.Add(partListLoadedEvent); } }
protected override void applyInternal(Material mat) { if (checkApply(mat)) { Texture2D texture = TexturesUnlimitedLoader.getTextureColor(colorString); if (texture == null) { Log.error("ERROR: KSPShaderLoader - TextureColor could not be created for string: " + colorString + " for texture slot: " + name + " while loading textures for material: " + mat); } mat.SetTexture(name, texture); } }
private void updateWindow(int id) { GUILayout.BeginVertical(); if (addButtonRow("Dump ReflectionData")) { Utils.dumpReflectionData(); } if (addButtonRow("Export UV and Model Data")) { TexturesUnlimitedLoader.dumpUVMaps(true); } GUILayout.EndVertical(); }
/// <summary> /// Return a new material instances instatiated with the shader and properties for this material data. /// Does not include applying any recoloring data -- that needs to be handled externally. /// </summary> /// <returns></returns> public Material createMaterial() { if (string.IsNullOrEmpty(this.shader)) { //TODO -- include texture set name somehow... throw new NullReferenceException("ERROR: No shader specified for texture set."); } Shader shader = TexturesUnlimitedLoader.getShader(this.shader); Material material = new Material(shader); TextureSet.updateMaterialProperties(material, shaderProperties); material.renderQueue = TexturesUnlimitedLoader.isTransparentMaterial(material) ? TexturesUnlimitedLoader.transparentTextureRenderQueue : TexturesUnlimitedLoader.diffuseTextureRenderQueue; return(material); }
//really, could probably just move this back to the base class, possibly with a config bool for toggling enable of the secondary updates public void Start() { TextureSet ts = TexturesUnlimitedLoader.getTextureSet(textureSet); if (ts != null) { //apply the textur set to the base model, use set-specified mask colors (does not support user recoloring) ts.enable(part.transform.FindRecursive("model"), ts.maskColors); TextureSetMaterialData tsmd = ts.textureData[materialIndex]; //adjust the already existing fairing materials and fairing panels ModuleProceduralFairing mpf = part.GetComponent <ModuleProceduralFairing>(); if (mpf != null) { if (mpf.FairingMaterial != null && mpf.FairingConeMaterial != null) { tsmd.apply(mpf.FairingMaterial); tsmd.apply(mpf.FairingConeMaterial); } if (mpf.Panels != null && mpf.Panels.Count > 0)//cones are included in regular panels { int len = mpf.Panels.Count; for (int i = 0; i < len; i++) { tsmd.apply(mpf.Panels[i].mat); tsmd.apply(mpf.Panels[i].go.GetComponent <Renderer>().material); } } } } //prev shader-only code... //Shader shader = TexturesUnlimitedLoader.getShader(this.shader); //if (mpf != null && shader != null && mpf.FairingMaterial != null) //{ // mpf.FairingMaterial.shader = shader; // if (mpf.FairingConeMaterial != null) { mpf.FairingConeMaterial.shader = shader; } // MonoBehaviour.print("Adjusted MPF materials!"); // if (mpf.Panels != null && mpf.Panels.Count > 0)//cones are included in regular panels // { // int len = mpf.Panels.Count; // for (int i = 0; i < len; i++) // { // mpf.Panels[i].mat.shader = shader; // mpf.Panels[i].go.GetComponent<Renderer>().material.shader = shader; // } // } //} }
/// <summary> /// Sets the shader and properties to the input material /// </summary> /// <param name="material"></param> public void apply(Material material, bool isIcon = false) { if (isIcon) { material.shader = TexturesUnlimitedLoader.iconShaders[shader].iconShader; } else { material.shader = TexturesUnlimitedLoader.getShader(shader); } TextureSet.updateMaterialProperties(material, shaderProperties); TextureSet.fillEmptyStockTextureSlots(material); material.renderQueue = renderQueue; material.mainTextureOffset = textureOffset; material.mainTextureScale = textureScale; Log.replacement("Updated material properties\n" + Debug.getMaterialPropertiesDebug(material)); }
/// <summary> /// Public utility method to retrieve just the display titles of the texture sets from the input collection of nodes. /// </summary> /// <param name="nodes"></param> /// <returns></returns> public static string[] getTextureSetTitles(ConfigNode[] nodes) { List <string> names = new List <string>(); string name; TextureSet set; int len = nodes.Length; for (int i = 0; i < len; i++) { name = nodes[i].GetStringValue("name"); set = TexturesUnlimitedLoader.getTextureSet(name); if (set != null) { names.Add(set.title); } } return(names.ToArray()); }
public readonly string mode;//ghetto enum - 'update' or 'create' are the only valid values public TextureSetMaterialData(TextureSet owner, ConfigNode node, string defaultMode) { this.owner = owner; shader = node.GetStringValue("shader"); meshNames = node.GetStringValues("mesh"); excludedMeshes = node.GetStringValues("excludeMesh"); shaderProperties = ShaderProperty.parse(node); inheritedTex = node.GetStringValues("inheritTexture"); inheritedFloat = node.GetStringValues("inheritFloat"); inheritedColor = node.GetStringValues("inheritColor"); if (!node.HasValue("mode")) { Log.error("TextureSet: " + owner.name + " did not have definition for mode (create/update). Using default value of: " + defaultMode + ". This may not function as desired, and may need to be corrected in the configuration file."); } mode = node.GetStringValue("mode", defaultMode); renderQueue = node.GetIntValue("renderQueue", (TexturesUnlimitedLoader.isTransparentShader(shader)? (int)RenderQueue.Transparent : (int)RenderQueue.Geometry)); textureScale = node.GetVector2("textureScale", Vector2.one); textureOffset = node.GetVector2("textureOffset", Vector2.zero); }
/// <summary> /// Restores texture set data and either loads default texture set or saved texture set (if any) /// </summary> private void initialize() { if (textureSets != null) { //already initialized from OnLoad (prefab, some in-editor parts) return; } ConfigNode node = Utils.parseConfigNode(configNodeData); string[] setNames = node.GetStringValues("textureSet", false); string modelShaderName = node.GetStringValue("modelShader"); List <TextureSet> allSets = new List <TextureSet>(); if (!string.IsNullOrEmpty(modelShaderName)) { TextureSet set = TexturesUnlimitedLoader.getModelShaderTextureSet(modelShaderName); if (set != null) { allSets.Add(set); } } TextureSet[] sets = TexturesUnlimitedLoader.getTextureSets(setNames); for (int i = 0; i < sets.Length; i++) { allSets.Add(sets[i]); } ConfigNode[] fullNodeSets = node.GetNodes("KSP_TEXTURE_SET"); for (int i = 0; i < fullNodeSets.Length; i++) { allSets.Add(new TextureSet(fullNodeSets[i], "create")); } textureSets = new TextureSetContainer(this, Fields[nameof(currentTextureSet)], Fields[nameof(persistentData)], allSets); if (string.IsNullOrEmpty(currentTextureSet)) { currentTextureSet = allSets[0].name; } this.updateUIChooseOptionControl(nameof(currentTextureSet), textureSets.getTextureSetNames(), textureSets.getTextureSetTitles(), true, currentTextureSet); textureSets.enableCurrentSet(getModelTransforms(), false); Fields[nameof(currentTextureSet)].guiName = sectionName; }
public void Start() { MonoBehaviour.print("TULoader - Start()"); INSTANCE = this; DontDestroyOnLoad(this); if (partListLoadedEvent == null) { partListLoadedEvent = new EventVoid.OnEvent(onPartListLoaded); GameEvents.OnPartLoaderLoaded.Add(partListLoadedEvent); } //check the graphics API, popup warning if using unsupported gfx (dx9/11/12/legacy-openGL) UnityEngine.Rendering.GraphicsDeviceType graphicsAPI = SystemInfo.graphicsDeviceType; if (graphicsAPI == UnityEngine.Rendering.GraphicsDeviceType.OpenGLCore) { //noop, everything is fine } else if (graphicsAPI == UnityEngine.Rendering.GraphicsDeviceType.Direct3D11) { //works, but needs alternate render alternateRender = true; } else if (graphicsAPI == UnityEngine.Rendering.GraphicsDeviceType.Direct3D9) { //has issues -- display warning, and needs alternate render alternateRender = true; if (apiCheckGUI == null) { apiCheckGUI = this.gameObject.AddComponent <GraphicsAPIGUI>(); apiCheckGUI.openGUI(); } } else { //unknown API -- display warning if (apiCheckGUI == null) { apiCheckGUI = this.gameObject.AddComponent <GraphicsAPIGUI>(); apiCheckGUI.openGUI(); } } }
public void toggleDebugSphere() { if (debugSphere != null) { GameObject.Destroy(debugSphere); debugSphere = null; } else { debugSphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); debugSphere.name = "ReflectionDebugSphere"; GameObject.DestroyImmediate(debugSphere.GetComponent <Collider>()); debugSphere.transform.localScale = Vector3.one * 10f; Shader metallic = TexturesUnlimitedLoader.getShader("SSTU/PBR/Metallic"); Material mat = new Material(metallic); mat.SetFloat("_Metallic", 1); mat.SetFloat("_Smoothness", 1); debugSphere.GetComponent <MeshRenderer>().material = mat; } }
public void Start() { MonoBehaviour.print("TULoader - Start()"); INSTANCE = this; DontDestroyOnLoad(this); if (partListLoadedEvent == null) { partListLoadedEvent = new EventVoid.OnEvent(onPartListLoaded); GameEvents.OnPartLoaderLoaded.Add(partListLoadedEvent); } //check the graphics API, popup warning if using unsupported gfx (dx9/11/12/legacy-openGL) UnityEngine.Rendering.GraphicsDeviceType graphicsAPI = SystemInfo.graphicsDeviceType; if (graphicsAPI != UnityEngine.Rendering.GraphicsDeviceType.OpenGLCore) { if (apiCheckGUI == null) { apiCheckGUI = this.gameObject.AddComponent <GraphicsAPIGUI>(); apiCheckGUI.openGUI(); } } }
private TextureSet getSet() { TextureSet set = null; if (!string.IsNullOrEmpty(textureSet) && (set = TexturesUnlimitedLoader.getTextureSet(textureSet)) != null) { modelShaderSet = string.Empty; return(set); } else if (!string.IsNullOrEmpty(modelShaderSet) && (set = TexturesUnlimitedLoader.getModelShaderTextureSet(modelShaderSet)) != null) { textureSet = string.Empty; return(set); } else if ((set = getSet(part.baseVariant)) != null) { return(set); } //if nothing found, clear out references modelShaderSet = textureSet = string.Empty; return(null); }
public TransparentShaderData(ConfigNode node) { shaderName = node.GetStringValue("name"); shader = TexturesUnlimitedLoader.getShader(shaderName); }
public TextureSet getSectionTexture(string name) { return(string.IsNullOrEmpty(textureSet)? TexturesUnlimitedLoader.getModelShaderTextureSet(modelShaderSet) : TexturesUnlimitedLoader.getTextureSet(textureSet)); }