SyntaxBomb - Indie Coders

Languages & Coding => Blitz2D, BlitzPlus, Blitz3D => Topic started by: RemiD on December 23, 2017, 21:55:27

Title: how to disable bilinear filtering (on textures) (Blitz3d)
Post by: RemiD on December 23, 2017, 21:55:27
I repost this here, because it is really useful, especially for the current competition (for those who choose the 3d path (meshes+textures))

instead of having textures which look "blurred" (with bilinear filtering) :
http://rd-stuff.fr/blitz3d/with-bilinear-filtering.png

you will have textures which look "sharp" (without bilinear filtering) :
http://rd-stuff.fr/blitz3d/without-bilinear-filtering.png

here : http://rd-stuff.fr/blitz3d/disable-bilinear-filtering-of-textures-201612021732.zip
Put the DX7DBF.dll and DX7DBF.decls in your Blitz3d/userlibs directory
Then when you want to distribute your game/tool, copy paste the DX7DBF.dll in the same directory than the executable...
Title: Re: how to disable bilinear filtering (on textures) (Blitz3d)
Post by: GW on December 24, 2017, 06:50:13
Cant you just use texturefilter?
Title: Re: how to disable bilinear filtering (on textures) (Blitz3d)
Post by: RemiD on December 24, 2017, 08:51:11
@GW>>the commands ClearTextureFilters() and TextureFilter() do not remove bilinear filtering on my computers, not sure why. See : http://wasted.nz/posts.php?topic=103591

But in any case, this is an alternative !
Title: Re: how to disable bilinear filtering (on textures) (Blitz3d)
Post by: MagosDomina on January 06, 2018, 01:53:20
What is your hardware specs?
Title: Re: how to disable bilinear filtering (on textures) (Blitz3d)
Post by: RemiD on January 06, 2018, 10:22:24
@MagosDomina>>
DualCore AMD E-450 1646 MHz, 6 Go DDR3 SDRAM, Radeon HD 6320 Graphics  (384 Mo), Windows 7 home premium 64 bits, (directx 9.0c installed)
Title: Re: how to disable bilinear filtering (on textures) (Blitz3d)
Post by: MagosDomina on January 06, 2018, 17:02:05
Hate to point the finger at the graphics and or driver. But doesn't Blitz3d have minor issue with ATI hardware? This was likely more of an issue back in the earlier days of Blitz3d.

Seems you are very familiar with this issue occurring. XD
http://wasted.nz/posts.php?topic=103591

