Skip to content

Commit 637641c

Browse files
committed
Update the Readme.
We will use a separate Typed schema DashDotPattern to save the pattern, instead to use a texture to save the pattern. A DashDotLines primitive will not bind a material. Instead, it can bind a DashDotPattern.
1 parent defc94d commit 637641c

1 file changed

Lines changed: 37 additions & 91 deletions

File tree

proposals/LineStyle/README.md

Lines changed: 37 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -31,130 +31,87 @@ You can also define other type of patterns.
3131
# The implementation of DashDot line style
3232
Our implementation will introduce a new type of primitive, the DashDotLines. It inherits from Curves. The primitive is a list of line segments or polylines. The width of the line will be uniform, and it will not change when camera changes. There can be no pattern in the line. Or there can be dash-dot pattern.
3333

34-
We also add a new rprim for the DashDotLines. We add a new shader file, the dashDotLines.glslfx, which includes both vertex and fragment shader. We also need two different materials: one is for a line with no pattern, and another is for a line with dash-dot pattern.
34+
The detail of the pattern will be put in a new type, the DashDotPattern. It inherits from Typed. There is an APISchema, the DashDotPatternAPI, which can bind a DashDotLines primitive with one DashDotPattern. One DashDotPattern can be bound to several different DashDotLines primitive.
35+
36+
We also add a new rprim for the DashDotLines. We add a new shader file, the dashDotLines.glslfx, which includes both vertex and fragment shader.
3537

3638
In the implementation, we also create special geometry for the primitive. Each line segment is converted to a rectangle which is composed from two triangles.
3739

3840
### The DashDotLines schema
3941
A new primitive DashDotLines is added, which inherits from Curves. It inherits properties from Curves.
4042
The shape of this primitive on the screen is a uniform-width line or polyline. Its width will not change when camera changes. It has either no pattern or dash-dot pattern.
4143

42-
The DashDotLines primitive must bind to a specific material. If the material contains a texture of the dash-dot pattern, the primitive will have dash-dot pattern. Or else, the primitive will have no pattern. The property of the style, such as the cap shape or the scale of the dash dot pattern, will also be set in the material via the surface input.
44+
The DashDotLines primitive can bind a DashDotPattern type. Then the lines will have dash-dot pattern. If it doesn't bind a DashDotPattern, it will not have a pattern.
4345

4446
These are properties which inherited from Curves:
4547
- curveVertexCounts
4648
- widths. Widths are now interpreted as the widths in screen space.
4749

4850
The DashDotLines has the following new properties:
49-
- screenSpacePattern. A bool uniform. By default it is true, which means the dash-dot pattern will be based on screen unit. If we zoom in, the pattern on the line will change in the world space, so that the dash size and the dash gap size in the screen space will not change. If it is false, the pattern will be based on world unit. If we zoom in, the pattern on the line will not change in world space. The dash size and the dash gap size in the screen space will be larger.
51+
- startCapType. A token uniform. It is the shape of the line cap at the start of the line. It can be "round", "triangle" or "square". The default value is "round".
52+
- endCapType. A token uniform. It is the shape of the line cap at the end of the line. It can be "round", "triangle" or "square". The default value is "round".
53+
- patternScale. A float uniform. It is valid when the primitive binds a DashDotPattern. The default value is 1. You can lengthen or compress the line pattern by setting this property. For example, if patternScale is set to 2, the length of each dash and each gap will be enlarged by 2 times. This value will not impact on the line width.
54+
- screenSpacePattern. A bool uniform. It is valid when the primitive binds a DashDotPattern. By default it is true, which means the dash-dot pattern will be based on screen unit. If we zoom in, the pattern on the line will change in the world space, so that the dash size and the dash gap size in the screen space will not change. If it is false, the pattern will be based on world unit. If we zoom in, the pattern on the line will not change in world space. The dash size and the dash gap size in the screen space will be larger.
5055

5156
![image of screenSpacePattern](screenSpacePattern.png)
5257

5358
### Extents of the DashDotLines
5459
Different from the other Curves, the extents of the DashDotLines is only the bound box of the control points. The width of the line will not be considered, because it is screen spaced, that it is implemented via the shader.
5560

