Hello,

I am having a hard time billboarding my particles. I am following this tutorial:

http://xnauk-randomc...utorial-vi.html

The instancing is not a problem and works. I understand the formulas for billboarding given in the link, but when I implement them, the particles disappear. The difference in my implementation is that I represent the particles by a position only, while the tutorial uses world matrices.

Here is the relevant shader code:

[source lang="cpp"]struct InstanceData{ float4 Position : TEXCOORD1; float4 Velocity : TEXCOORD2; float4 Acceleration : TEXCOORD3; float T0 : FOG0; float T1 : FOG1;};struct VSInput{ float4 Position : POSITION0; float2 TextureCoordinate : TEXCOORD0;};struct VSOutput{ float4 Position : POSITION0; float2 TextureCoordinate : TEXCOORD0; float Alpha : FOG0;};VSOutput InstancingVS(VSInput input, InstanceData instance){ VSOutput output = (VSOutput)0; // Calculate the particle's position float dt = T - instance.T0; input.Position += instance.Position; input.Position += dt * instance.Velocity; input.Position += 0.5 * dt * dt * instance.Acceleration; // start using float3 because we need cross products float3 center = mul(input.Position, World); // looks fishy since input.Position is float4, but it works in the tutorial float3 eyeVector = center - CameraPosition; float3 pos = center; float3 sideVector; float3 upVector; sideVector = normalize(cross(eyeVector, (float3)(0, 1, 0))); upVector = normalize(cross(sideVector, eyeVector)); // Billboarding offset pos += (input.TextureCoordinate.x - 0.5) * sideVector; pos += (0.5 - input.TextureCoordinate.y) * upVector; // pack into float4 float4 pos4 = (float4)(pos, 1); pos4 = mul(pos4, View); pos4 = mul(pos4, Projection); output.Position = pos4; output.TextureCoordinate = input.TextureCoordinate; output.Alpha = (instance.T1 - T) / (instance.T1 - instance.T0); return output;}float4 InstancingPS(VSOutput input) : COLOR0{ float4 color = tex2D(TextureSampler, input.TextureCoordinate); color.a = color.a * input.Alpha; return color;}[/source]

Now, I suspect there is something wrong with float3/float4 mixture. For example, If I change line 50 to

[source lang="cpp"]float4 pos4 = input.Position;[/source]

the particles are drawn correctly, but without billboarding, which is expected. However, if I try

[source lang="cpp"]float4 pos4 = (float4)(input.Position.xyz, 1);[/source]

which I assumed to do basically the same thing, I see nothing.

Can somebody explain this? I don't see the difference between the these two lines (except for the w-compenent, which shouldn't matter, should it?). I have been fiddling with those conversions for two days now and I am very much lost.

Appreciating any help.

### Show differencesHistory of post edits

### #3FromShadow

Posted 13 November 2012 - 02:21 PM

Hello,

I am having a hard time billboarding my particles. I am following this tutorial:

http://xnauk-randomc...utorial-vi.html

The instancing is not a problem and works. I understand the formulas for billboarding given in the link, but when I implement them, the particles disappear. The difference in my implementation is that I represent the particles by a position only, while the tutorial uses world matrices.

Here is the relevant shader code:

