would someone mind pointing out where im going wrong? (hlsl billboarding)

Started by
14 comments, last by MJP 15 years, 11 months ago


VS_OUTPUT VertexShader(VS_INPUT input)
{

	VS_OUTPUT Out;
    
    
	float4x4 vp = mul(View,Projection);
    
    float3 center = mul(input.Position,World);  
    
    float3 eyeVector = normalize(CameraPos.xyz - input.Position);
    
    float3 right = normalize(cross(eyeVector,worldUp));
    
    float3 finalPos = center;
    
    finalPos += right;
    
    finalPos += worldUp;
    
    float4 finalPos4 = float4(finalPos,1);    
    
    Out.Position = mul(finalPos4,vp);
    
    Out.TexCoord = input.TexCoord;
    
    Out.Color = input.Color;    
   
    return Out;
    
  
}


I'm just not seeing any billboard type movement at all. thanks in advance! [Edited by - nex7 on May 16, 2008 11:10:09 AM]
Advertisement
How are you differentiating the corners of the billboard? Seems like they're all being set to
center + right + worldUp
People always seem to get caught up in this "up vector, right vector" nonsense when billboarding.

VS_OUTPUT VertexShader(VS_INPUT input){    VS_OUTPUT Out;        float3 positionWS = input.Position + float3(World._41, World._42, World._43);    float3 positionVS = positionWS - CameraPos.xyz;  // Or you could use "+ float3(View._41, View._42, View.43)"          Out.Position = mul(positionVS, Projection);    Out.TexCoord = input.TexCoord;    Out.Color = input.Color;           return Out;}
Thanks for the replies!

Quote:Original post by gzboli
How are you differentiating the corners of the billboard? Seems like they're all being set to
center + right + worldUp



All of the corner verts have a position when they enter the shader..i send in prepositioned verts around the origin...


Quote:Original post by MJP
People always seem to get caught up in this "up vector, right vector" nonsense when billboarding.


with your shader I don't see anything on screen :(
OH never mind i got it....Thanks MJP

error was in the last multiply

Out.Position = mul(positionVS, Projection);

needed to be

Out.Position = mul(float4(positionVS,1.0f), Projection);

VS_OUTPUT VertexShader(VS_INPUT input){    VS_OUTPUT Out;        float3 positionWS = input.Position + float3(World._41, World._42, World._43);    float3 positionVS = positionWS - CameraPos.xyz;  // Or you could use "+ float3(View._41, View._42, View.43)"          Out.Position = mul(float4(positionVS,1.0f), Projection);    Out.TexCoord = input.TexCoord;    Out.Color = input.Color;           return Out;}



thanks again for your help
This method also has the unfortunate side effect of attaching the billboard to the camera instead of just leaving it in the world and rotating to the camera...ill work on that next.
Quote:Original post by nex7
This method also has the unfortunate side effect of attaching the billboard to the camera instead of just leaving it in the world and rotating to the camera...ill work on that next.


What do you mean by "attaching the billboard to the camera"? All this should do is move the quad to its world position, and never rotate it so that its always facing front. Are the quads moving when the camera moves?
The quads are moving when the camera rotates...


if i look up....the quads will kind of rotate up with the camera
rotate up (move up) but always face the camera
Ahh right, I'm an idiot. Don't use CameraPos, try this instead:

float3 positionVS = positionWS + float3(View._41, View._42, View.43);

This topic is closed to new replies.

Advertisement