浏览代码

Merge pull request #1330 from Unity-Technologies/Clean-code

Clean reflection code about camera creation
/main
GitHub 7 年前
当前提交
ef1dc366
共有 2 个文件被更改,包括 14 次插入54 次删除
  1. 64
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/ReflectionSystemInternal.cs
  2. 4
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/StackLit/StackLit.cs.hlsl

64
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/ReflectionSystemInternal.cs


#endif
// 1. Allocate if necessary target texture
var renderCamera = GetRenderCamera();
var hdCamera = HDCamera.Get(renderCamera);
if (hdCamera == null)
{
// Warning: this is a bad design pattern.
// An individual system should not create an HDCamera (which is a shared resource).
hdCamera = HDCamera.Create(renderCamera, null);
}
hdCamera.Update(probe.frameSettings, null, null);
if (!IsRealtimeTextureValid(probe.realtimeTexture, hdCamera))
if (!IsRealtimeTextureValid(probe.realtimeTexture))
{
if (probe.realtimeTexture != null)
probe.realtimeTexture.Release();

m_PlanarReflectionProbe_RequestRealtimeRender.Clear();
// 1. Allocate if necessary target texture
var camera = GetRenderCamera();
var hdCamera = HDCamera.Get(camera);
if (hdCamera == null)
{
// Warning: this is a bad design pattern.
// An individual system should not create an HDCamera (which is a shared resource).
hdCamera = HDCamera.Create(camera, null);
}
hdCamera.Update(probe.frameSettings, null, null);
if (!IsRealtimeTextureValid(probe.realtimeTexture, hdCamera))
if (!IsRealtimeTextureValid(probe.realtimeTexture))
{
if (probe.realtimeTexture != null)
probe.realtimeTexture.Release();

// }
//}
bool IsRealtimeTextureValid(RenderTexture renderTexture, HDCamera hdCamera)
bool IsRealtimeTextureValid(RenderTexture renderTexture)
{
return renderTexture != null
&& renderTexture.width == m_Parameters.planarReflectionProbeSize

public void Render(PlanarReflectionProbe probe, RenderTexture target, Camera viewerCamera = null)
{
var renderCamera = GetRenderHDCamera(probe);
renderCamera.camera.targetTexture = target;
var renderCamera = GetRenderCamera();
SetupCameraForRender(renderCamera.camera, probe, viewerCamera);
// Copy current frameSettings of this probe to the HDAdditionalData of the render camera
probe.frameSettings.CopyTo(s_RenderCameraData.GetFrameSettings());
renderCamera.targetTexture = target;
SetupCameraForRender(renderCamera, probe, viewerCamera);
renderCamera.camera.Render();
renderCamera.Render();
renderCamera.camera.targetTexture = null;
renderCamera.targetTexture = null;
target.IncrementUpdateCount();
}

var forward = reflectionMatrix.MultiplyVector(viewerCamera.transform.forward);
var up = reflectionMatrix.MultiplyVector(viewerCamera.transform.up);
captureRotation = Quaternion.LookRotation(forward, up);
}
public static HDCamera GetRenderHDCamera(PlanarReflectionProbe probe)
{
var camera = GetRenderCamera();
probe.frameSettings.CopyTo(s_RenderCameraData.GetFrameSettings());
var hdCamera = HDCamera.Get(camera);
if (hdCamera == null)
{
// Warning: this is a bad design pattern.
// An individual system should not create an HDCamera (which is a shared resource).
hdCamera = HDCamera.Create(camera, null);
}
hdCamera.Update(probe.frameSettings, null, null);
return hdCamera;
}
static Camera GetRenderCamera()

4
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/StackLit/StackLit.cs.hlsl


#define DEBUGVIEW_STACKLIT_SURFACEDATA_ANISOTROPY (1311)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_IRIDESCENCE_IOR (1312)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_IRIDESCENCE_THICKNESS (1313)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_COAT_ROUGHNESS (1314)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_COAT_SMOOTHNESS (1314)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_COAT_IOR (1315)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_COAT_THICKNESS (1316)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_COAT_EXTINCTION_COEFFICIENT (1317)

case DEBUGVIEW_STACKLIT_SURFACEDATA_IRIDESCENCE_THICKNESS:
result = surfacedata.iridescenceThickness.xxx;
break;
case DEBUGVIEW_STACKLIT_SURFACEDATA_COAT_ROUGHNESS:
case DEBUGVIEW_STACKLIT_SURFACEDATA_COAT_SMOOTHNESS:
result = surfacedata.coatPerceptualSmoothness.xxx;
break;
case DEBUGVIEW_STACKLIT_SURFACEDATA_COAT_IOR:

正在加载...
取消
保存