浏览代码

Merge branch 'master' of https://github.com/Unity-Technologies/ScriptableRenderLoop

# Conflicts:
#	Assets/ScriptableRenderLoop/fptl/Internal-DeferredReflections.shader
/main
vlad-andreev 8 年前
当前提交
ddafcda1
共有 3 个文件被更改,包括 34 次插入32 次删除
  1. 32
      Assets/ScriptableRenderLoop/fptl/FptlLighting.cs
  2. 32
      Assets/ScriptableRenderLoop/fptl/Internal-DeferredReflections.shader
  3. 2
      Assets/ScriptableRenderLoop/fptl/LightDefinitions.cs

32
Assets/ScriptableRenderLoop/fptl/FptlLighting.cs


// probe.m_BlendDistance
// Vector3f extents = 0.5*Abs(probe.m_BoxSize);
// C center of rendered refl box <-- GetComponent (Transform).GetPosition() + m_BoxOffset;
// P parameter position to shader: GetComponent (Transform).GetPosition()
// cube map capture point: GetComponent (Transform).GetPosition()
//Vector3[] Ps = new Vector3[3] { new Vector3(6.28f, -1.18f, -5.67f), new Vector3(14.23f, -1.18f, 0.21f), new Vector3(6.28f, -1.18f, 1.91f) };
//Vector3[] boxSizes = new Vector3[3] { new Vector3(20.0f, 10.0f, 10.0f), new Vector3(10.0f, 10.0f, 10.0f), new Vector3(10.0f, 10.0f, 10.0f) };
//Vector3 boxOffset = new Vector3(0.0f, 0.0f, 0.0f);
//float[] bd = new float[3] { 4.0f, 4.0f, 4.0f };
int numProbesOut = 0;
foreach (var rl in probes)

lightData[i].flags = 0;
Bounds bnds = rl.bounds;
Vector3 boxOffset = rl.center;
Vector3 boxOffset = rl.center; // reflection volume offset relative to cube map capture point
Matrix4x4 mat = rl.transform.localToWorldMatrix;
Vector3 cubeCapturePos = mat.GetColumn(3); // cube map capture position in world space
// C is reflection volume center in world space (NOT same as cube map capture point)
Vector3 C = bnds.center; // P + boxOffset;
Vector3 posForShaderParam = bnds.center - boxOffset; // gives same as rl.GetComponent<Transform>().position;
//Vector3 C = bnds.center; // P + boxOffset;
Vector3 C = mat.MultiplyPoint(boxOffset); // same as commented out line above when rot is identity
//Vector3 posForShaderParam = bnds.center - boxOffset; // gives same as rl.GetComponent<Transform>().position;
Vector3 posForShaderParam = cubeCapturePos; // same as commented out line above when rot is identity
Vector3 vx = new Vector3(1, 0, 0); // always axis aligned in world space for now
Vector3 vy = new Vector3(0, 1, 0);
Vector3 vz = new Vector3(0, 0, 1);
Vector3 vx = mat.GetColumn(0);
Vector3 vy = mat.GetColumn(1);
Vector3 vz = mat.GetColumn(2);
// transform to camera space (becomes a left hand coordinate frame in Unity since Determinant(worldToView)<0)
vx = worldToView.MultiplyVector(vx);

lightData[i].vLaxisX = vx;
lightData[i].vLaxisY = vy;
lightData[i].vLaxisZ = vz;
lightData[i].vProbeBoxOffset = boxOffset;
lightData[i].vLocalCubeCapturePoint = -boxOffset;
lightData[i].fProbeBlendDistance = blendDistance;
lightData[i].fLightIntensity = decodeVals.x;

32
Assets/ScriptableRenderLoop/fptl/Internal-DeferredReflections.shader


UnityLight light;
light.color = 0;
light.dir = 0;
//light.ndotl = 0;
float3 ints = 0;
const uint uNrLights = FetchLightCount(offs);

