浏览代码

Merge branch 'master' into scriptablerenderloop-materialgraph

/scriptablerenderloop-materialgraph
Paul Demeulenaere 8 年前
当前提交
353f6748
共有 4 个文件被更改,包括 65 次插入56 次删除
  1. 16
      Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs
  2. 14
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/LightDefinition.cs
  3. 30
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/LightDefinition.cs.hlsl
  4. 61
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/Lit.hlsl

16
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.shapeType = EnvShapeType.None;
l.envShapeType = EnvShapeType.None;
// TODO: Support sphere in the interface
l.shapeType = EnvShapeType.Box;
l.envShapeType = EnvShapeType.Box;
}
// remove scale from the matrix (Scale in this matrix is use to scale the widget)

l.forward = probe.localToWorld.GetColumn(2);
l.forward.Normalize();
l.innerDistance = probe.bounds.extents;
// Artists prefer to have blend distance inside the volume!
// So we let the current UI but we assume blendDistance is an inside factor instead
// Blend distance can't be larger than the max radius
// probe.bounds.extents is BoxSize / 2
float maxBlendDist = Mathf.Min(probe.bounds.extents.x, Mathf.Min(probe.bounds.extents.y, probe.bounds.extents.z));
float blendDistance = Mathf.Min(maxBlendDist, probe.blendDistance);
l.innerDistance = probe.bounds.extents - new Vector3(blendDistance, blendDistance, blendDistance);
l.blendDistance = probe.blendDistance;
l.blendDistance = blendDistance;
lights.Add(l);
}

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


public struct EnvLightData
{
public Vector3 positionWS;
public EnvShapeType shapeType;
public EnvShapeType envShapeType;
public int sliceIndex;
public float unused2;
public float blendDistance;
public float blendDistance; // blend transition outside the volume
public float unused0;
public int sliceIndex;
public Vector3 innerDistance;
public float unused1;
public Vector3 innerDistance; // equivalent to volume scale
public float unused0;
public float unused2;
public float unused1;
};
[GenerateHLSL]

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


struct EnvLightData
{
float3 positionWS;
int shapeType;
int envShapeType;
int sliceIndex;
float unused2;
float unused0;
int sliceIndex;
float unused0;
float3 offsetLS;
float3 offsetLS;
float unused2;
};
// Generated from UnityEngine.ScriptableRenderLoop.PlanarLightData

{
return value.positionWS;
}
int GetShapeType(EnvLightData value)
int GetEnvShapeType(EnvLightData value)
return value.shapeType;
return value.envShapeType;
int GetSliceIndex(EnvLightData value)
float GetUnused2(EnvLightData value)
return value.sliceIndex;
return value.unused2;
}
float3 GetUp(EnvLightData value)
{

{
return value.right;
}
float GetUnused0(EnvLightData value)
int GetSliceIndex(EnvLightData value)
return value.unused0;
return value.sliceIndex;
float GetUnused1(EnvLightData value)
float GetUnused0(EnvLightData value)
return value.unused1;
return value.unused0;
float GetUnused2(EnvLightData value)
float GetUnused1(EnvLightData value)
return value.unused2;
return value.unused1;
}
//

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


float3 R = rayWS;
float weight = 1.0;
// In this code we redefine a bit the behavior of the reflcetion proble. We separate the projection volume (the proxy of the scene) form the influence volume (what pixel on the screen is affected)
// 1. First determine the projection volume
if (lightData.shapeType == ENVSHAPETYPE_BOX)
{
// CAUTION: localToWorld is the transform use to convert the cubemap capture point to world space (mean it include the offset)
// 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.
// CAUTION: localToWorld is the transform use to convert the cubemap capture point to world space (mean it include the offset)
// 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.
// worldToLocal assume no scaling
float3x3 worldToLocal = transpose(float3x3(lightData.right, lightData.up, lightData.forward));
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);

R = (positionWS + dist * rayWS) - lightData.positionWS;
// TODO: add distance based roughness
// 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
// Smooth weighting
weight = smoothstep01(weight);
else if (lightData.shapeType == ENVSHAPETYPE_SPHERE)
else if (lightData.envShapeType == ENVSHAPETYPE_SPHERE)
// For now there is no specific interface for sphere proxy and it can have offset and arbitrary orientation. So we need to transform
// to local space position and direction like for OBB.
float3x3 worldToLocal = transpose(float3x3(lightData.right, lightData.up, lightData.forward));
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 sphereRadius = lightData.innerDistance.x;
float dist = SphereRayIntersectSimple(positionLS, rayLS, sphereRadius + lightData.blendDistance);
float sphereOuterDistance = lightData.innerDistance.x + lightData.blendDistance;
float dist = SphereRayIntersectSimple(positionLS, rayLS, sphereOuterDistance);
}
float distFade = length(positionWS - lightData.positionWS);
weight = saturate(((sphereRadius + lightData.blendDistance) - distFade) / max(lightData.blendDistance, 0.0001)); // avoid divide by zero
// Smooth weighting
weight = smoothstep01(weight);
// 2. Apply the influence volume (Box volume is used for culling whatever the influence shape)
if (lightData.envShapeType == ENVSHAPETYPE_SPHERE)
{
float distFade = max(length(positionLS) - lightData.innerDistance.x, 0.0);
weight = saturate(1.0 - distFade / max(lightData.blendDistance, 0.0001)); // avoid divide by zero
}
else // ENVSHAPETYPE_BOX or ENVSHAPETYPE_NONE
{
// 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
// Smooth weighting
weight = smoothstep01(weight);
// TODO: we must always perform a weight calculation as due to tiled rendering we need to smooth out cubemap at boundaries.
// So goal is to split into two category and have an option to say if we parallax correct or not.

正在加载...
取消
保存