Showing posts with label Light. Show all posts
Showing posts with label Light. Show all posts

Wednesday, January 4, 2012

XNA : Ambient 2D Light

Hi,

To apply an ambient light in your game,a very simple way without using shaders.
To do this, simply edit color when Draw each sprite.


Add a the top of your game class :

float ambient = 1f;
Color ambientColor = Color.White;

 In the Update method :

 KeyboardState c = Keyboard.GetState();
 if (c.IsKeyDown(Keys.Space))
 {
    ambient -= 0.01f;
    if (ambient <= 0)
       ambient = 1f;
 }

And finally , to apply ambient on sprites :

Color drawColor = new Color(ambientColor.R / 255f * ambient, ambientColor.G / 255f * ambient, ambientColor.B / 255f * ambient);
spriteBatch.Begin();
spriteBatch.Draw(mySprite, new Vector2(0,0), drawColor);
spriteBatch.End();

As you see, it's very easy :) With this, you could simulate for example day cycle.

XNA : Little 2D Tile Lighting test

For a new project, i test have rewrite my light engine from C++ and 3D, to XNA in 2D.
 

Here a first preview :

I will explain my technique in few times

Tuesday, January 3, 2012

Simple minecraft clone in C++

A few weeks ago I was bored on my server Minecraft, suddenly I was motivated to understand how it could be done and then make a prototype Minecraft engine.

For this, I wanted to try new things. So, I went on the C + + with the engine Ogre3D.

Here are some previews of my work :
There is 2 differents light mode , procedural and Ogre3D Lighning