@@ -84,14 +84,16 @@ PSInput main(uint vertexID : SV_VertexID)
84
84
if (objType == ObjectType::LINE || objType == ObjectType::QUAD_BEZIER || objType == ObjectType::POLYLINE_CONNECTOR)
85
85
{
86
86
LineStyle lineStyle = lineStyles[mainObj.styleIdx];
87
+
88
+ // Width is on both sides, thickness is one one side of the curve (div by 2.0f)
87
89
const float screenSpaceLineWidth = lineStyle.screenSpaceLineWidth + float (lineStyle.worldSpaceLineWidth * globals.screenToWorldRatio);
88
- const float antiAliasedLineWidth = screenSpaceLineWidth + globals.antiAliasingFactor * 2.0f ;
90
+ const float antiAliasedLineThickness = screenSpaceLineWidth * 0.5f + globals.antiAliasingFactor;
91
+ const float sdfLineThickness = screenSpaceLineWidth / 2.0f ;
92
+ outV.setLineThickness (sdfLineThickness);
93
+ outV.setCurrentWorldToScreenRatio ((float )(2.0 / (clipProjectionData.projectionToNDC[0 ][0 ] * globals.resolution.x)));
89
94
90
95
if (objType == ObjectType::LINE)
91
96
{
92
- outV.setLineThickness (screenSpaceLineWidth / 2.0f );
93
- outV.setCurrentWorldToScreenRatio ((float )(2.0 / (clipProjectionData.projectionToNDC[0 ][0 ] * globals.resolution.x)));
94
-
95
97
double2 points[2u];
96
98
points[0u] = vk::RawBufferLoad<double2 >(drawObj.geometryAddress, 8u);
97
99
points[1u] = vk::RawBufferLoad<double2 >(drawObj.geometryAddress + sizeof (LinePointInfo), 8u);
@@ -114,15 +116,15 @@ PSInput main(uint vertexID : SV_VertexID)
114
116
{
115
117
// work in screen space coordinates because of fixed pixel size
116
118
outV.position.xy = transformedPoints[0u]
117
- + normalToLine * (((float )vertexIdx - 0.5f ) * antiAliasedLineWidth )
118
- - lineVector * antiAliasedLineWidth * 0.5f ;
119
+ + normalToLine * (((float )vertexIdx - 0.5f ) * 2.0f * antiAliasedLineThickness )
120
+ - lineVector * antiAliasedLineThickness ;
119
121
}
120
122
else // if (vertexIdx == 2u || vertexIdx == 3u)
121
123
{
122
124
// work in screen space coordinates because of fixed pixel size
123
125
outV.position.xy = transformedPoints[1u]
124
- + normalToLine * (((float )vertexIdx - 2.5f ) * antiAliasedLineWidth )
125
- + lineVector * antiAliasedLineWidth * 0.5f ;
126
+ + normalToLine * (((float )vertexIdx - 2.5f ) * 2.0f * antiAliasedLineThickness )
127
+ + lineVector * antiAliasedLineThickness ;
126
128
}
127
129
128
130
outV.setLineStart (transformedPoints[0u]);
@@ -132,8 +134,6 @@ PSInput main(uint vertexID : SV_VertexID)
132
134
}
133
135
else if (objType == ObjectType::QUAD_BEZIER)
134
136
{
135
- outV.setLineThickness (screenSpaceLineWidth / 2.0f );
136
-
137
137
double2 points[3u];
138
138
points[0u] = vk::RawBufferLoad<double2 >(drawObj.geometryAddress, 8u);
139
139
points[1u] = vk::RawBufferLoad<double2 >(drawObj.geometryAddress + sizeof (double2 ), 8u);
@@ -143,7 +143,6 @@ PSInput main(uint vertexID : SV_VertexID)
143
143
const float patternStretch = vk::RawBufferLoad<float >(drawObj.geometryAddress + sizeof (double2 ) * 3u + sizeof (float ), 8u);
144
144
outV.setCurrentPhaseShift (phaseShift);
145
145
outV.setPatternStretch (patternStretch);
146
- outV.setCurrentWorldToScreenRatio ((float )(2.0 / (clipProjectionData.projectionToNDC[0 ][0 ] * globals.resolution.x)));
147
146
148
147
// transform these points into screen space and pass to fragment
149
148
float2 transformedPoints[3u];
@@ -174,7 +173,7 @@ PSInput main(uint vertexID : SV_VertexID)
174
173
175
174
// We only do this adaptive thing when "MinRadiusOfOsculatingCircle = RadiusOfMaxCurvature < screenSpaceLineWidth/4" OR "MaxCurvature > 4/screenSpaceLineWidth";
176
175
// which means there is a self intersection because of large lineWidth relative to the curvature (in screenspace)
177
- // the reason for division by 4.0f is 1. screenSpaceLineWidth is expanded on both sides and the fact that diameter/2=radius,
176
+ // the reason for division by 4.0f is 1. screenSpaceLineWidth is expanded on both sides and 2. the fact that diameter/2=radius,
178
177
const bool noCurvature = abs (dot (normalize (vectorAB), normalize (vectorAC)) - 1.0f ) < exp2 (-10.0f );
179
178
if (MaxCurvature * screenSpaceLineWidth > 4.0f || noCurvature)
180
179
{
@@ -183,7 +182,7 @@ PSInput main(uint vertexID : SV_VertexID)
183
182
float2 obbV1;
184
183
float2 obbV2;
185
184
float2 obbV3;
186
- quadraticBezier.computeOBB (screenSpaceLineWidth / 2.0f , obbV0, obbV1, obbV2, obbV3);
185
+ quadraticBezier.computeOBB (antiAliasedLineThickness , obbV0, obbV1, obbV2, obbV3);
187
186
if (subsectionIdx == 0 )
188
187
{
189
188
if (vertexIdx == 0u)
@@ -233,41 +232,41 @@ PSInput main(uint vertexID : SV_VertexID)
233
232
float2 interior0;
234
233
float2 interior1;
235
234
236
- float2 middleExteriorPoint = midPos - midNormal * screenSpaceLineWidth / 2.0f ;
235
+ float2 middleExteriorPoint = midPos - midNormal * antiAliasedLineThickness ;
237
236
238
237
239
238
float2 leftTangent = normalize (BezierTangent (transformedPoints[0u], transformedPoints[1u], transformedPoints[2u], optimalT));
240
239
float2 leftNormal = normalize (float2 (-leftTangent.y, leftTangent.x)) * flip;
241
- float2 leftExteriorPoint = QuadraticBezier (transformedPoints[0u], transformedPoints[1u], transformedPoints[2u], optimalT) - leftNormal * screenSpaceLineWidth / 2.0f ;
240
+ float2 leftExteriorPoint = QuadraticBezier (transformedPoints[0u], transformedPoints[1u], transformedPoints[2u], optimalT) - leftNormal * antiAliasedLineThickness ;
242
241
float2 exterior0 = nbl::hlsl::shapes::util::LineLineIntersection<float >(middleExteriorPoint, midTangent, leftExteriorPoint, leftTangent);
243
242
244
243
float2 rightTangent = normalize (BezierTangent (transformedPoints[0u], transformedPoints[1u], transformedPoints[2u], 1.0f - optimalT));
245
244
float2 rightNormal = normalize (float2 (-rightTangent.y, rightTangent.x)) * flip;
246
- float2 rightExteriorPoint = QuadraticBezier (transformedPoints[0u], transformedPoints[1u], transformedPoints[2u], 1.0f - optimalT) - rightNormal * screenSpaceLineWidth / 2.0f ;
245
+ float2 rightExteriorPoint = QuadraticBezier (transformedPoints[0u], transformedPoints[1u], transformedPoints[2u], 1.0f - optimalT) - rightNormal * antiAliasedLineThickness ;
247
246
float2 exterior1 = nbl::hlsl::shapes::util::LineLineIntersection<float >(middleExteriorPoint, midTangent, rightExteriorPoint, rightTangent);
248
247
249
248
// Interiors
250
249
{
251
250
float2 tangent = normalize (BezierTangent (transformedPoints[0u], transformedPoints[1u], transformedPoints[2u], 0.286f ));
252
251
float2 normal = normalize (float2 (-tangent.y, tangent.x)) * flip;
253
- interior0 = QuadraticBezier (transformedPoints[0u], transformedPoints[1u], transformedPoints[2u], 0.286 ) + normal * screenSpaceLineWidth / 2.0f ;
252
+ interior0 = QuadraticBezier (transformedPoints[0u], transformedPoints[1u], transformedPoints[2u], 0.286 ) + normal * antiAliasedLineThickness ;
254
253
}
255
254
{
256
255
float2 tangent = normalize (BezierTangent (transformedPoints[0u], transformedPoints[1u], transformedPoints[2u], 0.714f ));
257
256
float2 normal = normalize (float2 (-tangent.y, tangent.x)) * flip;
258
- interior1 = QuadraticBezier (transformedPoints[0u], transformedPoints[1u], transformedPoints[2u], 0.714f ) + normal * screenSpaceLineWidth / 2.0f ;
257
+ interior1 = QuadraticBezier (transformedPoints[0u], transformedPoints[1u], transformedPoints[2u], 0.714f ) + normal * antiAliasedLineThickness ;
259
258
}
260
259
261
260
if (subsectionIdx == 0u)
262
261
{
263
262
float2 endPointTangent = normalize (transformedPoints[1u] - transformedPoints[0u]);
264
263
float2 endPointNormal = float2 (-endPointTangent.y, endPointTangent.x) * flip;
265
- float2 endPointExterior = transformedPoints[0u] - endPointTangent * screenSpaceLineWidth / 2.0f ;
264
+ float2 endPointExterior = transformedPoints[0u] - endPointTangent * antiAliasedLineThickness ;
266
265
267
266
if (vertexIdx == 0u)
268
267
outV.position = float4 (nbl::hlsl::shapes::util::LineLineIntersection<float >(leftExteriorPoint, leftTangent, endPointExterior, endPointNormal), 0.0 , 1.0f );
269
268
else if (vertexIdx == 1u)
270
- outV.position = float4 (transformedPoints[0u] + endPointNormal * screenSpaceLineWidth / 2.0f - endPointTangent * screenSpaceLineWidth / 2.0f , 0.0 , 1.0f );
269
+ outV.position = float4 (transformedPoints[0u] + endPointNormal * antiAliasedLineThickness - endPointTangent * antiAliasedLineThickness , 0.0 , 1.0f );
271
270
else if (vertexIdx == 2u)
272
271
outV.position = float4 (exterior0, 0.0 , 1.0f );
273
272
else if (vertexIdx == 3u)
@@ -288,12 +287,12 @@ PSInput main(uint vertexID : SV_VertexID)
288
287
{
289
288
float2 endPointTangent = normalize (transformedPoints[2u] - transformedPoints[1u]);
290
289
float2 endPointNormal = float2 (-endPointTangent.y, endPointTangent.x) * flip;
291
- float2 endPointExterior = transformedPoints[2u] + endPointTangent * screenSpaceLineWidth / 2.0f ;
290
+ float2 endPointExterior = transformedPoints[2u] + endPointTangent * antiAliasedLineThickness ;
292
291
293
292
if (vertexIdx == 0u)
294
293
outV.position = float4 (nbl::hlsl::shapes::util::LineLineIntersection<float >(rightExteriorPoint, rightTangent, endPointExterior, endPointNormal), 0.0 , 1.0f );
295
294
else if (vertexIdx == 1u)
296
- outV.position = float4 (transformedPoints[2u] + endPointNormal * screenSpaceLineWidth / 2.0f + endPointTangent * screenSpaceLineWidth / 2.0f , 0.0 , 1.0f );
295
+ outV.position = float4 (transformedPoints[2u] + endPointNormal * antiAliasedLineThickness + endPointTangent * antiAliasedLineThickness , 0.0 , 1.0f );
297
296
else if (vertexIdx == 2u)
298
297
outV.position = float4 (exterior1, 0.0 , 1.0f );
299
298
else if (vertexIdx == 3u)
@@ -310,9 +309,6 @@ PSInput main(uint vertexID : SV_VertexID)
310
309
311
310
if (lineStyle.isRoadStyleFlag)
312
311
{
313
- const float sdfLineThickness = screenSpaceLineWidth / 2.0f ;
314
- outV.setLineThickness (sdfLineThickness);
315
-
316
312
const double2 circleCenter = vk::RawBufferLoad<double2 >(drawObj.geometryAddress, 8u);
317
313
const float2 v = vk::RawBufferLoad<float2 >(drawObj.geometryAddress + sizeof (double2 ), 8u);
318
314
const float cosHalfAngleBetweenNormals = vk::RawBufferLoad<float >(drawObj.geometryAddress + sizeof (double2 ) + sizeof (float2 ), 8u);
@@ -342,7 +338,7 @@ PSInput main(uint vertexID : SV_VertexID)
342
338
343
339
if (vertexIdx == 0u)
344
340
{
345
- const float2 V1 = normalize (mul (v, rotationMatrix)) * antiAliasedLineWidth ;
341
+ const float2 V1 = normalize (mul (v, rotationMatrix)) * antiAliasedLineThickness * 2.0f ;
346
342
const float2 screenSpaceV1 = circleCenterScreenSpace + V1;
347
343
outV.position = float4 (screenSpaceV1, 0.0f , 1.0f );
348
344
}
@@ -353,13 +349,13 @@ PSInput main(uint vertexID : SV_VertexID)
353
349
else if (vertexIdx == 2u)
354
350
{
355
351
// find intersection point vertex
356
- float2 intersectionPoint = v * antiAliasedLineWidth ;
352
+ float2 intersectionPoint = v * antiAliasedLineThickness * 2.0f ;
357
353
intersectionPoint += circleCenterScreenSpace;
358
354
outV.position = float4 (intersectionPoint, 0.0f , 1.0f );
359
355
}
360
356
else if (vertexIdx == 3u)
361
357
{
362
- const float2 V2 = normalize (mul (rotationMatrix, v)) * antiAliasedLineWidth ;
358
+ const float2 V2 = normalize (mul (rotationMatrix, v)) * antiAliasedLineThickness * 2.0f ;
363
359
const float2 screenSpaceV2 = circleCenterScreenSpace + V2;
364
360
outV.position = float4 (screenSpaceV2, 0.0f , 1.0f );
365
361
}
0 commit comments