浏览代码

[PlanarReflection] Updated baking

/main
Frédéric Vauchelles 7 年前
当前提交
6882761f
共有 4 个文件被更改,包括 41 次插入16 次删除
  1. 34
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/EditorReflectionSystem.cs
  2. 5
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/PlanarReflectionProbeEditor.cs
  3. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/PlanarReflectionProbe.cs
  4. 16
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/ReflectionSystemInternal.cs

34
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/EditorReflectionSystem.cs


if (!BakePlanarReflectionProbe(probe, path))
Debug.LogError("Failed to bake reflection probe to " + path);
EditorUtility.ClearProgressBar();
AssetDatabase.ImportAsset(path);
probe.customTexture = AssetDatabase.LoadAssetAtPath<Texture2D>(path);
EditorUtility.SetDirty(probe);
}
public static void BakeAllPlanarReflectionProbes()

public static void ResetProbeSceneTextureInMaterial(PlanarReflectionProbe p)
{
throw new NotImplementedException();
}
static MethodInfo k_Lightmapping_BakeReflectionProbeSnapshot = typeof(UnityEditor.Lightmapping).GetMethod("BakeReflectionProbeSnapshot", BindingFlags.Static | BindingFlags.NonPublic);

{
var rt = ReflectionSystem.NewRenderTarget(probe);
var bakedTexture = probe.bakedTexture as Texture2D;
if (bakedTexture == null)
var assetPath = string.Empty;
if (bakedTexture != null)
assetPath = AssetDatabase.GetAssetPath(bakedTexture);
if (string.IsNullOrEmpty(assetPath))
assetPath = GetBakePath(probe);
var importAsset = false;
if (bakedTexture == null || string.IsNullOrEmpty(assetPath))
var bakedAssetPath = GetBakePath(probe);
AssetDatabase.CreateAsset(bakedTexture, bakedAssetPath);
importAsset = true;
EditorUtility.SetDirty(probe);
}
ReflectionSystem.Render(probe, rt);

RenderTexture.active = art;
var assetPath = AssetDatabase.GetAssetPath(bakedTexture);
var bytes = bakedTexture.EncodeToEXR();
File.WriteAllBytes(assetPath, bytes);
if (importAsset)
AssetDatabase.CreateAsset(bakedTexture, assetPath);
else
{
var bytes = bakedTexture.EncodeToEXR();
File.WriteAllBytes(assetPath, bytes);
AssetDatabase.ImportAsset(assetPath);
}
return true;
}

var scene = probe.gameObject.scene;
var targetPath = GetSceneBakeDirectoryPath(scene);
if (Directory.Exists(targetPath) == false)
if (!Directory.Exists(targetPath))
return Path.GetFileNameWithoutExtension(AssetDatabase.GenerateUniqueAssetPath(Path.Combine(targetPath, fileName)));
return AssetDatabase.GenerateUniqueAssetPath(Path.Combine(targetPath, fileName));
}
static string GetSceneBakeDirectoryPath(Scene scene)

5
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/PlanarReflectionProbeEditor.cs


r.y + size.y * col + ((col > 0) ? (col - 1) * space.y : 0),
size.x,
size.y);
GUI.DrawTexture(itemRect, m_PreviewedTextures[i]);
EditorGUI.DrawPreviewTexture(itemRect, m_PreviewedTextures[i], null, ScaleMode.ScaleToFit, 0, 1);
GUI.Label(itemRect, _.GetContent("Not Available"));
EditorGUI.LabelField(itemRect, _.GetContent("Not Available"));
}
}
}

2
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/PlanarReflectionProbe.cs


get { return Quaternion.LookRotation(influencePosition - capturePosition, transform.up); }
}
public Vector3 influencePosition { get { return transform.TransformPoint(influenceVolume.boxBaseOffset); } }
public Texture customTexture { get { return m_CustomTexture; } }
public Texture customTexture { get { return m_CustomTexture; } set { m_CustomTexture = value; } }
public Texture bakedTexture { get { return m_BakedTexture; } set { m_BakedTexture = value; }}
public RenderTexture realtimeTexture { get { return m_RealtimeTexture; } internal set { m_RealtimeTexture = value; } }
public ReflectionProbeRefreshMode refreshMode { get { return m_RefreshMode; } }

16
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/ReflectionSystemInternal.cs


{
if (s_RenderCamera == null)
{
s_RenderCamera = new GameObject("Probe Render Camera").
AddComponent<Camera>();
s_RenderCameraData = s_RenderCamera.gameObject.AddComponent<HDAdditionalCameraData>();
s_RenderCamera.gameObject.SetActive(false);
var go = GameObject.Find("__Probe Render Camera") ?? new GameObject("__Probe Render Camera");
go.hideFlags = HideFlags.HideAndDontSave;
s_RenderCamera = go.GetComponent<Camera>();
if (s_RenderCamera == null || s_RenderCamera.Equals(null))
s_RenderCamera = go.AddComponent<Camera>();
s_RenderCameraData = go.GetComponent<HDAdditionalCameraData>();
if (s_RenderCameraData == null || s_RenderCameraData.Equals(null))
s_RenderCameraData = go.AddComponent<HDAdditionalCameraData>();
go.SetActive(false);
}
return s_RenderCamera;

正在加载...
取消
保存