Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 07 Nov 2012
Offline Last Active Jan 08 2013 06:05 PM

Topics I've Started

Anti-Aliased Lines from ShaderX7 not working

02 January 2013 - 06:03 PM

Hello everyone,


I followed the Chapter "2.3: Simplified High-Quality Anti-Aliased Lines" from the ShaderX7 book. I copy-pasted the shader file from the CD and carefully ported the managing class to XNA. I cannot guarantee that the buffers are correctly filled but I am pretty sure.


Have a look at the first screenshot. The perspective is not correct. I chose my Line texture to be a square to enhance the effect. Looking at the wireframe (second screenshot), you can see that the vertex positions are in fact correct. The error is in the texture lookup.


I assume I cannot upload the whole shader since it's from the CD, but here are the lines that set the texture coordinates:


    [...] // Calculate Vertex Positions (works)

    VS_OUTPUT output;
    output.textureUV.x = weights.z;
    output.textureUV.y = weights.w;
    output.textureUV.z = 0.0f;
    output.textureUV.w = 1.0f;
    return output;

    return g_Color * tex2Dproj( FilterTextureSampler, input.textureUV );



where weights contains the texture coordinates in z and w. g_Color is the Line's Color and FilterTextureSampler contains the square texture.


I understand that tex2Dproj divides the coordinates by the w-component. But w = 1.0f everywhere! Can somebody explain what this is supposed to do? Changing "tex2Dproj" to "tex2D" makes no difference. Why can't I just take the usual texture coordinates?

Problem with Billboarding Instanced Particles

13 November 2012 - 02:18 PM


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

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.

Space game graphics with Depth perception

07 November 2012 - 02:23 PM

Hi everyone,

so I'm working on a third person space shooter in XNA. The idea is to immerse the player in large scale battles with ships of different sizes and shapes, ranging from small interceptors to huge battle stations. So far i've primarily worked on the engine and i'm pretty happy with the results.

For the graphics, I have only a Sky box, (very) basic ship models with diffuse lighting and some basic fog.
My goal is to have a nice star background and to give the player a good perception of the other ship's 3D position/trajectory.

So my question is, what do I need for that?
Should I just add loads of fog? If so, what color should it have? white fog looks ugly when it's blended over my dark skybox. black fog works betters but all it does is smooth out my far clipping plane.
Many space games seem to have static "stardust" that doesnt move so the player has a sense of his motion. But I can't spawn millions of particles all over space, and generating them around the player seems costly too.
Also, games like Eve:Online don't look like they have skyboxes. distant stars seem to be light sources and have lense/flare effects, does that mean I need a full 3D galaxy model?

appreciating any insight!