Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8968833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:30:30+00:00 2026-06-15T17:30:30+00:00

I am working from the ParticleGS DirectX10 sample, to build a geometry shader based

  • 0

I am working from the ParticleGS DirectX10 sample, to build a geometry shader based particle system in DirectX 11.

Using the sample code, and changing it to my liking, I am able to draw a single quad (which is essentially one particle constantly recreating itself).

This is my shader code:

//Single particle stream-out shader which uses ping-pong buffers.
//Based on DirectX sample ParticlesGS

struct VSParticleIn
{
    float3 pos              : POSITION;         
    float3 vel              : NORMAL;           
    float  Timer            : TIMER;            
    uint   Type             : TYPE;     //Only one type for the moment.         
};

struct VSParticleDrawOut
{
    float3 pos : POSITION;
    float4 color : COLOR0;
    float radius : RADIUS;
};

struct PSSceneIn
{
    float4 pos : SV_Position;
    float2 tex : TEXTURE0;
    float4 color : COLOR0;
};

cbuffer cbRenderParticle
{
    float4x4 g_mWorldViewProj;
    float4x4 g_mInvView;
};

cbuffer cbAdvanceParticle
{
    float g_fGlobalTime;
    float g_fElapsedTime;
    float4 g_vFrameGravity;
    float g_fSecondsPerFirework = 1.0;
};

cbuffer cbImmutable
{
    float3 g_positions[4] =
    {
        float3( -1, 1, 0 ),
        float3( 1, 1, 0 ),
        float3( -1, -1, 0 ),
        float3( 1, -1, 0 ),
    };
    float2 g_texcoords[4] = 
    { 
        float2(0,1), 
        float2(1,1),
        float2(0,0),
        float2(1,0),
    };
};

Texture2D g_txDiffuse;
SamplerState g_samLinear
{
    Filter = MIN_MAG_MIP_LINEAR;
    AddressU = Clamp;
    AddressV = Clamp;
};

Texture1D g_txRandom;
SamplerState g_samPoint
{
    Filter = MIN_MAG_MIP_POINT;
    AddressU = Wrap;
};

RasterizerState mainState {
    FillMode = Solid;
    CullMode = None;
    FrontCounterClockwise = false;
};

BlendState AdditiveBlending
{
    AlphaToCoverageEnable = FALSE;
    BlendEnable[0] = TRUE;
    SrcBlend = SRC_ALPHA;
    DestBlend = ONE;
    BlendOp = ADD;
    SrcBlendAlpha = ZERO;
    DestBlendAlpha = ZERO;
    BlendOpAlpha = ADD;
    RenderTargetWriteMask[0] = 0x0F;
};

BlendState NoBlending
{
    AlphaToCoverageEnable = FALSE;
    BlendEnable[0] = FALSE;
};

DepthStencilState DisableDepth
{
    DepthEnable = FALSE;
    DepthWriteMask = ZERO;
};

DepthStencilState DSSLess
{
    DepthEnable = TRUE;
    DepthWriteMask = ALL;
    StencilEnable = TRUE;
    StencilReadMask = 0;
    StencilWriteMask = 0;

    FrontFaceStencilFunc = ALWAYS;
    FrontFaceStencilDepthFail = INVERT;
    FrontFaceStencilPass = KEEP;
    FrontFaceStencilFail = KEEP;

    BackFaceStencilFunc = ALWAYS;
    BackFaceStencilDepthFail = INVERT;
    BackFaceStencilPass = KEEP;
    BackFaceStencilFail = KEEP;

    DepthFunc = LESS;
};

VSParticleDrawOut RenderSceneVS(VSParticleIn input)
{
    VSParticleDrawOut output = (VSParticleDrawOut)0;
    output.pos = input.pos;
    output.radius = 3;
    output.color = float4(1,1,1,1);
    return output;
}

VSParticleIn PassthroughVS(VSParticleIn input)
{
    return input;
}

