can i tile a material across a terrain elevation?>

Software: Away3D 4.x

alpoman, Jr. Member
Posted: 02 April 2016 03:22 AM   Total Posts: 40

can i tile a material across a terrain elevation?>
if I set repeat to true, and scale uv to 2,2, it only renders it smaller in corner and the rest is black- doesnt repeat as a normal mesh would.  Am i missing something?

thanks for any tips!

andy

   

Avatar
Fabrice Closier, Administrator
Posted: 02 April 2016 10:12 AM   Total Posts: 1265   [ # 1 ]

material.repeat = true;
the scale of uv must be set on subgeometry.

the original mapping must be 0-1 on both u and v axises.
use Projector util class (projection top) if its not the case before applying scale to subgeometry

 

   

alpoman, Jr. Member
Posted: 02 April 2016 02:27 PM   Total Posts: 40   [ # 2 ]

I think I understand what you mean, I just dont know the correct syntax maybe.

var tMaterial = new TextureMaterial(Cast.bitmapTexture(Sand2),true,true,true);
tMaterial.repeat=true /// already declared above
myterrain.material=tMaterial
myterrain.geometry.subgeometry.scaleUV(5, 5);

ReferenceError: Error #1069: Property subgeometry not found on away3d.core.base.Geometry and there is no default value.

please a hint?

andy

 

   

alpoman, Jr. Member
Posted: 02 April 2016 02:44 PM   Total Posts: 40   [ # 3 ]

Fabrice, btw, using your program I noticed that a terrain generated using your built in terrain creator,  the uvs work perfectly as I’m able to tile it 2,2 correctly.  So, I suppose your software is automaticlly selecting it’s subgeometry to tile it correctly to fill the mesh.  I wish everything was as e wasy as PREFAB:)  I am proceduraly generating my terrain at runtime, so unfortunately I can’t use PREFAB for the terrain, but it is great for my other models and for learning in general -

thanks Fabrice,

andy

 

Image Attachments
sample.jpg
   

Avatar
Fabrice Closier, Administrator
Posted: 02 April 2016 05:13 PM   Total Posts: 1265   [ # 4 ]

your error is that you try to access a subgeometry by literally calling it subgeometry. the mesh geometry may have more than one subgeometries, therefor they are stored into a subGeometries vector.
the same code as myterrain.geometry.subGeometries[0] would do…
if course if your terrain is large, you would need loop and replace 0 by your iterator.
But (on top of my head) you should scale directly using mesh.geometry.scaleUV method. The class will update its geometries.

I wish everything was as easy as PREFAB:)
Glad to hear its handy to you smile  I hope release v3 one day, its now doing a zillion more things than the current public version…

 

 

   

alpoman, Jr. Member
Posted: 02 April 2016 05:51 PM   Total Posts: 40   [ # 5 ]

You are correct, and thank you sooo much, you are brilliant Fabrice!
I was able to access it as you describe, just one subgeometry, [0] as you said.
But, then I discovered that scaleuv the main terrian geomerty also works, but my error was I was using an iso camera from above center of terrain, and baking my terrian texture with lights and shadows - and taking that bitmapdata and recreating the terrain material - it took some tweaking, but it actually wokrs great for pre-baking the terrain at runtime.  But, when I was snapshotting the terrain with lights, I wasnt scaling the resulting bitmapdata correctly before re-applying it to the terrain.
So, my error, I’ll post my results here once i get it for others following -and I cant wait for the next version of PREFAB!!!!! 


here’s what I have so far for the pre-baked terrain at 59 fps on ipad 2-

 

Image Attachments
sample2.jpg
   

Avatar
Fabrice Closier, Administrator
Posted: 02 April 2016 06:03 PM   Total Posts: 1265   [ # 6 ]

looking good smile Can you develop on the way you prebake? you draw based on a “voxel” logic?

 

   

alpoman, Jr. Member
Posted: 02 April 2016 08:36 PM   Total Posts: 40   [ # 7 ]

Thanks!!

ok, here goes,

first I made a 3d array editor with differnt blocks, items, and stuff in the game.  For the terrain creation, I just use the block data.  The editor allows me to make custom areas on a 15x15x11 grid ( hight is 10 blocks high off of base which is 0)  I have little subroutines in the editor that can ‘spawn’ random terrain based on placed blocks on the floor to speed up creation of levels.  when I save my level, a text file of the data array is written to my server somewhere remote.  Then in my away game file, I read that text file from server, parse the 3d array numbers for my blocks and objects.  (editor screenshot attached below)
This is where it gets weird.  I then ‘draw’ the terrain obects on a 15x15 2d grid.  the blocks are drawn using gradient values diveded by increments of 11 from black to white. then I get a grid drawn as bitmapdata.  I overlay a lightly transparent design to give it some texture before I create the bitmapdata too.

then I make this terrain wiith that bitmapdata:

Object(root)[“terrain”+(drawlev)] = new Elevation(Object(root)[“terrainMaterial”+(drawlev)], Cast.bitmapData(Object(root)[“myBitmap”+(drawlev)]),1024,500,1024,200,200,255,0,false);

note: the graidents of the elevation map I drew also doubles as the base color(which I colorize per level later)  this gives a faux lighting on the terrain from black to white, neat effect for no lights, but not totally accurate for realism.  and thats the basic terrain mesh, now the prebake.
(this is attachment 3 i think, grayscale one)

this is the juicy part, which only a few people may be able to follow-

_width = stage.stageWidth;
_height = stage.stageHeight;
stage3DProxy.width = _width;
stage3DProxy.height = _height;
stage3DProxy.viewPort.width = _width;
stage3DProxy.viewPort.height = _height;

cameraController.tiltAngle=90
cameraController.panAngle=180
cameraController.update(false)
camera.lens = new OrthographicLens(1088);//40
camera.lens.far =2000
//skypoint is a dummy mesh I use to focus camera, d=68.27 or 1024/15 (terrain size/grid size)
skypoint.x=d*3.1;skypoint.y=0;skypoint.z=-d/2;
cameraController.lookAtObject=skypoint

var _bitmapData:BitmapData=new BitmapData(_width, _height, false, 0xFFFFFF);
var _bitmap:Bitmap = new Bitmap(_bitmapData);

stage3DProxy.clear();
view.render();
view.stage3DProxy.context3D.drawToBitmapData(_bitmapData);

///now crop that and make it a 512x512 sqaure
crop(_bitmapData,myrect)
var _bitmapc:Bitmap

function crop(  bitmapData:BitmapData, rectangle:Rectangle ):BitmapData {
  var bitmapData1:BitmapData = new BitmapData( bitmapData.width, bitmapData.height ); 
  bitmapData1.draw( bitmapData, new Matrix() );
  var bitmapData2:BitmapData = new BitmapData( rectangle.width, rectangle.height );
  var point:Point = new Point( 0, 0 );
  bitmapData2.copyPixels( bitmapData1, new Rectangle( rectangle.x, rectangle.y, rectangle.width, rectangle.height ), point);
  _bitmapc = new Bitmap(bitmapData2);
bitmapData1.dispose()
//bitmapData2.dispose()
return bitmapData2;
}; 
//this is a as3 class i found to resample to a specific size…
var bmpFromDisplayObj : Bitmap = BitmapResampler.getResampledBitmap(_bitmapc, 512 , 512);

///now apply this texture back to terrain and remove old data to free mem
ntm=new TextureMaterial(Cast.bitmapTexture(bmpFromDisplayObj));
Object(root)[“terrain”+(drawlev)].material=ntm
ntm.lightPicker =null;
Object(root)[“terrainMaterial”+(drawlev)].dispose()


I’m using proxy for starling, but it all works ok, and believe it or not, it renders all this really fast <1 sec on ipad 2. with a 2d loading screen or something to hide the stage3d draws.


In summary:
* make a 2d grid or terrain grayscale bitmap. import one, draw one, etc.
* make your elevation, and use that bitmap for its faux shading,
apply lights, hardshadow, colors, etc.
* snapshot it with ortho cam setup
* re-apply that bitmap to elevation.

Fabrice, if you could streamline a class to do this automatically, people would use it like crazy!!!  I’m not much of a programmer, I just fiddle a lot till it works usually, so my code is sloppppy;)

the trick is to center the ortho camera over mesh at that height 1088, dont know why that works for a 1024x1024 terrian, but…  and then snapshot that with your lights.  I did have to play with offsetting the camera a bit to account for my terrain being centered on a 1024x768 screen which isnt square.  thats why i use those goofy crop/ rescale functions to spit out the usable 512x512 bitmapdat.

Ley me know any thoughts, ideas, or any other questions of details on this,

andy

 

 

 

 

 

Image Attachments
prebake1.jpgeditor.jpggrid.jpg
   

alpoman, Jr. Member
Posted: 02 April 2016 08:49 PM   Total Posts: 40   [ # 8 ]

and the final scene.
note the shadows cast by high points and bridges - especially on the water.  the water is a plane that is processed seperately scince it extends way past the area of the terrain in all directions.

to get the bridges and other non-terrain elements to cast shadows, I change their material to transparent before prebake (keeping shadows) and then put their materials back on after.  there has been a lot of talk here about how to render a transparent mesh while still casting/recieving shadows - here it is.

omaterial2 = new ColorMaterial(0xFFFFFF,.99);
omaterial2.lightPicker =lightPicker;
omaterial2.shadowMethod = new HardShadowMapMethod(sunLight);
omaterial2.blendMode = BlendMode.MULTIPLY;
omaterial2.shadowMethod.alpha =.7//

the ket to this working, is the .99 transparency setting, anoy other setting doesnt give complete invisible or perfect shadows.


another trick i did is to blur the bitmapdata of terrain and water after prebake to soften the shadows a bit as they look a bit rough when shot from high up on an ortho cam.


andy

 

 

Image Attachments
final.jpg
   

Avatar
Fabrice Closier, Administrator
Posted: 02 April 2016 09:58 PM   Total Posts: 1265   [ # 9 ]

thats one hell of a job!
Looking very nice!

The reason it works the way you did, is because the map is 0-1 mapped
and the bleeding along voxels sides actually works in your advantage. basically a snapshot with the shadows on taken from top.

The moment you start to add custom mapping, like after an unwrap, this approach would never work.

on your code, you could save processes the map by using a width/height
of like 1024x1024, this way no reduction or adjustment forcing you to have a matrix and a new destination map and all calcs. by placing the camera at the exact position top the model (that could be rescaled if too big) to fit exactly 1024x1024, the returned map would be exactly the lightmap.
which also would not require to have any transparency, just a plain jpg, just flag use primary set on and mode multiply. Your ipad 2 would be grateful smile

in Prefab 3.0, I’m doing work in this direction, in both gpu and cpu mode.
Tho where I do get very high quality, I have introduced artefacts after implementing workers :(.(on pict workers are showing where busy in the coloured faces)...  need dive back into this when i’ll get some free time.

so I dunno if lots of people would be interested, but I know I am wink

 

Image Attachments
Screen_Shot_2016-04-02_at_23.53.55.jpg
   

alpoman, Jr. Member
Posted: 02 April 2016 11:06 PM   Total Posts: 40   [ # 10 ]

Thanks Fabrice,  this is great advice and will help me - I’ll keep working using your optimizations and post back with results.  I am interested in your work - and how you are always thinking of making things better, better looking and better working on all machines!!!  because if it looks good and runs good on a slow machine, it will be awesome on a fast one, with more everything possible.  But I read on your posts that if it can be baked, bake it - makes sense because dynamic lighting is just not fun on mobile, lol - unless your like 3 fps.  here is a shot with the terran texture not-faux shaded in advance.  it still does the melting side thing that terrains do which you mentioned works for this scene, but with one light, it looks flat without the multi-level faux shading material.  So, I’ll play with this, and try your suggestions. Thanks again,

Andy

 

Image Attachments
sample3.jpg
   

alpoman, Jr. Member
Posted: 04 April 2016 05:01 PM   Total Posts: 40   [ # 11 ]

Ok, I went back to my faux shading+ baked lights- it gives the best depth and cartoony look I’m after - and big thanks to Fabrice for the optimization tips (scaling at the exact size for pre-bake, and other multiply jpg trick to reduce alphas)  this works great on mobile. Frame rate so high I dont even need to monitor framerate if you know what I mean;)

andy

 

Image Attachments
level2.jpg
   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X