Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Don't forget to read Tuesday's email newsletter for your chance to win a free copy of Construct 2!


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.

  • You cannot reply to this topic
11 replies to this topic

#1 BlackJoker   Members   -  Reputation: 548

Like
0Likes
Like

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;
};


////////////////////////////////////////////////////////////////////////////////
// Vertex Shader
////////////////////////////////////////////////////////////////////////////////
PixelInputType LightVertexShader(VertexInputType input)
{
	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?



Sponsor:

#2 seacow2   Members   -  Reputation: 132

Like
1Likes
Like

Posted 30 March 2013 - 06:03 AM

Maybe...

 

technique LightVertexShader

{

 

  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



#3 BlackJoker   Members   -  Reputation: 548

Like
0Likes
Like

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.


#4 incertia   Crossbones+   -  Reputation: 779

Like
2Likes
Like

Posted 30 March 2013 - 10:48 AM

Why not just switch the rasterizer states?
//FillState and WireframeState have already been defined and created...
pImmediateContext->RSSetState(FillState);
//draw complete objects
pImmediateContext->RSSetState(WireframeState);
//draw wire objects

what

#5 BlackJoker   Members   -  Reputation: 548

Like
0Likes
Like

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?



#6 incertia   Crossbones+   -  Reputation: 779

Like
0Likes
Like

Posted 30 March 2013 - 11:47 AM

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

#7 Yourself   Crossbones+   -  Reputation: 1153

Like
0Likes
Like

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.

#8 BlackJoker   Members   -  Reputation: 548

Like
0Likes
Like

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?



#9 Jason Z   Crossbones+   -  Reputation: 5163

Like
3Likes
Like

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.



#10 BlackJoker   Members   -  Reputation: 548

Like
0Likes
Like

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.



#11 BlackJoker   Members   -  Reputation: 548

Like
0Likes
Like

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.



#12 Yourself   Crossbones+   -  Reputation: 1153

Like
0Likes
Like

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.

http://developer.download.nvidia.com/SDK/10/direct3d/samples.html#SolidWireframe




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.



PARTNERS