Material that always show an overlay image fullscreen or similar

Hello everyone,
In this days I’m trying a bit creating rooms in blender and render them for a game with pre-rendered backgrounds and low-poly objects, and now I’ve some difficults to implement my strategy.

There’s any way with materials to do one of the following stuffs?

1- Create a material for a room mesh, that always show my pre-rendered image at full screen (covering the entire mesh, but not the player, if the player pass behind an obstacle inside the room, the player (or part of it) must be hidden)

2- Create a material for a room mesh, that draws the depth but not the color, in a nutshell… the mesh is invisible, but if player pass behind an obstacle inside the room, the player, or the part of the player hidden by the obstacle must be made transparent.

In both cases the result will be a pre-rendered (fixed camera) background, where the background will cover entirely the room mesh. If it’s possible I will prefer the first case, because in this way in some situations I could blend the mesh and the pre-rendered background, if not possibile even the second way will be ok.
For OGRE I remember that was possibile implements the second way easily defining for a material the flags:
write_color=off
write_depth=on
But here I don’t know how to do it, could you help me please?

Thank you very much

What i’d do would be to have 2 viewports.
the first viewport with only a 1x1 quad with the material with the background texture on it. This material’s shader has to project the quad full screen, and just get the texture.
I don’t know if you’re comfortable around shaders, but see these shaders
that’s the .vert shader you need (like, with no modification)
https://code.google.com/p/jmonkeyengine/source/browse/trunk/engine/src/core-effects/Common/MatDefs/Post/Post.vert
and the frag shader should look like this one
https://code.google.com/p/jmonkeyengine/source/browse/trunk/engine/src/core-effects/Common/MatDefs/Post/Overlay.frag
but without the m_Color multiplication.
the m_Texture has to be fed with your pre rendered texture.
the j3md should look like that
https://code.google.com/p/jmonkeyengine/source/browse/trunk/engine/src/core-effects/Common/MatDefs/Post/Overlay.j3md
disregard the first technique and use the second, also the only material param you need is Texture2D Texture. remove the others.

That is for the displaying your pre rendered room full screen.
Now for the rest.

  • create a second view port and set it to only clear depth (viewPort.setClearFlags(false, true, false):wink:
  • add all objects that should be in the scene to that viewport
  • now for any object’s material in the scene except the player’s set color write to false (mat.getAdditionalRenderState.setColorWrite(false):wink:

and this should do the trick i guess…

For references on multi viewports see
https://code.google.com/p/jmonkeyengine/source/browse/trunk/engine/src/test/jme3test/renderer/TestMultiViews.java

hope that helps

Hello Nehon!
First of all thanks, thanks for having described in a such detali the procedure to solve my problem.
Sure I will try to follow it, I think for now is more than enough.

Thanks again