Followers 0

# WireFrame using HLSL 5

## 11 posts in this topic

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?

0

##### Share on other sites

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

1

##### Share on other sites

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
0

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

2

##### Share on other sites

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

0

##### Share on other sites
Draw it once with the FillState and draw it again with WireframeState?
0

##### Share on other sites

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?

0

##### Share on other sites

Jason Z

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

0

## Create an account

Register a new account