Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

118 Neutral

About GuoLei007

  • Rank
  1. GuoLei007

    GPU particles

    Thank you for your guidance?  you  are  great!  Thank you Very  much!   I  will  go  on study with  your  guidance.
  2. GuoLei007

    GPU particles

    You're welcome. Looks like the sample, so yeah, I think it's fine. Not sure if I understand your question (you might try google translate - no offense intended). Disabling depth write is ok. To correctly occlude particles you need to draw your other stuff first and the draw the particles with depth test only. @Telanor: I just have a gut feeling here. I suspect sort of a race condition or something with the static initialization. Does the sample work at all ? Could you try a non-static version ? I'm shooting in the dark: Do you have more - useful - information about that crash ? Call stack ? D3D debug log ?   Oh!  you understand me!  ....you are friendly!!..Is  that  you say  draw  other stuff first  and   draw the particles  depth Test with  only  read and  not  write ?   I have been doing this for a long time?  Is that right? 
  3. GuoLei007

    GPU particles

    Yea I noticed I missed the StructLayout after I posted that. I've since added it, it didn't make any difference though. GPUParticles is a static class because I was planning on running all the particles from that class.   I  has  success  I will  give  the  code  to  you   maybe the  elapsedTime  you  are  wrong   using SharpDX; using SharpDX.Direct3D; using SharpDX.Direct3D11; using SharpDX.DXGI; using System; using System.Runtime.InteropServices; using Buffer = SharpDX.Direct3D11.Buffer; using MapFlags = SharpDX.Direct3D11.MapFlags; using MoonLight.Graphics; using MoonLight.Vertex; using MoonLight.Scene; using MoonLight.Dispose; using MoonLight.Time; namespace MoonLight.Graphics.Particle { public class ParticleSystem:IMovableObj, IRenderableObj, IDisposable { BasicScene m_BasicScene; string m_Name; public string Name { get { return m_Name; } } SceneNode m_ParentSceneNode; public SceneNode ParentSceneNode { get { return m_ParentSceneNode; } set { m_ParentSceneNode = value; } } private const int MaxParticles = 1024 * 16; private const int MaxNew = 128; public const uint Flag_Constrained = 1; public const uint Flag_Fast_Fade = 2; private Buffer m_SpawnBuffer; private Buffer m_DrawFromBuffer; private Buffer M_StreamToBuffer; private EffectPass m_UpdatePass; private EffectPass m_RenderPass; private InputLayout m_InputLayout; ShaderResourceView m_ParticleTextureView; Effect m_Effect; private VertexParticle[] m_NewParticles; private int m_NumNew=0; private Random m_Random = new Random(); private float m_Elapsed; public ParticleSystem(BasicScene basicScene, string name, Effect effect, Texture2D particleTexture2D) { this.m_Name = name; m_BasicScene = basicScene; m_NewParticles = new VertexParticle[MaxNew]; m_SpawnBuffer = new Buffer(m_BasicScene.WPFRenderHost.Device, new BufferDescription(VertexParticle.SizeInBytes * MaxNew, ResourceUsage.Dynamic, BindFlags.VertexBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None, 0)); m_DrawFromBuffer = new Buffer(m_BasicScene.WPFRenderHost.Device, new BufferDescription(VertexParticle.SizeInBytes * MaxParticles, ResourceUsage.Default, BindFlags.VertexBuffer | BindFlags.StreamOutput, CpuAccessFlags.None, ResourceOptionFlags.None, 0)); M_StreamToBuffer = new Buffer(m_BasicScene.WPFRenderHost.Device, new BufferDescription(VertexParticle.SizeInBytes * MaxParticles, ResourceUsage.Default, BindFlags.VertexBuffer | BindFlags.StreamOutput, CpuAccessFlags.None, ResourceOptionFlags.None, 0)); m_UpdatePass = effect.GetTechniqueByName("UpdateTeq").GetPassByIndex(0); m_RenderPass = effect.GetTechniqueByName("RenderTeq").GetPassByIndex(0); m_InputLayout = new InputLayout(m_BasicScene.WPFRenderHost.Device, m_UpdatePass.Description.Signature, VertexParticle.VertexDeclaration); m_Effect = effect; m_ParticleTextureView = new ShaderResourceView(m_BasicScene.WPFRenderHost.Device, particleTexture2D); } public void Spawn(Vector3 position, Vector3 velocity, Color color, float sizeStart, float sizeEnd, float lifetime, bool constrained, bool fastFade) { // discard particle if buffer is full if (m_NumNew >= MaxNew) return; // create particle struct var v = new VertexParticle(position, velocity, color.ToVector4(), new Vector2(0, lifetime), 0, new Vector2(sizeStart, sizeEnd)); // set the particle's flags if (constrained) v.Flags |= Flag_Constrained; if (fastFade) v.Flags |= Flag_Fast_Fade; // append to buffer m_NewParticles[m_NumNew++] = v; } public void AddToRenderQneue(RenderQueue renderQneue) { renderQneue.AddRenderableObj(this); } private Vector3 RandomDirection(Vector3 direction, float max) { float r1 = ((float)m_Random.NextDouble() * 2 - 1) * max; float r2 = ((float)m_Random.NextDouble() * 2 - 1) * max; float r3 = ((float)m_Random.NextDouble() * 2 - 1) * max; Quaternion q = Quaternion.RotationYawPitchRoll(r1, r2, r3); return Vector3.Transform(direction, q); } public void Draw(RenderTimer renderTimer) { if (m_BasicScene.SceneManager.RenderType == RenderType.Normal) { for (int i = 0; i < 128; i++) { Vector3 position = Vector3.Zero; Vector3 velocity = RandomDirection(Vector3.UnitY, MathUtil.TwoPi) * (float)m_Random.NextDouble(1.0, 4.0); Color color = new Color((float)m_Random.NextDouble(), (float)m_Random.NextDouble(), (float)m_Random.NextDouble()); float startSize = 0.02f; float endSize = 0.2f; float lifetime = 2f; Spawn(Vector3.Zero, velocity, color, startSize, endSize, lifetime, false, false); } m_Elapsed += ((float)renderTimer.IntervalMillseconds) / 1000; Advance(); Render(); } } void Advance() { m_BasicScene.WPFRenderHost.Device.ImmediateContext.OutputMerger.SetDepthStencilState(m_BasicScene.WPFRenderHost.DeviceStates.NoneDepthStencilState); m_BasicScene.WPFRenderHost.Device.ImmediateContext.InputAssembler.InputLayout = m_InputLayout; m_BasicScene.WPFRenderHost.Device.ImmediateContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.PointList; m_BasicScene.WPFRenderHost.Device.ImmediateContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(m_DrawFromBuffer, VertexParticle.SizeInBytes, 0)); m_BasicScene.WPFRenderHost.Device.ImmediateContext.StreamOutput.SetTarget(M_StreamToBuffer, 0); m_UpdatePass.Apply(m_BasicScene.WPFRenderHost.Device.ImmediateContext); // Update particles on the gpu m_BasicScene.WPFRenderHost.Device.ImmediateContext.DrawAuto(); // See if we have any newly-spawned particles waiting if (m_NumNew > 0) { // Copy new particles to vertex buffer and draw them to append them to stream output target DataStream stream; m_BasicScene.WPFRenderHost.Device.ImmediateContext.MapSubresource(m_SpawnBuffer, MapMode.WriteDiscard, MapFlags.None, out stream); stream.WriteRange(m_NewParticles); m_BasicScene.WPFRenderHost.Device.ImmediateContext.UnmapSubresource(m_SpawnBuffer, 0); m_BasicScene.WPFRenderHost.Device.ImmediateContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.PointList; m_BasicScene.WPFRenderHost.Device.ImmediateContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(m_SpawnBuffer, VertexParticle.SizeInBytes, 0)); m_BasicScene.WPFRenderHost.Device.ImmediateContext.Draw(m_NumNew, 0); m_NumNew = 0; } m_BasicScene.WPFRenderHost.Device.ImmediateContext.StreamOutput.SetTargets(null); // Swap vertex buffers Utilities.Swap(ref m_DrawFromBuffer, ref M_StreamToBuffer); } void Render() { // Since we just swapped the vertex buffers, particleDrawFrom contains the current state m_BasicScene.WPFRenderHost.Device.ImmediateContext.OutputMerger.SetBlendState(m_BasicScene.WPFRenderHost.DeviceStates.AdditiveState); m_BasicScene.WPFRenderHost.Device.ImmediateContext.OutputMerger.SetDepthStencilState(m_BasicScene.WPFRenderHost.DeviceStates.NoneDepthState); Vector3 cameraForward = m_BasicScene.SceneManager.Camera.Direction; Matrix lookAtMatrix = Matrix.Billboard(Vector3.Zero, m_BasicScene.SceneManager.Camera.Position, Vector3.UnitY, cameraForward); m_Effect.GetVariableByName("_view").AsMatrix().SetMatrix(m_BasicScene.SceneManager.Camera.View); m_Effect.GetVariableByName("_proj").AsMatrix().SetMatrix(m_BasicScene.SceneManager.Camera.Projection); m_Effect.GetVariableByName("_lookAtMatrix").AsMatrix().SetMatrix(lookAtMatrix); m_Effect.GetVariableByName("_elapsedSeconds").AsScalar().Set(m_Elapsed); m_Effect.GetVariableByName("_camDir").AsVector().Set(cameraForward); m_Effect.GetVariableByName("_gravity").AsVector().Set(9.81f); m_Effect.GetVariableByName("_texture").AsShaderResource().SetResource(m_ParticleTextureView); this.m_Elapsed = 0; m_BasicScene.WPFRenderHost.Device.ImmediateContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(m_DrawFromBuffer, VertexParticle.SizeInBytes, 0)); m_BasicScene.WPFRenderHost.Device.ImmediateContext.InputAssembler.InputLayout = m_InputLayout; m_BasicScene.WPFRenderHost.Device.ImmediateContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.PointList; m_RenderPass.Apply(m_BasicScene.WPFRenderHost.Device.ImmediateContext); m_BasicScene.WPFRenderHost.Device.ImmediateContext.DrawAuto(); m_BasicScene.WPFRenderHost.Device.ImmediateContext.GeometryShader.Set(null); } public void Dispose() { Disposer.RemoveAndDispose(ref m_SpawnBuffer); Disposer.RemoveAndDispose(ref m_DrawFromBuffer); Disposer.RemoveAndDispose(ref M_StreamToBuffer); Disposer.RemoveAndDispose(ref m_ParticleTextureView); Disposer.RemoveAndDispose(ref m_InputLayout); } } }
  4. GuoLei007

    GPU particles

    There are up to four streams from your geometry shader you can select from, not just three. You're missing a NULL. Also, if I get the sample right, it uses one output stream only, so you can omit the (optional) buffer index altogether (an index of >3 e.g. doesn't make sense anyway, you only got 4 output streams). This should work (at least it compiles) GeometryShader gsStreamOut = ConstructGSWithSO( pGSComp, "SV_POSITION.xyz;NORMAL.xyz;COLOR.xyzw;TEXCOORD0.xy;TEXCOORD1.x;TEXCOORD2.xy;",NULL,NULL,NULL,-1); Note the -1 at the end. This is actually D3D11_SO_NO_RASTERIZED_STREAM, since you don't need rasterization for the particle update. Not sure this will work, try 0 first instead (PixelShader is NULL anyway).   Tanks!  I have  write that like  you  said  But  sitll  failed!  I  find the  particle  but it only  one pixel!  I don't know  why   Can you analysis  it by your Experience! 
  5. GuoLei007

    GPU particles

    No I never found a solution. The error makes no sense to me and I can't find any info about it on google, so I'm stuck with CPU particles for the time being.   Oh! I am  very  sad  to  hear  this.....  we  both  use  sharpdx11.......I also  can't  find  any info  about  this!!  
  6. GuoLei007

    GPU particles

      Here is MSDN's description of the Stream Out Syntax. You might also want to take a look at the ParticlesGS sample from the DirectX SDK.   I  use  the  same  modified  code  in your sample  It  also  can't  work!  I feel it's a simle  error  ! But  I  has  solve it  for  2  days...Now,Still  failed!  
  7. GuoLei007

    GPU particles

      Here is MSDN's description of the Stream Out Syntax. You might also want to take a look at the ParticlesGS sample from the DirectX SDK.   Yes  I  has  see  it  But  it  does't  work     The  modified code  is?    GeometryShader pGSComp = CompileShader(gs_5_0, GS_Update());  GeometryShader gsStreamOut = ConstructGSWithSO( pGSComp, "0:SV_POSITION.xyz;1:NORMAL.xyz;2:COLOR.xyzw;3:TEXCOORD0.xy;4:TEXCOORD1.x;5:TEXCOORD2.xy;",NULL,NULL,0); technique11 UpdateTeq {     pass Pass0     {      SetVertexShader( CompileShader( vs_5_0, VS_Passthrough() ) );      SetGeometryShader(gsStreamOut);     SetPixelShader( NULL);     } }   It  senms  to  right  !  but VS Prompt Me!   D:\Coding\???\ResourceEditer(2013.07.15DX11????)\ResourceEditer\ResourceEditer\bin\Debug\MoonLight.Material.ParticleEffect.fx(91,31): error X3000: parameter count mismatch (ConstructGSWithSO)   I  don't konw  why!  because MSDN  write like this!! Oh  !  I am  very  happy  you  can  reply Me!
  8. GuoLei007

    GPU particles

    Do you  solve  your  problem!  I  have  use  your  code in  another  XOBOX  forum    The  same  you  say  I  can't  see  any  partile   If  you  solve  the  problem  please Hlep I will  very  thanks  to  you! Sorry   My  english  is  very  bad!   hople you can  understand  me! 
  9. GuoLei007

    GPU particles

    Hello!  I  have  see  your  sample !  It's  very Good  But  I use  SharpDX11 to do this, not  Tookit!  The  Shader  your  sample  can't  recognize about "StreamOutput = "SV_POSITION.xyz; NORMAL.xyz; COLOR.xyzw; TEXCOORD0.xy; TEXCOORD1.x; TEXCOORD2.xy";  StreamOutputRasterizedStream = 0;"   I  can't  find  right  way  to  express  this  in  Shader model5.0  of Technique11!   Oh!   Sorry !  My English  is  bad!  hople you can  understand  me!  if  you  can  help  me  I am Very  thanks  to  you!
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!