Static background lighting and shadow

Bit of an ask but can anyone help me with this.

I have a pre-rendered background, and then a low poly version of the model used to make it (shown in wireframe).
My player walks around on the pre-rendered background.

In the bottom picture I’ve given the low poly model the Lighting material and added a spotlight and shadow.
What I’d like to do is draw the light and shadow colours with the background picture colours. (So the model is effectively transparent, but is used for creating a brightening light effect). So something like this

made this by combining the 2 in GIMP, its not perfect obviously.

Also I want to use the low poly model to stop rendering of the player when he is behind it, DESPITE it being completely transparent or even culled out of view.

Any help would be much much appreciated

Seems to me that the easiest solution might be to project the background onto the geometry itself with the unshaded material. Then everything else should ‘just work’, I guess.

Could be there are precision artifacts with that approach but it’s what I’d personally try first because it is far easier than any of the other solutions, I think.

1 Like

Even easier…

Render the low poly scene as normal.
Render the background as a quad but without writing or testing for depth (could even just do it in the guiNode but make sure the additional render state’s depth write is turned off for the material)
Use post process shadows.
…that’s it.

Edit: actually, can’t be in gui node because post process won’t run on the gui… just put it in the scene in the Gui bucket.

1 Like

Hi, thanks for the reply.

I’m a bit lost though. Currently I’m doing renderManager.createPreView(“background”, cam); and then attaching a Picture to it, and that gave me the background. I intended to render multiple backgrounds for different resolutions (or just use black borders). Either way if I use a quad the image gets scaled since its not p.o.t and does not line up with my view.

Also though, I drew a quad with depth test and write turned off - nothing showed up through it? When you say render the low poly scene as normal, the low poly scene is supposed to be invisible bar its lighting and shadow casts, tbh I’m not really sure what you ment or how that would result in the shadows or lighting how I want.

Thanks for helping though. I have tried the first approach but the resolution was a problem again. I was thinking I might have to use a shader that recieves the background someway, so it can use that as diffuse and light that, but still use the low poly models positions or something?

You will have to explain the situation with the resolution… I’m not sure I understand.

As far as “nothing showed up through it”, that was kind of the point though. The idea was to only render the low poly stuff to fill the depth buffer so that shadows will work… but it occurs to me that you can do it in a more classic ordering by turning color write off.

So, do like you are, render the background however as a background.
Then render the rest of your scene, presumably made of the low poly ‘map’ as well as your moving characters or whatever. It’s just that for the low poly map, turn color write off. You only want to write depth for that since JME shadows are based on depth.

That’s even easier than anything I’ve said so far because you don’t even have to worry about rendering order (other than rendering the background first).

IMO the simplest way to do this is to create a 1,1 quad place it in the sky bucket and have a shader that projects it full screen, and display the background image as a texture.
Then set the lighting material of the scene in blend mode modulate (through the additional render state).
Note that it will only work if your camera doesn’t move.

here is the code of a material I used to project an image on the background in Adventure.


MaterialDef Background {

    MaterialParameters {
        Texture2D Texture

    Technique {
        VertexShader GLSL100:   MatDefs/background.vert
        FragmentShader GLSL100: MatDefs/background.frag

        WorldParameters {

        Defines {


attribute vec4 inPosition;
attribute vec2 inTexCoord;
varying vec2 texCoord;

void main() {  
    vec2 pos = inPosition.xy * 2.0 - 1.0;
    gl_Position = vec4(pos, 0.0, 1.0);    
    texCoord = inTexCoord;


uniform sampler2D m_Texture;
varying vec2 texCoord;

void main() {
      gl_FragColor = texture2D(m_Texture, texCoord);        
1 Like

Not sure where the modulate thing comes in. He doesn’t want to actually render the low poly scene… just use it for shadows and occlusion. Rendering it would just be rendering a crappier version of what is already prerendered anyway.

The other part is helpful as it occurs to me that for shadows to work the background will have to be rendered as part of the main viewport and not the preview port as he’s doing now.

Well idk , the fist black and white picture also has lighting, with a spotlight

then he’s talking about combining them with GIMP.

My understanding was that he was trying to do that directly in the engine

Yes… he wants to combine them in the engine… presumably with JME shadows so that his characters walking around, etc. are also in shadow. I could have been wrong about that.

My assumption was that he wants to render a low poly scene with shadows but use the high quality non-shadowed render to drape over the low poly stuff so that it looks nice. Perhaps clarification is in order but that’s what I got from his description.

First, sorry I was not clearer about this, I appreciate you trying to help me.

Using what you first suggested pspeed I did achieve what I wanted and hopefully this explains better what I want:

So made by projecting the uv onto the texture, I have the pre-rendered background visible on the model, the shadows, and the light “lights up” my texture. (Can’t seem to get the projection perfect in blender though, floor is constantly messed up)

What I wanted ideally to achieve though was the exact same but just drawing the background image, then use the low poly mesh for depth, light, and shadow.

With renderManager.createPreView for the background image, and doing what you said pspeed with regards to turning off color write I get the depth and shadow part perfectly:

It is only missing the lighting. Worst case I will go with the projected texture, but ideally I’d like to do it without; I have had nothing but trouble making that projected UV work. Again, thanks for your help.

Ah, yes… the lighting part will be trickier. So close though! :slight_smile:

Edit: that could be where blend mode modulate might come in… and turn color write back on and just make sure the color of the low poly scene is muted grey in color or something.

Edit 2: and note, you would have to worry about render order in that case but there are solutions for that.

1 Like

I set the low poly model’s material to BlendMode.Modulate and you are right, some issues with the background

Still getting closer though

So I got the lighting working, shadows still fine.

(background isnt perfectly lined up as my pc died, new pc is win7 which can’t seem to take fullscreen screenshots ;))

The only thing thing that is not working is specular highlights, I have no idea what I could try to get them working.

I got this far by using both suggestions but on 2 different instances of the low poly model. One with colorwrite off and one with blendmode modulate.

I have set the material for the modulate model to shine with:
(also did it to the one without colorwrite just in hope)

mat2.setFloat(“Shininess”, 64f);

But shine does not come through with modulate, any ideas?


Not sure regarding specular. Can you post your whole material setup?

1 Like

Ahhh… course…

When I clean up my code to post it I find an ambient light that’s hiding my specular. Oh how I wish I had found that before I posted. So it’s pretty much working perfectly now. I have a few unrelated issues but I will save them for another topic and another day since everything is working so beautifully now.

Thanks for the help pspeed and nehon

Glad you got it working. It’s a technique I’ve kind of always wanted to have a reason to try. A few people seem to have tried it on the forum before (or similar) but yours I think is the best looking/farthest along.

Keep us posted about your game progress.

That’s pretty.
Glad you fixed your issue.
I wonder why the background looks so grainy though? Is it on purpose?

Thanks. The graininess is because I set the samples in the render really low to get it done, needs a few hours to get a half decent render. I’m going to be using Kerkythea for the final renders, probably going to take a day each or something horrible.

woah…almost real time :wink: