On 02/26/2012 06:58 AM, Cao Wenjie wrote:
Hi,


As OSG newbie, I'm working on a terrain texture brush task.

My goal:
Use mouse controlled brush paint grass area on a prebuild terrain(has original 
texture)

Progress:
Now I successfully complete a demo, but the method I use seems unattractive.

My implementation now:
(Use OverlayNode method)
1. Load prebuild terrain(T1) and it to scene.
2. Duplicate the terrain node(Terrain T2).
3. Change the texture of T2, make is full of grass texture.
4. Use T2 as OverlaySubgraph, T1 as child to OverlayNode, so now, in the scene, 
I can see a single terrain full of grass.
5. Set color of each vertex in T2, make it complete transparent.
6. handle my mouse brush area, calculate effected vertices of T2 in brush area, 
and raise the transparent value of those vertices.
7. now the brush area will gradually show grass texture.

I did some search about the question, seems multi-texture is another way, but I 
didn't figure out how. As I need control blend on individual vertex(brush 
area), I only found functions to change the blend of whole texture units.

  Any tip of a smart way will be grateful :-)

Hi, CaoWenjie

The Source engine (used by Half Life 2) uses a multitexturing technique to achieve what you're trying to do. I implemented a viewer for Source engine .bsp files a while back. If you look in src/osgPlugins/bsp/VBSPReader.cpp, starting around line 803, you'll see a way to do this using TexEnvCombine operations on two texture units.

The first combiner (on texture unit 0) does the interpolation between the two textures. The second combiner (on unit 1) just does the normal modulation between the combined color from the first unit and the vertex color.

In this case, the first combiner uses the Alpha value from the vertex color (SRC_ALPHA) to decide how much to blend between the two textures (that's Operand2 in the INTERPOLATE operation). In your case, you'd want to set Operand2 based on your brush value.

Note that your graphics card needs to support the ARB_tex_env_crossbar extension for this to work (most modern cards do).

Hope this is useful...

--"J"

_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to