Sand and grass mixing.

radome

Jeff Peterson
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.

Thanks
 
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.
 
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?
 
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.
 
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?

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.
 
grass2dirt.jpgblend.jpgblend_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.
 

Attachments

  • _shader.txt
    1.6 KB · Views: 365
  • grass.jpg
    grass.jpg
    100.6 KB · Views: 11,844
  • grass2drt.jpg
    grass2drt.jpg
    88.6 KB · Views: 432
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.

simply:
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?
 
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)


Dave
 
@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 !
 
Thx Cam, I'll need it.
Does my code work or not ? Any difference ?

Actually, I'm looking at decompiled/disassembled shader code from other sim games, just to get a better understanding how it internally works. Will probably bring/port some of them to Racer...

----8<------------------

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.
 
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.

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.

http://www.deep-shadows.com/hax/3DRipperDX.htm

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 :

http://http.developer.nvidia.com/Cg/index.html

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

http://racer.nl/reference/gpushader.htm
 
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.
 
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.

Dave
 
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.
 
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.
 
Sorry about the content being the flowers from the chapter. I haven't made one of grass yet.
https://www.cks-store.com/tile_pack.ppm

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.
 
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).
http://dl.dropbox.com/u/20733494/wangindex.ppm
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.
bnjuE.jpg


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
mode=linear
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:
yKJvu.jpg
 

Latest News

Online or Offline racing?

  • 100% online racing

    Votes: 76 7.1%
  • 75% online 25% offline

    Votes: 114 10.7%
  • 50% online 50% offline

    Votes: 155 14.6%
  • 25% online 75% offline

    Votes: 293 27.5%
  • 100% offline racing

    Votes: 423 39.7%
  • Something else, explain in comment

    Votes: 4 0.4%
Back
Top