61+
### The DashDotPattern schema
62+
The DashDotPattern schema inherits from Typed. It saves the detail of a dash-dot pattern. A dash-dot pattern is an array of symbols. Each symbol is either a dash, which is a line, or a dot, which is a point. The DashDotPattern can be bound to one or more DashDotLines primitive.
63+
64+
The DashDotPattern has the following new properties:
65+
- patternPeriod. A float uniform. It is the length of a pattern. By default it is zero. If there is no pattern, it should be zero.
66+
- pattern. An array of float2. It saves the dash-dot pattern. For each float2, the x value and the y value must be zero or positive. The x value saves the offset of the start of current symbol, from the end of the previous symbol. If the current symbol is the first symbol, the offset is from the start of the pattern to the start of current symbol. The y value saves the length of the current symbol. If it is zero, the current symbol is a dot. If it is larger than zero, the current symbol is a dash. As a result, the total sum of all the x value and y value will be the length from the start of the pattern to the end of the last symbol. This sum must be smaller than patternPeriod.
67+
68+
For example, assume the pattern is [(0, 10), (1, 4), (3, 0)]. It means the first symbol is a dash which is from 0 to 10. The second symbol is a dash which is from 11 to 15, and the third symbol is a dot which is at position 18. There are gaps between 10 and 11, and between 15 and 18. If the patternPeriod is 20, there is also a gap between 18 and 20.
69+
70+
An API schema DashDotPatternAPI is provided to bind the DashDotPattern to a DashDotLines primitive.
71+
5672
### The DashDotLines rprim and shader
5773
In HdStorm, we will add the HdDashDotLines rprim for the DashDotLines primitive. The topology of the DashDotLines requires the curveVertexCounts, curveIndices and whether the pattern is screenSpaced. In dashDotLines.glslfx, we add two sections of shader code: "DashDot.Vertex" and "DashDot.Fragment".
5874

5975
### Other inputs for the shader and screen space pattern implementation
6076
For a polyline, the shader need to know the sum of line lengths before each vertex. This value can be pre-calculated in CPU. To implement screen space dash-dot pattern, the sum must be based on line lengths on the screen. So to calculate the sum, we need to do matrix transformation for the lines in CPU, and this calculation must be done when camera is changed. (Maybe we can use the compute shader to do the calculation before the rendering process in each frame)
6177

