flat assembler
Message board for the users of flat assembler.

flat assembler > Windows > [solved]direct3d9, textures seam

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
vivik



Joined: 29 Oct 2016
Posts: 529
I'm writing an image viewer for direct3d9, I'm splitting an image into a bunch of 512x512 textures and joining them together. There is an ugly seam if I'm zooming out and setting filtering. What can I do about it?

Image

Also, what's the good way to zoom out a 2d image? Right now I'm simply regenerating the vertex buffer.


Last edited by vivik on 28 Feb 2018, 10:51; edited 1 time in total
Post 27 Feb 2018, 18:31
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 441
Location: Belarus
vivik wrote:
I'm writing an image viewer for direct3d9, I'm splitting an image into a bunch of 512x512 textures and joining them together. There is an ugly seam if I'm zooming out and setting filtering. What can I do about it?

Image

Also, what's the good way to zoom out a 2d image? Right now I'm simply regenerating the vertex buffer.

I’d say you’re using a tool that is not suitable for your task. To perform a resize (zoom a raster image in/out) it would be enough to use StretchBlt. If you need something that looks better than that, you can try some combination of such stretches, GDI+, some other library that focuses on image processing or even write such an algorithm yourself.

Direct3D is more about faster 3D to 2D transformations. And even if you want to use Direct3D, why not just use a billboard and change its world matrix? This would let you avoid:
1) frequent vertex buffer updates which are considered bad due to the way the graphics pipeline works;
2) splitting images into custom-sized parts, then trying to glue them back on the screen.
Post 27 Feb 2018, 21:35
View user's profile Send private message Visit poster's website Reply with quote
vivik



Joined: 29 Oct 2016
Posts: 529
Can't really avoid splitting them. Maximum texture size is 4096x4096, and image can potentially be bigger. Or there is some way?

I will try the world matrix now.
Post 28 Feb 2018, 06:03
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 441
Location: Belarus
vivik wrote:
Can't really avoid splitting them. Maximum texture size is 4096x4096, and image can potentially be bigger. Or there is some way?

I will try the world matrix now.

Then again, we should talk about Direct3D being the wrong tool. After all, textures have other limits as well, like that they should be squares.

If you have to glue something because you had to cut something beforehand then you’re definitely doing something wrong.
Post 28 Feb 2018, 09:58
View user's profile Send private message Visit poster's website Reply with quote
vivik



Joined: 29 Oct 2016
Posts: 529
Are you sure you know what you are talking about? There is a reason why photoshop and krita use 3d acceleration. I researched shit.

Actually, I'm considering using directdraw for that later, and doing all the rescaling by myself in software.

Found the solution, "Clamp Texture Address Mode":

g_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
g_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
Post 28 Feb 2018, 10:23
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 441
Location: Belarus
vivik wrote:
Are you sure you know what you are talking about? There is a reason why photoshop and krita use 3d acceleration. I researched shit.

“3D acceleration” is not equal to “using Direct3D”. You might want to do more research and learn about the graphics pipeline of a modern video card.

Quote:
Actually, I'm considering using directdraw for that later

Bad idea. DirectDraw has been deprecated for years since version 7. Since June 2010 even DirectDraw headers are not included in DirectX SDK anymore. Direct3D is the way to go for effective graphics output. But you should make difference between just graphics output and image processing: Direct3D itself has very limited capabilities in the latter.
Post 28 Feb 2018, 11:14
View user's profile Send private message Visit poster's website Reply with quote
vivik



Joined: 29 Oct 2016
Posts: 529
>“3D acceleration” is not equal to “using Direct3D”. You might want to do more research and learn about the graphics pipeline of a modern video card.

I don't get it.

>DirectDraw has been deprecated for years since version 7.

who cares about deprecations, like they are going to replace all the hardware they already sold. I'm using a pc, ide and sdk from 2005.
Post 28 Feb 2018, 16:15
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6979
Location: Kraków, Poland
I have been successfully using SDL to do scrolling of a very large image through stitched segments. If you're interested, I could perhaps share some code.
Post 28 Feb 2018, 17:40
View user's profile Send private message Visit poster's website Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 441
Location: Belarus
vivik wrote:
>DirectDraw has been deprecated for years since version 7.

who cares about deprecations, like they are going to replace all the hardware they already sold. I'm using a pc, ide and sdk from 2005.

They can (and have the right to) suddenly remove the API or break its underlying kernel support in future versions of Windows. They are unlikely to remove it (a lot of APIs from early 90s and even 80s are still there) but they will definitely stop testing the support, and some day simple copying of a DLL (which might be forbidden by license agreement) may stop working.
Post 28 Feb 2018, 18:39
View user's profile Send private message Visit poster's website Reply with quote
Siekmanski



Joined: 18 Jun 2006
Posts: 12
Location: The Netherlands
Direct3D9 is an excellent choice to do what you want.
It has nice texture filters (linear, mipmap etc.)
Use the D3DFVF_XYZRHW Vertex Format to project texures in 2D mode. ( no need to set up the 3D pipeline )
Errors in seamless connected textures can occur on older video cards, you can prevent that by setting the UV coords to 0.003 and 0.997 and setting the correct samplerstate UV addressing mode.
Use the Direct3D9 pixelshader to do any possible image processing with ease and incredible speed.
For examples see https://www.shadertoy.com/ it runs on a Direct3D9 engine.
I use Direct3D9 for ages now for all my graphics coding.
Post 28 Feb 2018, 19:03
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 441
Location: Belarus
Siekmanski wrote:
by setting the UV coords to 0.003 and 0.997

Why not 0.002 and 0.998? Isn’t it what we call a kludge?

Siekmanski wrote:
For examples see https://www.shadertoy.com/ it runs on a Direct3D9 engine.

The site (well-known among democoders) uses WebGL which is explicitly and clearly stated at the site itself. WebGL is based on OpenGL, not Direct3D. Even if it was Direct3D-based it would be more likely to be based on Direct3D 10 or 11: WebGL dates back to 2011 while Direct3D 10 has been around since 2006 and Direct 3D 11—since 2009.
Post 28 Feb 2018, 20:35
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2311
Location: Usono (aka, USA)
DimonSoft wrote:
vivik wrote:
>DirectDraw has been deprecated for years since version 7.

who cares about deprecations, like they are going to replace all the hardware they already sold. I'm using a pc, ide and sdk from 2005.

They can (and have the right to) suddenly remove the API or break its underlying kernel support in future versions of Windows. They are unlikely to remove it (a lot of APIs from early 90s and even 80s are still there) but they will definitely stop testing the support, and some day simple copying of a DLL (which might be forbidden by license agreement) may stop working.


ZDNet wrote:

http://www.zdnet.com/article/windows-10-on-arm-it-will-be-more-limited-and-heres-how-reveals-microsoft/

However, Arm does support x86 apps that use DirectX 9, DirectX 10, DirectX 11, and DirectX 12.


Just FYI. Laughing
Post 28 Feb 2018, 21:58
View user's profile Send private message Visit poster's website Reply with quote
Siekmanski



Joined: 18 Jun 2006
Posts: 12
Location: The Netherlands
DimonSoft wrote:
Siekmanski wrote:
by setting the UV coords to 0.003 and 0.997


Why not 0.002 and 0.998? Isn’t it what we call a kludge?

-> Because in the evening it is colder than outside????

Siekmanski wrote:
For examples see https://www.shadertoy.com/ it runs on a Direct3D9 engine.

DimonSoft wrote:

The site (well-known among democoders) uses WebGL which is explicitly and clearly stated at the site itself. WebGL is based on OpenGL, not Direct3D. Even if it was Direct3D-based it would be more likely to be based on Direct3D 10 or 11: WebGL dates back to 2011 while Direct3D 10 has been around since 2006 and Direct 3D 11—since 2009].


-> WebGl (opengl) -> Angle transpiler -> Direct3D9 executes the code.
Post 28 Feb 2018, 22:09
View user's profile Send private message Reply with quote
vivik



Joined: 29 Oct 2016
Posts: 529
@Tomasz Grysztar
>I have been successfully using SDL to do scrolling of a very large image through stitched segments. If you're interested, I could perhaps share some code.

I already got my code working, but I'm curious to look. Maybe I'll learn a thing or two.

@Siekmanski
>by setting the UV coords to 0.003 and 0.997

Hm, looks like my videocard isn't that old, D3DTADDRESS_CLAMP worked for me. Do you know somebody with a videocard like that? Model, prooflinks?
Post 01 Mar 2018, 06:41
View user's profile Send private message Reply with quote
Siekmanski



Joined: 18 Jun 2006
Posts: 12
Location: The Netherlands
+/- 20 years ago it was a commonly known trick to get seamless texture connections on older videocards.

It's all explained in the DirectX SDK.

Nearest-Point Sampling

Notice that the texture coordinates, 0.0 and 1.0 for this illustration, are exactly at the boundary between texels. Using the method by which Direct3D maps values, the texture coordinates range from [–0.5, 4 – 0.5], where 4 is the width of the texture. For this case, the sampled texel is the 0 texel for a texture index of 1.0. However, if the texture coordinate was only slightly less than 1.0, the sampled texel would be the n texel instead of the 0 texel.

The implication of this is that magnifying a small texture using texture coordinates of exactly 0.0 and 1.0 with nearest-point filtering on a screen-space aligned triangle results in pixels for which the texture map is sampled at the boundary between texels. Any inaccuracies in the computation of texture coordinates, however small, results in artifacts along the areas in the rendered image which correspond to the texel edges of the texture map.

Performing this mapping of floating point texture coordinates to integer texels with perfect accuracy is difficult, computationally time-consuming, and generally not necessary. Most hardware implementations use an iterative approach for computing texture coordinates at each pixel location within a triangle. Iterative approaches tend to hide these inaccuracies because the errors are accumulated evenly during iteration.
Post 01 Mar 2018, 08:00
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 441
Location: Belarus
rugxulo wrote:
DimonSoft wrote:
vivik wrote:
>DirectDraw has been deprecated for years since version 7.

who cares about deprecations, like they are going to replace all the hardware they already sold. I'm using a pc, ide and sdk from 2005.

