# Is it possible to have a real time reflections in bge 2.79b?

**URL:** <https://blenderartists.org/t/is-it-possible-to-have-a-real-time-reflections-in-bge-2-79b/1376108>\
**Category:** Game Engine Support and Discussion\
**Tags:** bge\
**Created:** [April 25, 2022, 9:17pm UTC](https://blenderartists.org/t/is-it-possible-to-have-a-real-time-reflections-in-bge-2-79b/1376108 "2022-04-25T21:17:25Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Saranoske](https://blenderartists.org/letter_avatar_proxy/v4/letter/s/cab0a1/32.png) [@Saranoske](https://blenderartists.org/u/Saranoske)\
**Post date:** [April 25, 2022, 9:17pm UTC](https://blenderartists.org/t/is-it-possible-to-have-a-real-time-reflections-in-bge-2-79b/1376108/1 "2022-04-25T21:17:25Z")

</div>

I have tried to follow this tutorial on reflections:

[![](https://blenderartists.org/uploads/default/original/4X/c/e/2/ce2e28cd6229507efec0cfc9ec17f60f47876884.jpeg "Create Realtime Blurred Reflections [Blender Game Engine]") ](https://www.youtube.com/watch?v=l0FI95_8ZdY)

But it just doesn’t work with this version of Blender and the texture just turns black.

---

<div class="post-metadata">

**Author:** ![MattFrnndz](https://blenderartists.org/letter_avatar_proxy/v4/letter/m/a8b319/32.png) [@MattFrnndz](https://blenderartists.org/u/MattFrnndz)\
**Post date:** [April 25, 2022, 10:06pm UTC](https://blenderartists.org/t/is-it-possible-to-have-a-real-time-reflections-in-bge-2-79b/1376108/2 "2022-04-25T22:06:13Z")

</div>

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](https://blenderartists.org/uploads/short-url/7DXXqEDN3BDL3fugwudCup9MghU.blend) (90.7 KB)

---

<div class="post-metadata">

**Author:** ![Saranoske](https://blenderartists.org/letter_avatar_proxy/v4/letter/s/cab0a1/32.png) [@Saranoske](https://blenderartists.org/u/Saranoske)\
**Post date:** [April 25, 2022, 11:17pm UTC](https://blenderartists.org/t/is-it-possible-to-have-a-real-time-reflections-in-bge-2-79b/1376108/4 "2022-04-25T23:17:06Z")

</div>

Ok, I guess it works but it seems I need a different texture for every object.

---

<div class="post-metadata">

**Author:** ![Saranoske](https://blenderartists.org/letter_avatar_proxy/v4/letter/s/cab0a1/32.png) [@Saranoske](https://blenderartists.org/u/Saranoske)\
**Post date:** [April 26, 2022, 3:56pm UTC](https://blenderartists.org/t/is-it-possible-to-have-a-real-time-reflections-in-bge-2-79b/1376108/5 "2022-04-26T15:56:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![MattFrnndz](https://blenderartists.org/letter_avatar_proxy/v4/letter/m/a8b319/32.png) [@MattFrnndz](https://blenderartists.org/u/MattFrnndz)\
**Post date:** [April 26, 2022, 5:44pm UTC](https://blenderartists.org/t/is-it-possible-to-have-a-real-time-reflections-in-bge-2-79b/1376108/6 "2022-04-26T17:44:21Z")

</div>

You have to update the texture source with the active camera, maybe something like this:

```auto
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)

```

---

<div class="post-metadata">

**Author:** ![Saranoske](https://blenderartists.org/letter_avatar_proxy/v4/letter/s/cab0a1/32.png) [@Saranoske](https://blenderartists.org/u/Saranoske)\
**Post date:** [April 26, 2022, 8:52pm UTC](https://blenderartists.org/t/is-it-possible-to-have-a-real-time-reflections-in-bge-2-79b/1376108/7 "2022-04-26T20:52:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Saranoske](https://blenderartists.org/letter_avatar_proxy/v4/letter/s/cab0a1/32.png) [@Saranoske](https://blenderartists.org/u/Saranoske)\
**Post date:** [April 26, 2022, 9:56pm UTC](https://blenderartists.org/t/is-it-possible-to-have-a-real-time-reflections-in-bge-2-79b/1376108/8 "2022-04-26T21:56:57Z")

</div>

[![](https://blenderartists.org/uploads/default/original/4X/3/b/1/3b1e573edc5a2a4069754abbc398ccb5e47ea578.jpeg "Forkaholic - reflection test") ](https://www.youtube.com/watch?v=48OGJc51aes)

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.

---

<div class="post-metadata">

**Author:** ![MattFrnndz](https://blenderartists.org/letter_avatar_proxy/v4/letter/m/a8b319/32.png) [@MattFrnndz](https://blenderartists.org/u/MattFrnndz)\
**Post date:** [April 26, 2022, 11:39pm UTC](https://blenderartists.org/t/is-it-possible-to-have-a-real-time-reflections-in-bge-2-79b/1376108/9 "2022-04-26T23:39:02Z")

</div>

Did you try reducing the texture size? Since it’s not a perfect mirror reflection, a lower resolution shouldn’t be too noticeable.

---

<div class="post-metadata">

**Author:** ![Daedalus\_MDW](https://blenderartists.org/user_avatar/blenderartists.org/daedalus_mdw/32/1460959_2.png) [@Daedalus\_MDW](https://blenderartists.org/u/Daedalus_MDW)\
**Post date:** [April 26, 2022, 11:55pm UTC](https://blenderartists.org/t/is-it-possible-to-have-a-real-time-reflections-in-bge-2-79b/1376108/10 "2022-04-26T23:55:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Saranoske](https://blenderartists.org/letter_avatar_proxy/v4/letter/s/cab0a1/32.png) [@Saranoske](https://blenderartists.org/u/Saranoske)\
**Post date:** [April 27, 2022, 1:10am UTC](https://blenderartists.org/t/is-it-possible-to-have-a-real-time-reflections-in-bge-2-79b/1376108/11 "2022-04-27T01:10:48Z")

</div>

[![](https://blenderartists.org/uploads/default/original/4X/a/7/5/a75116dbb5c60ec3d9c603ec12d36fd95a0bcc35.jpeg "Forkaholic - Reflection test 2") ](https://www.youtube.com/watch?v=TDlGw3zdjGw)

I have made another version where I’ve used nodes and tried to blur the texture.  
The resolution is 512.  
It works fine, and the way I coded it makes the mirror texture follow the player every so often.
