How can I make a "see-through" shader?

Hi everyone,

I am currently working on Hasty Melons, a watermelon racing game and I need some help to figure out how to make a specific shader.
In the game, sometimes relevant objects are behind walls and I would like to make them render in front of everything.
So far I managed to do something similar by tweaking the z-depth of the material but it gave unpredictable results.

Here is an example from a gif I made some time ago:

I tried to find resources about how to do that in a glsl shader but can’t find anything that seems related enough.
I’m very new to glsl shaders, so I would greatly appreciate if anyone had hints about how to achieve that :slight_smile:

So only when the watermelon is behind the wall will it be transparent? Also which game engine are you using?

Well using GLSL to appear the objects in front of everything is (almost) impossible.
What do you mean by “unpredictable results”? For me the result in gif is already pretty good :spin:

Yes, only when the watermelon is behind the wall. I already know how to check when it’s the case though. The game engine is vanilla BGE 2.77.

You could mask that particular part of the wall with the watermelon.

Impossible, really? Damn, I guess I will have to use tricks with overlays?
The result in the gif is ok indeed but it only worked on one of my machines. I had to use a really high z-depth value for it to work properly. Once you try to change alpha, or other z-depth objects it start to not work all the time.

yeah, just cast a ray from the camera to each actor, if obstructed, send a message to a overlay that is where to display the object using screenspace

camera.getScreenPosition() and camera.getScreenVect() are very handy.

sendMessage(screenPosition as str([pos.x,pos.y,pos.z])
moveOverlayObject to screenPosition in overlay using getScreenVect

edt: also - you can make game objects go alpha transparent selectively, or even per vertex…

Instead of shading the players make the obstacles transparent as BPR suggested. For most games like yours, making obstacles transparent is the right choice in terms of game play/game design. Shading or outlining the characters will be confusing for players in a fast paced game.

how about a second scene with a copy of only the melons in semitransparent. put it over the mainscene as an overlay scene. as long as the melons can be seen in the main scene, it doesn´t matter if there is a copy above them, but if the mainscenes melons are hidden, you will on only see the copy. the only problem is that you cannot see the racetrack with this variation.

RenderToTexture allows some pretty cool things, such as this:

Which looks a little like you want…

So how is it done? I talk a little about it here, but I’ll go into a little more detail. Pretty much it goes like this: updating a dynamic texture from a camera occurs when you do the texture.refresh(true). This means you can toggle objects visibility, render the texture, and then set all the visibilities back to normal and now you have a texture of only a few objects. You can then map this texture to a plane in front of the camera and you’re all set!
You will have one-frame of lag using this method, as putting the refresh() inside a pre-draw callback does strange things. This can be compensated for with the trick of lagging the camera by one frame as well.
The other problem is that render to texture requires another complete render which is quite expensive. Fortunately in this case the number of objects is low (because most are invisible) so it isn’t to bad even at high resolutions.

There is an example blend here for mirrors: