Ok, I’ve just committed/pushed some pretty major improvements/changes to mojo.
First up, mojo can now do 2d normal-map style lighting! It’s also very easy to use:
- Load ‘bumpmap’ images with Image.LoadBump(). This takes 3 file paths – a path for the ‘diffuse’ map, a path for the ‘normal’ map, and an optional path for the ‘specular’ map.
- Load ‘light’ images using Image.LoadLight(). Currently, all lighting is image based, ie: the image describes the size and and falloff of the light.
- Inside OnRender, use Canvas.BeginLighting() to put the canvas into ‘lighting mode’.
- While in lighting mode, use Canvas.AddLight() and Canvas.AddShadowCaster() to add lights and shadow casters to the canvas. These are transformed by the current 2d drawing matrix at the time they are added and, in the case of lights, the light color is also modulated by Canvas.Color.
- Finally, use Canvas.EndLighting() to actually render (and flush) lights and shadows.
- As in mx1, you can also add shadow casters to image so they’re automatically added when you DrawImage.
There are few restrictions on what you can do in lighting mode: you can’t modify the viewport, scissor or ambientlight properties, or Clear() the render target – this stuff must all be setup before you enter lighting mode – but apart from that you can use the full canvas API.
There are 2 simple lighting demos in the bananas folder: simplelight and lightsparks.
Secondly (and possibly breakingly) I’ve modified the texture filtering system. TextureFlags no longer contains ‘Filter’ or ‘Mipmap’ enums (currently, it only contains ‘Dynamic’). I considered leaving these in as NOPs for backward compatibility but I think that’d just confuse things. Instead, texture filtering is selected on the fly via Canvas.TextureFilter (similar to Canvas.DisableTextureFiltering – now deprecated), or you can force an image to using a particular filter mode via Image.TextureFilter. This is probably the change that will the affect the most projects (I had to tweak a few bananas) but it should be easy enough to deal with – basically, forget about texture flags unless you’re creating a dynamic image.
Thirdly, I’ve added some renderstate stuff to the Image class including BlendMode, TextureFilter and Color properties. BlendMode and TextureFilter default to ‘null’, which basically means ‘use the canvas property’, ie: old mojo behavior. But if you set these to non-null, they will override the canvas properties. Color defaults to white, and is modulated by canvas color.
Finally, the entire shader system has been completely rewritten. I severely doubt anyone was using the dodgy old undocced (and @hidden) system, but if you were, sorry, but it had to be done. The new system isn’t quite ready for public use yet, but it should be much easier for peple to play with shaders once it is.
Whew! I’ll probably do a follow up post tomorrow going into a bit more detail on how this stuff works, but that’ll have to do for now as I’m stuffed!