Drawing selector on terrain

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.

Drawing selector on terrain

Postby zealous » Fri Apr 13, 2012 12:45 am

Hello, I'm not strong in English, but I'll trying.

I want paint at terrain in realtime lighted square or maybe circle under the mouse cursor, first step is just receiving flat x,y coords in terrain from mouse coords, it's just raycasting from camera plane and it's done, but next step is directly painting in terrain texture or something similar and there I have a problem. This video is from warcraft 3 demonstrating that I want. http://www.youtube.com/watch?v=IKrZC49QY-c as you can see here is "spell circle" moving with mouse moves. due to distorsion it's obiously understand that it is just rendering on terrain texture. How can I do that? I have .png file with alpha channel, well what next? Oh yes terrain is rendering with EMT_DETAIL_MAP. I see two ways but both of them I can't release, first is writing straight to texture with itexture.lock, and in this case I have question like how write from iimage or there are another simply way to draw image in texture, and I think I have problems because it's permanent writing in texture, but in next frame I need paint image at other point. Second case I think is using shader, I'll just adding my image as third texture and then I make shader in which I pass coords where I need draw selection_tile, but there is also questions, I didn't work with shaders and I do not understand how my shader stack with base material e.g. DETAIL_MAP, and how textures are naming in shaders and many similar newbies question. Excuse me for English once more, and please help :roll:
zealous
 
Posts: 3
Joined: Fri Apr 13, 2012 12:18 am

Re: Drawing selector on terrain

Postby REDDemon » Fri Apr 13, 2012 9:28 am

You need a splatter (there is a good one inside snippets or projects if I remember well )or You can achieve that both using stencil (if you don't have shaders support), or just as post processing effect.

for stencil, don't know if possible with irrlicht because it already disable colors since shadows usually are black.
Istead of flattens a shadow on the ground you flatten your circle. probably will need a minor hack to Irrlicht, but should be
good having some more API for that.

for PP effect:
use planar mapping. The circle is planar mapped on the ground by taking only X,Z coords as parameter (Y wich is normally the height is not necessary). The you find wich are the X,Z coords of the groud's pixels. You add the coordinates of the circle and then you scale to texture space. Of course the circle must not wrapping over edges, else you'll see the circle repeated over the ground.
OpenGL is not hard. What you have to do is just explained in specifications. What is hard is dealing with poor OpenGL implementations.
User avatar
REDDemon
 
Posts: 831
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Re: Drawing selector on terrain

Postby zealous » Fri Apr 13, 2012 7:57 pm

Sorry, I do not understand PP case; what means use planar mapping? is that instead of material? where I can read about this much more in detail :D
I have this(it's from tutorial)
cpp Code: Select all
 
                 scene::ITerrainSceneNode* terrain = smgr->addTerrainSceneNode(
                "../../media/terrain-heightmap.bmp",
                0,                                      // parent node
                -1,                                     // node id
                core::vector3df(0.f, 0.f, 0.f),         // position
                core::vector3df(0.f, 0.f, 0.f),         // rotation
                core::vector3df(40.f, 1.4f, 40.f),      // scale
                video::SColor ( 255, 255, 255, 255 ),   // vertexColor
                5,                                      // maxLOD
                scene::ETPS_17,                         // patchSize
                4                                       // smoothFactor
                );
 
        terrain->setMaterialFlag(video::EMF_LIGHTING, false);
        video::ITexture * tex=driver->getTexture("../../media/terrain-texture.jpg");
        terrain->setMaterialTexture(0, tex);
        terrain->setMaterialTexture(1, driver->getTexture("../../media/detailmap3.jpg"));
        terrain->setMaterialType(video::EMT_DETAIL_MAP);
        terrain->scaleTexture(1.0f, 20.0f);
 

Where and what I must change? Thanks!
zealous
 
Posts: 3
Joined: Fri Apr 13, 2012 12:18 am

Re: Drawing selector on terrain

Postby REDDemon » Fri Apr 13, 2012 8:47 pm

means that you need a shader wich takes as input the depth of your scene, the color of your scene, the texture with the circle, the camera position/orientation, the circle position. And is able to draw the circle directly on the screen.

You'd better look at some shader tutorials ;-)
OpenGL is not hard. What you have to do is just explained in specifications. What is hard is dealing with poor OpenGL implementations.
User avatar
REDDemon
 
Posts: 831
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Re: Drawing selector on terrain

Postby zealous » Fri Apr 13, 2012 9:43 pm

Okay, thanks. However shaders. Well, can you explain me how shaders stack with irrlicht? I saw tutorial no 10. But I do not understand when i creating my own technique based on my shader i need point to base material, that base material applies to texture before or after texture? And how pass texture into shader? Sorry for my totally nooby question, I'm really want to study, but i don't know what i need to read. Also because english isn't my native lanquage and I tangle term "drawing" with "painting" with "rendering". What's the difference between painting and drawing ? :)
zealous
 
Posts: 3
Joined: Fri Apr 13, 2012 12:18 am

Re: Drawing selector on terrain

Postby REDDemon » Sat Apr 14, 2012 8:47 am

you can look at shader post processing framwork. Probably you 'll get something working quickly with that :)4
http://irrlicht.sourceforge.net/forum/viewtopic.php?t=43743

Basically that tutorial is not enough for you because you need 2 render target textures (1 for color and 1 for depth) or a multiple render target.
OpenGL is not hard. What you have to do is just explained in specifications. What is hard is dealing with poor OpenGL implementations.
User avatar
REDDemon
 
Posts: 831
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)


Return to Beginners Help

Who is online

Users browsing this forum: No registered users and 1 guest