float3 RandomDir(float fOffset)
{
    float tCoord = (g_fGlobalTime + fOffset) / 300.0;
    return g_txRandom.SampleLevel( g_samPoint, tCoord, 0 );
}


[maxvertexcount(128)]
void AdvanceParticlesGS(point VSParticleIn input[1], inout PointStream<VSParticleIn> ParticleOutputStream)
{
    //Just keeps emitting itself.
    ParticleOutputStream.Append( input[0] );
}


[maxvertexcount(4)]
void RenderSceneGS(point VSParticleDrawOut input[1], inout TriangleStream<PSSceneIn> SpriteStream)
{
    PSSceneIn output;

    for(int i=0; i<4; i++)
    {
        float3 position = g_positions[i]*input[0].radius;
        //position = mul( position, g_mInvView ) + input[0].pos;
        output.pos = mul( float4(position,1.0), g_mWorldViewProj );

        output.color = input[0].color;
        output.tex = g_texcoords[i];
        SpriteStream.Append(output);
    }
    SpriteStream.RestartStrip();
}

float4 RenderScenePS(PSSceneIn input) : SV_Target
{   
    return g_txDiffuse.Sample( g_samLinear, input.tex ) * input.color;
}

technique10 RenderParticles
{
    pass p0
    {
        SetVertexShader( CompileShader( vs_4_0, RenderSceneVS() ) );
        SetGeometryShader( CompileShader( gs_4_0, RenderSceneGS() ) );
        SetPixelShader( CompileShader( ps_4_0, RenderScenePS() ) );

        SetBlendState( AdditiveBlending, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF );
        SetRasterizerState( mainState );
        SetDepthStencilState( DSSLess, 0 );
    }  
}


GeometryShader gsStreamOut = ConstructGSWithSO( CompileShader( gs_4_0, AdvanceParticlesGS() ), "POSITION.xyz; NORMAL.xyz; TIMER.x; TYPE.x" );
technique10 AdvanceParticles
{
    pass p0
    {
        SetVertexShader( CompileShader( vs_4_0, PassthroughVS() ) );
        SetGeometryShader( gsStreamOut );
        SetPixelShader( NULL );

        SetRasterizerState( mainState );
        SetDepthStencilState(DisableDepth, 0);
    }  
}

However, I noticed a problem which was similar to one I once had: the rendered shape is distorted. Here is a video showcasing what is happening. http://youtu.be/6NY_hxjMfwY

Now, I used to have this issue when using several effects together, when I realised that I needed to explicitly set the geometry shader to null for the other effects. I solved this problem, as you can see in the video, as the rest of the scene is drawing properly. Note that some sides are being culled somehow, although I turned off culling in my main render state.

Run on its own, the shader has the same behaviour. Other shaders do not seem interfere with it.

My question is, what could cause the distortion of the quad? I verified my transformation matrices, and they seem to be correct. What could be the cause of the distortion? Or what are the common causes?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T17:30:31+00:00Added an answer on June 15, 2026 at 5:30 pm

    I finally have the solution!
    The problem lies within the RenderSceneGS geometry shader.
    The matrix should be multiplied in the other order, which is

    output.pos = mul( g_mWorldViewProj, float4(position,1.0));
    

    I find this strange, since this order is actually reversed compared to matrix multiplication in the vertex shader. I have been told that this is due to how the matrices are stored in memory, however, I do not have much more information on about the nature of this issue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working from some sample code, provided in PHP - we are using c#,
I'm working on a particle system using the compute shader right now. I put
I'm porting some (working) code from Linux to Windows 8. I'm using DDK. typedef
I am working from the GLSprite sample code example. What I want to know
I'm working from a JavaScript book and would like to create some menus using
I've done most of my code in as3, working from either document class or
I'm working on a particle system and point sprites would be nice to use.
I am trying to get some code working from an example I came across.
This is the code im working from: http://jsfiddle.net/X9SkK/ This is the javascript: function showmap()
This is the code I'm working from: http://jsfiddle.net/njDvn/36/ The weird thing is, the autosuggest

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.