Closed gh2k closed 5 years ago
Ah, never mind I got it working. I think it was the depth buffer getting in the way, so I disabled it.
I'll tidy this up and make a PR.
Ah, never mind I got it working. I think it was the depth buffer getting in the way, so I disabled it.
I'll tidy this up and make a PR.
Hi~ May I ask you how to render a picture with a transparent background? All my results are like:
I know I should adjust the background_attributes, but I do not know how to set it.
pixels = dirt.rasterise_deferred(
vertices=cube_vertices_clip,
vertex_attributes=tf.concat([
tf.ones_like(cube_vertices_object[:, :1]), # mask
cube_uvs, # texture coordinates
cube_normals_world # normals
], axis=1),
faces=cube_faces,
background_attributes=(tf.ones([frame_height, frame_width, 6])*255),
shader_fn=shader_fn,
shader_additional_inputs=[texture, light_direction]
)
Thanks for any help and guidance! Best, Frank
I'd like to render a stack of transparent shapes, and I'm wondering how easy this would be to achieve.
Currently, I'm rendering shape-by-shape and then alpha-compositing them in separate tensorflow operations, but this is slower than I'd like and I'm finding I'm debugging a number of problems where tf is trying to move things back and forth between the CPU and GPU.
I had a go at hacking together support, but I couldn't get it working. I don't really know opengl programming, so that is probably part of the problem.
Here's what I tried:
shaders.cpp
convertvec3
tovec4
forcolour_in
andcolous_out
in theforward
shaders: https://github.com/pmh47/dirt/blob/45119bb8c9e53830c76bde400c8ccfa7e776ec3c/csrc/shaders.cpp#L16-L43rasterise_egl.cpp
allow import of RGBA colours: https://github.com/pmh47/dirt/blob/45119bb8c9e53830c76bde400c8ccfa7e776ec3c/csrc/rasterise_egl.cpp#L308-L309glVertexAttribPointer
to take objects of size4
instead ofobjects.channels
: https://github.com/pmh47/dirt/blob/45119bb8c9e53830c76bde400c8ccfa7e776ec3c/csrc/rasterise_egl.cpp#L208glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
at the end ofinitialise_per_thread_objects
: https://github.com/pmh47/dirt/blob/45119bb8c9e53830c76bde400c8ccfa7e776ec3c/csrc/rasterise_egl.cpp#L214This still draws the triangles that I expect in the colours that I expect, but they are still opaque, not transparent. (The triangles I'm feeding in have random numbers for their vertex colour alpha components.)
Any ideas what else I might need to change to make this work?
[edit]: I was incorrect about the triangle colours:
If I pass an alpha of <1, the triangles are rendered in a lighter colour. So:
[1., 0., 0., 0.5], [1., 0., 0., 0.5], [1., 0., 0., 0.5]
then I get a pink triangle. which is what I would expect.[0., 0., 1., 0.5], [0., 0., 1., 0.5], [0., 0., 1., 0.5]
then it is rendered in light blue