This may be worth a look too:
http://wasted.nz/posts.php?topic=40848
Title: Re: how to disable bilinear filtering (on textures) (Blitz3d)
Post by: RemiD on January 06, 2018, 17:21:21
@MagosDomina>>there is no problem here, apparently there are several ways to activate/disactivate the bilinear filtering on textures in directx7, the way that i posted here, works on all computers that i have tested it on (on Windows xp, vista, 7, 8, 10)
Title: Re: how to disable bilinear filtering (on textures) (Blitz3d)
Post by: Yue on January 06, 2018, 17:22:54
I'm not sure, but apparently the configuration of the graphics card is above the application configuration. On my graphics card you have options to allow the configuration to be decided by the graphics card or blitz3d.
Title: Re: how to disable bilinear filtering (on textures) (Blitz3d)
Post by: Yue on January 06, 2018, 18:58:19
OFF / ON
(https://www.syntaxbomb.com/proxy.php?request=http%3A%2F%2Fi67.tinypic.com%2Fidi2gy.png&hash=d6b6ef2dd4f6f3a0301e18a0a7e193b1570aaca9)
Title: Re: how to disable bilinear filtering (on textures) (Blitz3d)
Post by: RemiD on January 06, 2018, 19:25:15
@Yue>>you won't notice the difference if the texel size of your textures is very small, or if you add others full screen effects (like on your example...)

To disable bilinear filtering of textures is useful for graphics where you want to see sharp texels like old 2d/3d games...
Title: Re: how to disable bilinear filtering (on textures) (Blitz3d)
Post by: Yue on January 06, 2018, 19:36:32
Here's the same scene with the bookstore.   I don't really know the difference very well.

(https://www.syntaxbomb.com/proxy.php?request=http%3A%2F%2Fi67.tinypic.com%2F20iuzrs.png&hash=c49a68d0c06be5888e898dba4ff95d377ed22da0)
Title: Re: how to disable bilinear filtering (on textures) (Blitz3d)
Post by: RemiD on January 06, 2018, 20:06:14
@Yue>>
bilinear filtering of a texture, calculates the progressive colors between one texel and its neighbours texels, but for the pixels displayed on screen...

Try this :
Create a quad of 1.0width 1.0height
Then create a texture of 8x8texels and apply it on the quad
Then try to display the same texture quad with bilinear filtering and without bilinear filtering, you will see the difference because the texel size is big enough to see the difference.
Title: Re: how to disable bilinear filtering (on textures) (Blitz3d)
Post by: RemiD on January 06, 2018, 20:24:56
try this code : (one time without bilinear filtering, one time with bilinear filtering)

Graphics3D(500,312,32,2)

;to disable bilinear filtering of textures
InitDX7Hack()
DisableTextureFilters()

;Camera
Global Camera = CreateCamera()
CameraViewport(Camera,0,0,GraphicsWidth(),GraphicsHeight())
CameraRange(Camera,0.1,100)
CameraClsColor(Camera,000,000,000)

;textured quad
Global Quad = CreateMesh()
Surface = CreateSurface(Quad)
AddVertex(Surface,0.5,0.5,0.0) : VertexTexCoords(Surface,0,Float(0)/8,Float(0)/8)
AddVertex(Surface,-0.5,0.5,0.0) : VertexTexCoords(Surface,1,Float(8)/8,Float(0)/8)
AddVertex(Surface,0.5,-0.5,0.0) : VertexTexCoords(Surface,2,Float(0)/8,Float(8)/8)
AddVertex(Surface,-0.5,-0.5,0.0) : VertexTexCoords(Surface,3,Float(8)/8,Float(8)/8)
AddTriangle(Surface,0,1,2)
AddTriangle(Surface,2,1,3)
UpdateNormals(Quad)
EntityColor(Quad,255,255,255)
EntityFX(Quad,1)

Texture = CreateTexture(8,8)
SetBuffer(TextureBuffer(Texture))
For PX% = 0 To 8-1 Step 1
For PY% = 0 To 8-1 Step 1
  Color(Rand(025,255),Rand(025,255),Rand(025,255))
  Plot(PX,PY)
Next
Next
EntityTexture(Quad,Texture) : FreeTexture(Texture)

PositionEntity(Camera,0,0,1.5,True)
RotateEntity(Camera,0,-180.0,0,True)

Global MainLoopTimer = CreateTimer(30)

Main()

End()

Function Main()

Repeat

  MainLoopMilliStart% = MilliSecs()

 
  SetBuffer(BackBuffer())
  CameraViewport(Camera,0,0,GraphicsWidth(),GraphicsHeight())
  CameraClsColor(Camera,000,000,000)

  RenderWorld()

  ;Flip(1)
  WaitTimer(MainLoopTimer)
  VWait():Flip(False)

  MainLoopMilliTime = MilliSecs() - MainLoopMilliStart
  If( MainLoopMilliTime < 1 )
   MainLoopMilliTime = 1
  EndIf

  FPS% = 1000.0/MainLoopMilliTime

Until( KeyDown(1)=1 )

End Function

Const D3DTSS_MAGFILTER      = 16
Const D3DTSS_MINFILTER      = 17
Const D3DTSS_MIPFILTER      = 18
Const D3DTSS_MIPMAPLODBIAS  = 19
Const D3DTSS_MAXMIPLEVEL    = 20

Const D3DTFG_POINT        = 1
Const D3DTFG_LINEAR       = 2
Const D3DTFP_NONE         = 1
Const D3DTFN_POINT        = 1
Const D3DTFN_LINEAR       = 2

Function InitDX7Hack()
DX7DBF_SetSystemProperties( SystemProperty("Direct3D7"), SystemProperty("Direct3DDevice7"), SystemProperty("DirectDraw7"), SystemProperty("AppHWND"), SystemProperty("AppHINSTANCE") )
End Function

Function DisableTextureFilters()
;DX7DBF_SetMipmapLODBias( -10.0, 0 )
For Level = 0 To 7
DX7DBF_SetTextureStageState( Level, D3DTSS_MAGFILTER, D3DTFG_POINT )
DX7DBF_SetTextureStageState( Level, D3DTSS_MINFILTER, D3DTFN_POINT )
DX7DBF_SetTextureStageState( Level, D3DTSS_MIPFILTER, D3DTFP_NONE  )
Next
End Function

(put a comma before InitDX7Hack() and one comma before DisableTextureFilters() to activate bilinear filtering)

The texture applied on the quad is the same with/without bilinear filtering, but the final render on screen is different because of the bilinear filtering...
Title: Re: how to disable bilinear filtering (on textures) (Blitz3d)
Post by: RemiD on January 06, 2018, 23:16:13
@Yue>>if you don't see the difference with/without bilinear filtering, using the code that i provided, maybe that's because of fastext which does something behind the scenes...
Title: Re: how to disable bilinear filtering (on textures) (Blitz3d)
Post by: Yue on January 07, 2018, 14:29:17

Nice!!
(https://www.syntaxbomb.com/proxy.php?request=http%3A%2F%2Fi68.tinypic.com%2F34ooprt.png&hash=0839d2f020183196100f3c8b0afc3963b407015f)
Title: Re: how to disable bilinear filtering (on textures) (Blitz3d)
Post by: MagosDomina on January 08, 2018, 00:44:22
What exactly is the InitDX7() doing here?
Title: Re: how to disable bilinear filtering (on textures) (Blitz3d)
Post by: Yue on January 08, 2018, 00:51:38
This is the function of the library that RemiD.
Title: Re: how to disable bilinear filtering (on textures) (Blitz3d)
Post by: RemiD on January 08, 2018, 07:43:34
This is not my library, these are functions from ashadow or devil shadow system (but initially made by TomSpeed)

The idea is to configure directx7 as you want for the Blitz3d window, so i suppose that InitDX7() setup that for the Blitz3d window. (it depends how the internal functions of the dll have been made, i don't know the details. But it works well...)

search for posts by "TomSpeed" or "devil child" or "Kryzon" on the old blitzbasic forum, there are some examples on how to setup directx7 for different things.
Title: Re: how to disable bilinear filtering (on textures) (Blitz3d)
Post by: JBR on December 31, 2020, 00:41:09
Hi RemiD,

I want to use bilinear on some textures and block one on others.

As I understand it your code changes the renderer so this is not possible.

There is one texture I want mipmapped, any ideas?

Jim
Title: Re: how to disable bilinear filtering (on textures) (Blitz3d)
Post by: RemiD on December 31, 2020, 09:24:12
@JBR>>this is not my decls dll but those of ashadow library, so i can't change it.

however, if you take a look the bb code :

Function DisableTextureFilters()
;DX7DBF_SetMipmapLODBias( -10.0, 0 )
For Level = 0 To 7
DX7DBF_SetTextureStageState( Level, D3DTSS_MAGFILTER, D3DTEXF_POINT )
DX7DBF_SetTextureStageState( Level, D3DTSS_MINFILTER, D3DTEXF_POINT )
DX7DBF_SetTextureStageState( Level, D3DTSS_MIPFILTER, D3DTEXF_POINT  )
Next
End Function

i think that 0 to 7 corresponds to the layers (of textures) that you can apply on a surface / mesh.
i am not sure that we can use the 8 layers with Blitz3d, in most cases i use 2 layers (layer 0 and layer 1)...
so maybe you could change the code so that all textures on layer 0 and layer 1 don't have bilinear filtering, and textures on layers 3 and 4 have bilinear filtering.

something like :

Function DisableTextureFilters()
;DX7DBF_SetMipmapLODBias( -10.0, 0 )
For Level = 0 To 1 ;disable bilinear filtering on all textures on layers 0-1
DX7DBF_SetTextureStageState( Level, D3DTSS_MAGFILTER, D3DTEXF_POINT )
DX7DBF_SetTextureStageState( Level, D3DTSS_MINFILTER, D3DTEXF_POINT )
DX7DBF_SetTextureStageState( Level, D3DTSS_MIPFILTER, D3DTEXF_POINT  )
Next
End Function

(not tested)

then when you apply a texture on a surface / mesh :

;without bilinear filtering :
entitytexture( mesh, texture, frame, layer ) ;layer must be 0 or 1
;or
brushtexture( brush, texture, frame, layer ) ;layer must be 0 or 1

;with bilinear filtering :
entitytexture( mesh, texture, frame, layer ) ;layer must be 2 or 3
;or
brushtexture( brush, texture, frame, layer ) ;layer must be 2 or 3