I'm trying to learn DirectX 11 at the moment and wanted to implement viewpoint oriented billboarding with the geometry shader.
I'm sending one vertex to the geometry shader and let it build the quadrangle which is oriented towards the camera position. But it doesn't work as supposed to be with my implementation. I'm using a free look camera and everytime i rotate my camera the billboard effect isn't seen anymore. Example: I'm facing the sprite and take some steps to the left. The sprite is facing the camera as it's supposed to be, but when I rotate the camera to the left, the sprite isn't changing it's direction and I can see the flat quadrangle.
Here is my code for the geometry Shader:
[maxvertexcount(4)]
void GS_Main(point PS_INPUT p[1], inout TriangleStream<PS_INPUT> triStream){
PS_INPUT p1 = (PS_INPUT)0;
float3 yUnitVector = {0.0f, 1.0f, 0.0f};
float3 normal = p[0].pos - camPosition;
float3 rightAxis = cross(yUnitVector, normal);
float3 upAxis = cross(normal, rightAxis);
rightAxis = normalize(rightAxis);
upAxis = normalize(upAxis);
float4 rightVector = {rightAxis.x, rightAxis.y, rightAxis.z, 0.0};
float4 upVector = {upAxis.x, upAxis.y, upAxis.z, 0.0};
p[0].pos = mul(p[0].pos, viewMatrix);
p1.pos = p[0].pos+rightVector*(0.1)+upVector*(0.1);
p1.tex0.x = 1.0f; p1.tex0.y = 0.0f;
p1.pos = mul(p1.pos, projMatrix);
triStream.Append(p1);
p1.pos = p[0].pos+rightVector*(0.1)+upVector*(-0.1);
p1.tex0.x = 1.0f; p1.tex0.y = 1.0f;
p1.pos = mul(p1.pos, projMatrix);
triStream.Append(p1);
p1.pos = p[0].pos+rightVector*(-0.1)+upVector*(0.1);
p1.tex0.x = 0.0f; p1.tex0.y = 0.0f;
p1.pos = mul(p1.pos, projMatrix);
triStream.Append(p1);
p1.pos = p[0].pos+rightVector*(-0.1)+upVector*(-0.1);
p1.tex0.x = 0.0f; p1.tex0.y = 1.0f;
p1.pos = mul(p1.pos, projMatrix);
triStream.Append(p1);
}Maybe something is wrong with my first person camera implementation, so i post its code too, just in case:
void CameraClass::renderFreeLookCamera(){
XMVECTOR up, forward, right, position;
XMMATRIX rotationMatrix;
up = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);
forward = XMVectorSet(0.0f, 0.0f, 1.0f, 0.0f);
position = XMLoadFloat3(&_position);
_pitch += _amountPitch;
_yaw += _amountYaw;
_roll += _amountRoll;
rotationMatrix = XMMatrixRotationRollPitchYaw(_pitch, _yaw, _roll);
forward = XMVector3Transform(forward, rotationMatrix);
forward = XMVector3Normalize(forward);
up = XMVector3Transform(up, rotationMatrix);
up = XMVector3Normalize(up);
right = XMVector3Cross(up, forward);
right = XMVector3Normalize(right);
position += forward*_amountZ;
position += right*_amountX;
position += up*_amountY;
_amountZ = _amountY = _amountX = 0;
_amountPitch = _amountYaw = _amountRoll = 0;
XMMATRIX viewMatrix = XMMatrixLookToLH(position, forward, up);
XMStoreFloat3(&_position, position);
XMStoreFloat3(&_lookTo, forward);
XMStoreFloat3(&_up, up);
XMStoreFloat4x4(&_viewMatrix, viewMatrix);
return;
}I think I figured out what the problem is. I'm not considering the direction in which my camera is looking when creating the quadrangle. It is always facing towards the camera position, but the position doesn't change when i rotate the camera. I tried different things to solve the problem but nothing worked out yet.






