如何在 DirectX 11 中使用曲面细分绘制虚线图案 3D 线
How to draw a dotted pattern 3D line with tessellation in DirectX 11?
我需要在directx 11中绘制线条,这将在GDI中显示像虚线笔画一样的颜色。我知道曲面细分会在每条线之间放置更多的顶点。有没有人告诉我如何在 directx 11 中获得虚线图案绘制线?
您可以在屏幕空间和像素着色器中平铺小纹理。像素着色器的外观如下:
Texture2D<float4> patternTexture : register(t0);
static const uint2 patternSize = uint2( 8, 8 );
float4 main( float4 screenSpace : SV_Position ) : SV_Target
{
// Convert position to pixels
const uint2 px = (uint2)screenSpace.xy;
// Tile the pattern texture.
// patternSize is constexpr;
// if it's power of 2, the `%` will compile into bitwise and, much faster.
const uint2 readPosition = px % patternSize;
// Read from the pattern texture
return patternTexture.Load( uint3( readposition, 0 ) );
}
或者,您可以在运行时生成模式,而无需读取纹理。这是一个像素着色器,它跳过每隔一个像素:
float4 main( float4 color: COLOR0, float4 screenSpace : SV_Position ) : SV_Target
{
// Discard every second pixel
const uint2 px = ((uint2)screenSpace.xy) & uint2( 1, 1 );
if( 0 != ( px.x ^ px.y ) )
return color;
discard;
return float4( 0 );
}
相关文章:
- QuadTree只在窗口的右上角绘制
- 绘制旋转的三角形
- flutter:即使shouldRepaint()返回true,自定义画家也不会重新绘制
- 如何在QT中的自定义视频小工具t上绘制矩形
- 如何在Visual Basic中使用矩形函数OpenGL绘制矩形
- 无法使用VAO和EBO(openGL)绘制多个对象
- 为什么我的点没有在 OpenGL 中绘制鼠标所在的位置?
- 绘制顺时针三角形,重新排序点
- 在顶点着色器中使用 OpenGl 的未声明标识符,我在顶点着色器中绘制三角形时遇到问题
- SFML 文本未绘制在窗口上
- 如何在快板的屏幕中显示子位图的绘制?
- 如何绘制自定义形状的元素?
- QPainter 将 QBrush 设置为 在 QT/C++ 中绘制文本
- 除非重新绘制大小,否则SDL_Texture在调整大小后呈现黑色
- 绘制文本问题
- 在 QT C++中绘制/操作多边形
- 如何在 Gnuplot 中分别绘制 2 个文件数据?我有一个文件"sin.txt",另一个文件"cos.txt",我想将它们分别绘制在一个图表上
- 在现代OpenGL中,绘制GL_TRIANGLE奇怪的z轴行为的填充圆
- 如何在 DirectX 11 中使用曲面细分绘制虚线图案 3D 线
- 在QML中绘制一条虚线和虚线贝塞尔曲线