浏览代码

Remove the double sided option for area lights

It reduces performance and doesn't trivially extend to the sphere light approximation.
/Branch_Batching2
Evgenii Golubev 8 年前
当前提交
7fd989cc
共有 6 个文件被更改,包括 69 次插入80 次删除
  1. 1
      Assets/ScriptableRenderPipeline/AdditionalLightData.cs
  2. 5
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightDefinition.cs
  3. 108
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightDefinition.cs.hlsl
  4. 8
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs
  5. 12
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl
  6. 15
      Assets/ScriptableRenderPipeline/ShaderLibrary/AreaLighting.hlsl

1
Assets/ScriptableRenderPipeline/AdditionalLightData.cs


public bool affectSpecular = true;
public LightArchetype archetype = LightArchetype.Punctual;
public bool isDoubleSided = false; // Rectangular area lights only
[Range(0.0f, 20.0f)]
public float lightLength = 0.0f; // Area & projector lights

5
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightDefinition.cs


public int IESIndex;
public int cookieIndex;
public Vector2 size; // Used by area, projector and spot lights; x = cot(outerHalfAngle) for spot lights
public Vector2 size; // Used by area, projector and spot lights; x = cot(outerHalfAngle) for spot lights
public bool twoSided; // Used by rectangular area lights only
public float unused;
};
[GenerateHLSL]

108
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightDefinition.cs.hlsl


int shadowIndex;
int IESIndex;
int cookieIndex;
int lightType;
bool twoSided;
int lightType;
float unused;
};
// Generated from UnityEngine.Experimental.Rendering.HDPipeline.DirectionalLightData

//
float3 GetPositionWS(LightData value)
{
return value.positionWS;
return value.positionWS;
return value.invSqrAttenuationRadius;
return value.invSqrAttenuationRadius;
return value.color;
return value.color;
return value.angleScale;
return value.angleScale;
return value.forward;
return value.forward;
return value.angleOffset;
return value.angleOffset;
return value.up;
return value.up;
return value.diffuseScale;
return value.diffuseScale;
return value.right;
return value.right;
return value.specularScale;
return value.specularScale;
return value.shadowDimmer;
return value.shadowDimmer;
return value.shadowIndex;
return value.shadowIndex;
return value.IESIndex;
return value.IESIndex;
return value.cookieIndex;
return value.cookieIndex;
int GetLightType(LightData value)
float2 GetSize(LightData value)
return value.lightType;
return value.size;
float2 GetSize(LightData value)
int GetLightType(LightData value)
return value.size;
return value.lightType;
bool GetTwoSided(LightData value)
float GetUnused(LightData value)
return value.twoSided;
return value.unused;
}
//

{
return value.forward;
return value.forward;
return value.diffuseScale;
return value.diffuseScale;
return value.up;
return value.up;
return value.invScaleY;
return value.invScaleY;
return value.right;
return value.right;
return value.invScaleX;
return value.invScaleX;
return value.positionWS;
return value.positionWS;
return value.tileCookie;
return value.tileCookie;
return value.color;
return value.color;
return value.specularScale;
return value.specularScale;
return value.cosAngle;
return value.cosAngle;
return value.sinAngle;
return value.sinAngle;
return value.shadowIndex;
return value.shadowIndex;
return value.cookieIndex;
return value.cookieIndex;
}
//

{
return value.worldToShadow;
return value.worldToShadow;
return value.bias;
return value.bias;
return value.quality;
return value.quality;
return value.unused;
return value.unused;
return value.unused2;
return value.unused2;
return value.invResolution;
return value.invResolution;
}
//

{
return value.positionWS;
return value.positionWS;
return value.envShapeType;
return value.envShapeType;
return value.forward;
return value.forward;
return value.envIndex;
return value.envIndex;
return value.up;
return value.up;
return value.blendDistance;
return value.blendDistance;
return value.right;
return value.right;
return value.unused0;
return value.unused0;
return value.innerDistance;
return value.innerDistance;
return value.unused1;
return value.unused1;
return value.offsetLS;
return value.offsetLS;
return value.unused2;
return value.unused2;
}

8
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs


