浏览代码

fix no namespace editor classe

/main
Remi Slysz 6 年前
当前提交
389d3eb5
共有 3 个文件被更改,包括 252 次插入247 次删除
  1. 166
      com.unity.render-pipelines.high-definition/HDRP/Editor/AssetProcessors/NormalMapAverageLengthTexturePostprocessor.cs
  2. 53
      com.unity.render-pipelines.high-definition/HDRP/Editor/BuildProcessors/HDRPPreprocessBuild.cs
  3. 280
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/HDCubemapInspector.cs

166
com.unity.render-pipelines.high-definition/HDRP/Editor/AssetProcessors/NormalMapAverageLengthTexturePostprocessor.cs


using System;
using UnityEditor;
public class NormalMapAverageLengthTexturePostprocessor : AssetPostprocessor
namespace UnityEditor.Experimental.Rendering.HDPipeline
// This class will process a normal map and add the value of average normal length to the blue or alpha channel
// The texture is save as BC7.
// Tangent space normal map: BC7 RGB (normal xy - average normal length)
// Object space normal map: BC7 RGBA (normal xyz - average normal length)
static string s_Suffix = "_NA";
//static string s_SuffixOS = "_OSNA"; // Suffix for object space case - TODO
public class NormalMapAverageLengthTexturePostprocessor : AssetPostprocessor
{
// This class will process a normal map and add the value of average normal length to the blue or alpha channel
// The texture is save as BC7.
// Tangent space normal map: BC7 RGB (normal xy - average normal length)
// Object space normal map: BC7 RGBA (normal xyz - average normal length)
static string s_Suffix = "_NA";
//static string s_SuffixOS = "_OSNA"; // Suffix for object space case - TODO
void OnPreprocessTexture()
{
// Any texture with _NA suffix will store average normal lenght in alpha
if (Path.GetFileNameWithoutExtension(assetPath).EndsWith(s_Suffix, StringComparison.InvariantCultureIgnoreCase))
void OnPreprocessTexture()
// Make sure we don't convert as a normal map.
TextureImporter textureImporter = (TextureImporter)assetImporter;
textureImporter.convertToNormalmap = false;
textureImporter.alphaSource = TextureImporterAlphaSource.None;
textureImporter.mipmapEnabled = true;
textureImporter.textureCompression = TextureImporterCompression.CompressedHQ; // This is BC7 for Mac/PC
// Any texture with _NA suffix will store average normal lenght in alpha
if (Path.GetFileNameWithoutExtension(assetPath).EndsWith(s_Suffix, StringComparison.InvariantCultureIgnoreCase))
{
// Make sure we don't convert as a normal map.
TextureImporter textureImporter = (TextureImporter)assetImporter;
textureImporter.convertToNormalmap = false;
textureImporter.alphaSource = TextureImporterAlphaSource.None;
textureImporter.mipmapEnabled = true;
textureImporter.textureCompression = TextureImporterCompression.CompressedHQ; // This is BC7 for Mac/PC
textureImporter.linearTexture = true; // Says deprecated but won't work without it.
textureImporter.linearTexture = true; // Says deprecated but won't work without it.
textureImporter.sRGBTexture = false; // But we're setting the new property just in case it changes later...
textureImporter.sRGBTexture = false; // But we're setting the new property just in case it changes later...
}
}
private static Color GetColor(Color[] source, int x, int y, int width, int height)
{
x = (x + width) % width;
y = (y + height) % height;
private static Color GetColor(Color[] source, int x, int y, int width, int height)
{
x = (x + width) % width;
y = (y + height) % height;
int index = y * width + x;
var c = source[index];
int index = y * width + x;
var c = source[index];
return c;
}
return c;
}
private static Vector3 GetNormal(Color[] source, int x, int y, int width, int height)
{
Vector3 n = (Vector4)GetColor(source, x, y, width, height);
n = 2.0f * n - Vector3.one;
n.Normalize();
private static Vector3 GetNormal(Color[] source, int x, int y, int width, int height)
{
Vector3 n = (Vector4)GetColor(source, x, y, width, height);
n = 2.0f * n - Vector3.one;
n.Normalize();
return n;
}
private static Vector3 GetAverageNormal(Color[] source, int x, int y, int width, int height, int texelFootprint)
{
Vector3 averageNormal = new Vector3(0, 0, 0);
return n;
}
// Calculate the average color over the texel footprint.
for (int i = 0; i < texelFootprint; ++i)
private static Vector3 GetAverageNormal(Color[] source, int x, int y, int width, int height, int texelFootprint)
for (int j = 0; j < texelFootprint; ++j)
Vector3 averageNormal = new Vector3(0, 0, 0);
// Calculate the average color over the texel footprint.
for (int i = 0; i < texelFootprint; ++i)
averageNormal += GetNormal(source, x + i, y + j, width, height);
for (int j = 0; j < texelFootprint; ++j)
{
averageNormal += GetNormal(source, x + i, y + j, width, height);
}
}
averageNormal /= (texelFootprint * texelFootprint);
averageNormal /= (texelFootprint * texelFootprint);
return averageNormal;
}
return averageNormal;
}
void OnPostprocessTexture(Texture2D texture)
{
if (Path.GetFileNameWithoutExtension(assetPath).EndsWith(s_Suffix, StringComparison.InvariantCultureIgnoreCase))
void OnPostprocessTexture(Texture2D texture)
// Based on The Order : 1886 SIGGRAPH course notes implementation. Sample all normal map
// texels from the base mip level that are within the footprint of the current mipmap texel.
Color[] source = texture.GetPixels(0);
for (int m = 1; m < texture.mipmapCount; m++)
if (Path.GetFileNameWithoutExtension(assetPath).EndsWith(s_Suffix, StringComparison.InvariantCultureIgnoreCase))
Color[] c = texture.GetPixels(m);
// Based on The Order : 1886 SIGGRAPH course notes implementation. Sample all normal map
// texels from the base mip level that are within the footprint of the current mipmap texel.
Color[] source = texture.GetPixels(0);
for (int m = 1; m < texture.mipmapCount; m++)
{
Color[] c = texture.GetPixels(m);
int mipWidth = Math.Max(1, texture.width >> m);
int mipHeight = Math.Max(1, texture.height >> m);
int mipWidth = Math.Max(1, texture.width >> m);
int mipHeight = Math.Max(1, texture.height >> m);
for (int x = 0; x < mipWidth; ++x)
{
for (int y = 0; y < mipHeight; ++y)
for (int x = 0; x < mipWidth; ++x)
int texelFootprint = 1 << m;
Vector3 averageNormal = GetAverageNormal(source, x * texelFootprint, y * texelFootprint,
texture.width, texture.height, texelFootprint);
for (int y = 0; y < mipHeight; ++y)
{
int texelFootprint = 1 << m;
Vector3 averageNormal = GetAverageNormal(source, x * texelFootprint, y * texelFootprint,
texture.width, texture.height, texelFootprint);
// Store the normal length for the average normal.
int outputPosition = y * mipWidth + x;
// Store the normal length for the average normal.
int outputPosition = y * mipWidth + x;
// Clamp to avoid any issue (TODO: Check this)
// Write into the blue channel
float averageNormalLength = Math.Max(0.0f, Math.Min(1.0f, averageNormal.magnitude));
// Clamp to avoid any issue (TODO: Check this)
// Write into the blue channel
float averageNormalLength = Math.Max(0.0f, Math.Min(1.0f, averageNormal.magnitude));
c[outputPosition].b = averageNormalLength;
c[outputPosition].a = 1.0f;
c[outputPosition].b = averageNormalLength;
c[outputPosition].a = 1.0f;
}
texture.SetPixels(c, m);
texture.SetPixels(c, m);
}
// Now overwrite the first mip average normal channel - order is important as above we read the mip0
// For mip 0, set the normal length to 1.
{
Color[] c = texture.GetPixels(0);
for (int i = 0; i < c.Length; i++)
// Now overwrite the first mip average normal channel - order is important as above we read the mip0
// For mip 0, set the normal length to 1.
c[i].b = 1.0f;
c[i].a = 1.0f;
Color[] c = texture.GetPixels(0);
for (int i = 0; i < c.Length; i++)
{
c[i].b = 1.0f;
c[i].a = 1.0f;
}
texture.SetPixels(c, 0);
texture.SetPixels(c, 0);
}
}
}

