• Create Account

# Spa8nky

Member Since 19 Apr 2009
Offline Last Active Sep 06 2012 04:33 AM

### In Topic: [XNA] Order independently drawn transparent model is not reading depth

22 July 2012 - 04:08 PM

Problem solved. This post can be deleted/ignored.

### In Topic: What is the C# equivalent of the following C++ code?

03 February 2012 - 05:10 AM

I'd wager you're looking at the value of trailFlags rather than the value of trailFlags[index] - these are not the same

I see now. My C++ experience is 'null'.

### In Topic: [XNA] Aligning texels to pixels doesn't work for small textures

31 January 2012 - 03:36 PM

So I've been trying to implement your suggestion but it doesn't solve the problem:

```

halfTexel.X = 0.5f / quadrangles[i].Width;
halfTexel.Y = 0.5f / quadrangles[i].Height;

// [0] Lower Left	   [1] -- [3]	 (0,0)--(1,0)
// [1] Upper Left		|	  |		|	  |
// [2] Lower Right	   |	  |		|	  |
// [3] Upper Right	  [0] -- [2]	 (0,1)--(1,1)

v[0].TexCoordDimension.X = halfTexel.X;						 // Texture Coordinates stored in X,Y Quadrangle Dimensions stored in Z,W
v[0].TexCoordDimension.Y = 1f - halfTexel.Y;
v[1].TexCoordDimension.X = halfTexel.X;
v[1].TexCoordDimension.Y = halfTexel.Y;
v[2].TexCoordDimension.X = 1f - halfTexel.X;
v[2].TexCoordDimension.Y = 1f - halfTexel.Y;
v[3].TexCoordDimension.X = 1f - halfTexel.X;
v[3].TexCoordDimension.Y = halfTexel.Y;

// Copy the vertex data to the drawer's large vertices array
v.CopyTo(vertices, i * 4);
```

or

```
v[0].TexCoordDimension.X += halfTexel.X;
v[0].TexCoordDimension.Y -= halfTexel.Y;

v[1].TexCoordDimension.X += halfTexel.X;
v[1].TexCoordDimension.Y += halfTexel.Y;

v[2].TexCoordDimension.X -= halfTexel.X;
v[2].TexCoordDimension.Y -= halfTexel.Y;

v[3].TexCoordDimension.X -= halfTexel.X;
v[3].TexCoordDimension.Y += halfTexel.Y;
```

How do I calculate one texel?

I have tried:

```
halfTexel.X = 0.5f / game.GraphicsDevice.PresentationParameters.BackBufferWidth;
halfTexel.Y = 0.5f / game.GraphicsDevice.PresentationParameters.BackBufferHeight;
```

and

```
halfTexel.X = 0.5f / game.TextureAtlas.Texture.Width;
halfTexel.Y = 0.5f / game.TextureAtlas.Texture.Height;
```

None of the above produces the correct result

### In Topic: [XNA] Aligning texels to pixels doesn't work for small textures

29 January 2012 - 11:24 AM

Ok I with you now. How can I determine which UV I am pinching without using conditional statements in HLSL?

u(0) += htw, v(0) += hth - u(1) -= htw, v(1) -= hth

Am I right in assuming that the pinching method will only work when passing in the UV coordinates as 4 corners of a quadrangle?

How would pinching work if the uv coordinates are not four corners of a quadrangle?

### In Topic: [XNA] Aligning texels to pixels doesn't work for small textures

29 January 2012 - 07:29 AM

The uvs you supply you need to pinch them 1/2 texel, not just move them all by the same value.

As in, u(0) += htw, v(0) += hth - u(1) -= htw, v(1) -= hth

Would you agree that the following clamping method is equivalent to your pinching method?

```// Half Pixel Clamp (Pinch)

//input.Position.x = max(input.Position.x, HalfPixelTexel.x);
//input.Position.y = max(input.Position.y, HalfPixelTexel.y);
//input.Position.x = min(input.Position.x, 1.0 - HalfPixelTexel.x);
//input.Position.y = min(input.Position.y, 1.0 - HalfPixelTexel.y);

// Half Texel Clamp (Pinch)
input.Position.x = max(input.Position.x, HalfPixelTexel.z);
input.Position.y = max(input.Position.y, HalfPixelTexel.w);
input.Position.x = min(input.Position.x, 1.0 - HalfPixelTexel.z);
input.Position.y = min(input.Position.y, 1.0 - HalfPixelTexel.w);
```

Neither the half texel clamp or the half pixel clamp produce the correct result when applied either before or after transformation.

PARTNERS