# DX11 [Video] Drawing the silhouette of an object

## Recommended Posts

Posted (edited)

I'm trying to find a good way to draw a silhouette of an object.

The particular mesh I am looking at is the nanosuit obj for the model from crysis.

The .obj and its related textures can be found here: https://github.com/JoeyDeVries/LearnOpenGL/tree/master/resources/objects/nanosuit

My idea was first to draw the object normally with a null pixel shader and just update the stencil buffer by incrementing the values it would draw to.

Then, i'd use a depth stencil state where I only draw to the pixels where the stencil buffer value is equal to 0 (pixels where the original object did not draw).

I was thinking that for the outline I could just have a vertex shader that extends the vertices out a bit by a fraction of their normals. Something like this...

#pragma pack_matrix( row_major )

cbuffer perObjectBuffer : register(b0)
{
float4x4 wvpMatrix;
};

struct VS_INPUT
{
float3 inPos : POSITION;
float3 inNormal : NORMAL;
};

struct VS_OUTPUT
{
float4 outPosition : SV_POSITION;
};

VS_OUTPUT main(VS_INPUT input)
{
VS_OUTPUT output;
output.outPosition = mul(float4(input.inPos + input.inNormal * 0.1f, 1.0f), wvpMatrix);
return output;
}

For my pixel shader for drawing the silhouette, I was going to use something like this.

struct PS_INPUT
{
float4 inPosition : SV_POSITION;
};

float4 main(PS_INPUT input) : SV_TARGET
{
return float4(1.0f, 1.0f, 1.0f, 1.0f);
}

However, there are a couple of problems with this approach. The first issue is that I can see lines where there are openings inside of the model. This is not a big deal, but it is an isssue none the less.

The next issue is I can see some lines in the actual outline of the model.

Here is a video demonstrating the issue.

The inconsistency in the outline of the object can be observed in the first half of the video. The second half demonstrates the openings inside of the object's silhouette. Is this just an issue with the model itself or is there something I could do to fix this? I am using assimp to load the model and I tried having one of the importer flags to be to smooth the normal, but it still didn't seem to fix my issues.

Edited by pindrought

## Create an account

Register a new account

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 12
• 18
• 15
• 9
• 9