Night/Dayish skydome

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
Tannz0rz
Posts: 35
Joined: Fri May 08, 2009 12:25 am
Location: Orlando FL, USA

Night/Dayish skydome

Post by Tannz0rz »

To be honest, I don't know what I'm doing half of the time when it comes to IrrLicht, but I've been messing around today and found this:

Code: Select all

ISceneNode* skydome;
ITexture* skytex;
u8 aph=200;
bool direction;

//==========

void Sky()
{
	u32 size = skytex->getSize().Width * skytex->getSize().Height;
    u16* color = (u16*)skytex->lock();
	u8 n_col;
	video::SColor m_col;

    for(u32 j=0; j<size; ++j)
	{
		m_col.setRed(getRed(color[j])-aph);
		m_col.setGreen(getGreen(color[j])-aph);
		m_col.setBlue(getBlue(color[j])-aph);
		m_col.toOpenGLColor(&n_col);
		color[j] = (u16)n_col;
	}
    skytex->unlock();

	skydome->setMaterialTexture(0, skytex);

	if(!direction) aph++;
	else aph--;

	if(aph >= 255) direction = true; 
	if(aph <= 150) direction = false;
}

//==========

int main()
{
	skytex = driver->getTexture("../draganddroptest/media/skybox/skydome.jpg");
	skydome = smgr->addSkyDomeSceneNode(skytex);
//...
while(device->run()) 
	{ 
		driver->beginScene(true, true, SColor(255,100,101,140)); 
		Sky();
		smgr->drawAll(); 
		guienv->drawAll(); 
		driver->endScene(); 
	} 

	device->drop(); 
	return 0;
}
It creates a rather cool atmosphere, somewhat like the passing of days. Not sure if anyone were to want to use it or not, but I thought that I would just share it with you all anyways.
Last edited by Tannz0rz on Mon Dec 28, 2009 3:07 pm, edited 1 time in total.
3D Ace
Posts: 66
Joined: Sun Oct 04, 2009 8:47 am
Location: Swakopmund, Namibia
Contact:

Post by 3D Ace »

Nice. This will come in handy. :)
Everything is possible, IF you know how.
Checkout my website for my upcoming game.(Currently on hold!)
http://www.projectbattle360.webege.com
Image
Virion
Competition winner
Posts: 2149
Joined: Mon Dec 18, 2006 5:04 am

Post by Virion »

To be honest, I don't know what I'm doing half of the time when it comes to IrrLicht
:lol:

anyway that's surely something cool.
My company: https://kloena.com
My profile: https://zhieng.com
My co-working space: https://deskspace.info
My game engine: https://kemena3d.com
sio2
Competition winner
Posts: 1003
Joined: Thu Sep 21, 2006 5:33 pm
Location: UK

Post by sio2 »

OMG. :shock:
I don't know what I'm doing half of the time when it comes to IrrLicht
Well, you said it yourself... :lol:

For educational purposes, here's a few issues:

1. Locking a texture every frame. skytex probably has to travel over the bus to vram after every unlock().
2. calling render() on a scenenode just before the smgr->drawAll() renders it again?
3. Assumed texture format of skytex texels.
4. circumventing Irrlicht's features, namely that this may be better suited to a scenenode

This screams out "replace me with programmable shaders". :wink:
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

I think the same effect could be achieved if the skybox would give accesst to its mesh, and thus allowing to change vertex colors to something darker.
sio2
Competition winner
Posts: 1003
Joined: Thu Sep 21, 2006 5:33 pm
Location: UK

Post by sio2 »

hybrid wrote:I think the same effect could be achieved if the skybox would give accesst to its mesh, and thus allowing to change vertex colors to something darker.
A lock and RMW on every vertex in a vertex buffer?

Either a DX5-style fixed-function triadic texture-stage blend or a simple pixel shader would do the trick (even SM1 can handle this)...
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Since the eight vertices of the mesh are anyway sent each frame there's no real benefit by using more than one texture. At least not in general. But I didn't argue that there's no other way, I just gave one other option.
sio2
Competition winner
Posts: 1003
Joined: Thu Sep 21, 2006 5:33 pm
Location: UK

Post by sio2 »

hybrid wrote:Since the eight vertices of the mesh are anyway sent each frame there's no real benefit by using more than one texture. At least not in general. But I didn't argue that there's no other way, I just gave one other option.
Eight vertices? How many vertices does the default skydome have (see OP code)?

Plus, I'm not suggesting an extra texture. A fixed-function triadic blend op uses a single texture-factor colour per texture stage to be used with the given texture op - the texture factor could be modulated (in hw) per-fragment instead the usual vertex-colour*fragment, for example.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Well, skydome has some more, but my post was about skyboxes (as explicitly mentioned). Anyway, just provide some code and we'll see.
sio2
Competition winner
Posts: 1003
Joined: Thu Sep 21, 2006 5:33 pm
Location: UK

Post by sio2 »

Well the original post references skydome not skybox.

Anyway, I'm commenting on how poor the snippet is as a general way of going about things. Should we not be educating people about these potential pitfalls?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Yes of course, hence provide and allow for all "good" ways. But those solutions which require new materials or new shaders should also come with some example code to make it possible for people to use them right away.
Tannz0rz
Posts: 35
Joined: Fri May 08, 2009 12:25 am
Location: Orlando FL, USA

Post by Tannz0rz »

hybrid wrote:Yes of course, hence provide and allow for all "good" ways. But those solutions which require new materials or new shaders should also come with some example code to make it possible for people to use them right away.
Indeed.

If you've got spare time, an example would be appreciated.
Post Reply