Discussion:
Disable Sampling
(too old to reply)
Felix Arends
2005-09-09 00:11:51 UTC
Permalink
Hi,

I am trying to copy a bitmap pixel-per-pixel to another one by having a
square (consisting of 4 vertices...) rendered to an offscreen surface and
save to a .bmp file. The problem is, that the resulting file is somewhat
"antialiized" and I wonder where that happens. I use

lpDevice->SamplerState->SamplerState [0]->MagFilter =
Microsoft::DirectX::Direct3D::TextureFilter::Point;

(the same thing for MinFilter, of course), but somehow it does not seem to
work. Where else does antialiizing take place or what else can go wrong?

Thanks and best regards,

Felix Arends
Eyal Teler
2005-09-09 07:53:56 UTC
Permalink
You need to offset drawing by -0.5. Read
http://blogs.msdn.com/jsteed/articles/209220.aspx. (This used to be
explained in the DX docs, but I can't find the page right now.)

Eyal
Post by Felix Arends
Hi,
I am trying to copy a bitmap pixel-per-pixel to another one by having a
square (consisting of 4 vertices...) rendered to an offscreen surface and
save to a .bmp file. The problem is, that the resulting file is somewhat
"antialiized" and I wonder where that happens. I use
lpDevice->SamplerState->SamplerState [0]->MagFilter =
Microsoft::DirectX::Direct3D::TextureFilter::Point;
(the same thing for MinFilter, of course), but somehow it does not seem to
work. Where else does antialiizing take place or what else can go wrong?
Thanks and best regards,
Felix Arends
Eyal Teler
2005-09-09 07:55:11 UTC
Permalink
It's "Directly Mapping Texels to Pixels" in the docs.

Eyal
Wessam Bahnassi
2005-09-09 11:10:48 UTC
Permalink
I suggest you relief yourself from all this and try to do it through
D3DXLoadSurfaceFromSomething() set of functions.
In case that doesn't work, try to always disable Mip filtering (set it to
none), and check out the texture alignment rules in the D3D documentation...
Another way to do it is via ID3DXSprite...
You see, the possiblities are unlimited :)

Wessam Bahnassi
Microsoft DirectX MVP,
Lead Programmer
In|Framez
Post by Felix Arends
Hi,
I am trying to copy a bitmap pixel-per-pixel to another one by having a
square (consisting of 4 vertices...) rendered to an offscreen surface and
save to a .bmp file. The problem is, that the resulting file is somewhat
"antialiized" and I wonder where that happens. I use
lpDevice->SamplerState->SamplerState [0]->MagFilter =
Microsoft::DirectX::Direct3D::TextureFilter::Point;
(the same thing for MinFilter, of course), but somehow it does not seem to
work. Where else does antialiizing take place or what else can go wrong?
Thanks and best regards,
Felix Arends
Felix Arends
2005-09-09 23:05:52 UTC
Permalink
The point is that I want to run a pixel shader over each pixel of the
texture. Is this possible with any of the methods you mentioned?

Regards,
Felix Arends
Post by Wessam Bahnassi
I suggest you relief yourself from all this and try to do it through
D3DXLoadSurfaceFromSomething() set of functions.
In case that doesn't work, try to always disable Mip filtering (set it to
none), and check out the texture alignment rules in the D3D
documentation... Another way to do it is via ID3DXSprite...
You see, the possiblities are unlimited :)
Wessam Bahnassi
Microsoft DirectX MVP,
Lead Programmer
In|Framez
Post by Felix Arends
Hi,
I am trying to copy a bitmap pixel-per-pixel to another one by having a
square (consisting of 4 vertices...) rendered to an offscreen surface and
save to a .bmp file. The problem is, that the resulting file is somewhat
"antialiized" and I wonder where that happens. I use
lpDevice->SamplerState->SamplerState [0]->MagFilter =
Microsoft::DirectX::Direct3D::TextureFilter::Point;
(the same thing for MinFilter, of course), but somehow it does not seem
to work. Where else does antialiizing take place or what else can go
wrong?
Thanks and best regards,
Felix Arends
legalize+ (Richard [Microsoft Direct3D MVP])
2005-09-10 01:51:55 UTC
Permalink
[Please do not mail me a copy of your followup]
Post by Felix Arends
The point is that I want to run a pixel shader over each pixel of the
texture. Is this possible with any of the methods you mentioned?
In order to do this, you'll need to render a textured quad with the
source texture on the quad and the destination surface set as the
current render target.
--
"The Direct3D Graphics Pipeline"-- code samples, sample chapter, FAQ:
<http://www.xmission.com/~legalize/book/>
Pilgrimage: Utah's annual demoparty
<http://pilgrimage.scene.org>
Felix Arends
2005-09-10 11:31:35 UTC
Permalink
Yes, that is exactly what I try to do. Now the question is, if I have a
texture which is 100x100 pixels in size and a Quad which has the four
vertices:

