3
\$\begingroup\$

I have a game where there a multiple floor levels between the player switches. The floor is not present everywhere, so you can look through it. When 'working' (playing, building stuff, etc.) on a specific floor I want to add a transparency value to everything that is NOT on the current floor. Ho can I accomplish that, and what is the best/most efficient way to do that?

sketch of the scene

\$\endgroup\$
2
\$\begingroup\$

Draw the floor (transparent part) after drawing the rest of the objects with transparency blending turned on.

Otherwise you can pass a currentFloor uniform to the fragment shader and a floor attribute to the objects so you can add the extra shade conditionally.

\$\endgroup\$
  • \$\begingroup\$ Needed to read that multiples times to understand that :) (I am just doing it as a hobby for a month ...) So the first solution is to apply a transparent blending shader to the transparent part of the floor, right? Can you explain the second solution more detailed? I don't know what all of it means, sorry. \$\endgroup\$ – RenK Nov 12 '15 at 16:31
0
\$\begingroup\$

Order of rendering is important.

You need to draw the objects in order, draw objects far away first. Using alpha values ofc, for an example alpha = 0.5.

Think this is called back to fron rendering.

So if you stand at X, floor is |, object are 1,2,4...

X | 1 2 3 4

Then you render 4, 3, 2, 1 and finally the floor |.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.