Incorrect render with orthographic lens

I need to make a grid on the floor size 8000x8000. To do this, I chose CardMaker and loaded it with a 4000x4000 pixel texture containing 40x40 cells. I also need to zoom and scale the floor grid. Unfortunately, no matter what I do, the texture does not render correctly at the bottom of the screen: the image flickers, disappears and appears at different camera heights.

my camerahandler:

class CameraHandler(DirectObject):
    __slots__ = ["_cam_height", "_min_height", "_lens", "_film_size"]

    def __init__(self, base: ShowBase):
        self._min_film_size = 5
        self._base = base
        self._film_size = 200


    def __setup_lens(self):
        self._lens = OrthographicLens()
        self._lens.setFilmSize(self._film_size, self._film_size * 0.75)

        self._lens.setNearFar(-50, 50)
        self._lens.setFov(180), 50, 0)

    def __setup_buttons(self):
        self.accept("wheel_up", self.__zoom_camera)
        self.accept("wheel_down", self.__zoom_out_camera)

    def __zoom_out_camera(self):
        self._film_size *= 1.05

    def __zoom_camera(self):
        if not self._base.mouseWatcherNode.hasMouse():

        if self._film_size < 10:

        mouse_pos = self._base.mouseWatcherNode.getMouse()
        mouse_x, mouse_y = mouse_pos.getX(), mouse_pos.getY()
        self._film_size *= 0.95
        delta_x, delta_y = mouse_x, mouse_y
        cam_pos =[0] + delta_x, cam_pos[1], cam_pos[2] + delta_y)

    def film_size(self):
        return self._film_size

Rendering ground grid:

    def __render_ground_plane(self, scale: float = 1.):
        card_maker = CardMaker("ground")
        card_maker.setFrame(-4000, 4000, -4000, 4000)
        repeats = 8000 / (scale * 80)
        card_maker.setUvRange((-repeats / 2, -repeats / 2), (repeats / 2, repeats / 2))
        card_gn = card_maker.generate()
        # card_maker.setFrameFullscreenQuad()
        texture = self._base.loader.load_texture("./viewport/resources/ground_grid.png")

First of all, greetings, and welcome to the forum! I hope that you find your time here to be positive! :slight_smile:

As to your issue, hmm… A little quick experimentation on my side seems to indicate that the “__render_ground_plane” method is fine.

However, looking at your camera-code… is your camera supposed to be able to see behind itself? That might be the cause of the problem, I suspect: the view of the floor in front of the camera is fighting with the view of the floor behind it.

Specifically, you’re setting a “near-far” pair of (-50, 50)–i.e. fifty units behind the camera to fifty units in front of it, I believe.

I’d suggest changing the first value to something small, but positive.

1 Like

Hi, u was very close to right solution! Worked for me setting nearfar to -8000, 8000. I have waisted a lot of time on this little mistake, thank you very much <3

1 Like

It’s my pleasure! :slight_smile:

Just to check: is your camera intended to render things behind it?

I think not, but I probably have cam positioned incorrectly because nearfar affects the vertical size of the rendering area

The thing is, a negative “near”-value will, I believe, result in geometry behind the camera being rendered. (It indicates a near-distance that’s negative–i.e. that far from the camera, but backwards instead of forwards.)

To see the effect, I suggest loading up a simple model–maybe the engine-provided smiley, or Ralph. Then try placing it first in front of the camera, then behind the camera. You should find that, even behind the camera, it appears on screen.