if (additionalData.archetype != LightArchetype.Punctual)
{
lightData.twoSided = additionalData.isDoubleSided;
lightData.size = new Vector2(additionalData.lightLength, additionalData.lightWidth);
}

Vector3 dimensions = new Vector3(lightData.size.x * 0.5f + radius, lightData.size.y * 0.5f + radius, radius);
if (!lightData.twoSided)
{
centerVS += zAxisVS * radius * 0.5f;
dimensions.z *= 0.5f;
}
dimensions.z *= 0.5f;
centerVS += zAxisVS * radius * 0.5f;
bound.center = centerVS;
bound.boxAxisX = dimensions.x * xAxisVS;

12
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl


float3 L = normalize(unL);
// Cosine of the angle between the light direction and the normal of the light's surface.
float cosLNs = dot(-L, Ns);
cosLNs = lightData.twoSided ? abs(cosLNs) : saturate(cosLNs);
float cosLNs = saturate(dot(-L, Ns));
// We calculate area reference light with the area integral rather than the solid angle one.
float illuminance = cosLNs * saturate(dot(bsdfData.normalWS, L)) / (sqrDist * lightPdf);

// Evaluate the diffuse part.
{
#ifdef LIT_DIFFUSE_LAMBERT_BRDF
ltcValue = LTCEvaluate(matL, V, bsdfData.normalWS, preLightData.NdotV, lightData.twoSided,
k_identity3x3);
ltcValue = LTCEvaluate(matL, V, bsdfData.normalWS, preLightData.NdotV, k_identity3x3);
ltcValue = LTCEvaluate(matL, V, bsdfData.normalWS, preLightData.NdotV, lightData.twoSided,
preLightData.ltcXformDisneyDiffuse);
ltcValue = LTCEvaluate(matL, V, bsdfData.normalWS, preLightData.NdotV, preLightData.ltcXformDisneyDiffuse);
#endif
if (ltcValue == 0.0)

float3 fresnelTerm = bsdfData.fresnel0 * preLightData.ltcGGXFresnelMagnitudeDiff
+ (float3)preLightData.ltcGGXFresnelMagnitude;
ltcValue = LTCEvaluate(matL, V, bsdfData.normalWS, preLightData.NdotV, lightData.twoSided,
preLightData.ltcXformGGX);
ltcValue = LTCEvaluate(matL, V, bsdfData.normalWS, preLightData.NdotV, preLightData.ltcXformGGX);
ltcValue *= lightData.specularScale;
specularLighting = fresnelTerm * lightData.color * ltcValue;
}

15
Assets/ScriptableRenderPipeline/ShaderLibrary/AreaLighting.hlsl


}
}
return irradiance;
return max(irradiance, 0.0);
float PolygonIrradiance(float4x3 L, bool twoSided)
float PolygonIrradiance(float4x3 L)
#ifdef SPHERE_APPROX
#ifdef SPHERE_LIGHT_APPROXIMATION
for (int i = 0; i < 4; i++)
{
L[i] = normalize(L[i]);

float f2 = saturate(dot(F, F));
float sinSqSigma = sqrt(f2);
float cosOmega = F.z * rsqrt(f2);
float irradiance = DiffuseSphereLightIrradiance(sinSqSigma, cosOmega);
return twoSided ? abs(irradiance) : max(irradiance, 0.0);
return DiffuseSphereLightIrradiance(sinSqSigma, cosOmega);
#else
// 1. ClipQuadToHorizon

sum *= INV_TWO_PI; // Normalization
sum = twoSided ? abs(sum) : max(sum, 0.0);
sum = max(sum, 0.0);
return isfinite(sum) ? sum : 0.0;
#endif

float LTCEvaluate(float4x3 L, float3 V, float3 N, float NdotV, bool twoSided, float3x3 invM)
float LTCEvaluate(float4x3 L, float3 V, float3 N, float NdotV, float3x3 invM)
{
// Construct a view-dependent orthonormal basis around N.
// TODO: it could be stored in PreLightData, since all LTC lights compute it more than once.

L = mul(L, invM);
// Polygon irradiance in the transformed configuration
return PolygonIrradiance(L, twoSided);
return PolygonIrradiance(L);
}
float LineFpo(float tLDDL, float lrcpD, float rcpD)

正在加载...
取消
保存