They can (and have the right to) suddenly remove the API or break its underlying kernel support in future versions of Windows. They are unlikely to remove it (a lot of APIs from early 90s and even 80s are still there) but they will definitely stop testing the support, and some day simple copying of a DLL (which might be forbidden by license agreement) may stop working.


ZDNet wrote:

http://www.zdnet.com/article/windows-10-on-arm-it-will-be-more-limited-and-heres-how-reveals-microsoft/

However, Arm does support x86 apps that use DirectX 9, DirectX 10, DirectX 11, and DirectX 12.


Just FYI. Laughing

So? How does it prevent DirectDraw from being removed in the future?
Post 01 Mar 2018, 09:26
View user's profile Send private message Visit poster's website Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 441
Location: Belarus
Siekmanski wrote:
DimonSoft wrote:
Siekmanski wrote:
by setting the UV coords to 0.003 and 0.997


Why not 0.002 and 0.998? Isn’t it what we call a kludge?

-> Because in the evening it is colder than outside????

Good way to write airplane-driving software Wink

Siekmanski wrote:
Siekmanski wrote:
For examples see https://www.shadertoy.com/ it runs on a Direct3D9 engine.

DimonSoft wrote:

The site (well-known among democoders) uses WebGL which is explicitly and clearly stated at the site itself. WebGL is based on OpenGL, not Direct3D. Even if it was Direct3D-based it would be more likely to be based on Direct3D 10 or 11: WebGL dates back to 2011 while Direct3D 10 has been around since 2006 and Direct 3D 11—since 2009].


-> WebGl (opengl) -> Angle transpiler -> Direct3D9 executes the code.

Good point, thanks. Happy to see that at least browser vendors are still worrying about using Direct3D versions that run on most hardware and Windows versions. Depends on the browser implementation though. What about Linux?

Note that this doesn’t necessarily make Direct3D a good tool for image processing.
Post 01 Mar 2018, 09:38
View user's profile Send private message Visit poster's website Reply with quote
Siekmanski



Joined: 18 Jun 2006
Posts: 12
Location: The Netherlands
IMHO for Windows ( from Win98 till Win10 ) Direct3D9 is the best candidate to do fast and very advanced Image Processing. You got all the resources to do everything you want.
Use the pixel shader to do complex processing per pixel by using the mathematical instrinsics provided by the HLSL shader language ps_3_0.
You don't need Matrices and Billboards as you mentioned before, to do 2D imaging.
You can set Direct3D9 up in 2D mode ( D3DFVF_XYZRHW Vertex Format ) and still use the vertex pipeline to do hardware accelerated zooming, scrolling, rotations, filtering etc.

You don't need badly written incomplete 3th party image processing wrapper libraries if you can do it all by yourself with the wonderful pixel shader provided by Direct3D9.

Here are some Masm Direct3D9 examples:

- A picture transpose 2D imaging routine as discussed at the Masm32 forum

- And some Pixel Shader examples ( incl. the executables of the examples, most of them translated from Shadertoy examples )
. One source to compile the shader code.
. One source to execute the precompiled shader byte code without the need of one of the D3DX9_xx.dll wrapper libs, so it executes on all windows computers with at least a shader v3.0 compatible graphics card.


Description:
Download
Filename: ShaderCompiler.zip
Filesize: 175.74 KB
Downloaded: 70 Time(s)

Description:
Download
Filename: 2D_Imaging_sources.zip
Filesize: 143.65 KB
Downloaded: 69 Time(s)

Post 01 Mar 2018, 10:58
View user's profile Send private message Reply with quote
vivik



Joined: 29 Oct 2016
Posts: 529
Thank you for your replies. To summarise this thread:

Use GDI+ if you want some simple gui, it will most likely be enough. It still uses 3D accel.

Use Direct3D if you want to work with hardware more directly and do some advanced image processing.

Use DirectDraw/SDL1 if you want to do everything on cpu for some unknown reason, like if your videocard got fried resently. And if you're not afraid of your code suddenly stopping working one day (like Fallout 1, which used DirectDraw + pallete. Colors displayed wrong. Fans made a patch that made it use RGB color instead).

Use SDL2 + OpenGL if you want to write crossplatform code and don't care about details and extra libraries.

Use ANGLE if you want to write crossplatform OpenGL code that still uses Direct3D internally on windows.

Use GTK/Qt for crossplatform gui, they most likely use OpenGL or something else.

Personally I'm writing for Direct3D right now, because that is what my browser uses internally. Using OpenGL causes a delay at the first start, i guess that's due to the driver loading. It also seems a bit less buggy on older devices.
Post 01 Mar 2018, 16:47
View user's profile Send private message Reply with quote
Hrstka



Joined: 05 May 2008
Posts: 12
Location: Czech republic
@Siekmanski

Wow, the pixel shader examples are really impressive.

However, I have an issue with the 2D Imaging. If I save the image, it's not exactly the same as the original, but seems a little blurred. I also used a png file instead of jpg as the source image, but the result was the same.
Post 28 Mar 2018, 08:06
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2018, Tomasz Grysztar.

Powered by rwasa.