Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: camera movement in particle system

  1. #1
    Member Regular Contributor
    Join Date
    Jun 2012
    Posts
    282

    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;
    Last edited by debonair; 07-29-2014 at 12:54 AM.

  2. #2
    Member Regular Contributor
    Join Date
    Jun 2012
    Posts
    282
    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
    Last edited by debonair; 07-29-2014 at 11:32 AM.

  3. #3
    Member Regular Contributor
    Join Date
    Jun 2012
    Posts
    282
    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.
    Last edited by debonair; 07-30-2014 at 10:24 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
  •