x


MiniMap Camera Terrain Vegitation

I have a MiniMap camera floating above my scene, and I want it to render my terrains without rendering the vegetation on them.

I have a script attached to the camera, the relevant parts of which are included below.

The script sets the terrain's terrainTreeDistance and terrainDetailDistance to 0 before the camera renders, and after the camera renders, it resets the terrain to it's previous state.

Interestingly enough, the minimap camera renders trees on the terrain even with this script present. I know the script is properly changing the terrain vars, because if I remove the OnPostRender() section of the script, the trees disappear.

It looks like the terrain object defers the application of my settings 'till after the camera has rendered, by which time it is too late to do any good. Could this be possible, and if not - what else could I be doing wrong?

Ryan Scott suggested that I use shader replacement to hide the trees - and I may end up needing to - but I would much rather save the terrain object all the work of feeding the trees to the graphics pipeline to begin with.

function OnPreRender () {
    revertFogState = RenderSettings.fog;
    RenderSettings.fog = false;

    if(World.terrains) {
    	if(World.terrains[0].lighting == TerrainLighting.Pixel) terrainLighting = true;
    	else terrainLighting = false;
    	terrainLOD = World.terrains[0].heightmapMaximumLOD;
    	terrainTreeDistance = World.terrains[0].treeDistance;
    	terrainDetailDistance = World.terrains[0].detailObjectDistance;
    	for (var trn : Terrain in World.terrains) {
    		if(Game.Settings.renderLevel > 4) trn.heightmapMaximumLOD = 3;
    		else if(Game.Settings.renderLevel > 3) trn.heightmapMaximumLOD = 4;
    		else trn.heightmapMaximumLOD = 5;
    		trn.lighting = TerrainLighting.Lightmap;
    		trn.treeDistance = 0;
    		trn.detailObjectDistance = 0;
    	}
    }
}

function OnPostRender () {
    RenderSettings.fog = revertFogState;

    if(World.terrains) for (var trn : Terrain in World.terrains) {
    	trn.lighting = (terrainLighting ? TerrainLighting.Pixel : TerrainLighting.Lightmap);
    	trn.treeDistance = terrainTreeDistance;
    	trn.detailObjectDistance = terrainDetailDistance;
    	trn.heightmapMaximumLOD = terrainLOD;
    }
}
more ▼

asked Dec 17 '09 at 04:19 AM

Aubrey Falconer gravatar image

Aubrey Falconer
657 45 53 68

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

How about making duplicate terrains on a different layer, which are the same as the regular terrains, but without vegetation? If you remove the terrain collider so there's no additional performance hit, I think the only drawback would be taking up extra memory.

more ▼

answered Jan 16 '10 at 07:45 AM

Eric5h5 gravatar image

Eric5h5
80.3k 42 132 521

Yes - that should definitely work. Somehow though, my innate sense of elegance just won't let me take that route though :)

Jan 17 '10 at 05:14 PM Aubrey Falconer
(comments are locked)
10|3000 characters needed characters left

Note: I attempted to post this as a comment on my original post, but the answers software wouldn't let me because it said my post was locked or deleted. This site sure is full of bugs!

I just attempted altering the tree's layers at runtime, but although Unity gives no errors - the trees still render on the terrain layer...

for(var tP : TreePrototype in trnDat.treePrototypes) tP.prefab.layer = 11;

If it would work, this would be the most elegant solution of all!

more ▼

answered Dec 17 '09 at 04:47 AM

Aubrey Falconer gravatar image

Aubrey Falconer
657 45 53 68

(comments are locked)
10|3000 characters needed characters left

Can the different cameras have different culling properties with respect to layers? Then you could assign the trees to a vegetation layer permanently, and not worry about changing layer at runtime.

more ▼

answered Dec 17 '09 at 05:15 PM

MikeB gravatar image

MikeB
59 2 2 7

The different cameras already have different culling properties - but I am loading worlds from AssetBundles and I can't rely on trees being on correct layers in each world ahead of time. If I could figure out a way to assign the trees to layers at runtime, that would be perfect.

Dec 17 '09 at 06:38 PM Aubrey Falconer
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5093
x17

asked: Dec 17 '09 at 04:19 AM

Seen: 2025 times

Last Updated: Dec 17 '09 at 04:19 AM