浏览代码

Added proper error messages for "ExportSkyToTexture" to the method.

/fptl_cleanup
Julien Ignace 8 年前
当前提交
5702f00d
共有 4 个文件被更改,包括 47 次插入42 次删除
  1. 1
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineMenuItems.cs
  2. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
  3. 83
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/SkyManager.cs
  4. 3
      Assets/ScriptableRenderPipeline/common/Resources/BlitCubemap.shader

1
Assets/ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineMenuItems.cs


Texture2D result = renderpipelineInstance.ExportSkyToTexture();
if(result == null)
{
Debug.LogError("Cannot export sky to an image, Sky is not setup properly.");
return;
}

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs


public Texture2D ExportSkyToTexture()
{
return m_SkyManager.ExportSkyToImage();
return m_SkyManager.ExportSkyToTexture();
}
void RenderForward(CullResults cullResults, Camera camera, ScriptableRenderContext renderContext, bool renderOpaque)

83
Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/SkyManager.cs


}
}
public Texture2D ExportSkyToImage()
public Texture2D ExportSkyToTexture()
if(m_Renderer != null && m_Renderer.IsSkyValid())
if(m_Renderer == null)
int resolution = (int)m_SkySettings.resolution;
Debug.LogError("Cannot export sky to a texture, no SkyRenderer is setup.");
return null;
}
RenderTexture tempRT = new RenderTexture(resolution * 6, resolution, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear);
tempRT.dimension = TextureDimension.Tex2D;
tempRT.useMipMap = false;
tempRT.autoGenerateMips = false;
tempRT.filterMode = FilterMode.Trilinear;
tempRT.Create();
if(m_SkySettings == null)
{
Debug.LogError("Cannot export sky to a texture, no Sky settings are setup.");
return null;
}
Texture2D temp = new Texture2D(resolution * 6, resolution, TextureFormat.RGBAFloat, false);
Texture2D result = new Texture2D(resolution * 6, resolution, TextureFormat.RGBAFloat, false);
int resolution = (int)m_SkySettings.resolution;
// Note: We need to invert in Y the cubemap faces because the current sky cubemap is inverted (because it's a RT)
// So to invert it again so that it's a proper cubemap image we need to do it in several steps because ReadPixels does not have scale parameters:
// - Convert the cubemap into a 2D texture
// - Blit and invert it to a temporary target.
// - Read this target again into the result texture.
int offset = 0;
for (int i = 0; i < 6; ++i)
{
Graphics.SetRenderTarget(m_SkyboxCubemapRT, 0, (CubemapFace)i);
temp.ReadPixels(new Rect(0, 0, resolution, resolution), offset, 0);
temp.Apply();
offset += resolution;
}
RenderTexture tempRT = new RenderTexture(resolution * 6, resolution, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear);
tempRT.dimension = TextureDimension.Tex2D;
tempRT.useMipMap = false;
tempRT.autoGenerateMips = false;
tempRT.filterMode = FilterMode.Trilinear;
tempRT.Create();
Texture2D temp = new Texture2D(resolution * 6, resolution, TextureFormat.RGBAFloat, false);
Texture2D result = new Texture2D(resolution * 6, resolution, TextureFormat.RGBAFloat, false);
// Note: We need to invert in Y the cubemap faces because the current sky cubemap is inverted (because it's a RT)
// So to invert it again so that it's a proper cubemap image we need to do it in several steps because ReadPixels does not have scale parameters:
// - Convert the cubemap into a 2D texture
// - Blit and invert it to a temporary target.
// - Read this target again into the result texture.
int offset = 0;
for (int i = 0; i < 6; ++i)
{
Graphics.SetRenderTarget(m_SkyboxCubemapRT, 0, (CubemapFace)i);
temp.ReadPixels(new Rect(0, 0, resolution, resolution), offset, 0);
temp.Apply();
offset += resolution;
}
// Flip texture.
// Temporarily disabled until proper API reaches trunk
//Graphics.Blit(temp, tempRT, new Vector2(1.0f, -1.0f), new Vector2(0.0f, 0.0f));
Graphics.Blit(temp, tempRT);
// Flip texture.
// Temporarily disabled until proper API reaches trunk
//Graphics.Blit(temp, tempRT, new Vector2(1.0f, -1.0f), new Vector2(0.0f, 0.0f));
Graphics.Blit(temp, tempRT);
result.ReadPixels(new Rect(0, 0, resolution * 6, resolution), 0, 0);
result.Apply();
result.ReadPixels(new Rect(0, 0, resolution * 6, resolution), 0, 0);
result.Apply();
Graphics.SetRenderTarget(null);
Object.DestroyImmediate(temp);
Object.DestroyImmediate(tempRT);
Graphics.SetRenderTarget(null);
Object.DestroyImmediate(temp);
Object.DestroyImmediate(tempRT);
return result;
}
else
{
return null;
}
return result;
}
}
}

3
Assets/ScriptableRenderPipeline/common/Resources/BlitCubemap.shader


Shader "Hidden/BlitCubemap" {
// Note: This shader is supposed to be removed at some point when Graphics.ConvertTexture can take a RenderTexture as a destination (it's only used by sky manager for now).
Shader "Hidden/BlitCubemap" {
SubShader {
// Cubemap blit. Takes a face index.
Pass {

正在加载...
取消
保存