62-
### Material to support the dash dot style
63-
There are two different materials specially for the DashDotLines primitive, which corresponding to two different surface shaders. The LineSketchSurface shader doesn't have a color input. If the material contains LineSketchSurface shader, the line will not have patterns. The DashDotSurface shader has a color input which linked to a texture shader, and the texture shader will contain the dash-dot pattern texture. If the material contains DashDotSurface shader, the line will have dash-dot patterns.
64-
65-
### LineSketchSurface
66-
The shader will decide the opacity of pixels around caps and joint. The materialTag for this material is translucent.
67-
68-
This surface also has these special input:
69-
- startCapType. An int input. It can be 0, 1, or 2. 0 means the cap type is round. 1 means the cap type is square. 2 means the cap type is triangle. The default value is 0.
70-
- endCapType. An int input. It can be 0, 1, or 2. 0 means the cap type is round. 1 means the cap type is square. 2 means the cap type is triangle. The default value is 0.
71-
- jointType. An int input. Currently it can only be 0, which means the joint type is round.
72-
73-
### DashDotSurface
74-
The shader will decide whether the pixel is within a dash or a gap, so that we can decide its opacity. It will also handle the caps and joint. The materialTag for this material is translucent.
75-
76-
The DashDotSurface must has a color input, which connects to another shader whose shader is DashDotTexture. The DashDotTexture shader links to a texture which saves the information of the dash-dot pattern.
77-
78-
This surface also has these special input:
79-
- startCapType. An int input. It can be 0, 1, or 2. 0 means the cap type is round. 1 means the cap type is square. 2 means the cap type is triangle. The default value is 0.
80-
- endCapType. An int input. It can be 0, 1, or 2. 0 means the cap type is round. 1 means the cap type is square. 2 means the cap type is triangle. The default value is 0.
81-
- jointType. An int input. Currently it can only be 0, which means the joint type is round.
82-
- patternScale. A float input. The default value is 1. You can lengthen or compress the line pattern by setting this property. For example, if patternScale is set to 2, the length of each dash and each gap will be enlarged by 2 times. This value will not impact on the line width.
83-
84-
### DashDotTexture
85-
The DashDotTexture shader is quite the same as UVTexture shader. The difference is that it outputs rgba value. The default value for wrap is clamp, and the default value for min/max filter is "nearest". The shader must have a dash-dot texture input.
86-
87-
### The dash-dot texture
88-
The dash-dot texture is a texture that saves a type of dash-dot pattern. In the four channels we will save if the pixel is within a dash or a gap, and the start and end position of the current dash.
89-
9078
# Examples
9179
### 2 DashDotLines primitives with dash-dot patterns
9280
```
9381
def DashDotLines "StyledPolyline1" (
94-
prepend apiSchemas = ["MaterialBindingAPI"]
82+
prepend apiSchemas = ["DashDotPatternAPI"]
9583
){
96-
uniform token[] xformOpOrder = ["xformOp:translate"]
97-
float3 xformOp:translate = (0, 0, 0)
98-
99-
bool screenSpacePattern = true
100-
rel material:binding = </LineMat1>
84+
uniform bool screenSpacePattern = true
85+
rel dashDotPattern:binding = </Pattern>
86+
uniform token startCapType = "round"
87+
uniform token endCapType = "round"
88+
float patternScale = 5
10189
int[] curveVertexCounts = [3, 4]
10290
point3f[] points = [(0, 0, 0), (10, 10, 0), (10, 20, 0), (0, 30, 0), (-10, 40, 0), (-10, 50, 0), (0, 60, 0)]
10391
float[] widths = [5] (interpolation = "constant")
10492
color3f[] primvars:displayColor = [(1, 0, 0)]
10593
}
10694
def DashDotLines "StyledPolyline2" (
107-
prepend apiSchemas = ["MaterialBindingAPI"]
95+
prepend apiSchemas = ["DashDotPatternAPI"]
10896
){
109-
uniform token[] xformOpOrder = ["xformOp:translate"]
110-
float3 xformOp:translate = (20, 0, 0)
111-
112-
bool screenSpacePattern = true
113-
rel material:binding = </LineMat2>
97+
uniform bool screenSpacePattern = true
98+
rel dashDotPattern:binding = </Pattern>
99+
uniform token startCapType = "triangle"
100+
uniform token endCapType = "triangle"
101+
uniform float patternScale = 11
114102
int[] curveVertexCounts = [3, 4]
115103
point3f[] points = [(0, 0, 0), (10, 10, 0), (10, 20, 0), (0, 30, 0), (-10, 40, 0), (-10, 50, 0), (0, 60, 0)]
116104
float[] widths = [10] (interpolation = "constant")
117105
color3f[] primvars:displayColor = [(0, 0, 1)]
118106
}
119107
120-
def Shader "PatternTexture"
108+
def DashDotPattern "Pattern"
121109
{
122-
uniform token info:id = "DashDotTexture"
123-
asset inputs:file = @DashDot.tif@
124-
float4 outputs:rgba
125-
}
126-
127-
def Shader "LineShader1"
128-
{
129-
uniform token info:id = "DashDotSurface"
130-
color4f inputs:diffuseColor.connect = </PatternTexture.outputs:rgba>
131-
int inputs:startCapType = 0
132-
int inputs:endCapType = 0
133-
float inputs:patternScale = 5
134-
token outputs:surface
135-
}
136-
137-
def Shader "LineShader2"
138-
{
139-
uniform token info:id = "DashDotSurface"
140-
color4f inputs:diffuseColor.connect = </PatternTexture.outputs:rgba>
141-
int inputs:startCapType = 2
142-
int inputs:endCapType = 2
143-
float inputs:patternScale = 11
144-
token outputs:surface
145-
}
146-
147-
def Material "LineMat1"
148-
{
149-
token outputs:surface.connect = </LineShader1.outputs:surface>
150-
}
151-
152-
def Material "LineMat2"
153-
{
154-
token outputs:surface.connect = </LineShader2.outputs:surface>
110+
uniform float patternPeriod = 10
111+
uniform float2[] pattern = [(0, 5), (2.5, 0)]
155112
}
156113
```
157-
In this example, there are two DashDotLines primitives. They all have dash-dot patterns, and the pattern is defined in the DashDot.tif texture.
114+
In this example, there are two DashDotLines primitives. They all bind to the same dash-dot pattern, and the pattern is defined in "Pattern". The period of the pattern is 10. There are two symbols in the pattern. The first symbol starts at 0, and it is a dash with length 5. The second symbol starts at 7.5, and it is a dot.
158115

159116
The first primitive has two polylines. One polyline has 3 vertices and another has 4 vertices. The line width on screen is 5. The startCapType and endCapType are both round. The patternScale is 5 which means the dashes and gaps will be lengthened by 5 times.
160117

@@ -168,24 +125,13 @@ The image for the 2 DashDotLines primitives.
168125
```
169126
def DashDotLines "StyledPolyline" (
170127
){
171-
rel material:binding = </LineMat>
128+
uniform token startCapType = "round"
129+
uniform token endCapType = "round"
172130
int[] curveVertexCounts = [3]
173131
point3f[] points = [(0, 0, 0), (10, 10, 0), (10, 20, 0)]
174132
float[] widths = [5] (interpolation = "constant")
175133
color3f[] primvars:displayColor = [(1, 0, 0)]
176134
}
177-
def Material "LineMat"
178-
{
179-
token outputs:surface.connect = </LineMat/LineShader.outputs:surface>
180-
181-
def Shader "LineShader"
182-
{
183-
uniform token info:id = "LineSketchSurface"
184-
token outputs:surface
185-
int inputs:startCapType = 0
186-
int inputs:endCapType = 0
187-
}
188-
}
189135
```
190136
In this example, there is one polyline. It has 3 vertices. The line width on screen is 5. The polyline doesn't have pattern. The startCapType and endCapType are both round.
191137

0 commit comments

Comments
 (0)