Tim Cooper
8 年前
当前提交
3094ee75
共有 14 个文件被更改,包括 344 次插入 和 136 次删除
-
128MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphEditWindow.cs
-
2MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphInspector.cs
-
8MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphPresenter.cs
-
2MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/GraphEditWindow.cs
-
88MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Presenters/TitleBarPresenter.cs
-
6MaterialGraphProject/Assets/UnityShaderEditor/Editor/AssetCallbacks/CreateShaderGraph.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphEditWindow.cs
-
67MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Graphs/MaterialGraphAsset.cs
-
58MaterialGraphProject/Assets/UnityShaderEditor/Editor/HelperShader.shader
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/HelperShader.shader.meta
-
9MaterialGraphProject/Assets/UnityShaderEditor/Editor/Importers.meta
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Importers/ShaderGraphImporter.cs.meta
-
86MaterialGraphProject/Assets/UnityShaderEditor/Editor/Importers/ShaderGraphImporter.cs
|
|||
Shader "Unlit/NewUnlitShader" |
|||
{ |
|||
Properties |
|||
{ |
|||
_MainTex ("Texture", 2D) = "white" {} |
|||
} |
|||
SubShader |
|||
{ |
|||
Tags { "RenderType"="Opaque" } |
|||
LOD 100 |
|||
|
|||
Pass |
|||
{ |
|||
CGPROGRAM |
|||
#pragma vertex vert |
|||
#pragma fragment frag |
|||
// make fog work |
|||
#pragma multi_compile_fog |
|||
|
|||
#include "UnityCG.cginc" |
|||
|
|||
struct appdata |
|||
{ |
|||
float4 vertex : POSITION; |
|||
float2 uv : TEXCOORD0; |
|||
}; |
|||
|
|||
struct v2f |
|||
{ |
|||
float2 uv : TEXCOORD0; |
|||
UNITY_FOG_COORDS(1) |
|||
float4 vertex : SV_POSITION; |
|||
}; |
|||
|
|||
sampler2D _MainTex; |
|||
float4 _MainTex_ST; |
|||
|
|||
v2f vert (appdata v) |
|||
{ |
|||
v2f o; |
|||
o.vertex = UnityObjectToClipPos(v.vertex); |
|||
o.uv = TRANSFORM_TEX(v.uv, _MainTex); |
|||
UNITY_TRANSFER_FOG(o,o.vertex); |
|||
return o; |
|||
} |
|||
|
|||
fixed4 frag (v2f i) : SV_Target |
|||
{ |
|||
// sample the texture |
|||
fixed4 col = tex2D(_MainTex, i.uv); |
|||
// apply fog |
|||
UNITY_APPLY_FOG(i.fogCoord, col); |
|||
return col; |
|||
} |
|||
ENDCG |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 9ab5e16c2083a4fe689209a8c1ae425e |
|||
timeCreated: 1495436993 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
nonModifiableTextures: |
|||
- Texture_2ad4e61d_d44e_4e70_b3d0_540eae630bdf_Uniform: {fileID: 2800000, guid: 76c3d794167d8524481195736f067518, |
|||
type: 3} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: a1485bce8acd0428fae1525629b9ed8b |
|||
folderAsset: yes |
|||
timeCreated: 1495357309 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 625f186215c104763be7675aa2d941aa |
|||
timeCreated: 1495357324 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEditor.Experimental.AssetImporters; |
|||
using UnityEngine.MaterialGraph; |
|||
using UnityEngine; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Linq; |
|||
#if UNITY_EDITOR
|
|||
using System.Reflection; |
|||
using UnityEditor; |
|||
#endif
|
|||
using UnityEngine.Graphing; |
|||
using System.Text; |
|||
|
|||
[ScriptedImporter(1, "ShaderGraph")] |
|||
public class ShaderGraphImporter : ScriptedImporter |
|||
{ |
|||
public override void OnImportAsset(AssetImportContext ctx) |
|||
{ |
|||
var textGraph = File.ReadAllText(ctx.assetPath, Encoding.UTF8); |
|||
var graph = JsonUtility.FromJson<MaterialGraph>(textGraph); |
|||
|
|||
if (graph == null) |
|||
return; |
|||
|
|||
var graphAsset = ScriptableObject.CreateInstance<MaterialGraphAsset> (); |
|||
graphAsset.materialGraph = graph; |
|||
ctx.SetMainAsset("MainAsset", graphAsset); |
|||
|
|||
var shader = RegenerateShader (graphAsset); |
|||
if (shader == null) |
|||
return; |
|||
|
|||
ctx.AddSubAsset("Shader", shader); |
|||
} |
|||
|
|||
public Shader RegenerateShader(MaterialGraphAsset asset) |
|||
{ |
|||
IMasterNode masterNode = asset.materialGraph.masterNode; |
|||
if (masterNode == null) |
|||
return null; |
|||
|
|||
var path = "Assets/UnityShaderEditor/Editor/HelperShader.shader"; |
|||
List<PropertyGenerator.TextureInfo> configuredTextures; |
|||
var shaderString = masterNode.GetFullShader(GenerationMode.ForReals, out configuredTextures); |
|||
|
|||
var shader = AssetDatabase.LoadAssetAtPath(path, typeof(Shader)) as Shader; |
|||
if (shader == null) |
|||
return null; |
|||
|
|||
File.WriteAllText (path, shaderString); |
|||
ShaderUtil.UpdateShaderAsset (shader, shaderString); |
|||
|
|||
var shaderImporter = AssetImporter.GetAtPath(path) as ShaderImporter; |
|||
if (shaderImporter == null) |
|||
return null; |
|||
|
|||
var textureNames = new List<string>(); |
|||
var textures = new List<Texture>(); |
|||
foreach (var textureInfo in configuredTextures.Where(x => x.modifiable == TexturePropertyChunk.ModifiableState.Modifiable)) |
|||
{ |
|||
var texture = EditorUtility.InstanceIDToObject(textureInfo.textureId) as Texture; |
|||
if (texture == null) |
|||
continue; |
|||
textureNames.Add(textureInfo.name); |
|||
textures.Add(texture); |
|||
} |
|||
shaderImporter.SetDefaultTextures(textureNames.ToArray(), textures.ToArray()); |
|||
|
|||
textureNames.Clear(); |
|||
textures.Clear(); |
|||
foreach (var textureInfo in configuredTextures.Where(x => x.modifiable == TexturePropertyChunk.ModifiableState.NonModifiable)) |
|||
{ |
|||
var texture = EditorUtility.InstanceIDToObject(textureInfo.textureId) as Texture; |
|||
if (texture == null) |
|||
continue; |
|||
textureNames.Add(textureInfo.name); |
|||
textures.Add(texture); |
|||
} |
|||
shaderImporter.SetNonModifiableTextures(textureNames.ToArray(), textures.ToArray()); |
|||
shaderImporter.SaveAndReimport(); |
|||
|
|||
var imported = shaderImporter.GetShader(); |
|||
return imported; |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue