[maxvertexcount(4)]
void GSMain(point VS_In p[1], inout TriangleStream<PS_In> billboardStream)
{
float3 eyeVec = normalize(p[0].position - cameraPosition);
float3 sideDir = cross(cameraUp, eyeVec);
PS_In vertex = (PS_In)0;
//left bottom
vertex.position = float4(p[0].position - sideDir*CLOUD_SIZE - cameraUp*CLOUD_SIZE, 1.0f);
vertex.worldPos = vertex.position;
vertex.position = mul(vertex.position, viewProjectionMatrix);
vertex.projectedPos = vertex.position;
vertex.textureCoords = float2(0, 1);
billboardStream.Append(vertex);
//left top
vertex.position = float4(p[0].position - sideDir*CLOUD_SIZE + cameraUp*CLOUD_SIZE, 1.0f);
vertex.worldPos = vertex.position;
vertex.position = mul(vertex.position, viewProjectionMatrix);
vertex.projectedPos = vertex.position;
vertex.textureCoords = float2(0, 0);
billboardStream.Append(vertex);
//right bottom
vertex.position = float4(p[0].position + sideDir*CLOUD_SIZE - cameraUp*CLOUD_SIZE, 1.0f);
vertex.worldPos = vertex.position;
vertex.position = mul(vertex.position, viewProjectionMatrix);
vertex.projectedPos = vertex.position;
vertex.textureCoords = float2(1, 1);
billboardStream.Append(vertex);
//right top
vertex.position = float4(p[0].position + sideDir*CLOUD_SIZE + cameraUp*CLOUD_SIZE, 1.0f);
vertex.worldPos = vertex.position;
vertex.position = mul(vertex.position, viewProjectionMatrix);
vertex.projectedPos = vertex.position;
vertex.textureCoords = float2(1, 0);
billboardStream.Append(vertex);
billboardStream.RestartStrip();
}
float4 PSMain(PS_In fragment) : SV_TARGET0
{
float2 offset = perlinNoise.Sample(cloudSampler, fragment.textureCoords).rg;
offset = offset * 2.0f - 1.0f;
float4 color;
color = cloudTexture.Sample(cloudSampler, fragment.projectedPos + offset / length(cameraPosition - fragment.worldPos));
//color = float4(1.0f, 0.0f, 0.0f, 1.0f);
return color;
}
As you can see in the first screenshot billboard and sphere is fine (It was the easy part anyways ). And other two screenshots are the results with different camera positions.
And lastly are there any other good looking volumetric cloud tutorials you can suggest. I searched a little but most of the tutorials are very old so I am curious if there are any newer techniques for volumetric clouds. Thanks.