Jump to content
  • Advertisement
Sign in to follow this  

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

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!