// Draw Reflection probe preview sphere
private void OnPreSceneGUICallback(SceneView sceneView)
{
if (Event.current.type != EventType.Repaint)
{
return;
}
foreach (var t in targets)
{
ReflectionProbe p = (ReflectionProbe)t;
if (!reflectiveMaterial)
{
return;
}
if (!StageUtility.IsGameObjectRenderedByCameraAndPartOfEditableScene(p.gameObject, Camera.current))
{
return;
}
Matrix4x4 m = new Matrix4x4();
// @TODO: use MaterialPropertyBlock instead - once it actually works!
// Tried to use MaterialPropertyBlock in 5.4.0b2, but would get incorrectly set parameters when using with Graphics.DrawMesh
if (!m_CachedGizmoMaterials.ContainsKey(p))
{
m_CachedGizmoMaterials.Add(p, Instantiate(reflectiveMaterial));
}
Material mat = m_CachedGizmoMaterials[p] as Material;
if (!mat)
{
return;
}
{
// Get mip level
float mipLevel = 0.0F;
TextureInspector cubemapEditor = m_CubemapEditor as TextureInspector;
if (cubemapEditor)
{
mipLevel = cubemapEditor.GetMipLevelForRendering();
}
mat.SetTexture("_MainTex", p.texture);
mat.SetMatrix("_CubemapRotation", Matrix4x4.identity);
mat.SetFloat("_Mip", mipLevel);
mat.SetFloat("_Alpha", 0.0f);
mat.SetFloat("_Intensity", GetProbeIntensity(p));
// draw a preview sphere that scales with overall GO scale, but always uniformly
var scale = p.transform.lossyScale.magnitude * 0.5f;
m.SetTRS(p.transform.position, Quaternion.identity, new Vector3(scale, scale, scale));
Graphics.DrawMesh(sphereMesh, m, mat, 0, SceneView.currentDrawingSceneView.camera, 0);
}
}
}