繁体   English   中英

如何在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 );
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM