I have a model without any transparency. If I render it without any shading and then take a screenshot, I get this:
If you click through, you can see that the background is transparent (where nothing is being drawn), but the model itself has no alpha.
When I turn on render.setShaderAuto(True), I get a strange effect where the black areas are being saved with an alpha of 0, turning them transparent:
This happens consistently with many models. Any idea why the auto shader is setting an alpha value of 0 when my material doesn’t have any transparency on it? To be clear, it renders properly - this is only when calling GraphicsWindow.getScreenshot().
It was suggested in IRC to render twice - once with a transparent background and once without. You can then figure out the parts of the image that aren’t supposed to be transparent. Code is below. It works, but it’s ugly. If anyone has any better suggestions, let me know.
Are you trying to make a screenshot with base.screenshot ? I think you could use another image format, such as jpg. If the render artifacts of jpg are an issue to you, maybe you could set to save it as RGB png, not RGBA.
This is a weird issue you’re describing. Is it possible that your texture doesn’t “use” alpha, but still has “alpha” channel in the image?
I don’t think that’s the issue either. This particular model has two materials - one for the orange and one for the black. Neither have any transparency. Printing out the RenderState for each one:
That is a little strange. Have you tried inspecting the generated shaders to see if you can tell where it is computing the alpha value from?
Note that, to be perfectly clear here, the shader is not technically generating transparency. It is simply writing an alpha value of 0 where your black material falls. It does appear that the alpha value should be 1 where your black material falls, but perhaps the generated shader doesn’t respect this due to an oversight.
Yeah, and it displays properly on the screen. It’s only when I extract the screen buffer so I can save it as a screenshot that the alpha values are incorrect.