(-0.5f, -0.5f, 1.0f)
(-0.5f, 0.5f, 1.0f)
( 0.5f, 0.5f, 1.0f)
( 0.5f, -0.5f, 1.0f)

What are the texture coordinates for those vertices? Currently, I use:

(0, 1)
(0, 0)
(1, 0)
(1, 1)

and the size of the destination Surface is, of course, 100x100.

Still, I have a kind of "blurring" effect. Even if I change my pixelshader
to render a black dot, if the texture pixel is colored and a white dot if
it's not colored (i.e. white), then the resulting picture looks somewhat
messed up. I am pretty sure that this is related to the effect Eyal Teler
mentioned in the other post, but so far I just could not correct it.

Thanks a lot for your help,
Felix Arends
Post by legalize+ (Richard [Microsoft Direct3D MVP])
[Please do not mail me a copy of your followup]
Post by Felix Arends
The point is that I want to run a pixel shader over each pixel of the
texture. Is this possible with any of the methods you mentioned?
In order to do this, you'll need to render a textured quad with the
source texture on the quad and the destination surface set as the
current render target.
--
<http://www.xmission.com/~legalize/book/>
Pilgrimage: Utah's annual demoparty
<http://pilgrimage.scene.org>
legalize+ (Richard [Microsoft Direct3D MVP])
2005-09-10 18:22:06 UTC
Permalink
[Please do not mail me a copy of your followup]
Post by Felix Arends
Yes, that is exactly what I try to do. Now the question is, if I have a
texture which is 100x100 pixels in size and a Quad which has the four
(-0.5f, -0.5f, 1.0f)
(-0.5f, 0.5f, 1.0f)
( 0.5f, 0.5f, 1.0f)
( 0.5f, -0.5f, 1.0f)
What are the texture coordinates for those vertices? [...]
See the section in the docs "Directly Mapping Texels to Pixels"
<http://msdn.microsoft.com/library/?url=/library/en-us/directx9_c/directx/graphics/programmingguide/gettingstarted/direct3dtextures/coordinates/mappingtexelstopixels.asp?frame=true>
--
"The Direct3D Graphics Pipeline"-- code samples, sample chapter, FAQ:
<http://www.xmission.com/~legalize/book/>
Pilgrimage: Utah's annual demoparty
<http://pilgrimage.scene.org>
Felix Arends
2005-09-12 11:19:57 UTC
Permalink
Post by legalize+ (Richard [Microsoft Direct3D MVP])
Post by Felix Arends
What are the texture coordinates for those vertices? [...]
See the section in the docs "Directly Mapping Texels to Pixels"
<http://msdn.microsoft.com/library/?url=/library/en-us/directx9_c/directx/graphics/programmingguide/gettingstarted/direct3dtextures/coordinates/mappingtexelstopixels.asp?frame=true>
Yes, I tried that (i.e. use coordinates -0.005 and 0.995), but that also
messed up the resulting bitmap, because the texture was aligned too far to
the right (and it was still blurred).

I have to use a quad, because I want to process two textures with my pixel
shader. The idea behind all that is that those textures represent other data
which I want to be processed by the pixel shader. That's why it has to be
very precise.

