question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Variable width path

See original GitHub issue

Here is a working fiddle with an example of multi-coloured paths, where each coordinate has a different colour, and each segment of the path gets two colours.

Here’s a snippet of the code

class MultiColouredPathLayer extends deck.PathLayer {
  
    initializeState() {
      super.initializeState();           
      this.state.attributeManager.addInstanced({
        colors: {
          size: this.props.colorFormat.length,
          vertexOffset: 0,
          type: 0x1401,  // UNSIGNED_BYTE
          normalized: true,
          accessor: 'getColor',
          transition: ATTRIBUTE_TRANSITION,
          defaultValue: DEFAULT_COLOR,
          shaderAttributes: {
            instanceFirstColour: {
              vertexOffset: 0
            },
            instanceLastColour: {
              vertexOffset: 1
            }
          }
        }
      });
    }
  
    getShaders() {
      return {
        ...super.getShaders(),
        inject: {
          'vs:#decl': `          
          attribute vec4 instanceFirstColour;
          attribute vec4 instanceLastColour; 
          
          varying vec4 firstColour;
          varying vec4 lastColour;
          `,
          'vs:#main-end':`
          firstColour = vec4( instanceFirstColour.rgb, instanceFirstColour.a * opacity );
          lastColour = vec4( instanceLastColour.rgb, instanceLastColour.a * opacity );

          vColor = mix( firstColour, lastColour, positions.x );          
          `
        }
      }
    };
  }

I’ve tried to extend this where each coordinate also gets its own width

widths: {
          size: 1,
          vertexOffset: 0,
          type: 0x140a, // DOUBLE
          //normalized: true,
          accessor: 'getWidth',
          //transition: ATTRIBUTE_TRANSITION,
          defaultValue: 1,
          shaderAttributes: {
            instanceFirstWidth: {
              vertexOffset: 0
            },
            instanceLastWidth: {
              vertexOffset: 1
            }
          }
        }

but I can’t see how to inject into the vertex shader these Instance Width values so the vec2 widthPixels variable uses them.

So my question is, is it possible to have a segment where either end has a different width, and if so, how do I inject these values into the shader?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10

github_iconTop GitHub Comments

1reaction
Pessimistresscommented, Oct 12, 2020

This issue can serve as the feature request.

0reactions
Pessimistresscommented, Oct 13, 2020

For loops you need to repeat two vertices’ worth of colors/widths to match the internal positions attribute structure:

path: [
        [-0.3,0.3],    // top-left
        [0.3,0.3],     // top-right
        [0.3,-0.3],    // bottom-right
        [-0.3,-0.3],    // bottom-left
        [-0.3,0.3],
      ],
colour: [
        [255,0,0,255],  // Red
        [0,255,0,255],  // Green
        [0,0,255,255],  // Blue
        [0,0,0,255],     // Black
        [255,0,0,255],
        [0,255,0,255]
      ],
width: [
        2000,
        4000,
        6000,
        8000,
        2000,
        4000,
      ]

It has to do with each join requiring 3 vertices (before, current, after) to render correctly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

variable width path - Beginners' Questions - Inkscape Forum
I'm hoping the answer to this is yes, as in illustrator I found a cool trick to make lightning effects by varying the...
Read more >
How to Create Variable-width Stroke Profiles in Adobe Illustrator
Creating a variable width stroke is one technique that is often used to give ... want the stroke to be wider, then click,...
Read more >
Proposals/Variable width stroke - SVG
If only one number is specified, the stroke width is symmetrical. Positions list: <percentage> values represent percentages of the path length.
Read more >
Create a stroke with variable width using the Width tool
Learn how to create strokes with variable width in Illustrator. ... Select the trunk path, then head to the tool bar to select...
Read more >
Variable-width strokes - The Battle for Wesnoth Wiki
Variable-width strokes · Create your path with any tool you like. · From "Path -> Linked Offset" create a path whose size (and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found