├── Matcap Generator ├── Models │ ├── Sphere.fbx │ └── MatcapGeneratorMaterial.mat ├── Editor │ └── MatcapGeneratorEditor.cs ├── MatcapGenerator.cs └── Matcap Generator.prefab ├── LICENSE └── README.md /Matcap Generator/Models/Sphere.fbx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bomul0327/Unity-Matcap-Generator/HEAD/Matcap Generator/Models/Sphere.fbx -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Unity-Matcap-Generator 2 | 3 | ## Overview 4 | 5 | This is a simple matcap texture generator for Unity users. You can check a generated matcap texture in realtime. Also, you can save the texture if you want. This one can generate various types of material, if you can handle unity's rendering system, such as lights, materials, shaders or something else. 6 | 7 | The detailed documentation will be added at Wiki soon. 8 | 9 | ## Checked Unity version 10 | * 2018.4.14 11 | * 2019.2.16f1 12 | 13 | I didn't check URP or HDRP version. It may works but you need to modify a material, because the Standard shader in Unity is not supported in URP or HDRP. 14 | 15 | ## Usage 16 | ### Download 17 | You can download this from the github repository or from releases(https://github.com/bomul0327/Unity-Matcap-Generator/releases) 18 | 19 | ### Install 20 | Please install through package, not source code. 21 | 22 | ### How to Use? 23 | 1. Place "Matcap Generator" prefab on your scene. 24 | 2. Select the prefab. 25 | 3. By changing variables, you can change the size of texture, path. 26 | 4. If you want to apply your matcap texture to your material, add the material on "Target Material". Then, Check "Apply Matcap Texture". 27 | 5. By changing "Target Texture Property", you can apply matcap texture where you want. 28 | 6. Press "Save Matcap Texture" to save your matcap texture. 29 | 30 | ## License 31 | You can use this for free. 32 | -------------------------------------------------------------------------------- /Matcap Generator/Editor/MatcapGeneratorEditor.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEditor; 5 | 6 | namespace UnrealChan 7 | { 8 | [CustomEditor(typeof(MatcapGenerator))] 9 | public class MatcapGeneratorEditor : Editor 10 | { 11 | SerializedProperty texturePropertiesIdxProp; 12 | 13 | Texture2D texture; 14 | 15 | void OnEnable() 16 | { 17 | texturePropertiesIdxProp = serializedObject.FindProperty("CurrentTexturePropertiesIdx"); 18 | } 19 | 20 | public override void OnInspectorGUI() 21 | { 22 | base.OnInspectorGUI(); 23 | serializedObject.Update(); 24 | 25 | MatcapGenerator script = target as MatcapGenerator; 26 | 27 | texture = script.GeneratedTexture; 28 | 29 | if (script.TargetMaterial != null) 30 | { 31 | var properties = script.TargetMaterial.GetTexturePropertyNames(); 32 | texturePropertiesIdxProp.intValue = EditorGUILayout.Popup("Target Texture Property", texturePropertiesIdxProp.intValue, properties); 33 | script.TextureProperty = properties[texturePropertiesIdxProp.intValue]; 34 | } 35 | 36 | EditorGUILayout.BeginHorizontal(); 37 | 38 | if (GUILayout.Button("Save Matcap Texture")) 39 | { 40 | if (script.TextureProperty != string.Empty) 41 | { 42 | var fullPath = script.SaveTexture(texture); 43 | AssetDatabase.Refresh(); 44 | 45 | Texture2D saved = (Texture2D)AssetDatabase.LoadAssetAtPath(fullPath, typeof(Texture2D)); 46 | 47 | script.ApplyToMaterial(saved); 48 | } 49 | } 50 | 51 | EditorGUILayout.EndHorizontal(); 52 | 53 | GUILayout.Label("Generated Matcap Preview"); 54 | if (texture != null) 55 | { 56 | GUILayout.Label(texture); 57 | } 58 | 59 | serializedObject.ApplyModifiedProperties(); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Matcap Generator/Models/MatcapGeneratorMaterial.mat: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!21 &2100000 4 | Material: 5 | serializedVersion: 6 6 | m_ObjectHideFlags: 0 7 | m_CorrespondingSourceObject: {fileID: 0} 8 | m_PrefabInstance: {fileID: 0} 9 | m_PrefabAsset: {fileID: 0} 10 | m_Name: MatcapGeneratorMaterial 11 | m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0} 12 | m_ShaderKeywords: 13 | m_LightmapFlags: 4 14 | m_EnableInstancingVariants: 0 15 | m_DoubleSidedGI: 0 16 | m_CustomRenderQueue: -1 17 | stringTagMap: {} 18 | disabledShaderPasses: [] 19 | m_SavedProperties: 20 | serializedVersion: 3 21 | m_TexEnvs: 22 | - _BumpMap: 23 | m_Texture: {fileID: 0} 24 | m_Scale: {x: 1, y: 1} 25 | m_Offset: {x: 0, y: 0} 26 | - _DetailAlbedoMap: 27 | m_Texture: {fileID: 0} 28 | m_Scale: {x: 1, y: 1} 29 | m_Offset: {x: 0, y: 0} 30 | - _DetailMask: 31 | m_Texture: {fileID: 0} 32 | m_Scale: {x: 1, y: 1} 33 | m_Offset: {x: 0, y: 0} 34 | - _DetailNormalMap: 35 | m_Texture: {fileID: 0} 36 | m_Scale: {x: 1, y: 1} 37 | m_Offset: {x: 0, y: 0} 38 | - _EmissionMap: 39 | m_Texture: {fileID: 0} 40 | m_Scale: {x: 1, y: 1} 41 | m_Offset: {x: 0, y: 0} 42 | - _MainTex: 43 | m_Texture: {fileID: 0} 44 | m_Scale: {x: 1, y: 1} 45 | m_Offset: {x: 0, y: 0} 46 | - _MetallicGlossMap: 47 | m_Texture: {fileID: 0} 48 | m_Scale: {x: 1, y: 1} 49 | m_Offset: {x: 0, y: 0} 50 | - _OcclusionMap: 51 | m_Texture: {fileID: 0} 52 | m_Scale: {x: 1, y: 1} 53 | m_Offset: {x: 0, y: 0} 54 | - _ParallaxMap: 55 | m_Texture: {fileID: 0} 56 | m_Scale: {x: 1, y: 1} 57 | m_Offset: {x: 0, y: 0} 58 | m_Floats: 59 | - _BumpScale: 1 60 | - _Cutoff: 0.5 61 | - _DetailNormalMapScale: 1 62 | - _DstBlend: 0 63 | - _GlossMapScale: 1 64 | - _Glossiness: 0 65 | - _GlossyReflections: 1 66 | - _Metallic: 0 67 | - _Mode: 0 68 | - _OcclusionStrength: 1 69 | - _Parallax: 0.02 70 | - _SmoothnessTextureChannel: 0 71 | - _SpecularHighlights: 1 72 | - _SrcBlend: 1 73 | - _UVSec: 0 74 | - _ZWrite: 1 75 | m_Colors: 76 | - _Color: {r: 0.8, g: 0.8, b: 0.8, a: 1} 77 | - _EmissionColor: {r: 0, g: 0, b: 0, a: 0} 78 | -------------------------------------------------------------------------------- /Matcap Generator/MatcapGenerator.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using System.IO; 5 | 6 | [ExecuteInEditMode] 7 | public class MatcapGenerator : MonoBehaviour 8 | { 9 | public int Size = 512; 10 | 11 | public string folderPath = "Assets/MatcapTextures/"; 12 | 13 | public string FileName = "Default"; 14 | 15 | public Material TargetMaterial; 16 | 17 | public bool ApplyMatcapTexture = false; 18 | 19 | [HideInInspector] 20 | public string TextureProperty; 21 | 22 | [HideInInspector] 23 | public int CurrentTexturePropertiesIdx; 24 | 25 | [HideInInspector] 26 | public Texture2D GeneratedTexture; 27 | 28 | private int texturePropertyID; 29 | 30 | private Camera cam; 31 | 32 | void OnEnable() 33 | { 34 | cam = GetComponent(); 35 | } 36 | 37 | void LateUpdate() 38 | { 39 | GeneratedTexture = Capture(); 40 | 41 | if (ApplyMatcapTexture && TextureProperty != string.Empty) 42 | { 43 | ApplyToMaterial(GeneratedTexture); 44 | } 45 | } 46 | 47 | public Texture2D Capture() 48 | { 49 | RenderTexture rt = new RenderTexture(Size, Size, 24); 50 | cam.targetTexture = rt; 51 | 52 | cam.Render(); 53 | RenderTexture.active = rt; 54 | 55 | Texture2D texture = new Texture2D(Size, Size, TextureFormat.RGB24, false); 56 | Rect rect = new Rect(0, 0, Size, Size); 57 | texture.ReadPixels(rect, 0, 0); 58 | texture.Apply(); 59 | 60 | RenderTexture.active = null; 61 | 62 | cam.targetTexture = null; 63 | rt.Release(); 64 | rt = null; 65 | 66 | return texture; 67 | } 68 | 69 | public void ApplyToMaterial(Texture2D texture) 70 | { 71 | if (TargetMaterial == null) return; 72 | texturePropertyID = Shader.PropertyToID(TextureProperty); 73 | TargetMaterial.SetTexture(texturePropertyID, texture); 74 | } 75 | 76 | public string SaveTexture(Texture2D texture) 77 | { 78 | if (!Directory.Exists(folderPath)) 79 | { 80 | Directory.CreateDirectory(folderPath); 81 | } 82 | 83 | byte[] bytes = texture.EncodeToPNG(); 84 | 85 | var filePath = folderPath + FileName + TextureProperty + "_" + System.DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"); 86 | 87 | File.WriteAllBytes(filePath + ".png", bytes); 88 | 89 | return filePath + ".png"; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /Matcap Generator/Matcap Generator.prefab: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!1 &6476403933402816896 4 | GameObject: 5 | m_ObjectHideFlags: 0 6 | m_CorrespondingSourceObject: {fileID: 0} 7 | m_PrefabInstance: {fileID: 0} 8 | m_PrefabAsset: {fileID: 0} 9 | serializedVersion: 6 10 | m_Component: 11 | - component: {fileID: 6476403933402816901} 12 | - component: {fileID: 6476403933402816898} 13 | - component: {fileID: 4750627481860845763} 14 | m_Layer: 0 15 | m_Name: Matcap Generator 16 | m_TagString: MainCamera 17 | m_Icon: {fileID: 0} 18 | m_NavMeshLayer: 0 19 | m_StaticEditorFlags: 0 20 | m_IsActive: 1 21 | --- !u!4 &6476403933402816901 22 | Transform: 23 | m_ObjectHideFlags: 0 24 | m_CorrespondingSourceObject: {fileID: 0} 25 | m_PrefabInstance: {fileID: 0} 26 | m_PrefabAsset: {fileID: 0} 27 | m_GameObject: {fileID: 6476403933402816896} 28 | m_LocalRotation: {x: -0.00095669675, y: 0.97306013, z: -0.0034323332, w: -0.23052418} 29 | m_LocalPosition: {x: 0.28722307, y: 1.0045589, z: -10.040047} 30 | m_LocalScale: {x: 1, y: 1, z: 1} 31 | m_Children: 32 | - {fileID: 9070001049751283849} 33 | m_Father: {fileID: 0} 34 | m_RootOrder: 0 35 | m_LocalEulerAnglesHint: {x: 0.40800002, y: 206.65599, z: -0.016} 36 | --- !u!20 &6476403933402816898 37 | Camera: 38 | m_ObjectHideFlags: 0 39 | m_CorrespondingSourceObject: {fileID: 0} 40 | m_PrefabInstance: {fileID: 0} 41 | m_PrefabAsset: {fileID: 0} 42 | m_GameObject: {fileID: 6476403933402816896} 43 | m_Enabled: 0 44 | serializedVersion: 2 45 | m_ClearFlags: 2 46 | m_BackGroundColor: {r: 0, g: 0, b: 0, a: 0} 47 | m_projectionMatrixMode: 1 48 | m_GateFitMode: 2 49 | m_FOVAxisMode: 0 50 | m_SensorSize: {x: 36, y: 24} 51 | m_LensShift: {x: 0, y: 0} 52 | m_FocalLength: 50 53 | m_NormalizedViewPortRect: 54 | serializedVersion: 2 55 | x: 0 56 | y: 0 57 | width: 1 58 | height: 1 59 | near clip plane: 0.3 60 | far clip plane: 1 61 | field of view: 60 62 | orthographic: 0 63 | orthographic size: 5 64 | m_Depth: -1 65 | m_CullingMask: 66 | serializedVersion: 2 67 | m_Bits: 4294967295 68 | m_RenderingPath: -1 69 | m_TargetTexture: {fileID: 0} 70 | m_TargetDisplay: 0 71 | m_TargetEye: 3 72 | m_HDR: 1 73 | m_AllowMSAA: 1 74 | m_AllowDynamicResolution: 0 75 | m_ForceIntoRT: 0 76 | m_OcclusionCulling: 0 77 | m_StereoConvergence: 10 78 | m_StereoSeparation: 0.022 79 | --- !u!114 &4750627481860845763 80 | MonoBehaviour: 81 | m_ObjectHideFlags: 0 82 | m_CorrespondingSourceObject: {fileID: 0} 83 | m_PrefabInstance: {fileID: 0} 84 | m_PrefabAsset: {fileID: 0} 85 | m_GameObject: {fileID: 6476403933402816896} 86 | m_Enabled: 1 87 | m_EditorHideFlags: 0 88 | m_Script: {fileID: 11500000, guid: ff4ea276ac2224e16926207934bccc56, type: 3} 89 | m_Name: 90 | m_EditorClassIdentifier: 91 | Size: 512 92 | folderPath: Assets/MatcapTextures/ 93 | FileName: Default 94 | TargetMaterial: {fileID: 0} 95 | TextureProperty: _MainTex 96 | CurrentTexturePropertiesIdx: 0 97 | GeneratedTexture: {fileID: 0} 98 | --- !u!1001 &9070001049751679497 99 | PrefabInstance: 100 | m_ObjectHideFlags: 0 101 | serializedVersion: 2 102 | m_Modification: 103 | m_TransformParent: {fileID: 6476403933402816901} 104 | m_Modifications: 105 | - target: {fileID: 400000, guid: 7c4ae7bc5f7674d6a99a234ef706268b, type: 3} 106 | propertyPath: m_LocalPosition.x 107 | value: 0 108 | objectReference: {fileID: 0} 109 | - target: {fileID: 400000, guid: 7c4ae7bc5f7674d6a99a234ef706268b, type: 3} 110 | propertyPath: m_LocalPosition.y 111 | value: 0 112 | objectReference: {fileID: 0} 113 | - target: {fileID: 400000, guid: 7c4ae7bc5f7674d6a99a234ef706268b, type: 3} 114 | propertyPath: m_LocalPosition.z 115 | value: 1 116 | objectReference: {fileID: 0} 117 | - target: {fileID: 400000, guid: 7c4ae7bc5f7674d6a99a234ef706268b, type: 3} 118 | propertyPath: m_LocalRotation.x 119 | value: 0 120 | objectReference: {fileID: 0} 121 | - target: {fileID: 400000, guid: 7c4ae7bc5f7674d6a99a234ef706268b, type: 3} 122 | propertyPath: m_LocalRotation.y 123 | value: 0 124 | objectReference: {fileID: 0} 125 | - target: {fileID: 400000, guid: 7c4ae7bc5f7674d6a99a234ef706268b, type: 3} 126 | propertyPath: m_LocalRotation.z 127 | value: 0 128 | objectReference: {fileID: 0} 129 | - target: {fileID: 400000, guid: 7c4ae7bc5f7674d6a99a234ef706268b, type: 3} 130 | propertyPath: m_LocalRotation.w 131 | value: 1 132 | objectReference: {fileID: 0} 133 | - target: {fileID: 400000, guid: 7c4ae7bc5f7674d6a99a234ef706268b, type: 3} 134 | propertyPath: m_RootOrder 135 | value: 0 136 | objectReference: {fileID: 0} 137 | - target: {fileID: 400000, guid: 7c4ae7bc5f7674d6a99a234ef706268b, type: 3} 138 | propertyPath: m_LocalEulerAnglesHint.x 139 | value: 0 140 | objectReference: {fileID: 0} 141 | - target: {fileID: 400000, guid: 7c4ae7bc5f7674d6a99a234ef706268b, type: 3} 142 | propertyPath: m_LocalEulerAnglesHint.y 143 | value: 0 144 | objectReference: {fileID: 0} 145 | - target: {fileID: 400000, guid: 7c4ae7bc5f7674d6a99a234ef706268b, type: 3} 146 | propertyPath: m_LocalEulerAnglesHint.z 147 | value: 0 148 | objectReference: {fileID: 0} 149 | - target: {fileID: 400000, guid: 7c4ae7bc5f7674d6a99a234ef706268b, type: 3} 150 | propertyPath: m_LocalScale.x 151 | value: 39 152 | objectReference: {fileID: 0} 153 | - target: {fileID: 400000, guid: 7c4ae7bc5f7674d6a99a234ef706268b, type: 3} 154 | propertyPath: m_LocalScale.y 155 | value: 39 156 | objectReference: {fileID: 0} 157 | - target: {fileID: 400000, guid: 7c4ae7bc5f7674d6a99a234ef706268b, type: 3} 158 | propertyPath: m_LocalScale.z 159 | value: 39 160 | objectReference: {fileID: 0} 161 | - target: {fileID: 100000, guid: 7c4ae7bc5f7674d6a99a234ef706268b, type: 3} 162 | propertyPath: m_Name 163 | value: Sphere 164 | objectReference: {fileID: 0} 165 | m_RemovedComponents: [] 166 | m_SourcePrefab: {fileID: 100100000, guid: 7c4ae7bc5f7674d6a99a234ef706268b, type: 3} 167 | --- !u!4 &9070001049751283849 stripped 168 | Transform: 169 | m_CorrespondingSourceObject: {fileID: 400000, guid: 7c4ae7bc5f7674d6a99a234ef706268b, 170 | type: 3} 171 | m_PrefabInstance: {fileID: 9070001049751679497} 172 | m_PrefabAsset: {fileID: 0} 173 | --------------------------------------------------------------------------------