[source lang="cpp"]struct InstanceData{ float4 Position : TEXCOORD1; float4 Velocity : TEXCOORD2; float4 Acceleration : TEXCOORD3; float T0 : FOG0; float T1 : FOG1;};struct VSInput{ float4 Position : POSITION0; float2 TextureCoordinate : TEXCOORD0;};struct VSOutput{ float4 Position : POSITION0; float2 TextureCoordinate : TEXCOORD0; float Alpha : FOG0;};VSOutput InstancingVS(VSInput input, InstanceData instance){ VSOutput output = (VSOutput)0; // Calculate the particle's position float dt = T - instance.T0; input.Position += instance.Position; input.Position += dt * instance.Velocity; input.Position += 0.5 * dt * dt * instance.Acceleration; // start using float3 because we need cross products float3 center = mul(input.Position, World); // looks fishy since input.Position is float4, but it works in the tutorial float3 eyeVector = center - CameraPosition; float3 pos = center; float3 sideVector; float3 upVector; sideVector = normalize(cross(eyeVector, (float3)(0, 1, 0))); upVector = normalize(cross(sideVector, eyeVector)); // Billboarding offset pos += (input.TextureCoordinate.x - 0.5) * sideVector; pos += (0.5 - input.TextureCoordinate.y) * upVector; // pack into float4 float4 pos4 = (float4)(pos, 1); pos4 = mul(pos4, View); pos4 = mul(pos4, Projection); output.Position = pos4; output.TextureCoordinate = input.TextureCoordinate; output.Alpha = (instance.T1 - T) / (instance.T1 - instance.T0); return output;}float4 InstancingPS(VSOutput input) : COLOR0{ float4 color = tex2D(TextureSampler, input.TextureCoordinate); color.a = color.a * input.Alpha; return color;}[/source]

Now, I suspect there is something wrong with float3/float4 mixture. For example, If I change line 47 to

[source lang="cpp"]float4 pos4 = input.Position;[/source]

the particles are drawn correctly, but without billboarding, which is expected. However, if I try

[source lang="cpp"]float4 pos4 = (float4)(input.Position.xyz, 1);[/source]

which I assumed to do basically the same thing, I see nothing.

Can somebody explain this? I don't see the difference between the these two lines (except for the w-compenent, which shouldn't matter, should it?). I have been fiddling with those conversions for two days now and I am very much lost.

Appreciating any help.

I am having a hard time billboarding my particles. I am following this tutorial:

http://xnauk-randomc...utorial-vi.html

The instancing is not a problem and works. I understand the formulas for billboarding given in the link, but when I implement them, the particles disappear. The difference in my implementation is that I represent the particles by a position only, while the tutorial uses world matrices.

Here is the relevant shader code:

[source lang="cpp"]struct InstanceData{ float4 Position : TEXCOORD1; float4 Velocity : TEXCOORD2; float4 Acceleration : TEXCOORD3; float T0 : FOG0; float T1 : FOG1;};struct VSInput{ float4 Position : POSITION0; float2 TextureCoordinate : TEXCOORD0;};struct VSOutput{ float4 Position : POSITION0; float2 TextureCoordinate : TEXCOORD0; float Alpha : FOG0;};VSOutput InstancingVS(VSInput input, InstanceData instance){ VSOutput output = (VSOutput)0; // Calculate the particle's position float dt = T - instance.T0; input.Position += instance.Position; input.Position += dt * instance.Velocity; input.Position += 0.5 * dt * dt * instance.Acceleration; // start using float3 because we need cross products float3 center = mul(input.Position, World); // looks fishy since input.Position is float4, but it works in the tutorial float3 eyeVector = center - CameraPosition; float3 pos = center; float3 sideVector; float3 upVector; sideVector = normalize(cross(eyeVector, (float3)(0, 1, 0))); upVector = normalize(cross(sideVector, eyeVector)); // Billboarding offset pos += (input.TextureCoordinate.x - 0.5) * sideVector; pos += (0.5 - input.TextureCoordinate.y) * upVector; // pack into float4 float4 pos4 = (float4)(pos, 1); pos4 = mul(pos4, View); pos4 = mul(pos4, Projection); output.Position = pos4; output.TextureCoordinate = input.TextureCoordinate; output.Alpha = (instance.T1 - T) / (instance.T1 - instance.T0); return output;}float4 InstancingPS(VSOutput input) : COLOR0{ float4 color = tex2D(TextureSampler, input.TextureCoordinate); color.a = color.a * input.Alpha; return color;}[/source]

Now, I suspect there is something wrong with float3/float4 mixture. For example, If I change line 47 to

[source lang="cpp"]float4 pos4 = input.Position;[/source]

the particles are drawn correctly, but without billboarding, which is expected. However, if I try

[source lang="cpp"]float4 pos4 = (float4)(input.Position.xyz, 1);[/source]

which I assumed to do basically the same thing, I see nothing.

Can somebody explain this? I don't see the difference between the these two lines (except for the w-compenent, which shouldn't matter, should it?). I have been fiddling with those conversions for two days now and I am very much lost.

