Live data from Hacker News

Zdog – Pseudo-3D JavaScript engine for Canvas and SVG

zzz.dog

91–96 of 96 posts

Re: Zdog – Pseudo-3D JavaScript engine for Canvas and SVG

#91
post #87

Earlier quoted context omitted.

I think our fundamental disagreement here is that I think the main use for this is interactive graphics, and that's how it seems to be marketed, and you seem to think its main utility is as an art tool for generating SVGs. I personally think it would be a pretty awkward way to generate an SVG compared to the alternatives, since pulling the data out of the browser requires using dev tools or saving the entire pages' H…

Yes, I am including both interactive and non-interactive use cases in my argument. You are assuming Zdog is limited and can only be used interactively in practice. I do disagree with your assumption. > Hours is really misrepresenting things. It's not ray tracing. It takes milliseconds. You can do it hundreds of times per second, with scenes that are vastly more rich and complicated than this can do. This is still irr…

> You are assuming Zdog is limited and can only be used interactively in practice.

Well, it is pretty limited, by design, in terms of possible constructions you can make with it. I would not call it a general purpose tool. As far as I can tell it doesn't even have an export function, you'd have to scrape the SVG data out of the tag yourself. (might be wrong, haven't closely looked at the api, just went through the examples)

> Zdog & SVG is two-pass and there's an intermediate 2d resolution independent representation.

I realize this, but there are reasons why I think this is of niche utility:

- The constructions I can make are limited; IE, this isn't a general purpose tool. It's mostly a neat toy. To me, for it to be a general purpose tool it'd need to be able to handle intersecting objects properly and it fundamentally cannot do this. I like it as a neat toy, that's not a criticism! It's good at being what it is. I just think that you can do more with other techniques, if you want to do more.

- Yes SVG is a useful format, but there are some downsides to rendering a 3d scene into an SVG: specifically, now you have to parse and interpret that data before you can even display it. That's definitely not computationally trivial. Also, having written things that render vector graphics, I can tell you that rendering vector graphics on 3d hardware is extremely hard to do efficiently. Either you need to tessellate into very high polygon meshes, or ignore the GPU entirely and do it in software on the CPU (slow!), or use much more obscure methods. I'm sure the clever people working on Chrome have done this well, but the point still stands that SVGs aren't some magical way to make graphics fast. What they're very good at is being resolution independent. Ironically, one of the more cutting edge ways to try to rasterize vector graphics faster is: ... by using signed distance fields :-) (Look up how Valve renders fonts, for instance)

- If you're saying that SVGs are more space efficient in this context then rasterized graphics, maybe, but I'd point out that even with a huge image we're talking about very few colors (in this style). You could store it in an 8bit png with extremely good lossless compression.

Re: Zdog – Pseudo-3D JavaScript engine for Canvas and SVG

#92
post #82

Earlier quoted context omitted.

> Don't constructors always have side effects? The only side effect they should have is creating a new instance, no playing around with some other object's hierarchy. > think of it as a graph property. addTo is setting up a tree structure The problem is that the hierarchy here is backwards. You usually add children to the parent, not parent to the children. Having a link back to your parent does help with navigating,…

> The only side effect they should have is creating a new instance, no playing around with some other object’s hierarchy. You might be making assumptions. The ‘addTo’ property does not imply the constructor is touching any other object. You might be getting confused because the name is a verb. Again, addTo isn’t very standard naming, but what it represents is the parent property. You should think of it as a property…

But the example calls render on `illo`, which is the parent. So at some point the "double link" between illo and the child was created, which is a side-effect, no?

Re: Zdog – Pseudo-3D JavaScript engine for Canvas and SVG

#93
post #82

Earlier quoted context omitted.

> The only side effect they should have is creating a new instance, no playing around with some other object’s hierarchy. You might be making assumptions. The ‘addTo’ property does not imply the constructor is touching any other object. You might be getting confused because the name is a verb. Again, addTo isn’t very standard naming, but what it represents is the parent property. You should think of it as a property…

But the example calls render on `illo`, which is the parent. So at some point the "double link" between illo and the child was created, which is a side-effect, no?

Presumably updateGraph() and even render() can both tidy up linkages and anything else that needs updating. The shape constructor might well have a side-effect though, I don't know.

Hey I hear your point, this API is a little bit different. Maybe since it's early your feedback is fully justified. Just from my perspective it didn't strike me as "very strange", only perhaps a little bit. I don't think you're wrong, it's just a matter of degree... which is subjective anyway, so take this as lukewarm agreement with you. :)

Re: Zdog – Pseudo-3D JavaScript engine for Canvas and SVG

#95

Earlier quoted context omitted.

Are you suggesting ray marching the object instead of drawing 2D shapes?

Yes, if you don't want z-fighting. If you don't care then this is perfectly fine. But since both approaches can be expressed in a very similar way (primitives that can easily be mathematically modeled), and rendered in the same style, I figured it's an interesting way of achieving the same thing if you want the same style and scalability while allowing for intersecting objects. The trade-off is that ray marching is m…

Perhaps if you want to stay truer to the spirit of the system, then you might have zDog generate faux depth buffers for each of its shapes (using gradients when necessary).

Then you might still take advantage of Chrome’s “optimized” SVG rasterization, but also use the GPU to do depth compositing on the color buffer afterward. As a bonus, depth-fade intersection shaders could work (which are tricky with raymarching).

Re: Zdog – Pseudo-3D JavaScript engine for Canvas and SVG

#96

Earlier quoted context omitted.

This was my initial attempt using an Illustration https://codepen.io/anon/pen/NVORrZ This is my 2nd attempt using the docs you linked https://codepen.io/anon/pen/QRZKxy?editors=0010 What do you think - is updateGraph + render supposed to work more than once?

No, the underlying flatgraph (which is used to generate the drawing commands) is cached and only updated on first call. Reset it by calling scene.updateFlatGraph(); after adding new shapes, before updating the graph & rendering (see https://github.com/metafizzy/zdog/blob/master/js/anchor.js#L... ) edit: made an issue https://github.com/metafizzy/zdog/issues/21

Cheers!
Post reply on HN