groverburger / g3d

Simple and easy 3D engine for LÖVE.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Transparency when draw image behind 3D object

ddabrahim opened this issue · comments

Hi.

I would like to draw images behind the 3D object, however when I do that the image is remain visible:

image-seetrough

One way I have solved this problem is to draw the 3D object on to a canvas and then draw the canvas on to the screen.
It is solves the problem, however when I move the camera, 3D objects get out of the view within the canvas it is drawn to

object-out-of-view

Could someone please tell me if is there any other solution I can try to draw images behind the 3D object?

Here is a project that reproduce the problem with drawing the image behind the 3D object:
image-behind-3d-test.zip

I would appreciate any advice.

Love2D 11.4
G3D 1.5.1
macOS 12.2.1

Thank you.

commented

I'd recommend playing around with Depth Modes instead of using canvases. (https://love2d.org/wiki/love.graphics.setDepthMode)

What I'd do here is render the image before the 3D model, with the depth mode set like so: love.graphics.setDepthMode("always", false) so the image is rendered unconditionally and does not affect the z-buffer.

Then I switch the depth mode back to love.graphics.setDepthMode("lequal", true) and render the 3D meshes.

Hopefully that gets you the effect you're looking for!

Thanks a lot appreciate it!

To add to that, another solution is to discard alpha pixels to stop them affecting the depth buffer with a pixel shader;

vec4 effect(vec4 color, Image tex, vec2 texture_coords, vec2 screen_coords)
{
    vec4 texturecolor = Texel(tex, texture_coords);
    if (texturecolor.a < 0.001)
        discard;
    return texturecolor * color;
}

Thank you! Looks like an interesting solution to try.