Request : 2D filter to make close objects semi-transparent

As i tried/struggle to find solutions with rays , materials and changing alpha channel of objects, i was wondering if applying a 2d filter wouldnt make things easier and more elegant

I have no knowledges in glsl so i was wondering if someone can help me program a 2d filter in which , below an X distance of the focal point of the camera (X would be the distance camera - character) , the more a vertex is close to the camera, the more it will be transparent … kinda “reverse fog”

?

1 Like

Not sure of the glsl method, but I think I might be able to do this with python, will try to code it tommorow

its a 2d filter, it has to be in glsl (opengl)

I can easily set the r,g,b channels but the alpha channel doesnt operate

uniform sampler2D bgl_RenderedTexture;
 
void main(void)
{
    vec4 color = texture2D(bgl_RenderedTexture, gl_TexCoord[0].st); 
    vec4 temp = color.rgba ;
    temp.a = 0.2 ;
    gl_FragColor = temp ;
}

im pretty sure transparency needs to be enabled on the material, ive had this happen before.

i just tested, it doesnt change the thing.
Ofc, i cant modify the alpha of the object, but here’s it really the pixels of the scene that are targeted

1 Like

You can modify the alpha of an object with python with this

C = logic.getCurrentControllers
O = C.owner

o.color = [r, g, b, a] #r =red values, g = green, b = blue and a = alpha values

We could use the near sensor in some way to manipulate the alpha values with this code, thats what I was saying

But i dunno any glsl methods

Its a misunderstood of me ; 2d filters are only a process on a rendered image , so its impossible to “scratch” the pixel to see what’s hidden behind in order to blend both … so transparency - blending front pixels with “back” pixels is not an option.

@Daedalus_MDW kindly helped the newbie i am with materials and gave me a conveniant solution. Thx to him

@ANSH, it was not about dynalicaly setting a color to an object, (i use this to underline a target selection for example) but more acting on a “pixel level” .

1 Like

Does this tutorial help. It has the basic mechanics.

1 Like

yeah that’s pretty cool too. Will test it tomorrow. The only thing is that it doesnt seem to use distances. Will see tomorrow with Math nodes

what you are looking for is most likely something like this

transparent-by-distance.blend (532.2 KB)

it is basically the same technique used in Yo Frankie! to make leaves transparent when you got close.

1 Like

greater/less than math node would be much more efficient when paired with clip

i used clip here to get a clear hole, normally you would use alpha blend to get soft edges and see thru, and the other reason i used a color ramp where laziness, it is a fast way to clip the result in the 0 to 1 space.

and another reason is who cares if it works.

linked