How can I have a png image with transparency, visible only from *front*? - image

I'm using a prefab for a box shape, which has a front and back plane.
My images are PNG and have transparent areas around the edge. I dragged the image onto my front plane, which now has a drop-down box for "Shader".
First I chose Shader: "Standard" but the transparent areas of my PNG image weren't transparent, so in order to fix that I changed it to "Sprites / Diffuse"... now the image looks fine (from the front).
However, when I rotate the shape, the image is also visible from the back. I want a way to not see the image / texture from the back.
How can I make the images only visible from the front side of a plane, whilst also preserving the transparency areas of the image / texture?

If you are using the standard built-in shader, you need to set the rendering mode to transparent in order for the texture's alpha channel to be transparent. The sprite shader, by default, forces the rendering of otherwise invisible back-faces, whereas the standard shader does not.

Related

GLES remove logo from texture with a black and white mask

I would like to delete a portion of a texture defined by a black and white mask and replace it with the color of the adjacent pixels
this is an example to make you understand better
this is my try
first I draw the mask with the white area with the part of the image to be preserved and black with the portion to be obscured with
glDisable (GL_BLEND);
then I draw over the image with
glEnable (GL_BLEND);
glBlendFunc (GL_DST_COLOR, GL_ZERO);
in this way I can delete the part defined by the mask but I don't know how to fill it inside with the colors of the adjacent pixels
thx!
EDIT
I found this shadertoy that does exactly what i'm looking for
https://www.shadertoy.com/view/4ty3Dy
but I have to apply this to a video, and this shader seems to modify a static image multiple times by calling itself while the frames are running
I should have the effect generated for each frame in the simplest and lighter manner to run the shader on a rpi4

Draw texture to FrameBufferObject using specific color

I have a texture and I want to draw it to a FrameBufferObject. The texture has transparent areas. I would like the following:
For all transparent pixels, let them be drawn transparent in the FrameBufferObject.
For all non-transparent pixels, let them be drawn using a color of my choosing, ie pure red (ignore their actual rgb value)
I've tried Batch.setColor(red) before drawing the texture, but that just tints it - I want all non-transparent pixels to be drawn pure red.
I am also trying to figure out how to achieve this in just opengl directly, looks like there may be a way to do this with blending, which can then be related back to gdx.
Thanks
You need to write a shader and the shader is the OpenGL program that renders the texture. So your shader would render transparency without change and all else would the color of your own choosing.
The following link has libgdx shaders for palette swapping i.e. direct reassignment of color at render, which you can easily adapt for single color and transparency.
https://www.javaer101.com/en/article/12241616.html

How to render a 3D model with semi-transparent textures in Xcode?

I cannot get a 3D model with texture transparencies to be rendered correctly in Xcode.
The 3D model of hair consists of two geometries (hair and cap) and was created in Maya. It was bought off-the-shelf from here.
The correctly rendered model looks like this (without the head):
I exported the model to COLLADA format (DAE), put it into a folder model.scnassets together with its textures and added it to Xcode. However in Xcode Scene Editor it is rendered like this:
What is wrong here?
Update:
Setting Transparent > Intensity = 5, Settings > Transparency > Blend Mode = Double Sided, Settings > Transparency > Options > Writes depth = false gives this image where hair polygons against the blue sphere are rendered correctly, but above the blue sphere the rendered hair polygons are not the ones nearest to the camera but seem to be the ones on the back side of the hair model. This is apparently because of Writes depth = false, but it seems to be necessary to disable it to render the semi-transparent hair. (Using a brown texture here instead of the read one, but the result is the same regardless of the chose texture)
If you want to see a correct result of Transparent slot in Xcode Scene Editor you need to use premultiplied TIFF or PNG files for transparent parts of your 3D object. TIFF and PNG file formats can hold four channels (RGBA), but JPEG can hold only three channels (RGB).
Premultiplied means RGB * Alpha = RGBA (the opposite to it is unpremult, or RGB, A).
After applying the premultiplied texture to Transparent slot, set its Intensity property to 1...5 and Components property to desired channel from drop-down menu (All, Red, Green, Blue, Alpha).
Apple Documentation.
By default, the transparent property’s contents object is a fully opaque black color, causing the property to have no visible effect. Setting the transparent property’s contents to any solid color uniformly fades the opacity of the material based on that color’s opacity value. To make parts of a material appear transparent, set the property’s contents to an image or other texture-mapped content whose alpha channel defines areas of full or partial opacity.

Transparent textured face on transparent textured face rendering

Is there a way to correctly display more than one transparent texture in three.js? There are no problems if you try to render a transparent texture on a non-transparent textured plane below, but if you have more than a transparent plane, the nearest will "delete" the others below as you can see here:
On the left pic, there's what I would have (achieved adding depthWrite = false to every transparent material), on the right there's what I have, only setting transparent = true to materials with RGBA textures.
I already tried using alphaTest, but it isn't what I need, and depthWrite sometimes can't satisfy my needs (look at the green line bounding the path in the first screen, which hasn't been covered by the house shadow).

Blending two sprites in OpenGL ES without affecting background

Basically what I want to achieve is a sprite highlight animation effect as displayed below.
The idea is that the white-translucent gradient sprite moves on top of the other sprite (left-to-right), using a blend mode like Overlay (Photoshop). The difficult part is that the top gradient sprite should only be drawn on the visible pixels of the sprite underneath. The other part of the gradient overlay should be discarded to not affect the background or other sprites underneath (like on the image to the far right).
Is it possible to achieve that effect with a clever combination of OpenGL blend modes and how, or would I have to create a custom shader to combine these sprites?
Background: I'm using libgdx with OpenGL ES 2.0 and the app runs on Desktop, Android and iOS.
There arę many ways to do it. The simplest one:
You should render button and hilight in a single pass. In fragment shader, after sampling button texture and hilight texture calc the output color as for blending (could be mix(c1,c2,c2.a)) and alpha as button texture alpha only. Of course enable blending in usual way: (srcalpha,1-srcalpha)

Resources