Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Line rendering example #1794

Closed
lobneroO opened this issue Feb 6, 2024 · 8 comments
Closed

Line rendering example #1794

lobneroO opened this issue Feb 6, 2024 · 8 comments

Comments

@lobneroO
Copy link

lobneroO commented Feb 6, 2024

Is there an example for line rendering somewhere? I couldn't find any sample code so far, but rendering lines would be helpful in contexts like ray tracer debugging or graph creation.

I have found the documentation regarding some of the necessary objects, but it is not clear to me yet, how to set this up. E.g. the rasterization for lines needs to be set up as pNext pointer of a pipeline rasterization, but does that require the pipeline rasterization to be set up in a specific way?

@asuessenbach
Copy link
Contributor

I assume, you're not asking for vk::PolygonMode::eLine?
That is, would you elaborate a bit more in detail what you're looking for?

@lobneroO
Copy link
Author

lobneroO commented Feb 6, 2024

I am trying to render a line(/vector) in 3D space. Not a wireframe, i.e. not lines of triangles, but of two points. In my case, I just want to debug rays in a ray tracer and visualizing a few may be a great help. It's obviously not as trivial as just connecting the start and end of every ray, but to get anything going at all, I need to render a line between to points in 3D space and have a depth test enabled.

An example of the effect would be the "draw debug line" that Unreal Engine offers:
https://youtu.be/ts4p1Sh52ek?feature=shared&t=61
The guy created a line that is fixed in 3D space through two world positions and if he moves about, the line stays at its world position (of course it's redrawn every frame for this to work, I'm not expecting miracles :-) ).

@asuessenbach
Copy link
Contributor

Would vk::PrimitiveTopology::eLineList in the vk::PipelineInputAssemblyStateCreateInfo (or vk::CommandBuffer::setPrimitiveTopology() when corresponding dynamic state is set) and vk::PipelineRasterizationStateCreateInfo::lineWidth (or vk::CommandBuffer::setLineWidth() when the corresponding dynamic state is set) do what you need?

@lobneroO
Copy link
Author

lobneroO commented Feb 7, 2024

I actually have my input assembly set up with that primitive topology, but I'm not yet at a point of rendering. If that is sufficient to render lines, what is the special line rasterizer VkPipelineRasterizationLineStateCreateInfoEXT for? I had been trying to integrate this into the pipeline rasterizer's pNext chain.

If your suggestion is sufficient, that's basically the example I had been asking for, I guess. Hard to say, as I am just getting into this topic - but I couldn't see any example code (even outside of this repository) about simple line rendering.

@asuessenbach
Copy link
Contributor

VkPipelineRasterizationLineStateCreateInfoEXT is part of the VK_KHR_line_rasterization extension:

This extension adds some line rasterization features that are commonly used in CAD applications and supported in other APIs like OpenGL. Bresenham-style line rasterization is supported, smooth rectangular lines (coverage to alpha) are supported, and stippled lines are supported for all three line rasterization modes.

That is, for simple line drawings, you don't need that. Only if you want to use more sophisticated line stippling and such, you need to go that route.

@asuessenbach
Copy link
Contributor

Assuming, this question is answered...

@lobneroO
Copy link
Author

Sorry for the delay. Finally got round to work on it and get the first results. The suggested solution works, and I do get a line on screen. I still think, it'd be neat to have an example (e.g. draw a histogram or something like that).
Either way, thank you for the help!

@asuessenbach
Copy link
Contributor

Maybe you could file an issue requesting for such a sample on https://github.com/KhronosGroup/Vulkan-Samples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants