Disabling mipmaps for video/render textures

No matter how I try, I can’t seem to disable mipmaps for video/render-to textures in the UPBGE (2.79). I’ve tried using SetMipmapping(0), turning off mipmapping in user preferences, etc etc and no matter what the video texture always appears blurry. Is there a way to disable mipmaps for the video texture before it’s rendered?

The script needs to be tweaked to properly run, but once the fixing is done, it works.

Oddly while this does work in regular blender game for me, it doesn’t seem to work in UPBGE (neither viewport and windowed):
image
What version of blender did you use to make this?

I didn’t make it, the guy who posted it did.
I use the script in Blender 2.79b (Not UPBGE)
The reason it doesn’t work in UPBGE is probably because of changed commit code.

@BluePrintRandom, @aWeirdOwl or @lordloki_reloaded can help with the latest code conversion.

1 Like

I should probably show the version I’m using:

image
The reason I am using this version (unrelated but worth mentioning) is that it uses the old bullet physics, since the newer version(s) of UPBGE has buggy/dysfunctional collision. Also I’ve had a bug when exporting versions of the game and running it on my friend’s computer - render-to-texture only seems to work correctly with this version of UPBGE.

So basically, it’s an old bullet engine offshoot of the main UPBGE version, but it is the most stable one I have used.

EDIT - Wendigo’s file didn’t have a script in it, but they were able to alter the setting per object. The (only?) way to access the mipmapping per object AFAIK in my versions of blender is through the data-blocks in the outliner as there doesn’t seem to be an option in the properties panel anymore under image sampling. But by checking and unchecking it, it still doesn’t seem to make a difference for me :frowning:
image

hmm none of your images are showing

That’s weird, they’re showing fine for me…

Here’s what shows up on the splash screen:

UPBGE 0.2.4

Date: 2019-08-03 01:34
Hash: cc1f03406592
Branch: ge_23a_old_bullet

Yeah it must have been my connection

I am looking it over now

Upbge 0.2.5 may be better to use @festive_enthusiast

About the render to texture api I will pop it up in a sec

https://shuvit.org/python_api/bge.types.KX_TextureRenderer.html#KX_TextureRenderer.lodDistanceFactor

this should be what you need*

2 Likes

Ok…it took a long time of trial and error (a literal week), but I finally found a way to do this that works for me.

So, I am not ENTIRELY sure if this is how it works, but here is the issue I think I was getting, and then I’ll show the solution.

In order to have a video/render-to texture in a scene, there obviously needs to be a placeholder texture assigned to the object, and no matter what that texture will be switched to the render on the first logic tic. If mipmapping is set to disable on the same frame as the first render, it will render the initial texture without mipmapping but the Render-to-texture script won’t run, and you will get a pixelated version of the placeholder texture (I used a color grid for that). So, in order for this to work, I set the mipmapping(0) script to run on the frame(s) after the first render-to-texture frame and it will turn mipmapping off for the render and not the placeholder texture.

import bge
from bge import render, logic

controller = bge.logic.getCurrentController()
owner = controller.owner

cameraName = owner['cam']
materialName = owner['material']
whichScene = owner['whichScene']
scenes = bge.logic.getSceneList()
for scene in scenes:
    if scene.name.startswith(whichScene):
        if "RenderToTexture" in owner:
            owner["RenderToTexture"].refresh(True)
            bge.render.setMipmapping(0)
        else:
            import VideoTexture
            objList = scene.objects
            camName = owner['cam']
            cam = objList[camName]
            matID = VideoTexture.materialID(owner, "MA" + owner['material'])
            renderToTexture = VideoTexture.Texture(owner, matID)
            source = VideoTexture.ImageRender(scene,cam)
            owner["RenderToTexture"] = renderToTexture
            source.capsize = [640, 480]
            renderToTexture.source = source


Yay!! Sharp edges for objects on the Z axis :smiley:

When adding an overlay scene, the next problem I ran into is that sometimes it wouldn’t work unless I “refreshed” the mipmapping by having a script run for one frame:

bge.render.setMipmapping(1)
bge.render.setMipmapping(0)

This seemed to solve the problem. However, there was a slight flicker, which I solved by adding a motion blur filter for that frame set to 1 to hide the flicker.

Yeah I know this is a very complicated solution to a simple problem (my workflow can only be compared to the construction of the winchester house sometimes), but it works and I’m relieved.