Small Tweaks: Anisotropic Filtering, PickedUVW()

BlitzMax Forums/MiniB3D Module/Small Tweaks: Anisotropic Filtering, PickedUVW()

GNS(Posted 2010) [#1]
Hey folks,

Here's a couple of minib3d tweaks that might be useful.

The first adds anisotropic filtering support. It detects whether the player's hardware supports aniso. filtering and if so, the max samples their hardware supports. You can enable/disable anisotropic filtering in your own programs by using the new AnisotropicFiltering(enable%, samples#) command. You can also find out the status of anisotropic filtering support via the new GetAnisotropicSamples() command.

Step 1: Open THardwareInfo.bmx. Around line 30 (just under the Global MaxLights : Int declaration) add:
Global MaxAniso : Float


Around line 48 (just under the THardwareInfo.AnIsoSupport = ... line) add:
		If THardwareInfo.AnIsoSupport
			glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, Varptr(THardwareInfo.MaxAniso))
		EndIf


Save THardwareInfo.bmx and close it.

Step 2: Open TGlobal.bmx. At the top of the file, just under the Global vbo_supported = ... line) add:
	Global aniso_enabled:Byte = False
	Global aniso_samples:Float 'number of anisotropic filtering samples


After the function declaration for Graphics3D (approximately line 53), add:


Save TGlobal.bmx and close it.

Step 3: Open TMesh.bmx. Search for the comment "masked texture flag" (should appear around line 1790). Just before this comment add:


Save TMesh.bmx and close it.

Step 4: Open functions.bmx. Somewhere in this file add the following functions (I preferred to put them alphabetical order, your choice though :)):





Save functions.bmx and close it.

Step 5: Build modules and docs. To make use of anisotropic filtering, simply call AnisotropicFiltering(samples, True), where 'samples' is some amount ranging from 0-GetAnisotropicSamples().

A note on this one:

* It may be possible to rework this so it works as a texture filter rather than a global setting. Doing this would in theory allow you to set anisotropic filtering on a per-texture basis. Why you would want to do this (and even if it's possible) I'm not sure. For my purposes having it as a global on/off switch works fine.


GNS(Posted 2010) [#2]
This tweak adds PickedU(), PickedV() and PickedW(). These commands return the texture coordinates of the last picked location. A must-have for a number of things (i.e. adjusting the color of your player mesh based on the lightmap pixel color). Big thanks to fredborg for the original B3D code!

Step 1: Open functions.bmx. Somewhere in this file (again, I prefer to add them alphabetically but it's your call), add the following functions:


Save functions.bmx and close it.

Step 2: Open TPick.bmx. Near the top of the file (just under the Global picked_triangle:Int line) add:
Global picked_u:Float[4], picked_v:Float[4], picked_w:Float[4]


Step 3: Further down, between the function declarations for PickedX() and PickedNX() (around line 128), add:


Step 4: Even further down, in the Pick() function (just after the line picked_triangle=C_CollisionTriangle()) add:
calcPickedUVW()


Step 5: Just after the Pick() function, add:


Save TPick.bmx. Build modules and docs. PickedU(), PickedV(), PickedW() should now be working. :)

Couple of notes on this one:

* It doesn't support rotated textures. You'll have to rework things to add support for texture rotation.

* The coordSet parameter refers to the UV coordinate you'd like to grab the UVW location from. This should be either 0 or 1.


Kryzon(Posted 2010) [#3]
Very interesting, thanks for sharing.


ima747(Posted 2010) [#4]
Very cool indeed. Can't wait to give them a try!