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?
Render Burning Object (ie.building) with deformation?
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:
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;
}
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
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.
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
Want a Games Education? Try The Academy of Interactive Entertainment
Currently Irrlicht doesn't store vertices in graphics memory. Every vertex goes across the bus every frame.Zeuss wrote:So any changes to the mesh made within the vertex shader changes the mesh stored in graphics card memory
Irrlicht Demos: http://irrlicht.sourceforge.net/forum/viewtopic.php?f=6&t=45781
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)sio2 wrote:Currently Irrlicht doesn't store vertices in graphics memory. Every vertex goes across the bus every frame.Zeuss wrote:So any changes to the mesh made within the vertex shader changes the mesh stored in graphics card memory