Results 1 to 3 of 3

Thread: camera movement in particle system

  1. #1
    Senior Member Regular Contributor
    Join Date
    Apr 2012
    Posts
    318

    camera movement in particle system

    I am rendering particles with billboard technique. The problem is that when I move the camera to extreme right side, still they get displayed. But when I move the camera to left side they turn and disappears as expected. The problem also arises when on right side, when I move to near or far side. input to geometry shader is position in world space. Here is my Geometry shader:

    Code :
    	vec3 pos=gl_in[0].gl_Position.xyz;
    	vec3 cameraV=normalize(EyePosition.xyz - pos );
     
     
    	vec3 up= vec3(0.0, 1.0, 0.0);
     
    	vec3 right= normalize(cross(up,cameraV))*0.01;
    	up=cross(cameraV,right);
     
     
    	gl_Position=vec4(pos - (right + up),1.0);
    	TexCord = vec2(0.0, 0.0);
    	EmitVertex();
     
    	gl_Position=vec4(pos + ( right- up),1.0);
    	TexCord = vec2(0.0, 1.0);
    	EmitVertex();
     
    	gl_Position=vec4(pos- (right - up),1.0);
    	TexCord = vec2(1.0, 0.0);
    	EmitVertex();
     
    	gl_Position=vec4(pos + ( right+ up),1.0);
    	TexCord = vec2(1.0, 1.0);
    	EmitVertex();
     
     
    	EndPrimitive();

    My settings for Culling are:

    Code :
        CullMode                       = GL_BACK;
        Front Face            = GL_CW;

  2. #2
    Senior Member Regular Contributor
    Join Date
    Apr 2012
    Posts
    318
    I was wrong, they should be facing towards the camera and should not disappear.
    In above code, I am multiplying position by world matrix, and passing this position into GS, which is wrong. Now instead of modifying position in VS, for each output position in GS, I am multiplying it with View matrix, but now particles are not displayed

  3. #3
    Senior Member Regular Contributor
    Join Date
    Apr 2012
    Posts
    318
    Got it working:

    Code :
    float3 pos=gin[0].Position.xyz;
    float3 right=float3(InverseView[0][0],InverseView[1][0],InverseView[2][0]); 
    float3 up=float3(InverseView[0][1],InverseView[1][1],InverseView[2][1]); 
     
    float dist=distance(EyePosition.xyz,pos);
    dist=1/dist;
     
     
    gout.position=float4(pos - (right + up)*dist,1.0);                    
    gout.TexCord = float2(0.0, 0.0);
    triStream.Append(gout);
     
     
    gout.position=float4(pos + (right - up)*dist,1.0) ;    
    gout.TexCord = float2(1.0, 0.0);
    triStream.Append(gout);
     
     
     
    gout.position=float4(pos + (right + up)*dist,1.0)  ;   
    gout.TexCord  = float2(1.0, 1.0);
    triStream.Append(gout);
     
     
    gout.position=float4(pos - (right + up)*dist,1.0);                    
    gout.TexCord = float2(0.0, 0.0);
    triStream.Append(gout);
     
    gout.position=float4(pos + (right + up)*dist,1.0)  ;   
    gout.TexCord  = float2(1.0, 1.0);
    triStream.Append(gout);
     
    gout.position=float4(pos - (right - up)*dist,1.0)  ;   
    gout.TexCord  = float2(0.0, 1.0);
    triStream.Append(gout);
     
     
     
     
    triStream.RestartStrip();

    The size of particles changes as camera moves towards or away.

Similar Threads

  1. Particle system help
    By EchoDolphin in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 01-11-2018, 10:23 AM
  2. Particle System
    By micetta2482 in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 05-14-2010, 11:05 AM
  3. Particle System API
    By cochondinde in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 02-20-2005, 03:37 AM
  4. Particle System
    By Coluna in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 03-13-2003, 09:09 PM
  5. Particle system?
    By CyBBe in forum OpenGL: Basic Coding
    Replies: 8
    Last Post: 05-16-2000, 11:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean