浏览代码

[PlanarReflectionProbe] Fixed capture position

/main
Frédéric Vauchelles 7 年前
当前提交
b0889a10
共有 3 个文件被更改,包括 32 次插入42 次删除
  1. 24
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoop.cs
  2. 41
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoopDef.hlsl
  3. 9
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/LitReference.hlsl

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


if (probe.mode == ReflectionProbeMode.Realtime && camera.cameraType == CameraType.Reflection)
return false;
var capturePosition = Vector3.zero;
var influenceToWorld = probe.influenceToWorld;
// 31 bits index, 1 bit cache type
var envIndex = -1;
switch (probe.texture.dimension)

float nearClipPlane, farClipPlane, aspect, fov;
Color backgroundColor;
CameraClearFlags clearFlags;
Vector3 capturePosition;
Quaternion captureRotation;
Matrix4x4 worldToCamera, projection;

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);
capturePosition -= camera.transform.position;
}
var vp = gpuProj * gpuView;
m_Env2DCapturePositionWS.Add(capturePosition);

case TextureDimension.Cube:
envIndex = m_ReflectionProbeCache.FetchSlice(cmd, probe.texture);
envIndex = envIndex << 1 | (int)EnvCacheType.Cubemap;
capturePosition = (Vector3)influenceToWorld.GetColumn(3) + probe.reflectionProbe.center;
break;
}
// -1 means that the texture is not ready yet (ie not convolved/compressed yet)

// Build light data
var envLightData = new EnvLightData();
var influenceToWorld = probe.influenceToWorld;
envLightData.envShapeType = probe.influenceShapeType;
envLightData.dimmer = probe.dimmer;

envLightData.right = influenceToWorld.GetColumn(0).normalized;
envLightData.up = influenceToWorld.GetColumn(1).normalized;
envLightData.forward = influenceToWorld.GetColumn(2).normalized;
envLightData.capturePositionWS = Vector3.zero; //captureToWorld.GetColumn(3);
envLightData.capturePositionWS = capturePosition;
envLightData.positionWS = influenceToWorld.GetColumn(3);
envLightData.envIndex = envIndex;

m_lightList.envProxies[n - 1] = envProjData;
}
}
}
// We make the light position camera-relative as late as possible in order
// to allow the preceding code to work with the absolute world space coordinates.
if (ShaderConfig.s_CameraRelativeRendering != 0)
{
for (var i = 0; i < m_Env2DCaptureVP.Count; i++)
m_Env2DCaptureVP[i] = m_Env2DCaptureVP[i] * Matrix4x4.Translate(camPosWS);
for (var i = 0; i < m_Env2DCapturePositionWS.Count; i++)
m_Env2DCapturePositionWS[i] = (Vector3)m_Env2DCapturePositionWS[i] - camPosWS;
}
}

41
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoopDef.hlsl


// Note: index is whatever the lighting architecture want, it can contain information like in which texture to sample (in case we have a compressed BC6H texture and an uncompressed for real time reflection ?)
// EnvIndex can also be use to fetch in another array of struct (to atlas information etc...).
float4 SampleEnv(LightLoopContext lightLoopContext, int index, float3 texCoord, float lod)
{
// 31 bit index, 1 bit cache type
uint cacheType = index & 1;
index = index >> 1;
// This code will be inlined as lightLoopContext is hardcoded in the light loop
if (lightLoopContext.sampleReflection == SINGLE_PASS_CONTEXT_SAMPLE_REFLECTION_PROBES)
{
if (cacheType == ENVCACHETYPE_TEXTURE2D)
return SAMPLE_TEXTURE2D_ARRAY_LOD(_Env2DTextures, s_trilinear_clamp_sampler, texCoord.xy, index, 0);
else if (cacheType == ENVCACHETYPE_CUBEMAP)
return SAMPLE_TEXTURECUBE_ARRAY_LOD_ABSTRACT(_EnvCubemapTextures, s_trilinear_clamp_sampler, texCoord, index, lod);
return float4(0, 0, 0, 0);
}
else // SINGLE_PASS_SAMPLE_SKY
{
return SampleSkyTexture(texCoord, lod);
}
}
float3 GetSampleEnvCoordinates(LightLoopContext lightLoopContext, int index, float3 texCoord, float lod, out float outWeight)
// Cubemap : texCoord = direction vector
// Texture2D : texCoord = projectedPositionWS - lightData.capturePosition
float4 SampleEnv(LightLoopContext lightLoopContext, int index, float3 texCoord, float lod, out float weight)
{
// 31 bit index, 1 bit cache type
uint cacheType = index & 1;

{
if (cacheType == ENVCACHETYPE_TEXTURE2D)
{
float2 positionNCD = ComputeNormalizedDeviceCoordinates(_Env2DCapturePositionWS[index] + texCoord, _Env2DCaptureVP[index]);
outWeight = any(positionNCD.xy > 1) || any(positionNCD.xy < 0) ? 0 : 1;
return float3(positionNCD, 1);
float2 ndc = ComputeNormalizedDeviceCoordinates(_Env2DCapturePositionWS[index] + texCoord, _Env2DCaptureVP[index]);
weight = any(ndc < 0) || any(ndc > 1) ? 0 : 1;
return SAMPLE_TEXTURE2D_ARRAY_LOD(_Env2DTextures, s_trilinear_clamp_sampler, ndc, index, 0);
outWeight = 1;
return texCoord;
weight = 1;
return SAMPLE_TEXTURECUBE_ARRAY_LOD_ABSTRACT(_EnvCubemapTextures, s_trilinear_clamp_sampler, texCoord, index, lod);
outWeight = 0;
weight = 0;
outWeight = 1;
return texCoord;
weight = 1;
return SampleSkyTexture(texCoord, lod);
}
}

9
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/LitReference.hlsl


if (NdotL > 0.0)
{
float4 val = SampleEnv(lightLoopContext, lightData.envIndex, L, 0);
float sampleWeight = 1;
float4 val = SampleEnv(lightLoopContext, lightData.envIndex, L, 0, sampleWeight);
// We don't multiply by 'bsdfData.diffuseColor' here. It's done only once in PostEvaluateBSDF().
acc += LambertNoPI() * weightOverPdf * val.rgb;

// in weightOverPdf of ImportanceSampleLambert call.
float disneyDiffuse = DisneyDiffuse(NdotV, NdotL, LdotV, bsdfData.perceptualRoughness);
float4 val = SampleEnv(lightLoopContext, lightData.envIndex, L, 0);
float sampleWeight = 1;
float4 val = SampleEnv(lightLoopContext, lightData.envIndex, L, 0, sampleWeight);
// We don't multiply by 'bsdfData.diffuseColor' here. It's done only once in PostEvaluateBSDF().
acc += disneyDiffuse * weightOverPdf * val.rgb;
}

// Fresnel component is apply here as describe in ImportanceSampleGGX function
float3 FweightOverPdf = F_Schlick(bsdfData.fresnel0, VdotH) * weightOverPdf;
float4 val = SampleEnv(lightLoopContext, lightData.envIndex, L, 0);
float sampleWeight = 1;
float4 val = SampleEnv(lightLoopContext, lightData.envIndex, L, 0, sampleWeight);
acc += FweightOverPdf * val.rgb;
}

正在加载...
取消
保存