浏览代码

Rename intersection functions for consistency

/Yibing-Project-2
Evgenii Golubev 7 年前
当前提交
0666c94b
共有 2 个文件被更改,包括 25 次插入23 次删除
  1. 40
      ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/GeometricTools.hlsl
  2. 8
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.hlsl

40
ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/GeometricTools.hlsl


#ifndef UNITY_GEOMETRICTOOLS_INCLUDED
#define UNITY_GEOMETRICTOOLS_INCLUDED
// Solves the quadratic equation of the form: a*t^2 + b*t + c = 0.
// Returns 'false' if there are no real roots, 'true' otherwise.
// Numerically stable.
// Ref: Numerical Recipes in C++ (3rd Edition)
bool SolveQuadraticEquation(float a, float b, float c, out float2 roots)
{
float d = b * b - 4 * a * c;
float q = -0.5 * (b + FastMulBySignOf(b, sqrt(d)));
roots = float2(q / a, c / q);
return (d >= 0);
}
//-----------------------------------------------------------------------------
// Intersection functions
//-----------------------------------------------------------------------------

}
// This simplified version assume that we care about the result only when we are inside the box
float BoxRayIntersectSimple(float3 start, float3 dir, float3 boxMin, float3 boxMax)
float IntersectRayAABBSimple(float3 start, float3 dir, float3 boxMin, float3 boxMax)
{
float3 invDir = 1.0 / dir;

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

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

intersect = true;
}
return intersections;
return intersect;
float SphereRayIntersectSimple(float3 start, float3 dir, float radius)
float IntersectRaySphereSimple(float3 start, float3 dir, float radius)
{
float b = dot(dir, start) * 2.0;
float c = dot(start, start) - radius * radius;

}
float3 RayPlaneIntersect(in float3 rayOrigin, in float3 rayDirection, in float3 planeOrigin, in float3 planeNormal)
float3 IntersectRayPlane(in float3 rayOrigin, in float3 rayDirection, in float3 planeOrigin, in float3 planeNormal)
}
// Solves the quadratic equation of the form: a*t^2 + b*t + c = 0.
// Returns 'false' if there are no real roots, 'true' otherwise.
// Ref: Numerical Recipes in C++ (3rd Edition)
bool SolveQuadraticEquation(float a, float b, float c, out float2 roots)
{
float d = b * b - 4 * a * c;
float q = -0.5 * (b + FastSign(b) * sqrt(d));
roots = float2(q / a, c / q);
return (d >= 0);
}
// Can support cones with an elliptic base: pre-scale 'coneAxisX' and 'coneAxisY' by (h/r_x) and (h/r_y).

8
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.hlsl


float3 dirLS = mul(R, worldToLocal);
float sphereOuterDistance = lightData.influenceExtents.x;
float projectionDistance = SphereRayIntersectSimple(positionLS, dirLS, sphereOuterDistance);
float projectionDistance = IntersectRaySphereSimple(positionLS, dirLS, sphereOuterDistance);
projectionDistance = max(projectionDistance, lightData.minProjectionDistance); // Setup projection to infinite if requested (mean no projection shape)
// We can reuse dist calculate in LS directly in WS as there is no scaling. Also the offset is already include in lightData.positionWS
R = (positionWS + projectionDistance * R) - lightData.positionWS;

{
dirLS = mul(coatR, worldToLocal);
projectionDistance = SphereRayIntersectSimple(positionLS, dirLS, sphereOuterDistance);
projectionDistance = IntersectRaySphereSimple(positionLS, dirLS, sphereOuterDistance);
coatR = (positionWS + projectionDistance * coatR) - lightData.positionWS;
}

// 1. First process the projection
float3 dirLS = mul(R, worldToLocal);
float3 boxOuterDistance = lightData.influenceExtents;
float projectionDistance = BoxRayIntersectSimple(positionLS, dirLS, -boxOuterDistance, boxOuterDistance);
float projectionDistance = IntersectRayAABBSimple(positionLS, dirLS, -boxOuterDistance, boxOuterDistance);
projectionDistance = max(projectionDistance, lightData.minProjectionDistance); // Setup projection to infinite if requested (mean no projection shape)
// No need to normalize for fetching cubemap

if (bsdfData.materialId == MATERIALID_LIT_CLEAR_COAT && HasMaterialFeatureFlag(MATERIALFEATUREFLAGS_LIT_CLEAR_COAT))
{
dirLS = mul(coatR, worldToLocal);
projectionDistance = BoxRayIntersectSimple(positionLS, dirLS, -boxOuterDistance, boxOuterDistance);
projectionDistance = IntersectRayAABBSimple(positionLS, dirLS, -boxOuterDistance, boxOuterDistance);
coatR = (positionWS + projectionDistance * coatR) - lightData.positionWS;
}

正在加载...
取消
保存