Appreciating any help.

### #2FromShadow

Posted 13 November 2012 - 02:21 PM

Hello,

I am having a hard time billboarding my particles. I am following this tutorial:

http://xnauk-randomc...utorial-vi.html

The instancing is not a problem and works. I understand the formulas for billboarding given in the link, but when I implement them, the particles disappear. The difference in my implementation is that I represent the particles by a position only, while the tutorial uses world matrices.

Here is the relevant shader code:

[source lang="cpp"]struct InstanceData{ float4 Position : TEXCOORD1; float4 Velocity : TEXCOORD2; float4 Acceleration : TEXCOORD3; float T0 : FOG0; float T1 : FOG1;};struct VSInput{ float4 Position : POSITION0; float2 TextureCoordinate : TEXCOORD0;};struct VSOutput{ float4 Position : POSITION0; float2 TextureCoordinate : TEXCOORD0; float Alpha : FOG0;};VSOutput InstancingVS(VSInput input, InstanceData instance){ VSOutput output = (VSOutput)0; // Calculate the particle's position float dt = T - instance.T0; input.Position += instance.Position; input.Position += dt * instance.Velocity; input.Position += 0.5 * dt * dt * instance.Acceleration; // start using float3 because we need cross products float3 center = mul(input.Position, World); // looks fishy since input.Position is float4, but it works in the tutorial float3 eyeVector = center - CameraPosition; float3 pos = center; float3 sideVector; float3 upVector; sideVector = normalize(cross(eyeVector, (float3)(0, 1, 0))); upVector = normalize(cross(sideVector, eyeVector)); // Billboarding offset pos += (input.TextureCoordinate.x - 0.5) * sideVector; pos += (0.5 - input.TextureCoordinate.y) * upVector; // pack into float4 float4 pos4 = (float4)(pos, 1); pos4 = mul(pos4, View); pos4 = mul(pos4, Projection); output.Position = pos4; output.TextureCoordinate = input.TextureCoordinate; output.Alpha = (instance.T1 - T) / (instance.T1 - instance.T0); return output;}float4 InstancingPS(VSOutput input) : COLOR0{ float4 color = tex2D(TextureSampler, input.TextureCoordinate); color.a = color.a * input.Alpha; return color;}[/source]

Now, I suspect there is something wrong with float3/float4 mixture. For example, If I change line 47 to

[source lang="cpp"]float4 pos4 = input.Position;[/source]

the particles are drawn correctly, but without billboarding, which is expected. However, if I try

[source lang="cpp"]float4 pos4 = (float4)(input.Position.xyz, 1);[/source]

which I assumed to do basically the same thing, I see nothing.

Can somebody explain this? I don't see the difference between the these two lines (except for the w-compenent, which shouldn't matter, should it?). I have been fiddling with those conversions for two days now and I am very much lost.

Appreciating any help.

I am having a hard time billboarding my particles. I am following this tutorial:

http://xnauk-randomc...utorial-vi.html

The instancing is not a problem and works. I understand the formulas for billboarding given in the link, but when I implement them, the particles disappear. The difference in my implementation is that I represent the particles by a position only, while the tutorial uses world matrices.

Here is the relevant shader code:

