PDA

View Full Version : camera movement in particle system



debonair
07-28-2014, 11:15 PM
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:



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:



CullMode = GL_BACK;
Front Face = GL_CW;

debonair
07-29-2014, 10:34 AM
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

debonair
07-30-2014, 02:23 PM
Got it working:



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.