浏览代码

HDRenderLoop: Update reflection probe behavior (change agin)

- We still split influence and projecotin volume, but they must ahve the
same shape, and influence volume must be conatin by projection volume
- without UI for now this have no effect.
/main
sebastienlagarde 8 年前
当前提交
7a1f23a5
共有 4 个文件被更改,包括 26 次插入57 次删除
  1. 8
      Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs
  2. 13
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/LightDefinition.cs
  3. 26
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/LightDefinition.cs.hlsl
  4. 36
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/Lit.hlsl

8
Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs


// CAUTION: localToWorld is the transform for the widget of the reflection probe. i.e the world position of the point use to do the cubemap capture (mean it include the local offset)
l.positionWS = probe.localToWorld.GetColumn(3);
l.projectionShapeType = ProjectionShapeType.None;
l.envShapeType = EnvShapeType.None;
l.projectionShapeType = ProjectionShapeType.Box;
l.envShapeType = EnvShapeType.Box;
// TODO add influence volume in interface, for now it is coupled with projection volume
// Note that even when there is no projection volume, there is an influence volume.
l.influenceShapeType = InfluenceShapeType.Box;
// remove scale from the matrix (Scale in this matrix is use to scale the widget)
l.right = probe.localToWorld.GetColumn(0);

13
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/LightDefinition.cs


};
[GenerateHLSL]
public enum ProjectionShapeType
public enum EnvShapeType
{
None,
Box,

[GenerateHLSL]
public enum InfluenceShapeType
{
Box,
Sphere
};
[GenerateHLSL]
public ProjectionShapeType projectionShapeType;
public EnvShapeType envShapeType;
public InfluenceShapeType influenceShapeType;
public float unused2;
public Vector3 up;
public float blendDistance; // blend transition outside the volume

26
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/LightDefinition.cs.hlsl


#define AREASHAPETYPE_CYLINDER (5)
//
// UnityEngine.ScriptableRenderLoop.ProjectionShapeType: static fields
//
#define PROJECTIONSHAPETYPE_NONE (0)
#define PROJECTIONSHAPETYPE_BOX (1)
#define PROJECTIONSHAPETYPE_SPHERE (2)
//
// UnityEngine.ScriptableRenderLoop.InfluenceShapeType: static fields
// UnityEngine.ScriptableRenderLoop.EnvShapeType: static fields
#define INFLUENCESHAPETYPE_BOX (0)
#define INFLUENCESHAPETYPE_SPHERE (1)
#define ENVSHAPETYPE_NONE (0)
#define ENVSHAPETYPE_BOX (1)
#define ENVSHAPETYPE_SPHERE (2)
// Generated from UnityEngine.ScriptableRenderLoop.PunctualLightData
// PackingRules = Exact

struct EnvLightData
{
float3 positionWS;
int projectionShapeType;
int envShapeType;
int influenceShapeType;
float unused2;
float3 up;
float blendDistance;
float3 right;

{
return value.positionWS;
}
int GetProjectionShapeType(EnvLightData value)
int GetEnvShapeType(EnvLightData value)
return value.projectionShapeType;
return value.envShapeType;
int GetInfluenceShapeType(EnvLightData value)
float GetUnused2(EnvLightData value)
return value.influenceShapeType;
return value.unused2;
}
float3 GetUp(EnvLightData value)
{

36
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/Lit.hlsl


// the center of the bounding box is thus in locals space: positionLS - offsetLS
// We use this formulation as it is the one of legacy unity that was using only AABB box.
if (lightData.projectionShapeType == PROJECTIONSHAPETYPE_BOX)
{
float3x3 worldToLocal = transpose(float3x3(lightData.right, lightData.up, lightData.forward)); // worldToLocal assume no scaling
float3 positionLS = positionWS - lightData.positionWS;
positionLS = mul(positionLS, worldToLocal).xyz - lightData.offsetLS; // We want to calculate the intersection from the center of the bounding box.
float3x3 worldToLocal = transpose(float3x3(lightData.right, lightData.up, lightData.forward)); // worldToLocal assume no scaling
float3 positionLS = positionWS - lightData.positionWS;
positionLS = mul(positionLS, worldToLocal).xyz - lightData.offsetLS; // We want to calculate the intersection from the center of the bounding box.
if (lightData.envShapeType == ENVSHAPETYPE_BOX)
{
float3 rayLS = mul(rayWS, worldToLocal);
float3 boxOuterDistance = lightData.innerDistance + float3(lightData.blendDistance, lightData.blendDistance, lightData.blendDistance);
float dist = BoxRayIntersectSimple(positionLS, rayLS, -boxOuterDistance, boxOuterDistance);

// TODO: add distance based roughness
}
else if (lightData.projectionShapeType == PROJECTIONSHAPETYPE_SPHERE)
else if (lightData.envShapeType == ENVSHAPETYPE_SPHERE)
float3x3 worldToLocal = transpose(float3x3(lightData.right, lightData.up, lightData.forward)); // worldToLocal assume no scaling
float3 positionLS = positionWS - lightData.positionWS;
positionLS = mul(positionLS, worldToLocal).xyz - lightData.offsetLS; // We want to calculate the intersection from the center of the bounding box.
float3 rayLS = mul(rayWS, worldToLocal);
float sphereOuterDistance = lightData.innerDistance.x + lightData.blendDistance;
float dist = SphereRayIntersectSimple(positionLS, rayLS, sphereOuterDistance);

// 2. Apply the influence volume (Box volume is used for culling whatever the influence shape)
// TODO: Optimize this code! We can remove offset in case of influence volume!
if (lightData.influenceShapeType == INFLUENCESHAPETYPE_BOX)
if (lightData.envShapeType == ENVSHAPETYPE_SPHERE)
float3x3 worldToLocal = transpose(float3x3(lightData.right, lightData.up, lightData.forward)); // worldToLocal assume no scaling
float3 positionLS = positionWS - lightData.positionWS;
positionLS = mul(positionLS, worldToLocal).xyz - lightData.offsetLS; // We want to calculate the intersection from the center of the bounding box.
// Calculate falloff value, so reflections on the edges of the volume would gradually blend to previous reflection.
float distFade = DistancePointBox(positionLS, -lightData.innerDistance, lightData.innerDistance);
float distFade = max(length(positionLS) - lightData.innerDistance.x, 0.0);
else // INFLUENCESHAPETYPE_SPHERE
else // ENVSHAPETYPE_BOX or ENVSHAPETYPE_NONE
float3x3 worldToLocal = transpose(float3x3(lightData.right, lightData.up, lightData.forward)); // worldToLocal assume no scaling
float3 positionLS = positionWS - lightData.positionWS;
positionLS = mul(positionLS, worldToLocal).xyz - lightData.offsetLS; // We want to calculate the intersection from the center of the bounding box.
float distFade = max(length(positionLS) - lightData.innerDistance.x, 0.0);
// Calculate falloff value, so reflections on the edges of the volume would gradually blend to previous reflection.
float distFade = DistancePointBox(positionLS, -lightData.innerDistance, lightData.innerDistance);
weight = saturate(1.0 - distFade / max(lightData.blendDistance, 0.0001)); // avoid divide by zero
}

正在加载...
取消
保存