I have tried to follow this tutorial on reflections:
But it just doesn’t work with this version of Blender and the texture just turns black.
I have tried to follow this tutorial on reflections:
But it just doesn’t work with this version of Blender and the texture just turns black.
It should work on 2.79b. I made this template for myself, using the same method, it works on 2.97b, (but crashes on 2.78):
RenderToTexture-MirrorTemplate.blend (90.7 KB)
Ok, I guess it works but it seems I need a different texture for every object.
I have a problem that the reflection works with the first active camera only.
If I change the camera it still follows the first one.
You have to update the texture source with the active camera, maybe something like this:
from bge import logic, texture
cont = logic.getCurrentController()
own = cont.owner
scene = logic.getCurrentScene()
texChannel = 0
texSize = 1024
if 'mirrorTexture' not in own:
materialName = 'renderedtexturematerial'
matID = texture.materialID(own, "MA"+materialName)
tex = texture.Texture(own, matID, texChannel)
tex.source = texture.ImageMirror(scene, scene.active_camera, own, texChannel)
tex.source.capsize = [texSize, texSize]
own['mirrorTexture'] = tex
own['active_camera'] = scene.active_camera
else:
tex = own['mirrorTexture']
if own['active_camera'] != scene.active_camera: # camera changed?
tex.source = texture.ImageMirror(scene, scene.active_camera, own, texChannel)
tex.source.capsize = [texSize, texSize]
own['active_camera'] = scene.active_camera
tex.refresh(True)
Thank you, it works great.
But I’m still not sure if I’ll use it in the end.
A lot of mirror objects could drop the fps a lot.
This is the result.
But for my purpose, it might not be so useful.
I had to set it to refresh after every 2nd frame instead of immediately.
Otherwise, it would tank my fps. Don’t know if it’s possible to optimize it.
Especially because my game’s level is generated real-time to save memory.
Did you try reducing the texture size? Since it’s not a perfect mirror reflection, a lower resolution shouldn’t be too noticeable.
so much this. 512x512 should be good. the texture is actually stretched along viewport (set the generated image to color grid to see) so using your screen resolution might seem like a good idea, but textures not power of 2 (128, 256, 512 etc) arent stored efficiently in gpu.