1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Sand and grass mixing.

Discussion in 'Racer Physics and Technical' started by radome, Mar 2, 2011.

  1. I would like to see some treatments by the community of a number of "sand and grass mixing" examples.

    re: http://www.racer.nl/tutorial/shading_tracks.htm

    Like where world-mapped grass texture is made to look radomly patchy with a more precisly mapped control texture resulting in faithful representations of particular real-world scenes.

  2. I've created a track which uses the mix shader, so yeah it looks not that bad...check LiL Lake in the tracks section, more updates to come soon.

    Was also thinking to add some decals...
    & also, somehow we would need someday a proper smoke for those mixed textures, for now it's looking kind of weird.
  3. Thanks QCM, I like it. I'm looking for guidance on making a grass surface for my track which will closely follow the real thing. Is it possible to have fairly high-res sand and the grass textures which are world-mapped and then have the control texture mapped precisely and at a different scale?
  4. I posted a bug with the mix cg's where headlights cause the blend areas to be black at night so if you have a fix please post it.
  5. So I'm thinking that what I'm looking for is texture painting in Blender 2.5.
    is a tutorial that shows how to do it. Just need to figure out how to export the GLSL shader to a cg shader.
  6. Yeah sure, the prob was, they recently updated the shader, so I had some struggle to make it work again...Had to edit & get an understanding of what they've been doing.

    With CG anyway, possibilities are quite infinite, so you could come with a slight modification of the original shader to get your ideas materialized.
  7. grass2dirt.jpg blend.jpg blend_trk.jpg
    Here is what I have done with my Watkins Glen track that works quite nicely.

    I coludn't upload the gras and grass2drt.tga images as the forum won't accept them.

    I'll convert them to .jpg's and upload them, they don't use an alpha channel.

    Attached Files:

  8. Doesn't look that bad, thx for sharing !
  9. I've been playing with the Wang Tiling example stuff from the Nvidia GPU Gems 2 CD content. Using GNU Octave, and with very little fiddling I was able to get the tiles.m program to output a packed set of Wang tiles. It took a lllllooooonnnnnnggggg time though. I kept thinking that the script was simply locking up but when I attached the process to gdb it appeared to be "working". So I just finally let it go and after about an hour it produced a couple of windows. One showing the separated Wang tiles and another showing them all packed together.

    download the matlabPyrTools package from http://www.cns.nyu.edu/~lcv/software.php and un-gzip-tar it
    in Octave do an addpath command for the root directory of the unpacked tools and one for the MEX folder within.
    refer to (and/or edit and use) the compile script included in the MEX folder. Use mkoctfile --mex and comment out the <matrix.h> includes

    Has anyone done any work on a Wang tile shader?
  10. I've used a similar technique, for both non-repeating edge tiles, and repeating asphalt surface tiles.

    Camsinny helped me with a randomiser for the UVW coords so I could just generate my grid and texture atlas, and then randomise the material mappings for each quad.
    It worked really well too. Repeating is not evident at all, the surfaces look random and realistic.

    I'll be using the technique in future too. It just makes sense moving forward. We want higher poly road surfaces to drive on, so using lots of smaller texture fragments with more random variation of the surface appearance, doesn't cost much, indeed it may result in more performance and better visual quality!
    You just need to generate the texture so it can be used in that manner (hardest part from my experience)

    It looks like the tools above automate some of that process for you.

    As said, the main one was generating the nice textures so they could repeat, and also contain specific details where needed (ie, decal certain tiles with say damage or something, that you use much more rarely)

  11. @randome

    No I didn't yet but I've read the official docs. I would be interested in testing new shaders, so if you got something new to try, let me know, I'm here.

    Looking forward from your work !
  12. QuadCoreMax,
    How do you profile, disassemble, or Tee-off code from other games. I would like to extract the cg source from the output of CgWangTilesC.cpp (from the GPU Gems 2 Chapter 12 CD Content) before it gets compiled into assembly code.

    Thanks for any insight, tips or direction you can provide on this subject.
  13. Okay, here's the trick, I use 3D Ripper DX (Xentax tool) which is a tool which extracts everything from a 3D DX9 scene : dds textures, shaders + obj & mtl files :). I've been learning & looking at the shader 'disassembled' code to see what instructions it throws thru the shader engine. It's then a matter of reverse-engineering the code into cg files.


    I'm also using as an Cg editor : CgEddie : http://sirmike.org/projects/cgeddie/
    + gdebugger for deeper Racer Cg understanding (stencil, alpha, light, AO etc maps). http://www.gremedy.com/
    Don't forget to disable your racer.ini FBOs...

    Racer uses arbvp 1 + arbfp 1 profiles, more here :


    You must know Racer shader 'hardcoded' variables for custom implementation :

  14. I looked at their online code - http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter12.html - it appears they have two methods for finding the tile.
    1) based on the edges of the tile - could be implemented for any pseudorandom grid across the UV map, since it converts from a pair of edges to a coordinate in the texture. Could also be painted on at a low resolution (1 pixel per tile) to give the game hints about what texture to use, if you put specific details on some tiles. For example, you could do the sand-grass blending with a set of Wang tiles where 0-0 is sand, 1-1 is grass, and 0-1 & 1-0 are the borders, and then have the index texture show 0 where there's sand, 1 where there's grass.
    2) an index texture that is specifically generated for this purpose - each pixel represents a single tile, and has red/green channels indicate where on the tile texture to grab from.

    First option would require implementing more code in the cg shader - a pseudorandom function (Perlin noise is available to road noise, but I think not to shaders yet), the indexing function (which as written would be very inefficient - I'd probably spend some time changing it...), and then the shader itself to combine these things.

    Second option is probably easier to implement, will use a little more texture memory, but also requires figuring out these C files to generate the right indexing texture.

    Of course in both cases, code to generate the Wang tiles is needed. I'll have to look through that Octave code.
  15. Thanks Stereo !
  16. So the Wang tiles are the textures basically? That is the hardest part of it all.

    Mapping UVW's isn't hard in authoring, rather than automating it randomly on the fly (sounds costly vs a lookup)

    Lookup (or uvw's set in the model), also allows you more artistic creativity to use exactly the tiles you want where you want them.

  17. Thank you all,
    You've provided a lot of info to digest. I think the Wang tiles are more for non-UV mapped texturing. I'm trying to get Nvidia's FX Composer with shader debugger plugin installed. As regards the textures being the hardest part, the matlab scripts do that part of it. The shader author "just" has to work out the Cg code to map the correct fragment from the possible choices on the fly. The author of the Chapter 12 article, Li-Yi Wei provides an example fragment shader but I find it difficult to grasp that part.
  18. It's pretty straightforward to copy it over, I hope. Could you post some sample textures without the red/green edge lines marked? (both the Wang tiling texture and the index texture) Something I can throw ingame in place of Carlswood's grass, to make sure the shader works. I don't have Octave/MATLAB installed right now so I can't generate my own. I think I could work out the index texture on my own, but I don't know how to do the other one.
  19. Sorry about the content being the flowers from the chapter. I haven't made one of grass yet.

    I didn't follow closely what they meant about the index texture in the article. I didn't make one but I did fiddle with this PPM in gimp. Using the guides function I divided it up into 16 equal blocks to satisfy myself that all the colored borders were packed as described in the article.
  20. Hmm. I think this is the right way to create an index texture. This one's for a 4x4 tiling like the flowers texture (two edge types).
    I'm not 100% sure I have the y axis correct because they weren't entirely specific in the chapter. Could take a vertical mirror to correct.
    Code written in R cause I'm more familiar with it... I can generate more like it fairly easily if it's correct.

    I guess once I have the shader implemented, I'll see if it works right... :p

    Edit: Modified texture so I could see what was happening. Numbered from the bottom left (0) across, then the next row up, and so on, to 15.

    The column scramble is working, anyway - you can see it goes fairly randomly. But row scramble, not so great (thus 12-15 are pretty much all in the same row, as are 8-11, 4-7, 0-3). I believe this is due to a bug in my index texture, cause when I use the x-coord both ways, it looks much more scrambled.

    I'm also having trouble with
    Within the track.shd. The .tga has only 4 brightnesses: 0%, 33%, 66%, 100%. And yet this is producing weird in between results...

    & number free result, which looks more random since the tiles aren't all marked: