浏览代码

[PlanarReflection] (wip) fixing planar probe projection

/main
Frédéric Vauchelles 7 年前
当前提交
89777ddd
共有 4 个文件被更改,包括 43 次插入15 次删除
  1. 11
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/PlanarReflectionProbeEditor.cs
  2. 33
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoop.cs
  3. 4
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/ReflectionSystemInternal.cs
  4. 10
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.hlsl

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


using System;
using System.Collections.Generic;
using System.Reflection;
using UnityEditor.Callbacks;
using UnityEngine;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Experimental.Rendering.HDPipeline;

public static bool TryGetUIStateFor(PlanarReflectionProbe p, out PlanarReflectionProbeUI r)
{
return s_StateMap.TryGetValue(p, out r);
}
[DidReloadScripts]
static void DidReloadScripts()
{
foreach (var probe in FindObjectsOfType<PlanarReflectionProbe>())
{
if (probe.enabled)
ReflectionSystem.RegisterProbe(probe);
}
}
SerializedPlanarReflectionProbe m_SerializedAsset;

33
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoop.cs


using UnityEngine.Rendering;
using System;
using System;
using UnityEngine.Assertions;
using UnityEngine.Experimental.Rendering.HDPipeline.Internal;
using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{

envIndex = m_ReflectionPlanarProbeCache.FetchSlice(cmd, probe.texture);
envIndex = envIndex << 1 | (int)EnvCacheType.Texture2D;
Matrix4x4 worldToCamera, projection;
float nearClipPlane, farClipPlane, aspect, fov;
Color backgroundColor;
CameraClearFlags clearFlags;
ReflectionSystem.CalculateCaptureCameraViewProj(
probe.planarReflectionProbe,
out worldToCamera, out projection,
out capturePosition, out captureRotation,
Matrix4x4 worldToCamera, projection;
ReflectionSystem.CalculateCaptureCameraProperties(
probe.planarReflectionProbe,
out nearClipPlane, out farClipPlane,
out aspect, out fov, out clearFlags, out backgroundColor,
out worldToCamera, out projection, out capturePosition, out captureRotation,
var vp = projection * worldToCamera;
var gpuProj = GL.GetGPUProjectionMatrix(projection, true); // Had to change this from 'false'
var gpuView = worldToCamera;
if (ShaderConfig.s_CameraRelativeRendering != 0)
{
// Zero out the translation component.
gpuView *= Matrix4x4.Translate(camera.transform.position);
}
var vp = gpuProj * gpuView;
m_Env2DCaptureVP.Add(Matrix4x4.Scale(new Vector3(1, -1, 1)) * vp);
m_Env2DCaptureVP.Add(vp);
break;
}
case TextureDimension.Cube:

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


{
nearClipPlane = viewerCamera.nearClipPlane;
farClipPlane = viewerCamera.farClipPlane;
aspect = viewerCamera.aspect;
aspect = 1;
fov = viewerCamera.fieldOfView;
clearFlags = viewerCamera.clearFlags;
backgroundColor = viewerCamera.backgroundColor;

captureRotation = Quaternion.LookRotation(forward, up);
}
static HDCamera GetRenderHDCamera(PlanarReflectionProbe probe)
public static HDCamera GetRenderHDCamera(PlanarReflectionProbe probe)
{
var camera = GetRenderCamera();

10
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.hlsl


float sampleWeight = 1;
float3 texCoord = GetSampleEnvCoordinates(lightLoopContext, lightData.envIndex, R, iblMipLevel, sampleWeight);
//weight *= sampleWeight;
float2 ndc = ComputeNormalizedDeviceCoordinates(positionWS, UNITY_MATRIX_VP);
//float4 preLD = SampleEnv(lightLoopContext, lightData.envIndex, texCoord, iblMipLevel);
float4 preLD = SAMPLE_TEXTURE2D_ARRAY_LOD(_Env2DTextures, s_trilinear_clamp_sampler, ndc.xy, lightData.envIndex >> 1, 0);
uint index = lightData.envIndex >> 1;
float2 positionNCD = ComputeNormalizedDeviceCoordinates(positionWS, _Env2DCaptureVP[index]);
texCoord = positionNCD.xyy;
float4 preLD = SampleEnv(lightLoopContext, lightData.envIndex, texCoord, iblMipLevel);
// Smooth weighting
weight = Smoothstep01(weight);

正在加载...
取消
保存