WireFrame using HLSL 5

Started by
10 comments, last by Yourself 11 years ago

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?

Advertisement

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

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.

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

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

Draw it once with the FillState and draw it again with WireframeState?
what
Solid witeframe (http://developer.download.nvidia.com/SDK/10.5/direct3d/Source/SolidWireframe/Doc/SolidWireframe.pdf ) is the technique I prefer.

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?

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.

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.

This topic is closed to new replies.

Advertisement