Render Burning Object (ie.building) with deformation?

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
popo
Posts: 2
Joined: Thu Mar 15, 2007 5:48 am

Render Burning Object (ie.building) with deformation?

Post by popo »

I'm considering to render a burning building of deformation, but cann't find a good way.

The way i thought out is to use an formula or algorithm to dynamically change vertex of the polygon ( not efficient....)

But i still cann't think out the way about the change of texture mapping with burning.

Is there anyone have good idea about it?
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

Two ways comming on my mind:

You can modify scene node material atributes like AmbientColor, DiffuseColor, EmissiveColor or others,

or you may manipulate texture itself.

small demo which will burn like cube. You have to provide your own texture.bmp file:

Code: Select all

#include <irrlicht.h>
using namespace irr;

// this code will work only if texture is in default 32 bit color format (ECF_A8R8G8B8) 

void burn(scene::ISceneNode* node, u32 amouth)
{
    // get texture of node
    // note that depending on type node may have more than one material with seweral textures each
    video::ITexture* texture = node->getMaterial(0).Texture1;
    
    // find size of texture
    core::dimension2d<s32> size = texture->getSize();
    
    // get pointer to texture data
    s32* p = (s32*)texture->lock();
    
    for(s32 i=0; i<size.Width*size.Height; i++)
    {
        // get color of pixel
        video::SColor color = p[i];
        
        // darken color until black
        if(color.getRed() > amouth) color.setRed(color.getRed() - amouth);
        else color.setRed(0);
        
        if(color.getGreen() > amouth) color.setGreen(color.getGreen() - amouth);
        else color.setGreen(0);
        
        if(color.getBlue() > amouth) color.setBlue(color.getBlue() - amouth);
        else color.setBlue(0);
        
        // set new color to pixel
        p[i] = color.color;
    }
    
    texture->unlock();
}

int main()
{
    IrrlichtDevice *device = createDevice(video::EDT_OPENGL, core::dimension2d<s32>(640, 480), 16, false, false, false, 0);
    
    device->setWindowCaption(L"Burn Cube");
    
    video::IVideoDriver* driver = device->getVideoDriver();
	scene::ISceneManager* smgr = device->getSceneManager();
	
	scene::ISceneNode* node = smgr->addCubeSceneNode();
	node->setMaterialTexture(0, driver->getTexture("texture.bmp") );
	node->setMaterialFlag(video::EMF_LIGHTING, false);
	
	smgr->addCameraSceneNode(0, core::vector3df(7,10,-15), core::vector3df(0,0,0));
    
    // howe much to burn
    s32 n = 150; // change to burn more/ less
    
    // since color RGB components are stored as u32 we can nott decrement with 
    // lower number than 1. To make burning proces bit slower we burn cube only 
    // once per 100 frames
    s32 frames = 0;
    
	while(device->run())
    {
        driver->beginScene(true, true, video::SColor(255,100,101,140));
		
		if(frames > 0)
            frames--;
		else
		{
		  if(n > 0)
            {
                burn(node, 1);
                n--;
            }
            frames = 100; // change to burn faster/slower
        }
        
        smgr->drawAll();
        
		driver->endScene();
    }
    device->drop();
    
    return 0;
}
imjinc2k
Posts: 5
Joined: Mon Dec 25, 2006 6:14 am

Post by imjinc2k »

I'm thinking use a vertex shader for the deformation, and a pixel shader with sliding alpha texture to create 'holes' in the wall. I've never personally used a VS for deformation before. I've only seen the results. You may not even need to slide the texture. If you applied a static alpha 'rip' texture to the deformed surface, as you pull that vertex outward the rip would get larger as well, just from the UVs. I suppose you would still want to make sure it was aligned with the vertex you were tugging on though. I dunno, this is all wild speculation :)
Zeuss
Posts: 114
Joined: Mon Nov 08, 2004 9:02 pm
Location: Canberra - Australia
Contact:

Post by Zeuss »

In my little car game 3XTREME I have car deformations based off collisions.

It simply runs through the mesh buffer and pushes it in, bit slow but not too bad, but not something you would want to do each frame.

I have also done a little VS and PS programming, but a bit rusty, I don't know if there is a way to have the Vertex's passed in by reference so to speak. So any changes to the mesh made within the vertex shader changes the mesh stored in graphics card memory, that would be quick clean and fast.

the only vertex deformation shader examples that I have seen so far, only change the local vertex that has been passed in to the shader, no permanent mesh change.
Help make Irrlicht even Better! Create and submit your own Irrlicht Extension
Want a Games Education? Try The Academy of Interactive Entertainment
sio2
Competition winner
Posts: 1003
Joined: Thu Sep 21, 2006 5:33 pm
Location: UK

Post by sio2 »

Zeuss wrote:So any changes to the mesh made within the vertex shader changes the mesh stored in graphics card memory
Currently Irrlicht doesn't store vertices in graphics memory. Every vertex goes across the bus every frame.
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

sio2 wrote:
Zeuss wrote:So any changes to the mesh made within the vertex shader changes the mesh stored in graphics card memory
Currently Irrlicht doesn't store vertices in graphics memory. Every vertex goes across the bus every frame.
sweet so this means we cud modify vertices at our will without loss in speed? (As opposed to vertices being stored in graphics where it wud be much faster to just leave them alone lol)
Post Reply