Skip to main content
GameDev.net gamedev.net
🔒 Locked

Transformation matrix in geometry shader ?

Started by Freddy Indra Wiryadi Mar 17, 2013 at 5:59 AM 1 replies 2.2k views
Original Post
Freddy Indra Wiryadi
Freddy Indra Wiryadi
Hi, are there any differences between doing the transformation from world space to screen space on vertex shader and geometry shader ?
I am doing it in geometry shader right now but the objects aren't displayed properly on screen..
before, when I am only using vertex shader and doing the transformation there, the transformation works correctly..

Here is some piece of my code on geometry shader:

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

struct GeometryInputType
{
    float4 position : POSITION;
    float2 tex : TEXCOORD0;
	float4 color : COLOR;
	float pSize : PARTICLE_SIZE;
};
 
struct PixelInputType
{
    float4 position : SV_POSITION;
    float2 tex : TEXCOORD0;
	float4 color : COLOR;
};


void GS( point GeometryInputType vert[1], inout TriangleStream triStream )
{
        PixelInputType output;	
	GeometryInputType temp;

	//1
	temp = vert[0];
	// Calculate the position of the vertex against the world, view, and projection matrices.
        output.position = mul(temp.position, worldMatrix);
        output.position = mul(temp.position, viewMatrix);
        output.position = mul(temp.position, projectionMatrix);

	output.tex = temp.tex;
	output.color = temp.color;

	triStream.Append(output);

etc etc etc....
Jason Z
Jason Z

There is no difference at all. Actually the only requirement is that the SV_Position attribute contains a homogenous position value at the input to the rasterizer stage, and that doesn't matter if it comes directly from the vertex shader stage, the domain shader stage, or the geometry shader stage.

As for your problem, can you describe in more detail how the symptoms look? Is the object appearing, but in the wrong place? Have you checked the contents of the contstant buffer to ensure that it is correctly set within the geometry shader?

One thing I noticed is that you are taking as input a single vertex (as a point) and then transforming and appending it to the output stream. This works fine if you are creating another point stream, but if you want to have triangles, then you have to append at least three vertices per geometry shader invocation. If any less than three is appended, then the geometry shader throws out the results as an incomplete primitive. So most likely you will want to declare three vertices from a triangle as input, and then use the triangle stream to transform three at a time. That will probably fix the issue!

Jason Zink :: DirectX MVP   Direct3D 11 engine on CodePlex: Hieroglyph 3 Direct3D Books: 

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.