{
SFiniteLightData lgtDat = g_vLightData[uIndex];
float3 vLp = lgtDat.vLpos.xyz;
float3 fromProbeToSurfPoint = vP - vLp; // in camera space
float3 posInProbeSpace = float3( dot(fromProbeToSurfPoint, lgtDat.vLaxisX), dot(fromProbeToSurfPoint, lgtDat.vLaxisY), dot(fromProbeToSurfPoint, lgtDat.vLaxisZ) );
float3 vecToSurfPos = vP - vLp; // vector from reflection volume to surface position in camera space
float3 posInReflVolumeSpace = float3( dot(vecToSurfPos, lgtDat.vLaxisX), dot(vecToSurfPos, lgtDat.vLaxisY), dot(vecToSurfPos, lgtDat.vLaxisZ) );
float3 worldNormal0;
float3 sampleDir;
if((lgtDat.flags&IS_BOX_PROJECTED)!=0)
{
// For box projection, use expanded bounds as they are rendered; otherwise

//worldNormal0 = BoxProjectedCubemapDirection (worldNormalRefl, worldPos, unity_SpecCube0_ProbePosition, boxMin, boxMax);
//sampleDir = BoxProjectedCubemapDirection (worldNormalRefl, worldPos, unity_SpecCube0_ProbePosition, boxMin, boxMax);
worldNormal0 = BoxProjectedCubemapDirection(worldNormalRefl, posInProbeSpace, float4(-lgtDat.vProbeBoxOffset, 1.0), -vBoxOuterDistance, vBoxOuterDistance);
// if rotation is NOT supported
sampleDir = BoxProjectedCubemapDirection(worldNormalRefl, posInReflVolumeSpace, float4(lgtDat.vLocalCubeCapturePoint, 1.0), -vBoxOuterDistance, vBoxOuterDistance);
float3 probeSpaceRefl = float3( dot(vspaceRefl, lgtDat.vLaxisX), dot(vspaceRefl, lgtDat.vLaxisY), dot(vspaceRefl, lgtDat.vLaxisZ) );
float3 vPR = BoxProjectedCubemapDirection(probeSpaceRefl, posInProbeSpace, float4(-lgtDat.vProbeBoxOffset, 1.0), -vBoxOuterDistance, vBoxOuterDistance); // probe space corrected reflection vector
worldNormal0 = mul( (float3x3) g_mViewToWorld, vPR.x*lgtDat.vLaxisX + vPR.y*lgtDat.vLaxisY + vPR.z*lgtDat.vLaxisZ );
float3 volumeSpaceRefl = float3( dot(vspaceRefl, lgtDat.vLaxisX), dot(vspaceRefl, lgtDat.vLaxisY), dot(vspaceRefl, lgtDat.vLaxisZ) );
float3 vPR = BoxProjectedCubemapDirection(volumeSpaceRefl, posInReflVolumeSpace, float4(lgtDat.vLocalCubeCapturePoint, 1.0), -vBoxOuterDistance, vBoxOuterDistance); // Volume space corrected reflection vector
sampleDir = mul( (float3x3) g_mViewToWorld, vPR.x*lgtDat.vLaxisX + vPR.y*lgtDat.vLaxisY + vPR.z*lgtDat.vLaxisZ );
worldNormal0 = worldNormalRefl;
sampleDir = worldNormalRefl;
g.reflUVW = worldNormal0;
g.reflUVW = sampleDir;
half3 env0 = Unity_GlossyEnvironment(UNITY_PASS_TEXCUBEARRAY(_reflCubeTextures), lgtDat.iSliceIndex, float4(lgtDat.fLightIntensity, lgtDat.fDecodeExp, 0.0, 0.0), g);

half3 rgb = UNITY_BRDF_PBS(0, data.specularColor, oneMinusReflectivity, data.smoothness, data.normalWorld, vWSpaceVDir, light, ind).rgb;
// Calculate falloff value, so reflections on the edges of the probe would gradually blend to previous reflection.
// Also this ensures that pixels not located in the reflection probe AABB won't
// accidentally pick up reflections from this probe.
// Calculate falloff value, so reflections on the edges of the Volume would gradually blend to previous reflection.
// Also this ensures that pixels not located in the reflection Volume AABB won't
// accidentally pick up reflections from this Volume.
half3 distance = distanceFromAABB(posInProbeSpace, -lgtDat.vBoxInnerDist, lgtDat.vBoxInnerDist);
half3 distance = distanceFromAABB(posInReflVolumeSpace, -lgtDat.vBoxInnerDist, lgtDat.vBoxInnerDist);
half falloff = saturate(1.0 - length(distance)/blendDistance);
ints = lerp(ints, rgb, falloff);

2
Assets/ScriptableRenderLoop/fptl/LightDefinitions.cs


public Vec3 vBoxInvRange;
public float fPad0;
public Vec3 vProbeBoxOffset;
public Vec3 vLocalCubeCapturePoint;
public float fProbeBlendDistance;
};

正在加载...
取消
保存