Sign in to follow this  
nex7

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

Recommended Posts

nex7    192

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]

Share this post


Link to post
Share on other sites
gzboli    122
How are you differentiating the corners of the billboard? Seems like they're all being set to
center + right + worldUp

Share this post


Link to post
Share on other sites
MJP    19755
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;
}



Share this post


Link to post
Share on other sites
nex7    192
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 :(

Share this post


Link to post
Share on other sites
nex7    192
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

Share this post


Link to post
Share on other sites
nex7    192
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.

Share this post


Link to post
Share on other sites
MJP    19755
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?

Share this post


Link to post
Share on other sites
nex7    192
The quads are moving when the camera rotates...


if i look up....the quads will kind of rotate up with the camera

Share this post


Link to post
Share on other sites
nex7    192
yeah i thought the same thing (not the idiot part ofcourse :)) but using the matrix vals yields the same result.

Share this post


Link to post
Share on other sites
nex7    192
so i have all of the billboards arranged in a spiral going up like a spring...when I rotate the camera to look up...the spiral leans in towards me...and leans away when i look down...very odd

Share this post


Link to post
Share on other sites
MJP    19755
For some reason my idiocy continues. I know wrote a shader to do exactly this a long time ago, but apparently I forgot what I did and my brain turned to mush.

Anyway try this:


float4x4 WorldView = mul(World, View)
float3 positionVS = input.Position + float3(WorldView._41, WorldView._42, WorldView._43);

Share this post


Link to post
Share on other sites
nex7    192
well that makes sense....

Thanks works like a charm...

every other method of billboarding I've seen has always used the up and right vectors....this is much more straight forward.

Thanks again!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this