ShiVa Developer Forum • View topic - Terrain vegation
 

Terrain vegation

Shaders, Level design, Sound design, Special effects

Terrain vegation

Postby unistudios » 2017-01-07 21:09

just wondering if the terrain vegetation can be affected by the dynamic light, I am using a dark scene but look like the vegetation is the only one who is not affected.
unistudios
Fresh Boarder
Fresh Boarder
 
Posts: 10
Joined: 2016-07-01 07:57

Re: Terrain vegation

Postby broozar » 2017-01-07 22:42

hi, unfortunately no, all you have in 192 are the Albedo and Lightmap influence slider, which are static values, not related to dynamic lighting. If you want dynamic lighting on vegetation, you need to use actual models and not vegetation layers.
User avatar
broozar
Administrator
Administrator
 
Posts: 4172
Joined: 2007-09-16 10:22
Location: Berlin - Germany

Re: Terrain vegation

Postby Fraser » 2017-01-10 17:55

If you do use real models for lit vegetation then I found the following:

Many tree model assets for sale use double planes (for single sided material) and vertex normals are generally perpendicular to these planes.

It's better to use single sided planes for your foliage layers with double sided material.
A double sided material will break the planar lighting, but no problem because planar lighting is not the best...

To make double sided foliage lighting good do this:

For each model:
Find center of all foliage planes: vcXYY.
Enumerate all foliage vertex: vnXYZ.
Set each foliage vertex normal to be vnXYZ - cXYZ (scaled such that longest vertex normal just reaches 1).

Code: Select all
    --  CREATE POOL IF NEEDED
    local hPoolTrees_hi = application.getCurrentUserSceneTaggedObject ( "POOL_TREES_HI" )
    if not hPoolTrees_hi
    then
        hPoolTrees_hi = scene.createRuntimeObject ( hScene, "trees_hi" )
        scene.setObjectTag ( hScene, hPoolTrees_hi, "POOL_TREES_HI" )

        --  FOLIAGE NORMALS POINT OUT RADIALY
        local hTree, hMesh, nVerts, nX, nY, nZ, nU, nV
        for nTree = 0, object.getChildCount ( hPoolTrees_hi ) - 1
        do
            hTree = object.getChildAt ( hPoolTrees_hi, nTree )
            hMesh = shape.getMesh ( hTree )
            nVerts = mesh.getSubsetVertexCount ( hMesh, 0 )
           
            mesh.lockSubsetVertexBuffer ( hMesh, 0, mesh.kLockModeReadWrite )
            for nVert = 0, nVerts - 1
            do
                nU, nV = mesh.getSubsetVertexTexCoord ( hMesh, 0, nVert, 0 )
                -- ONLY MODIFY VERTEX THAT ARE ON THE FOLIAGE UV PART OF THE TREE ATLAS TEXTURE
                if nV > 0.5
                then
                    nX, nY, nZ = mesh.getSubsetVertexPosition ( hMesh, 0, nVert )
                    nX, nY, nZ = math.vectorNormalize ( nX, nY-2, nZ )
                    mesh.setSubsetVertexNormal ( hMesh, 0, nVert, nX, nY, nZ )
                end
            end
            mesh.unlockSubsetVertexBuffer ( hMesh, 0 )
        end
    end


If you runtime spawn your trees then you only need to do this for one of each model type you want to use and keep them invisibly pooled.
Then when you runtime create new instances of the model it will have this modded mesh.

Or if you prefer you can get the trees normals all set up in a 3D tool and then just import into regular ShiVa scene, setting in code is nicer though because you can tweak things for all models with the stroke of a key.

This trick halves the triangle budget and gives more pleasing lighting to boot.
The whole foliage cluster acts somewhat like a self shadowing volume of translucent leaves:

These scenes run 60 FPS on mid range mobile devices:
Image
Image
Last edited by Fraser on 2017-01-10 20:51, edited 1 time in total.
User avatar
Fraser
Platinum Boarder
Platinum Boarder
 
Posts: 1324
Joined: 2012-02-05 19:28
Location: Europe

Re: Terrain vegation

Postby broozar » 2017-01-10 20:35

thumbs up fraser, snippet should be on the store :)
User avatar
broozar
Administrator
Administrator
 
Posts: 4172
Joined: 2007-09-16 10:22
Location: Berlin - Germany

Re: Terrain vegation

Postby unistudios » 2017-01-11 06:26

this is great, thanks for the post
unistudios
Fresh Boarder
Fresh Boarder
 
Posts: 10
Joined: 2016-07-01 07:57


Return to Creation

Who is online

Users browsing this forum: No registered users and 1 guest

cron