浏览代码

[Shader Graph] Remove time hacks and use time overrides when rendering. Use real editor time.

/main
Tim Cooper 9 年前
当前提交
e902d076
共有 4 个文件被更改,包括 14 次插入77 次删除
  1. 3
      UnityProject/Assets/UnityShaderEditor/Editor/Source/BaseMaterialGraph.cs
  2. 38
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/BaseMaterialNode.cs
  3. 24
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/SinTimeNode.cs
  4. 26
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/TimeNode.cs

3
UnityProject/Assets/UnityShaderEditor/Editor/Source/BaseMaterialGraph.cs


get
{
if (m_PreviewUtility == null)
{
EditorUtility.SetCameraAnimateMaterials(m_PreviewUtility.m_Camera, true);
}
return m_PreviewUtility;
}

38
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/BaseMaterialNode.cs


var preview = RenderPreview(rect);
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
GL.sRGBWrite = (QualitySettings.activeColorSpace == ColorSpace.Linear);
GL.sRGBWrite = false;
}
#region Nodes

#endregion
#region Previews
protected virtual void SetEditorPreviewMaterialValues()
{
if (!needsUpdate)
return;
if (previewMaterial.HasProperty("EDITOR_TIME"))
{
var time = (float)EditorApplication.timeSinceStartup;
previewMaterial.SetVector("EDITOR_TIME", new Vector4(time / 20.0f, time, time * 2.0f, time * 3));
}
if (previewMaterial.HasProperty("EDITOR_SIN_TIME"))
{
var time = (float)EditorApplication.timeSinceStartup;
previewMaterial.SetVector("EDITOR_SIN_TIME",
new Vector4(
Mathf.Sin(time / 8.0f),
Mathf.Sin(time / 4.0f),
Mathf.Sin(time / 2.0f),
Mathf.Sin(time)));
}
}
public virtual bool UpdatePreviewMaterial()
{
MaterialWindow.DebugMaterialGraph("RecreateShaderAndMaterial : " + name + "_" + GetInstanceID());

var previewUtil = bmg.previewUtility;
previewUtil.BeginPreview(targetSize, GUIStyle.none);
// update the time in the preview material
SetEditorPreviewMaterialValues();
EditorUtility.SetCameraAnimateMaterialsTime(previewUtil.m_Camera, Time.realtimeSinceStartup);
previewUtil.m_Light[0].intensity = .5f;
previewUtil.m_Light[0].transform.rotation = Quaternion.Euler(50f, 50f, 0);
previewUtil.m_Light[1].intensity = .5f;
previewUtil.m_Light[0].intensity = 1.0f;
previewUtil.m_Light[0].transform.rotation = Quaternion.Euler (50f, 50f, 0);
previewUtil.m_Light[1].intensity = 1.0f;
InternalEditorUtility.SetCustomLighting(previewUtil.m_Light, amb);
previewUtil.DrawMesh(s_Meshes[0], Vector3.zero, Quaternion.Euler(-20, 0, 0) * Quaternion.Euler(0, 0, 0), previewMaterial, 0);

}
else
{
Graphics.Blit(null, previewMaterial);
EditorUtility.UpdateGlobalShaderProperties(Time.realtimeSinceStartup);
Graphics.Blit(null, previewMaterial);
}
return previewUtil.EndPreview();
}

24
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/SinTimeNode.cs


public override string GetOutputVariableNameForSlot(Slot s, GenerationMode generationMode)
{
return generationMode.IsPreview() ? "EDITOR_SIN_TIME" : "_SinTime";
}
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
{
base.GeneratePropertyBlock(visitor, generationMode);
if (!generationMode.IsPreview())
return;
visitor.AddShaderProperty(new VectorPropertyChunk("EDITOR_SIN_TIME", "EDITOR_SIN_TIME", Vector4.one, true));
}
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
base.GeneratePropertyUsages(visitor, generationMode);
if (!generationMode.IsPreview())
return;
visitor.AddShaderChunk(precision + "4 " + GetPropertyName() + ";", true);
return "_SinTime";
public string GetPropertyName() {return "EDITOR_SIN_TIME"; }
}
}

26
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/TimeNode.cs


namespace UnityEditor.Graphs.Material
{
[Title("Time/Time Node")]
public class TimeNode : BaseMaterialNode, IGenerateProperties, IRequiresTime
public class TimeNode : BaseMaterialNode, IRequiresTime
{
private const string kOutputSlotName = "Time";

public override string GetOutputVariableNameForSlot(Slot s, GenerationMode generationMode)
{
return generationMode.IsPreview() ? "EDITOR_TIME" : "_Time";
}
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
{
base.GeneratePropertyBlock(visitor, generationMode);
if (!generationMode.IsPreview())
return;
visitor.AddShaderProperty(new VectorPropertyChunk("EDITOR_TIME", "EDITOR_TIME", Vector4.one, true));
return "_Time";
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
base.GeneratePropertyUsages(visitor, generationMode);
if (!generationMode.IsPreview())
return;
visitor.AddShaderChunk(precision + "4 " + GetPropertyName() + ";", true);
}
public string GetPropertyName() {return "EDITOR_TIME"; }
}
}
正在加载...
取消
保存