Skip to content

Commit

Permalink
Add a new sample - dynamic line rasterization
Browse files Browse the repository at this point in the history
  • Loading branch information
Krzysztof-Dmitruk-Mobica committed Sep 1, 2023
1 parent 4d0eb95 commit 954bbf8
Show file tree
Hide file tree
Showing 9 changed files with 881 additions and 0 deletions.
6 changes: 6 additions & 0 deletions samples/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,12 @@ Demonstrate how to create multiple color blend attachments and then toggle them

Demonstrate how to use shader objects.

=== link:./extensions/dynamic_line_rasterization[Dynamic line rasterization]

*Extensions:* https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_EXT_line_rasterization.html[`VK_EXT_line_rasterization`], https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_EXT_extended_dynamic_state3.html[`VK_EXT_extended_dynamic_state3`]

Demonstrate methods for dynamically customizing the appearance of the rendered lines.

== Tooling Samples

The goal of these samples is to demonstrate usage of tooling functions and libraries that are not directly part of the api.
Expand Down
33 changes: 33 additions & 0 deletions samples/extensions/dynamic_line_rasterization/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright (c) 2023, Mobica Limited
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 the "License";
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

get_filename_component(FOLDER_NAME ${CMAKE_CURRENT_LIST_DIR} NAME)
get_filename_component(PARENT_DIR ${CMAKE_CURRENT_LIST_DIR} PATH)
get_filename_component(CATEGORY_NAME ${PARENT_DIR} NAME)

add_sample(
ID ${FOLDER_NAME}
CATEGORY ${CATEGORY_NAME}
AUTHOR "Khronos"
NAME "dynamic_line_rasterization"
DESCRIPTION "Sample description"
SHADER_FILES_GLSL
"dynamic_line_rasterization/base.vert"
"dynamic_line_rasterization/base.frag"
"dynamic_line_rasterization/grid.vert"
"dynamic_line_rasterization/grid.frag"
)
61 changes: 61 additions & 0 deletions samples/extensions/dynamic_line_rasterization/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
////
- Copyright (c) 2023, Mobica Limited
-
- SPDX-License-Identifier: Apache-2.0
-
- Licensed under the Apache License, Version 2.0 the "License";
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
////
= Dynamic line rasterization

== Overview

This sample demonstrates functions from various extensions related to dynamic line rasterization. These functions can be useful for developing CAD applications.

* From the `VK_EXT_line_rasterization` extension:
** `vkCmdSetLineStippleEXT` - sets the stipple pattern.
* From the `VK_EXT_extended_dynamic_state3` extension:
** `vkCmdSetPolygonModeEXT` - sets how defined primitives should be rasterized.
** `vkCmdSetLineRasterizationModeEXT` - sets the algorithm for line rasterization.
** `vkCmdSetLineStippleEnableEXT` - toggles stippling for lines.
* And also from the core Vulkan:
** `vkCmdSetLineWidth` - sets the line width.
** `vkCmdSetPrimitiveTopologyEXT` - defines which type of primitives is being drawn.

== The sample

Dynamic line rasterization contains a wireframed cube whose appearance can be modified by the user. The cube edges and filling are rendered in a single pipeline, using a different set of indices. The `vkCmdSetPrimitiveTopologyEXT` and `vkCmdSetPolygonModeEXT` functions are used to change the way they are rendered.

Users can modify the line width (`vkCmdSetLineWidth`) and choose how the line is drawn (`vkCmdSetLineRasterizationModeEXT`). The sample also demonstrates the ability to stipple the line. Stippling is defined by two variables:

** `lineStipplePattern` - a `uint16_t` where each bit represents whether a point on the line is colored (1) or transparent (0).
** `lineStippleFactor` - a factor used to determine how many consecutive points are affected by a single pattern bit.

The sample also contains a grid rendered beneath the cube using a different pipeline. This grid represents another approach to line rasterization based on the fragment shader. Consequently, the appearance of the gridlines cannot be modified by the user.

== Credits

The infinite grid shader is based on the code from the https://asliceofrendering.com/scene%20helper/2020/01/05/InfiniteGrid/[asliceofrendering.com] blog.

== Documentation links

https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkCmdSetLineStippleEXT.html

https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkCmdSetPolygonModeEXT.html

https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkCmdSetLineRasterizationModeEXT.html

https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkCmdSetLineStippleEnableEXT.html

https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkCmdSetLineWidth.html
Loading

0 comments on commit 954bbf8

Please sign in to comment.