• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# WireFrame using HLSL 5

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

11 replies to this topic

### #1BlackJoker  Members

Posted 30 March 2013 - 05:03 AM

Hello,

Could someone write how to make wireframe using HLSL?

Now I have the following code inside vertex shader:

cbuffer MatrixBuffer
{
matrix worldMatrix;
matrix viewMatrix;
matrix projectionMatrix;
};

//////////////
// TYPEDEFS //
//////////////
struct VertexInputType
{
float4 position : POSITION;
float2 tex : TEXCOORD0;
float3 normal : NORMAL;

};

struct PixelInputType
{
float4 position : SV_POSITION;
float2 tex : TEXCOORD0;
float3 normal : NORMAL;
};

////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
{
const float C = 0.1f;
float Far = 100000000.0f;
PixelInputType output;

// Change the position vector to be 4 units for proper matrix calculations.
input.position.w = 1.0f;

// Calculate the position of the vertex against the world, view, and projection matrices.
output.position = mul(input.position, worldMatrix); //перемещение, вращение м скейлинг вертексов
output.position = mul(output.position, viewMatrix);
output.position = mul(output.position, projectionMatrix);

output.position.z = log(C*output.position.z + 1) / log(C*Far + 1) * output.position.w;

// Store the texture coordinates for the pixel shader.
output.tex = input.tex;

// Calculate the normal vector against the world matrix only.
output.normal = mul(input.normal, (float3x3)worldMatrix);

// Normalize the normal vector.
output.normal = normalize(output.normal);

return output;
}


What I need to add to have a possibility switch wireframe on and off using only shader?

### #2seacow2  Members

Posted 30 March 2013 - 06:03 AM

Maybe...

{

pass P0

{

FillMode          = WireFrame;

}

}

Works for me. Of course, you probably have to make it a global var in the shader if you want to turn it on and off....but that raises the question, if you are turning it on and off, why not just do it setting the render state? That's how I always do it. Hope this helps.

http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.renderstate_members%28v=xnagamestudio.31%29.aspx

### #3BlackJoker  Members

Posted 30 March 2013 - 07:08 AM

Thanks.

I want to turn it on and off for different objects. For exmaple one object I want to render with fill mode fill and another - with wireframe.

Edited by BlackJoker, 30 March 2013 - 07:08 AM.

### #4incertia  Members

Posted 30 March 2013 - 10:48 AM

Why not just switch the rasterizer states?
//FillState and WireframeState have already been defined and created...
//draw complete objects
//draw wire objects


what

### #5BlackJoker  Members

Posted 30 March 2013 - 11:23 AM

And how in that case I could draw different object with and without wireframe at the same time?

### #6incertia  Members

Posted 30 March 2013 - 11:47 AM

Draw it once with the FillState and draw it again with WireframeState?
what

### #7Yourself  Members

Posted 30 March 2013 - 11:53 AM

Solid witeframe (http://developer.download.nvidia.com/SDK/10.5/direct3d/Source/SolidWireframe/Doc/SolidWireframe.pdf ) is the technique I prefer.

### #8BlackJoker  Members

Posted 30 March 2013 - 12:19 PM

Draw it once with the FillState and draw it again with WireframeState?

OK, but if I will do it for a lot amout of objects at the same time is this technique will not influence on performance?

### #9Jason Z  Members

Posted 30 March 2013 - 12:59 PM

Draw it once with the FillState and draw it again with WireframeState?

OK, but if I will do it for a lot amout of objects at the same time is this technique will not influence on performance?

There is an impact on performance for every time you switch a state.  That is why people usually collect objects into groups of similar states and process them all together to minimize state changes.  Doing something inside the shader will most likely be much more expensive than switching the rasterizer state directly though - so if performance is your goal then you should definitely try out using multiple rasterizer states and using them accordingly.

Jason Zink :: DirectX MVP

Direct3D 11 engine on CodePlex: Hieroglyph 3

Games: Lunar Rift

### #10BlackJoker  Members

Posted 30 March 2013 - 02:19 PM

Solid witeframe (http://developer.download.nvidia.com/SDK/10.5/direct3d/Source/SolidWireframe/Doc/SolidWireframe.pdf ) is the technique I prefer.

Is there an example how to implement this? In pdf I diвnt find it.

### #11BlackJoker  Members

Posted 30 March 2013 - 02:23 PM

Jason Z

Thanks for the information. I thought that drawing wireframe with shaders will not repduce performance, but I was wrong.

### #12Yourself  Members

Posted 30 March 2013 - 11:30 PM

Solid witeframe (http://developer.download.nvidia.com/SDK/10.5/direct3d/Source/SolidWireframe/Doc/SolidWireframe.pdf ) is the technique I prefer.

Is there an example how to implement this? In pdf I diвnt find it.