53
com.unity.render-pipelines.high-definition/HDRP/Editor/BuildProcessors/HDRPPreprocessBuild.cs


using UnityEditor;
using UnityEngine;
class HDRPPreprocessBuild : IPreprocessBuildWithReport
namespace UnityEditor.Experimental.Rendering.HDPipeline
public int callbackOrder { get { return 0; } }
class HDRPPreprocessBuild : IPreprocessBuildWithReport
{
public int callbackOrder { get { return 0; } }
public void OnPreprocessBuild(BuildReport report)
{
// Don't execute the preprocess if we are not HDRenderPipeline
HDRenderPipeline hdrp = RenderPipelineManager.currentPipeline as HDRenderPipeline;
if (hdrp == null)
return;
public void OnPreprocessBuild(BuildReport report)
{
// Don't execute the preprocess if we are not HDRenderPipeline
HDRenderPipeline hdrp = RenderPipelineManager.currentPipeline as HDRenderPipeline;
if (hdrp == null)
return;
// Note: If you add new platform in this function, think about adding support in IsSupportedPlatform() function in HDRenderPipeline.cs
// Note: If you add new platform in this function, think about adding support in IsSupportedPlatform() function in HDRenderPipeline.cs
// If platform is supported all good
if (report.summary.platform == BuildTarget.StandaloneWindows ||
report.summary.platform == BuildTarget.StandaloneWindows64 ||
report.summary.platform == BuildTarget.StandaloneLinux64 ||
report.summary.platform == BuildTarget.StandaloneLinuxUniversal ||
report.summary.platform == BuildTarget.StandaloneOSX ||
report.summary.platform == BuildTarget.XboxOne ||
report.summary.platform == BuildTarget.PS4 ||
report.summary.platform == BuildTarget.Switch)
{
return;
}
// If platform is supported all good
if (report.summary.platform == BuildTarget.StandaloneWindows ||
report.summary.platform == BuildTarget.StandaloneWindows64 ||
report.summary.platform == BuildTarget.StandaloneLinux64 ||
report.summary.platform == BuildTarget.StandaloneLinuxUniversal ||
report.summary.platform == BuildTarget.StandaloneOSX ||
report.summary.platform == BuildTarget.XboxOne ||
report.summary.platform == BuildTarget.PS4 ||
report.summary.platform == BuildTarget.Switch)
{
return;
}
string msg = "The platform " + report.summary.platform.ToString() + " is not supported with Hight Definition Render Pipeline";
string msg = "The platform " + report.summary.platform.ToString() + " is not supported with Hight Definition Render Pipeline";
// Throw an exception to stop the build
throw new BuildFailedException(msg);
// Throw an exception to stop the build
throw new BuildFailedException(msg);
}
}
}

