Jump to content

  • Log In with Google      Sign In   
  • Create Account


swdever

Member Since 03 Mar 2013
Offline Last Active Nov 05 2013 02:13 AM

Topics I've Started

Problem about vertex shader in Skybox

05 June 2013 - 04:50 AM

   Suppose my skybox is a sphere. I have learned that when draw a skybox, we can make the sphere's z value equal to its w value in the vertex shader, like this:

   

VertexOut VS(VertexIn vin)
{
	VertexOut vout;
	
        //PosH stand for position in Homogeneous coordinate 
  	vout.PosH = mul(float4(vin.PosL, 1.0f), gWorldViewProj).xyww;
	
        //PosL stan for position in local coordinate,used as a lookup vector in cubemap
	vout.PosL = vin.PosL;
	
	return vout;
}

 

   I can't totally undestand why we can do like that.  If we do so, after perspective divide, wouldn't there be two part of the sphere becomes in  the view frustum's far plane, one behind the camera originally and the other in front of the camera originally? If they already in the view frustum, then, how can the pipeline clip out the one which behind the camera originally? Hope someone help me figure it out!


Where is my particle?

18 May 2013 - 04:25 AM

   Hey,

   I am studying the sample ParticlesGS in the DX SDK. I try to implement a simpler fireworks myself. But there's some thing wrong in my Stream Out Geometry Shader. Here's my GS code.

[maxvertexcount(100)]
void StreamOutGS( point Particle input[1], inout PointStream<Particle> pStream )
{
	input[0].age += gTimeStep;
	if( input[0].type == PT_EMITTER )
		GSEmitterHandler( input[0], pStream );
	else if( input[0].type == PT_SHELL )
		GSShellHandler( input[0], pStream );
	else if( input[0].type == PT_EMBER1 )
		GSEmber1Handler( input[0], pStream );
}

 

  The struction and functions used in the StreamOutGS are defined before,like these:

struct Particle
{
	float3 pos : POSITION;
	float3 vel : VELOCITY;
	float2 size : SIZE;
	float age : AGE;
	uint type : TYPE;
};

   

cbuffer cbFixed
{
	float gSecondPerShell = 1.0;
	float gShellLife = 3.0;
	float gEmber1Life = 2.0;

	float3 gAcceW = { 0.0f, -9.8f, 0.0f };
};


#define PT_EMITTER 0//particle type
#define PT_SHELL   1
#define PT_EMBER1  2

void GSGenericHandler( Particle input, inout PointStream<Particle> pStream )
{
	input.pos += input.vel * gTimeStep + 0.5 * gTimeStep * gTimeStep * gAcceW;
	input.vel += gTimeStep * gAcceW;
	pStream.Append( input );
}

void GSEmitterHandler( Particle input, inout PointStream<Particle> pStream )
{
	if( input.age > gSecondPerShell )
	{
		float3 vRandom = RandUnitVec( PT_SHELL );//return a random unit vector,defined before
		Particle p;
		p.pos = input.pos;
		p.vel = input.vel + 8.0f * vRandom;
		p.size = float2( 1.0f, 1.0f );
		p.age = 0.0f;
		p.type = PT_SHELL;
		
		input.age = 0.0f;
		pStream.Append( p );
	}
	pStream.Append( input );
}

void GSShellHandler( Particle input, inout PointStream<Particle> pStream )
{
	if( input.age >= gShellLife )
	{
		Particle p;
		float3 vRandom = float3( 0.0f, 0.0f, 0.0f );

		for( int i = 0; i < 30; ++i )
		{
			vRandom = RandUnitVec( PT_EMBER1 + i );////return a random unit vector
			p.pos = input.pos;
			p.vel = input.vel + 15.0 * vRandom;
			p.size = float2( 0.8f, 0.8f );
			p.age = 0.0f;
			p.type = PT_EMBER1;

			pStream.Append( p );
		}
	}
	else
		GSGenericHandler( input, pStream );
}

void GSEmber1Handler( Particle input, inout PointStream<Particle> pStream )
{
	if( input.age < gEmber1Life )
		GSGenericHandler( input, pStream );
} 

 

It seems that the emitter works well. But the shell just explodes into one ember,not thirty as I defined,that is,maybe the loop in GSShellHandler  just loops one time for each shell,I guess.Can anybody tell me where the bug is?

 

   In addition, I use the visual stdio 2012.I debug my HLSL code with its Graphics Diagnostic Tools. Each time I capture one frame,I only can access one input for debug. For example,if there are ten particles pass through my StreamOutGS,one emitter,two shells and seven embers.When I capture one frame and debug StreamOutGS,mostly,the input particle is a ember.I have no idea how to access and use the other nine particles to debug. Also,I don't know how to access a shell to debug at the exactly time it explodes. That's why I don't know how to debug my loop in GSShellHandler. Hope somebody give some help. 


How does the pipeline know the index what it need when it draws a quad using the vertic...

02 April 2013 - 09:47 PM

   Hi! I am learning how the Geometry Shader works in D3D11. I am studying a sample which inputs one point into the Geometry Shader and outputs a quad each time. As shown in the figure below, the sample specifies the vertices generated by the Geometry Shader.(Sorry. I don't know how to upload a image. Hope you can understand the figure.)

 

 

v1               v3

------------------

|                 |

|                 |

|                 |

|                 |

------------------

v0                v2

  With general method,if we want to draw a quad, we pass four vertices to the VertexBuffer, then create a IndexBuffer, binding them to the pipeline. Then the pipeline uses the data in the IndexBuffer and the VertexBuffer to draw two triangles what make up a quad. But in the sample I am studying, there is no IndexBuffer. The sample just generates these four vertices and append them to a TriangleStream object in the order: v0,v1,v2,v3, at the end of the Geometry Shader. Since D3D11 uses counter-clockwise culling state by default, visible triangles must be drawn in clockwise order. But how does the pipeline determine which three vertices of these four vertices to choose and their order to draw a visible triangle. There is no IndexBuffer in the sample. Maybe the Geometry Shader's output is drawn using a fixed index?Can anybody help me figure it out?

 

PS: The sample works well.


How does the pipeline know the index what it need when it draws a quad using the vertic...

02 April 2013 - 08:50 PM

   Hi! I am learning how the Geometry Shader works in D3D11. I am studying a sample which inputs one point into the Geometry Shader and outputs a quad each time. As shown in the figure below, the sample specifies the vertices generated by the Geometry Shader.(Sorry. I don't know how to upload a image. Hope you can understand the figure.)

 

 

v1               v2

------------------

|                 |

|                 |

|                 |

|                 |

------------------

v0                v3

  With general method,if we want to draw a quad, we pass four vertices to the VertexBuffer, then create a IndexBuffer, binding them to the pipeline. Then the pipeline uses the data in the IndexBuffer and the VertexBuffer to draw two triangles what make up a quad. But in the sample I am studying, there is no IndexBuffer. The sample just generates these four vertices and append them to a TriangleStream object in the order: v0,v1,v2,v3, at the end of the Geometry Shader. Since D3D11 uses counter-clockwise culling state by default, visible triangles must be drawn in clockwise order. But how does the pipeline determine which three vertices of these four vertices to choose and their order to draw a visible triangle. There is no IndexBuffer in the sample. Maybe the Geometry Shader's output is drawn using a fixed index?Can anybody help me figure it out?

 

PS: The sample works well.


PARTNERS