Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stereo rendering works incorrectly with pandagles2 display #815

Closed
mbait opened this issue Dec 17, 2019 · 16 comments
Closed

Stereo rendering works incorrectly with pandagles2 display #815

mbait opened this issue Dec 17, 2019 · 16 comments
Assignees
Labels
bug
Milestone

Comments

@mbait
Copy link

@mbait mbait commented Dec 17, 2019

Below are examples of stereo rendering of the same scene in Panda3D with two different pipelines:
eglGraphicsPipe
stereo-eglGraphicsPipe
glxGraphicsPipe
stereo-glxGraphicsPipe
Source code

import numpy as np
from cv2 import cv2
from direct.showbase.ShowBase import ShowBase
from panda3d.core import *

#load_prc_file_data("", "load-display pandagles2")

base = ShowBase(windowType='offscreen')
base.camNode.get_display_region(0).set_active(False)

props = FrameBufferProperties()
# Request 8 RGB bits, no alpha bits, and a depth buffer.
props.set_rgba_bits(8, 8, 8, 0)
props.set_rgb_color(True)
props.set_depth_bits(16)
props.set_stereo(True)

# Create a WindowProperties object set to 512x512 size.
win_prop = WindowProperties.size(512, 512)

# Don't open a window - force it to be an offscreen buffer.
flags = GraphicsPipe.BFFbPropsOptional | GraphicsPipe.BF_refuse_window
#flags = GraphicsPipe.BFFbPropsOptional

buffer = base.graphicsEngine.make_output(base.pipe, "stereo buffer", -100,
                                         props,
                                         win_prop, flags, base.win.getGsg(),
                                         base.win)
texture = Texture()
buffer.addRenderTexture(texture, GraphicsOutput.RTM_copy_ram)

lens = PerspectiveLens()
lens.setFov(54.611362)
lens.setFocalLength(1.37795276)
lens.set_interocular_distance(50)
lens.set_convergence_distance(float('inf'))

render = NodePath('stereo')
cam = base.makeCamera(buffer)
cam.node().setLens(lens)
cam.node().setScene(render)
dp = buffer.makeDisplayRegion()
dp.setCamera(cam)

# scene = StrawberryPlant.create_random()
# ModelAssembly(render, scene)

base.camera.set_pos(100, -500, 0)
cube = base.loader.loadModel('misc/rgbCube')
cube.reparent_to(render)
cube.set_scale(100)
cube.set_z(100)

def stereo1():
    base.graphicsEngine.renderFrame()
    image = np.asarray(memoryview(texture.getRamImage())).reshape(1024, 512, 3)
    left = image[0:512, ...]
    right = image[512:1024, ...]
    #cv2.imshow('left-right', np.vstack((left, right)))
    cv2.imwrite('stereo.png', np.vstack((left, right)))
    cv2.waitKey(0)

if __name__ == '__main__':
    import timeit
    # built-in: 0.0171750984987
    # manual: 0.0173542866707
    stereo1()

    # timer = timeit.Timer('stereo1()', 'from __main__ import stereo1')
    # print sum(timer.repeat(30, 100)) / 3000
@mbait

This comment has been minimized.

Copy link
Author

@mbait mbait commented Dec 17, 2019

I ran that on 25217d9.

@rdb rdb self-assigned this Dec 18, 2019
@rdb rdb added the bug label Dec 18, 2019
rdb added a commit that referenced this issue Dec 18, 2019
@rdb

This comment has been minimized.

Copy link
Member

@rdb rdb commented Dec 18, 2019

The GLES port was done before GLES supported multiple FBO attachments, so some of the code (particularly the bits that select which render attachment to render to) is ifdeffed out for OpenGL ES.

I'm unable to test it myself, but could you perhaps see if 3c3eee2 fixes it?

@rdb rdb removed their assignment Dec 18, 2019
@mbait

This comment has been minimized.

Copy link
Author

@mbait mbait commented Dec 18, 2019

Yes, it does! Thank you for such prompt fix.

@mbait mbait closed this Dec 18, 2019
@mbait

This comment has been minimized.

Copy link
Author

@mbait mbait commented Dec 18, 2019

Sorry, I didn't notice at first, but now both eyes contain left view, so the bug is still there:
stereo

@mbait mbait reopened this Dec 18, 2019
@rdb rdb self-assigned this Dec 29, 2019
@rdb rdb added this to the 1.10.5 milestone Dec 29, 2019
@rdb

This comment has been minimized.

Copy link
Member

@rdb rdb commented Dec 29, 2019

OK, I see that the missing piece is that we aren't calling glReadBuffer properly. Will check in a fix shortly.

@rdb rdb closed this in fccffb4 Dec 30, 2019
@mbait

This comment has been minimized.

Copy link
Author

@mbait mbait commented Jan 2, 2020

@rdb After pulling from fresh master I still see the problem. Can't see the button to re-open this issue.

@rdb rdb reopened this Jan 2, 2020
@rdb

This comment has been minimized.

Copy link
Member

@rdb rdb commented Jan 3, 2020

How is this evident in your testing? I am using your code, except with the stereo1 method modified to the following:

def stereo1():
    base.graphicsEngine.renderFrame()
    texture.write("stereoL.png", 0, 0, False, False)
    texture.write("stereoR.png", 1, 0, False, False)

I am seeing a stereoL.png and stereoR.png being written, which show the box being in different X positions.

If this is not what you are seeing, could you please capture and attach an apitrace .trace file, using a command like the following:

apitrace trace --api=egl python test.py

For the record, I'm testing on ArchLinux with an NVIDIA GeForce MX150.

@mbait

This comment has been minimized.

Copy link
Author

@mbait mbait commented Jan 3, 2020

Are you sure you use eglGraphicsPipe?

@rdb

This comment has been minimized.

Copy link
Member

@rdb rdb commented Jan 3, 2020

Quite.

@mbait

This comment has been minimized.

Copy link
Author

@mbait mbait commented Jan 3, 2020

What is the commit hash you're testing on?

@rdb

This comment has been minimized.

Copy link
Member

@rdb rdb commented Jan 3, 2020

I'm testing on 3755e15, the latest master. Of course, I also verified that the fix was effective back when I checked in fccffb4.

I'd like to see the output with notify-level-gles2gsg debug (or spam) set for you, and if you can, the .trace file generated by the command I mentioned earlier.

@mbait

This comment has been minimized.

Copy link
Author

@mbait mbait commented Jan 3, 2020

tracelog.zip

I test on Asus GTX1060 3GB if it matters, Ubuntu 16.04 with the proprietary drivers 384.

@rdb

This comment has been minimized.

Copy link
Member

@rdb rdb commented Jan 3, 2020

The log shows that it reports the presence of the needed extensions, and the API trace shows that it does query the pointer of glDrawBuffers. However, it does not show an attempt to query the glReadBuffer functionality. That strongly suggests to me that your build does not include fccffb4; could you double-check that you have pulled and built the latest changes?

@mbait

This comment has been minimized.

Copy link
Author

@mbait mbait commented Jan 3, 2020

Sorry, that was my bad. I fetched changes from upstream to my work, and it started to work as expected.

@mbait mbait closed this Jan 3, 2020
@mbait

This comment has been minimized.

Copy link
Author

@mbait mbait commented Jan 3, 2020

Thank you for your help and patience!

@rdb

This comment has been minimized.

Copy link
Member

@rdb rdb commented Jan 3, 2020

Great, thank you for verifying.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.