280
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/HDCubemapInspector.cs


using UnityEngine;
using UnityEditor;
[CustomEditorForRenderPipeline(typeof(Cubemap), typeof(HDRenderPipelineAsset))]
class HDCubemapInspector : Editor
namespace UnityEditor.Experimental.Rendering.HDPipeline
private enum NavMode
[CustomEditorForRenderPipeline(typeof(Cubemap), typeof(HDRenderPipelineAsset))]
class HDCubemapInspector : Editor
None = 0,
Zooming = 1,
Rotating = 2
}
private enum NavMode
{
None = 0,
Zooming = 1,
Rotating = 2
}
static GUIContent s_MipMapLow, s_MipMapHigh, s_ExposureLow;
static GUIStyle s_PreLabel;
static Mesh s_SphereMesh;
static GUIContent s_MipMapLow, s_MipMapHigh, s_ExposureLow;
static GUIStyle s_PreLabel;
static Mesh s_SphereMesh;
static Mesh sphereMesh
{
get { return s_SphereMesh ?? (s_SphereMesh = Resources.GetBuiltinResource(typeof(Mesh), "New-Sphere.fbx") as Mesh); }
}
static Mesh sphereMesh
{
get { return s_SphereMesh ?? (s_SphereMesh = Resources.GetBuiltinResource(typeof(Mesh), "New-Sphere.fbx") as Mesh); }
}
Material m_ReflectiveMaterial;
PreviewRenderUtility m_PreviewUtility;
float m_CameraPhi = 0.75f;
float m_CameraTheta = 0.5f;
float m_CameraDistance = 2.0f;
NavMode m_NavMode = NavMode.None;
Vector2 m_PreviousMousePosition = Vector2.zero;
Material m_ReflectiveMaterial;
PreviewRenderUtility m_PreviewUtility;
float m_CameraPhi = 0.75f;
float m_CameraTheta = 0.5f;
float m_CameraDistance = 2.0f;
NavMode m_NavMode = NavMode.None;
Vector2 m_PreviousMousePosition = Vector2.zero;
public float previewExposure = 0f;
public float mipLevelPreview = 0f;
public float previewExposure = 0f;
public float mipLevelPreview = 0f;
void Awake()
{
m_ReflectiveMaterial = new Material(Shader.Find("Debug/ReflectionProbePreview"))
void Awake()
hideFlags = HideFlags.HideAndDontSave
};
}
m_ReflectiveMaterial = new Material(Shader.Find("Debug/ReflectionProbePreview"))
{
hideFlags = HideFlags.HideAndDontSave
};
}
void OnEnable()
{
if (m_PreviewUtility == null)
InitPreview();
m_ReflectiveMaterial.SetTexture("_Cubemap", target as Texture);
}
void OnEnable()
{
if (m_PreviewUtility == null)
InitPreview();
void OnDisable()
{
if (m_PreviewUtility != null)
m_PreviewUtility.Cleanup();
}
m_ReflectiveMaterial.SetTexture("_Cubemap", target as Texture);
}
public override bool HasPreviewGUI()
{
return true;
}
void OnDisable()
{
if (m_PreviewUtility != null)
m_PreviewUtility.Cleanup();
}
public override void OnPreviewGUI(Rect r, GUIStyle background)
{
if (m_ReflectiveMaterial != null)
public override bool HasPreviewGUI()
m_ReflectiveMaterial.SetFloat("_Exposure", previewExposure);
m_ReflectiveMaterial.SetFloat("_MipLevel", mipLevelPreview);
return true;
if (m_PreviewUtility == null)
InitPreview();
public override void OnPreviewGUI(Rect r, GUIStyle background)
{
if (m_ReflectiveMaterial != null)
{
m_ReflectiveMaterial.SetFloat("_Exposure", previewExposure);
m_ReflectiveMaterial.SetFloat("_MipLevel", mipLevelPreview);
}
UpdateCamera();
if (m_PreviewUtility == null)
InitPreview();
m_PreviewUtility.BeginPreview(r, GUIStyle.none);
m_PreviewUtility.DrawMesh(sphereMesh, Matrix4x4.identity, m_ReflectiveMaterial, 0);
m_PreviewUtility.camera.Render();
m_PreviewUtility.EndAndDrawPreview(r);
UpdateCamera();
if (Event.current.type != EventType.Repaint)
{
if (HandleMouse(r))
Repaint();
m_PreviewUtility.BeginPreview(r, GUIStyle.none);
m_PreviewUtility.DrawMesh(sphereMesh, Matrix4x4.identity, m_ReflectiveMaterial, 0);
m_PreviewUtility.camera.Render();
m_PreviewUtility.EndAndDrawPreview(r);
if (Event.current.type != EventType.Repaint)
{
if (HandleMouse(r))
Repaint();
}
}
public override void OnPreviewSettings()
{
if (s_MipMapLow == null)
InitIcons();
var mipmapCount = 0;
var cubemap = target as Cubemap;
var rt = target as RenderTexture;
if (cubemap != null)
mipmapCount = cubemap.mipmapCount;
if (rt != null)
mipmapCount = rt.useMipMap
? (int)(Mathf.Log(Mathf.Max(rt.width, rt.height)) / Mathf.Log(2))
: 1;
public override void OnPreviewSettings()
{
if (s_MipMapLow == null)
InitIcons();
GUI.enabled = true;
var mipmapCount = 0;
var cubemap = target as Cubemap;
var rt = target as RenderTexture;
if (cubemap != null)
mipmapCount = cubemap.mipmapCount;
if (rt != null)
mipmapCount = rt.useMipMap
? (int)(Mathf.Log(Mathf.Max(rt.width, rt.height)) / Mathf.Log(2))
: 1;
GUILayout.Box(s_ExposureLow, s_PreLabel, GUILayout.MaxWidth(20));
GUI.changed = false;
previewExposure = GUILayout.HorizontalSlider(previewExposure, -10f, 10f, GUILayout.MaxWidth(80));
GUILayout.Space(5);
GUILayout.Box(s_MipMapHigh, s_PreLabel, GUILayout.MaxWidth(20));
GUI.changed = false;
mipLevelPreview = GUILayout.HorizontalSlider(mipLevelPreview, 0, mipmapCount, GUILayout.MaxWidth(80));
GUILayout.Box(s_MipMapLow, s_PreLabel, GUILayout.MaxWidth(20));
}
GUI.enabled = true;
void InitPreview()
{
if (m_PreviewUtility != null)
m_PreviewUtility.Cleanup();
m_PreviewUtility = new PreviewRenderUtility(false, true);
m_PreviewUtility.cameraFieldOfView = 50.0f;
m_PreviewUtility.camera.nearClipPlane = 0.01f;
m_PreviewUtility.camera.farClipPlane = 20.0f;
m_PreviewUtility.camera.transform.position = new Vector3(0, 0, 2);
m_PreviewUtility.camera.transform.LookAt(Vector3.zero);
}
GUILayout.Box(s_ExposureLow, s_PreLabel, GUILayout.MaxWidth(20));
GUI.changed = false;
previewExposure = GUILayout.HorizontalSlider(previewExposure, -10f, 10f, GUILayout.MaxWidth(80));
GUILayout.Space(5);
GUILayout.Box(s_MipMapHigh, s_PreLabel, GUILayout.MaxWidth(20));
GUI.changed = false;
mipLevelPreview = GUILayout.HorizontalSlider(mipLevelPreview, 0, mipmapCount, GUILayout.MaxWidth(80));
GUILayout.Box(s_MipMapLow, s_PreLabel, GUILayout.MaxWidth(20));
}
bool HandleMouse(Rect Viewport)
{
var result = false;
void InitPreview()
{
if (m_PreviewUtility != null)
m_PreviewUtility.Cleanup();
m_PreviewUtility = new PreviewRenderUtility(false, true);
m_PreviewUtility.cameraFieldOfView = 50.0f;
m_PreviewUtility.camera.nearClipPlane = 0.01f;
m_PreviewUtility.camera.farClipPlane = 20.0f;
m_PreviewUtility.camera.transform.position = new Vector3(0, 0, 2);
m_PreviewUtility.camera.transform.LookAt(Vector3.zero);
}
if (Event.current.type == EventType.MouseDown)
bool HandleMouse(Rect Viewport)
if (Event.current.button == 0)
m_NavMode = NavMode.Rotating;
else if (Event.current.button == 1)
m_NavMode = NavMode.Zooming;
var result = false;
m_PreviousMousePosition = Event.current.mousePosition;
result = true;
}
if (Event.current.type == EventType.MouseDown)
{
if (Event.current.button == 0)
m_NavMode = NavMode.Rotating;
else if (Event.current.button == 1)
m_NavMode = NavMode.Zooming;
if (Event.current.type == EventType.MouseUp || Event.current.rawType == EventType.MouseUp)
m_NavMode = NavMode.None;
m_PreviousMousePosition = Event.current.mousePosition;
result = true;
}
if (m_NavMode != NavMode.None)
{
var mouseDelta = Event.current.mousePosition - m_PreviousMousePosition;
switch (m_NavMode)
if (Event.current.type == EventType.MouseUp || Event.current.rawType == EventType.MouseUp)
m_NavMode = NavMode.None;
if (m_NavMode != NavMode.None)
case NavMode.Rotating:
m_CameraTheta = (m_CameraTheta - mouseDelta.x * 0.003f) % (Mathf.PI * 2);
m_CameraPhi = Mathf.Clamp(m_CameraPhi - mouseDelta.y * 0.003f, 0.2f, Mathf.PI - 0.2f);
break;
case NavMode.Zooming:
m_CameraDistance = Mathf.Clamp(mouseDelta.y * 0.01f + m_CameraDistance, 1, 10);
break;
var mouseDelta = Event.current.mousePosition - m_PreviousMousePosition;
switch (m_NavMode)
{
case NavMode.Rotating:
m_CameraTheta = (m_CameraTheta - mouseDelta.x * 0.003f) % (Mathf.PI * 2);
m_CameraPhi = Mathf.Clamp(m_CameraPhi - mouseDelta.y * 0.003f, 0.2f, Mathf.PI - 0.2f);
break;
case NavMode.Zooming:
m_CameraDistance = Mathf.Clamp(mouseDelta.y * 0.01f + m_CameraDistance, 1, 10);
break;
}
result = true;
result = true;
m_PreviousMousePosition = Event.current.mousePosition;
return result;
m_PreviousMousePosition = Event.current.mousePosition;
return result;
}
void UpdateCamera()
{
var pos = new Vector3(Mathf.Sin(m_CameraPhi) * Mathf.Cos(m_CameraTheta), Mathf.Cos(m_CameraPhi), Mathf.Sin(m_CameraPhi) * Mathf.Sin(m_CameraTheta)) * m_CameraDistance;
m_PreviewUtility.camera.transform.position = pos;
m_PreviewUtility.camera.transform.LookAt(Vector3.zero);
}
void UpdateCamera()
{
var pos = new Vector3(Mathf.Sin(m_CameraPhi) * Mathf.Cos(m_CameraTheta), Mathf.Cos(m_CameraPhi), Mathf.Sin(m_CameraPhi) * Mathf.Sin(m_CameraTheta)) * m_CameraDistance;
m_PreviewUtility.camera.transform.position = pos;
m_PreviewUtility.camera.transform.LookAt(Vector3.zero);
}
static void InitIcons()
{
s_MipMapLow = EditorGUIUtility.IconContent("PreTextureMipMapLow");
s_MipMapHigh = EditorGUIUtility.IconContent("PreTextureMipMapHigh");
s_ExposureLow = EditorGUIUtility.IconContent("SceneViewLighting");
s_PreLabel = "preLabel";
static void InitIcons()
{
s_MipMapLow = EditorGUIUtility.IconContent("PreTextureMipMapLow");
s_MipMapHigh = EditorGUIUtility.IconContent("PreTextureMipMapHigh");
s_ExposureLow = EditorGUIUtility.IconContent("SceneViewLighting");
s_PreLabel = "preLabel";
}
}
}
正在加载...
取消
保存