@@ -218,16 +218,16 @@ bool ConicPointIsValid(float3 p) =>
218218 // Intersect lines with y-plane and clip if needed.
219219 var l1t = math . dot ( - lightPositionVS , planeNormal ) / math . dot ( l1 , planeNormal ) ;
220220 var l1x = lightPositionVS + l1 * l1t ;
221- if ( l1t >= 0 && l1t <= 1 && l1x . z >= near ) planeRange . Expand ( ( short ) ViewToTileSpace ( l1x ) . x ) ;
221+ if ( l1t >= 0 && l1t <= 1 && l1x . z >= near ) planeRange . Expand ( ( short ) math . clamp ( ViewToTileSpace ( l1x ) . x , 0 , tileCount . x - 1 ) ) ;
222222
223223 var l2t = math . dot ( - lightPositionVS , planeNormal ) / math . dot ( l2 , planeNormal ) ;
224224 var l2x = lightPositionVS + l2 * l2t ;
225- if ( l2t >= 0 && l2t <= 1 && l2x . z >= near ) planeRange . Expand ( ( short ) ViewToTileSpace ( l2x ) . x ) ;
225+ if ( l2t >= 0 && l2t <= 1 && l2x . z >= near ) planeRange . Expand ( ( short ) math . clamp ( ViewToTileSpace ( l2x ) . x , 0 , tileCount . x - 1 ) ) ;
226226
227227 if ( IntersectCircleYPlane ( planeY , baseCenter , lightDirectionVS , baseUY , baseVY , baseRadius , out var circleTile0 , out var circleTile1 ) )
228228 {
229- if ( circleTile0 . z >= near ) planeRange . Expand ( ( short ) ViewToTileSpace ( circleTile0 ) . x ) ;
230- if ( circleTile1 . z >= near ) planeRange . Expand ( ( short ) ViewToTileSpace ( circleTile1 ) . x ) ;
229+ if ( circleTile0 . z >= near ) planeRange . Expand ( ( short ) math . clamp ( ViewToTileSpace ( circleTile0 ) . x , 0 , tileCount . x - 1 ) ) ;
230+ if ( circleTile1 . z >= near ) planeRange . Expand ( ( short ) math . clamp ( ViewToTileSpace ( circleTile1 ) . x , 0 , tileCount . x - 1 ) ) ;
231231 }
232232
233233 if ( coneIsClipping )
@@ -237,21 +237,14 @@ bool ConicPointIsValid(float3 p) =>
237237 var theta = FindNearConicYTheta ( near , lightPositionVS , lightDirectionVS , r , coneU , coneV , y ) ;
238238 var p0 = math . float3 ( EvaluateNearConic ( near , lightPositionVS , lightDirectionVS , r , coneU , coneV , theta . x ) . x , y , near ) ;
239239 var p1 = math . float3 ( EvaluateNearConic ( near , lightPositionVS , lightDirectionVS , r , coneU , coneV , theta . y ) . x , y , near ) ;
240- if ( ConicPointIsValid ( p0 ) ) planeRange . Expand ( ( short ) ViewToTileSpace ( p0 ) . x ) ;
241- if ( ConicPointIsValid ( p1 ) ) planeRange . Expand ( ( short ) ViewToTileSpace ( p1 ) . x ) ;
240+ if ( ConicPointIsValid ( p0 ) ) planeRange . Expand ( ( short ) math . clamp ( ViewToTileSpace ( p0 ) . x , 0 , tileCount . x - 1 ) ) ;
241+ if ( ConicPointIsValid ( p1 ) ) planeRange . Expand ( ( short ) math . clamp ( ViewToTileSpace ( p1 ) . x , 0 , tileCount . x - 1 ) ) ;
242242 }
243243
244- // Only consider ranges that intersect the tiling extents.
245- // The logic in the below 'if' statement is a simplification of:
246- // !((planeRange.start < 0) && (planeRange.end < 0)) && !((planeRange.start > tileCount.x - 1) && (planeRange.end > tileCount.x - 1))
247- if ( ( ( planeRange . start >= 0 ) || ( planeRange . end >= 0 ) ) && ( ( planeRange . start <= tileCount . x - 1 ) || ( planeRange . end <= tileCount . x - 1 ) ) )
248- {
249- // Write to tile ranges above and below the plane. Note that at `m_Offset` we store Y-range.
250- var tileIndex = m_Offset + 1 + planeIndex ;
251- planeRange . Clamp ( 0 , ( short ) ( tileCount . x - 1 ) ) ;
252- tileRanges [ tileIndex ] = InclusiveRange . Merge ( tileRanges [ tileIndex ] , planeRange ) ;
253- tileRanges [ tileIndex - 1 ] = InclusiveRange . Merge ( tileRanges [ tileIndex - 1 ] , planeRange ) ;
254- }
244+ // Write to tile ranges above and below the plane. Note that at `m_Offset` we store Y-range.
245+ var tileIndex = m_Offset + 1 + planeIndex ;
246+ tileRanges [ tileIndex ] = InclusiveRange . Merge ( tileRanges [ tileIndex ] , planeRange ) ;
247+ tileRanges [ tileIndex - 1 ] = InclusiveRange . Merge ( tileRanges [ tileIndex - 1 ] , planeRange ) ;
255248 }
256249 }
257250
0 commit comments