About Monkey 2 › Forums › Monkey 2 Programming Help › Layering lighting.
This topic contains 4 replies, has 2 voices, and was last updated by 
 Mark Sibly
 2 years, 5 months ago.
- 
		AuthorPosts
 - 
		
			
				
October 29, 2016 at 1:22 pm #4696
Hi,
I’m working on ways to layer lighting within my gaming framework. Can I do a loop like in this pseudo code?
Monkey1234567891011121314151617181920212223Method New()... Create shadow castersEnd MethodMethod OnRender()App.RequestRender()canvas.BeginLighting()For myobject=Eachin MyList... draw images... add lightsNextcanvas.EndLighting()canvas.BeginLighting()For myobject=Eachin MyOtherList... draw images... add lightsNextcanvas.EndLighting()End MethodThis seems to work for me but I am noticing an issue. Before I continue I wanted to make sure implementing lighting this way is kosher.
October 29, 2016 at 2:41 pm #4697The above does seem to work. In the attached image I have lighting applied to two separate layers of asteroids. You can see that this so because the bright light of the weapons impact does not effect the blue lighted layer of asteroids below. It is awesome to be able to layer lighting this way.
I have encountered an issue where a light will wink out based on map position. I am not sure why this happens yet but I am able to get the light to stop winking out by moving my particle effect out of lighting (Begin/End Lighting). I’m not altering viewport or scissors with particles (uses non-bumped images) and I am able to draw other non-bumped images with no issues while lighting is on.
I will try to duplicate this issue and post some code assuming layering lighting in this way is proper.
Attachments:
October 29, 2016 at 10:44 pm #4700> Can I do a loop like in this pseudo code?
This should work fine, just remember that EndLighting() clears out all add lights and shadowcasters, but that’s generally what you want if you’re doing ‘layers’.
Beats the hell out of the old ‘renderer’ system doesn’t it?
October 30, 2016 at 1:41 am #4701Beats the hell out of the old ‘renderer’ system doesn’t it?
OMG Yes! It’s flexible enough to just sort of plugin to my window frameworks render. Layering it ought to yield some cool effects.
but that’s generally what you want if you’re doing ‘layers’.
It is. For example, in my case, I can layer impact lighting among five layers of asteroids. That should add to depth. Time to experiment.
October 30, 2016 at 5:46 am #4703I’d recommend doing things like this if possible:
For each layer:
Draw unlit background (if any)
BeginLighting
Add lights and draw any opaque/alpha stuff that needs to be lit.
EndLighting
Draw non-additive particles (if any)
Draw additive particles/fake lights.
Draw unlit overlays (if any)
Next
Drawing particles/fake lights inside lighting should still work, but it will incur extra overhead.
 - 
		AuthorPosts
 
You must be logged in to reply to this topic.
