How lighted is my screen

Problems building or running the engine, queries about how to use features etc.
Post Reply
User avatar
Darkauk
Gnoblar
Posts: 7
Joined: Thu Jul 31, 2014 11:17 pm
Location: France

How lighted is my screen

Post by Darkauk »

Hi everybody :)
I want to know how lighted is my screen.
If the player is in a room without light, his stress increase. But I have absolutely no idea how to implement this :(

Thanks for all your answers, and sorry for my bad English I'm French :D
User avatar
paul424
Gnome
Posts: 314
Joined: Thu May 24, 2012 7:16 pm
x 13

Re: How lighted is my screen

Post by paul424 »

What I understand is that you want to simulate a scene 1) there is no light whatsoever ( absolute darkness -- draw a black rectangle ) 2) there is little light .
You haven't written what kind of game it is ( do you see the scene by the eyes of your character or third person -- al'a Tomb Rider ? ) , Is your scene outside ( than stars and moon give a little light ) , semi-opened ( ruined buildings etc. ) or closed ( dungeons , cellars and such ... ) ?
Please have a look at gamma correction anyway : http://en.wikipedia.org/wiki/Gamma_correction
Also you can ask in French in here, and maybe some nice user translate it for you ? Also do you know what screen is in English ? : https://www.google.com/search?q=screen& ... 80&bih=630
User avatar
Darkauk
Gnoblar
Posts: 7
Joined: Thu Jul 31, 2014 11:17 pm
Location: France

Re: How lighted is my screen

Post by Darkauk »

Thanks for your answer.

In fact, I already have a scene with lights. What I want is to know how illuminated is my rendering.
After some research, I have found RenderWindow::copyContentsToMemory, but when I use it, I juste have a black rendering instead of my scene.

Code: Select all

Ogre::Viewport *v = camera->getViewport();

    int left, top, width, height;
    v->getActualDimensions(left, top, width, height);

    Ogre::PixelFormat format = window->suggestPixelFormat();
    int outWidth = width;
    int outHeight = height;
    int outBytesPerPixel = Ogre::PixelUtil::getNumElemBytes(format);

    Ogre::Box extents(left, top, left + width, top + height);
    Ogre::PixelBox pb(extents, format);

    window->copyContentsToMemory(pb); // -> make a black rendering

    float result=0.;

//average the value of the pixels ( 0 = dark, 255=blank)

    for(int i=0; i<pb.getWidth(); i++)
        for(int j=0; j<pb.getHeight(); j++)
        {
            Ogre::ColourValue c = pb.getColourAt(i,j,0);
            result += (c.b+c.g+c.r)/3.;
        }
    result /= pb.getHeight()*pb.getWidth();

    std::cout << result << std::endl;
Sorry for the "screen" :roll:
User avatar
areay
Bugbear
Posts: 819
Joined: Wed May 05, 2010 4:59 am
Location: Auckland, NZ
x 69

Re: How lighted is my screen

Post by areay »

That's an interesting idea and problem you have there. You'll have to be pretty careful with it.

If it is a FPS game then an honest way of doing this would be to create an RTT from the character's eyes looking ahead. You'd do this at a pretty low resolution then apply a blur or some other convolution of the image data then sample it to determine overall luminosity. Based on this you'd use it to increase or decrease the character's fear levels. You might only do this once per second and use some sort of fuzzy-logic type algorithm with high and low watermarks to avoid flapping between scared and not-scared states. You'd have to be careful to avoid situations where the player was standing in a well-lit area but was looking closeup at a black object which would affect the method I detailed above.

Another way would be to have a proxy-object of some kind centred inside the model (or just the character's head) and then figure out how much light is hitting it by doing raycasting to light sources.

If you use the whole viewport image data you might start getting interference from GUI elements or, depending on how your camera works, might be able to cheat by rotating the camera around the character so the screen is lighter overall by looking back at where the character came from or directly at a light source etc.

Let me know what you do, I'm interested!
User avatar
Darkauk
Gnoblar
Posts: 7
Joined: Thu Jul 31, 2014 11:17 pm
Location: France

Re: How lighted is my screen

Post by Darkauk »

Hi, thanks for your answer :D

I'm going to take a look to create a RTT, it might be a good solution !

Your idea of raycasting to light sources seems very interesting, but how do you do that ? Are we need to raycast in all directions ?
User avatar
areay
Bugbear
Posts: 819
Joined: Wed May 05, 2010 4:59 am
Location: Auckland, NZ
x 69

Re: How lighted is my screen

Post by areay »

Darkauk wrote:Your idea of raycasting to light sources seems very interesting, but how do you do that ? Are we need to raycast in all directions ?
No, not at all. You just need to maintain a collection of light sources and then raycast directly to them. This should be easy if you are using real Ogre::Light's as your only lights because you can get a list of from Ogre's scenemanager. Alternatively, you could keep a std::vector collection of light sources, this would also let you treat non-Ogre::Light objects as light sources too. For example, you may have models or textures which you treat as lights despite not actually lighting the scene. Using a STL collection means you could manage this easily and add/remove things that you think should impact the characters 'fear level'.

So, after you've figured out which light sources you're interested in, you would raycast straight at them from the character and then, using Ogre's Ogre::RaySceneQueryResult (like in http://www.ogre3d.org/tikiwiki/tiki-ind ... =Tutorials), you would determine if there are solid objects between the lightsource and the character. If there are objects in the way then the light doesn't count towards the overall lightHittingTheCharacter variable. If there is nothing blocking then you'd use the distance and luminosity power of the lightsource and add that to the variable I mentioned before. You could get creative by using visibility masks to ignore objects that will show up in your raycast resultset so a moth/bird/smallobject placed between the character and lightsource wouldn't impact the fear level.

This is a pretty crude system because it doesn't take into account ambient lighting, reflections and such but with some tuning it could work well.

Hope that helps
User avatar
Darkauk
Gnoblar
Posts: 7
Joined: Thu Jul 31, 2014 11:17 pm
Location: France

Re: How lighted is my screen

Post by Darkauk »

Thank you very much, I'll try this as soon as possible !
I'll get back to you if I try something else :)
Post Reply