[source lang="cpp"]struct InstanceData{ float4 Position : TEXCOORD1; float4 Velocity : TEXCOORD2; float4 Acceleration : TEXCOORD3; float T0 : FOG0; float T1 : FOG1;};struct VSInput{ float4 Position : POSITION0; float2 TextureCoordinate : TEXCOORD0;};struct VSOutput{ float4 Position : POSITION0; float2 TextureCoordinate : TEXCOORD0; float Alpha : FOG0;};VSOutput InstancingVS(VSInput input, InstanceData instance){ VSOutput output = (VSOutput)0; // Calculate the particle's position float dt = T - instance.T0; input.Position += instance.Position; input.Position += dt * instance.Velocity; input.Position += 0.5 * dt * dt * instance.Acceleration; // start using float3 because we need cross products float3 center = mul(input.Position, World); // looks fishy since input.Position is float4, but it works in the tutorial float3 eyeVector = center - CameraPosition; float3 pos = center; float3 sideVector; float3 upVector; sideVector = normalize(cross(eyeVector, (float3)(0, 1, 0))); upVector = normalize(cross(sideVector, eyeVector)); // Billboarding offset pos += (input.TextureCoordinate.x - 0.5) * sideVector; pos += (0.5 - input.TextureCoordinate.y) * upVector; // pack into float4 float4 pos4 = (float4)(pos, 1); pos4 = mul(pos4, View); pos4 = mul(pos4, Projection); output.Position = pos4; output.TextureCoordinate = input.TextureCoordinate; output.Alpha = (instance.T1 - T) / (instance.T1 - instance.T0); return output;}float4 InstancingPS(VSOutput input) : COLOR0{ float4 color = tex2D(TextureSampler, input.TextureCoordinate); color.a = color.a * input.Alpha; return color;}[/source]

Now, I suspect there is something wrong with float3/float4 mixture. For example, If I change line 47 to

[source lang="cpp"]float4 pos4 = input.Position;[/source]

the particles are drawn correctly, but without billboarding, which is expected. However, if I try

[source lang="cpp"]float4 pos4 = (float4)(input.Position.xyz, 1);[/source]

which I assumed to do basically the same thing, I see nothing.

Can somebody explain this? I don't see the difference between the these two lines (except for the w-compenent, which shouldn't matter, should it?). I have been fiddling with those conversions for two days now and I am very much lost.

Appreciating any help.

### #1FromShadow

Posted 13 November 2012 - 02:18 PM

Hello,

I am having a hard time billboarding my particles. I am following this tutorial:

http://xnauk-randomc...utorial-vi.html

The instancing is not a problem and works. I understand the formulas for billboarding given in the link, but when I implement them, the particles disappear. The difference in my implementation is that I represent the particles by a position only, while the tutorial uses world matrices.

Here is the relevant shader code:

[source lang="cpp"]struct InstanceData{ float4 Position : TEXCOORD1; float4 Velocity : TEXCOORD2; float4 Acceleration : TEXCOORD3; float T0 : FOG0; float T1 : FOG1;};struct VSInput{ float4 Position : POSITION0; float2 TextureCoordinate : TEXCOORD0;};struct VSOutput{ float4 Position : POSITION0; float2 TextureCoordinate : TEXCOORD0; float Alpha : FOG0;};VSOutput InstancingVS(VSInput input, InstanceData instance){ VSOutput output = (VSOutput)0; // Calculate the particle's position float dt = T - instance.T0; input.Position += instance.Position; input.Position += dt * instance.Velocity; input.Position += 0.5 * dt * dt * instance.Acceleration; // start using float3 because we need dot products float3 center = mul(input.Position, World); // looks fishy since input.Position is float4, but it works in the tutorial float3 eyeVector = center - CameraPosition; float3 pos = center; float3 sideVector; float3 upVector; sideVector = normalize(cross(eyeVector, (float3)(0, 1, 0))); upVector = normalize(cross(sideVector, eyeVector)); // Billboarding offset pos += (input.TextureCoordinate.x - 0.5) * sideVector; pos += (0.5 - input.TextureCoordinate.y) * upVector; // pack into float4 float4 pos4 = (float4)(pos, 1); pos4 = mul(pos4, View); pos4 = mul(pos4, Projection); output.Position = pos4; output.TextureCoordinate = input.TextureCoordinate; output.Alpha = (instance.T1 - T) / (instance.T1 - instance.T0); return output;}float4 InstancingPS(VSOutput input) : COLOR0{ float4 color = tex2D(TextureSampler, input.TextureCoordinate); color.a = color.a * input.Alpha; return color;}[/source]

Now, I suspect there is something wrong with float3/float4 mixture. For example, If I change line 47 to

[source lang="cpp"]float4 pos4 = input.Position;[/source]

the particles are drawn correctly, but without billboarding, which is expected. However, if I try

[source lang="cpp"]float4 pos4 = (float4)(input.Position.xyz, 1);[/source]

which I assumed to do basically the same thing, I see nothing.

Can somebody explain this? I don't see the difference between the these two lines (except for the w-compenent, which shouldn't bother me, should it?). I have been fiddling with the conversions for two days now and I am very much lost.

