浏览代码

HDRenderLoop: Fix OBB and sphere project for reflection probe, now working

/main
sebastienlagarde 8 年前
当前提交
21454a21
共有 4 个文件被更改,包括 41 次插入38 次删除
  1. 2
      Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.asset.meta
  2. 31
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/Lit.hlsl
  3. 42
      Assets/ScriptableRenderLoop/ShaderLibrary/GeometricTools.hlsl
  4. 4
      Assets/ScriptableRenderLoop/common/TextureCache.cs

2
Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.asset.meta


fileFormatVersion: 2
guid: 2400b74f5ce370c4481e5dc417d03703
timeCreated: 1476718001
timeCreated: 1476798250
licenseType: Pro
NativeFormatImporter:
userData:

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


// float shrinkedRoughness = AnisotropicStrechAtGrazingAngle(bsdfData.roughness, bsdfData.perceptualRoughness, NdotV);
// Note: As explain in GetPreLightData we use normalWS and not iblNormalWS here (in case of anisotropy)
//float3 rayWS = GetSpecularDominantDir(bsdfData.normalWS, prelightData.iblR, bsdfData.roughness);
float3 rayWS = prelightData.iblR;
float3 rayWS = GetSpecularDominantDir(bsdfData.normalWS, prelightData.iblR, bsdfData.roughness);
/*
float4x4 worldToLocal = transpose(float4x4(float4(lightData.right, 0.0), float4(lightData.up, 0.0), float4(lightData.forward, 0.0), float4(light.positionWS, 1.0)));
float3 positionLS = mul(lightData.worldToLocal, float4(positionWS, 1.0)).xyz;
float3 rayLS = mul((float3x3)lightData.worldToLocal, rayWS);
float3x3 worldToLocal = transpose(float3x3(lightData.right, lightData.up, lightData.forward));
float3 positionLS = positionWS - lightData.positionWS;
positionLS = mul(positionLS, worldToLocal).xyz;
float3 rayLS = mul(rayWS, worldToLocal);
R = (positionWS + dist * rayWS) - lightData.capturePointWS; // TODO: check that
R = (positionWS + dist * rayWS) - lightData.capturePointWS;
// TODO: add distance based roughness

// Smooth weighting
weight = smoothstep01(weight);
}
}
float2 intersections;
SphereRayIntersect(intersections, positionWS - lightData.positionWS, R, sphereRadius);
// TODO: check if we can have simplified formula like for box
float intersection = SphereRayIntersectSimple(positionWS - lightData.positionWS, R, sphereRadius + lightData.blendDistance);
R = (positionWS + intersections.y * rayWS) - lightData.capturePointWS;
R = (positionWS + intersection * rayWS) - lightData.capturePointWS;
float distFade = length(positionWS - lightData.positionWS);
weight = saturate(((sphereRadius + lightData.blendDistance) - distFade) / max(lightData.blendDistance, 0.0001)); // avoid divide by zero

}
*/
// 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.
// TODO: compare current Morten version: offline cubemap with a particular remap + the bias in perceptualRoughnessToMipmapLevel
// to classic remap like unreal/Frobiste. The function GetSpecularDominantDir can result in a better matching in this case
// We let GetSpecularDominantDir currently as it still an improvement but not as good as it could be
float mip = perceptualRoughnessToMipmapLevel(bsdfData.perceptualRoughness);
float4 preLD = UNITY_SAMPLE_ENV_LOD(_EnvTextures, R, lightData, mip);
specularLighting.rgb = preLD.rgb * prelightData.specularFGD;

42
Assets/ScriptableRenderLoop/ShaderLibrary/GeometricTools.hlsl


return intersections;
}
// TODO: Describe difference with above
// AND compare with intersections.y
// This simplified version assume that we care about the result only when we are inside the box
// Assume dir is normalize
float BoxRayIntersectSimple(float3 start, float3 dir, float3 boxMin, float3 boxMax)
{

return min(min(rbminmax.x, rbminmax.y), rbminmax.z);
}
// Sphere is at the origin
bool SphereRayIntersect(out float2 intersections, float3 start, float3 dir, float radius)
// Assume Sphere is at the origin (i.e start = position - spherePosition)
float2 SphereRayIntersect(float3 start, float3 dir, float radius, out bool intersect)
{
float a = dot(dir, dir);
float b = dot(dir, start) * 2.0;

bool intersect = false;
float2 intersections = float2(0.0, 0.0);
intersect = false;
if (discriminant < 0.0 || a == 0.0)
{
intersections.x = 0.0;

intersect = true;
}
return intersect;
return intersections;
}
// This simplified version assume that we care about the result only when we are inside the sphere
// Assume Sphere is at the origin (i.e start = position - spherePosition) and dir is normalized
// Ref: http://http.developer.nvidia.com/GPUGems/gpugems_ch19.html
float SphereRayIntersectSimple(float3 start, float3 dir, float radius)
{
float b = dot(dir, start) * 2.0;
float c = dot(start, start) - radius * radius;
float discriminant = b * b - 4.0 * c;
return abs(sqrt(discriminant) - b) * 0.5;
}
float3 RayPlaneIntersect(in float3 rayOrigin, in float3 rayDirection, in float3 planeOrigin, in float3 planeNormal)

// Distance functions
//-----------------------------------------------------------------------------
/*
// Ref: real time detection collision page 131
float DistancePointBox(float3 pos, float3 boxMin, float3 boxMax)
{
// Clamp to find closest point then calc distance
float3 distanceToMin = pos < boxMin ? (boxMin - pos) * (boxMin - pos) : 0.0;
float3 distancesToMax = pos > boxMax ? (pos - boxMax) * (pos - boxMax) : 0.0;
float distanceSquare = dot(distanceToMin, float3(1.0, 1.0, 1.0)) + dot(distancesToMax, float3(1.0, 1.0, 1.0));
return sqrt(distanceSquare);
}
*/
// TODO: check that this code is effectively equivalent to code above (it should)
float DistancePointBox(float3 pos, float3 boxMin, float3 boxMax)
float DistancePointBox(float3 position, float3 boxMin, float3 boxMax)
return length(max(max(pos - boxMax, boxMin - pos), float3(0.0, 0.0, 0.0)));
return length(max(max(position - boxMax, boxMin - position), float3(0.0, 0.0, 0.0)));
}
#endif // UNITY_GEOMETRICTOOLS_INCLUDED

4
Assets/ScriptableRenderLoop/common/TextureCache.cs


m_Cache = new CubemapArray(width, numCubeMaps, format, isMipMapped)
{
hideFlags = HideFlags.HideAndDontSave,
wrapMode = TextureWrapMode.Clamp
wrapMode = TextureWrapMode.Clamp,
filterMode = FilterMode.Trilinear,
anisoLevel = 0 // It is important to set 0 here, else unity force anisotropy filtering
};
return res;

正在加载...
取消
保存