how to disable bilinear filtering (on textures) (Blitz3d)

Started by RemiD, December 23, 2017, 21:55:27

Previous topic - Next topic

RemiD

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...

GW


RemiD

@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 !


RemiD

@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)

MagosDomina

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

RemiD

@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)

Yue

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.


RemiD

@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...

Yue

Here's the same scene with the bookstore.   I don't really know the difference very well.


RemiD

@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.

RemiD

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...

RemiD

@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...