Hello! Thanks for the forum and possible answers to my stupid questions.
In Vertex Shader (only this stage before Pixel Shader!) i give the vertex coordinates so:
struct STATIC_VS_INPUT
{
float3 position : POSITION0;
float3 normal : NORMAL0;
float2 texcoord : TEXCOORD0;
uint VertexId : SV_VERTEXID0;
};
struct STATIC_VS_OUT
{
float4 Pos : SV_POSITION0;
float4 Color : COLOR0;
float2 Tex : TEXCOORD;
uint VertexId : VERTEXID0;
float4 VertexPos : CURRENT0;
};
STATIC_VS_OUT main(STATIC_VS_INPUT vin)
{
STATIC_VS_OUT output;
output.Pos = mul(float4(vin.position, 1.0f), cbVS.wvp);
output.VertexPos = float4(output.Pos.xyzw);
output.Color = float4(saturate(dot(g_LightDir, (output.Pos * 0.5f).xyz) * g_LightColor), 1.0f);
output.Tex = vin.texcoord;
output.VertexId = vin.VertexId;
return output;
}
In Pixel Shader, I do the following:
cbuffer ConstantBufferPS : register(b0)
{
/* __declspec(align(16)) struct ConstantBuffer_StaticPS
* {
* uint WndBufWidth;
* uint WndBufHeight;
* uint SelectedVertexID;
* uint SelectedPrimitiveID;
* }; */
ConstantBuffer_StaticPS cbPS;
};
struct STATIC_PS_OUT
{
float4 Color : SV_TARGET;
float Depth : SV_DEPTH;
};
STATIC_PS_OUT main(STATIC_VS_OUT input, in uint PrimitiveID : SV_PrimitiveID)
{
// 1. after RS input.Pos 'x' and 'y' are in units of pixels;
// 2. Our input.VertexPos (the dublicate of input.Pos in VS) still is in "View Space'
STATIC_PS_OUT output;
output.Depth = input.Pos.z;
// if current 'Vertex' must be selected we draw it white:
if (input.VertexId == cbPS.SelectedVertexID)
{
output.Color = float4(1.0f, 1.0f, 1.0f, 1.0f); // white
}
else
{
output.Color = meshTex2D.Sample(samplerState, input.Tex) * input.Color;
}
return output;
}
In theory, I should only get white pixels next to the "selected" vertex. But I get not only these white pixels, but also completely white triangles (see pic.):
In the picture, these white triangles on the bus buffer (on front). My task is to separate only the 'Selected Vertex'. But for some reason all the fragments in the triangles next to this Vertex turned white. How do I get what I want? I also tried to get separately the position of the vertex in another field of the structure (see above ). Then it translated to 'screen space coordinate system (in PS)':
// float screen_x = (vertex.x / vertex.w + 1) * 0.5 * screenwidth;
float screen_x = (input.VertexPos.x / input.VertexPos.w + 1.f) * .5f * cbPS.WndBufWidth;
But again, I got the position (may be interpolated in Rasterizer Stage - 'RS') of the current pixel (not the Vertex!) in Pixel Shader stage. Tell me how to solve this problem. Thank.