Appreciating any help.

I am having a hard time billboarding my particles. I am following this tutorial:

http://xnauk-randomc...utorial-vi.html

The instancing is not a problem and works. I understand the formulas for billboarding given in the link, but when I implement them, the particles disappear. The difference in my implementation is that I represent the particles by a position only, while the tutorial uses world matrices.

Here is the relevant shader code:

[source lang="cpp"]struct InstanceData{ float4 Position : TEXCOORD1; float4 Velocity : TEXCOORD2; float4 Acceleration : TEXCOORD3; float T0 : FOG0; float T1 : FOG1;};struct VSInput{ float4 Position : POSITION0; float2 TextureCoordinate : TEXCOORD0;};struct VSOutput{ float4 Position : POSITION0; float2 TextureCoordinate : TEXCOORD0; float Alpha : FOG0;};VSOutput InstancingVS(VSInput input, InstanceData instance){ VSOutput output = (VSOutput)0; // Calculate the particle's position float dt = T - instance.T0; input.Position += instance.Position; input.Position += dt * instance.Velocity; input.Position += 0.5 * dt * dt * instance.Acceleration; // start using float3 because we need dot products float3 center = mul(input.Position, World); // looks fishy since input.Position is float4, but it works in the tutorial float3 eyeVector = center - CameraPosition; float3 pos = center; float3 sideVector; float3 upVector; sideVector = normalize(cross(eyeVector, (float3)(0, 1, 0))); upVector = normalize(cross(sideVector, eyeVector)); // Billboarding offset pos += (input.TextureCoordinate.x - 0.5) * sideVector; pos += (0.5 - input.TextureCoordinate.y) * upVector; // pack into float4 float4 pos4 = (float4)(pos, 1); pos4 = mul(pos4, View); pos4 = mul(pos4, Projection); output.Position = pos4; output.TextureCoordinate = input.TextureCoordinate; output.Alpha = (instance.T1 - T) / (instance.T1 - instance.T0); return output;}float4 InstancingPS(VSOutput input) : COLOR0{ float4 color = tex2D(TextureSampler, input.TextureCoordinate); color.a = color.a * input.Alpha; return color;}[/source]

Now, I suspect there is something wrong with float3/float4 mixture. For example, If I change line 47 to

[source lang="cpp"]float4 pos4 = input.Position;[/source]

the particles are drawn correctly, but without billboarding, which is expected. However, if I try

[source lang="cpp"]float4 pos4 = (float4)(input.Position.xyz, 1);[/source]

which I assumed to do basically the same thing, I see nothing.

Can somebody explain this? I don't see the difference between the these two lines (except for the w-compenent, which shouldn't bother me, should it?). I have been fiddling with the conversions for two days now and I am very much lost.

Appreciating any help.