Thanks for your help,
Felix Arends
Timo Kruse
2005-09-12 17:55:37 UTC
Permalink
Post by Felix Arends
Yes, that is exactly what I try to do. Now the question is, if I have a
texture which is 100x100 pixels in size and a Quad which has the four
(-0.5f, -0.5f, 1.0f)
(-0.5f, 0.5f, 1.0f)
( 0.5f, 0.5f, 1.0f)
( 0.5f, -0.5f, 1.0f)
You are trying to match a quad directly onto another texture, right?
Coordinates of -0.5f to 0.5f do not look like already transformed. When
using fixed function for vertex processing your vertices should be defined
with D3DFVF_XYZRHW. In case you are using a vertex shader, forget about
world, camera and perspective transformations. Just make sure that the
output of the vertexshader for these 4 vertices is exactly:
-0.5f, -0.5f
-0.5f, 99.5f
99.5f, 99.5f
99.5f, -0.5f
When you talk about a 100x100 texture you will draw pixels from 0 to 99 in
both directions. You set the vertex coordinates 0.5 pixel out of that range,
for the reasons given in the documentation under "Rasterization Rules".
Post by Felix Arends
(0, 1)
(0, 0)
(1, 0)
(1, 1)
and the size of the destination Surface is, of course, 100x100.
If you are sure that Source and Destination surface is always exactly the
same size, then you are done here, just using 0 and 1 as texture
coordinates. As the vertices have an offset of 0.5 that difference pushes
the sampling directly to the centre of the pixel and no distortion will
appear. To assure yourself of that, just calculate the texturecoordinates at
the position (0,0) and (99,99) and you will see that you hit directly the
centre of the first and the last pixel.
In case you want to stretch or compress setting the texture coordinates will
be a bit more difficult, but from what you have written so far, i hope that
we can avoid to discuss this.
Felix Arends
2005-09-12 20:00:07 UTC
Permalink
Post by Timo Kruse
You are trying to match a quad directly onto another texture, right?
Coordinates of -0.5f to 0.5f do not look like already transformed. When
using fixed function for vertex processing your vertices should be defined
with D3DFVF_XYZRHW. In case you are using a vertex shader, forget about
world, camera and perspective transformations. Just make sure that the
...
Post by Felix Arends
...
and the size of the destination Surface is, of course, 100x100.
If you are sure that Source and Destination surface is always exactly the
same size, then you are done here, just using 0 and 1 as texture
coordinates. As the vertices have an offset of 0.5 that difference pushes
the sampling directly to the centre of the pixel and no distortion will
appear. To assure yourself of that, just calculate the texturecoordinates
at the position (0,0) and (99,99) and you will see that you hit directly
the centre of the first and the last pixel.
Okay, seems to be working pretty well, and -- yes, source and destination
surfaces always have equal size. I still get this strage blurring effect!
There must be some setting which is wrong, because pixels are really blurred
in
all drections:

Loading Image...
Loading Image...

You will have to magnify those images (note the black dots in the
corners...).

I can't figure out where this blurring occurs!

Hm. And by the way, the following pixel shader gives me a completely white
image:

ps.1.4
def c1, 1, 1, 1, 1

def c0, 0, 0, 0, 1

texld r0,t0

cmp r0,r0,c1,c0

Why is that? The pixelshader I used to generate the above result.png looks
like:

ps.1.4

texld r0,t0

Thanks a lot,
Felix Arends
legalize+ (Richard [Microsoft Direct3D MVP])
2005-09-12 21:47:34 UTC
Permalink
[Please do not mail me a copy of your followup]
Post by Felix Arends
Okay, seems to be working pretty well, and -- yes, source and destination
surfaces always have equal size. I still get this strage blurring effect!
There must be some setting which is wrong, because pixels are really blurred
in
http://www.codedx.net/stuff/input.png
http://www.codedx.net/stuff/result.png
You will have to magnify those images (note the black dots in the
corners...).
I can't figure out where this blurring occurs!
Are you setting your texture sampling filters to point? Also, check
how you're creating your source texture. If your image isn't an exact
power of two, then you'll need to use a subregion of the texture and
make sure that your texture coordinates are appropriately aligned. If
you're using D3DX to create the textures from images and they aren't
powers of two in dimension, then D3DX may be stretching your image to
fit the texture.
--
"The Direct3D Graphics Pipeline"-- code samples, sample chapter, FAQ:
<http://www.xmission.com/~legalize/book/>
Pilgrimage: Utah's annual demoparty
<http://pilgrimage.scene.org>
Felix Arends
2005-09-13 08:22:04 UTC
Permalink
Post by legalize+ (Richard [Microsoft Direct3D MVP])
Post by Felix Arends
I can't figure out where this blurring occurs!
Are you setting your texture sampling filters to point? Also, check
how you're creating your source texture. If your image isn't an exact
power of two, then you'll need to use a subregion of the texture and
make sure that your texture coordinates are appropriately aligned. If
you're using D3DX to create the textures from images and they aren't
powers of two in dimension, then D3DX may be stretching your image to
fit the texture.
Ah, finally!
That did the trick. Of course, the source texture was only 100x100 and thus
was anti-aliized as soon as it was loaded, I guess.

Thank you very much!

Felix Arends

Wessam Bahnassi
2005-09-11 05:31:16 UTC
Permalink
You can use pixel shaders with ID3DXSprite too. That would be much easier
IMO...
Just apply the pixel shader prior to ID3DXSprite::Draw() and don't forget to
ID3DXSprite::Flush() directly so you make sure you're using your pixel
shader...

Wessam Bahnassi
Microsoft DirectX MVP,
Lead Programmer
In|Framez
Post by legalize+ (Richard [Microsoft Direct3D MVP])
[Please do not mail me a copy of your followup]
Post by Felix Arends
The point is that I want to run a pixel shader over each pixel of the
texture. Is this possible with any of the methods you mentioned?
In order to do this, you'll need to render a textured quad with the
source texture on the quad and the destination surface set as the
current render target.
--
<http://www.xmission.com/~legalize/book/>
Pilgrimage: Utah's annual demoparty
<http://pilgrimage.scene.org>
Continue reading on narkive:
Loading...